github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/pkg/importer/foursquare/api.go (about)

     1  /*
     2  Copyright 2014 The Camlistore Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8       http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // Types for Foursquare's JSON API.
    18  
    19  package foursquare
    20  
    21  type user struct {
    22  	Id        string
    23  	FirstName string
    24  	LastName  string
    25  }
    26  
    27  type userInfo struct {
    28  	Response struct {
    29  		User user
    30  	}
    31  }
    32  
    33  type checkinsList struct {
    34  	Response struct {
    35  		Checkins struct {
    36  			Items []*checkinItem
    37  		}
    38  	}
    39  }
    40  
    41  type checkinItem struct {
    42  	Id        string
    43  	CreatedAt int64 // unix time in seconds from 4sq
    44  	Venue     venueItem
    45  }
    46  
    47  type venueItem struct {
    48  	Id         string // eg 42474900f964a52087201fe3 from 4sq
    49  	Name       string
    50  	Location   *venueLocationItem
    51  	Categories []*venueCategory
    52  }
    53  
    54  type photosList struct {
    55  	Response struct {
    56  		Photos struct {
    57  			Items []*photoItem
    58  		}
    59  	}
    60  }
    61  
    62  type photoItem struct {
    63  	Id     string
    64  	Prefix string
    65  	Suffix string
    66  	Width  int
    67  	Height int
    68  }
    69  
    70  func (vi *venueItem) primaryCategory() *venueCategory {
    71  	for _, c := range vi.Categories {
    72  		if c.Primary {
    73  			return c
    74  		}
    75  	}
    76  	return nil
    77  }
    78  
    79  func (vi *venueItem) icon() string {
    80  	c := vi.primaryCategory()
    81  	if c == nil || c.Icon == nil || c.Icon.Prefix == "" {
    82  		return ""
    83  	}
    84  	return c.Icon.Prefix + "bg_88" + c.Icon.Suffix
    85  }
    86  
    87  type venueLocationItem struct {
    88  	Address    string
    89  	City       string
    90  	PostalCode string
    91  	State      string
    92  	Country    string // 4sq provides "US"
    93  	Lat        float64
    94  	Lng        float64
    95  }
    96  
    97  type venueCategory struct {
    98  	Primary bool
    99  	Name    string
   100  	Icon    *categoryIcon
   101  }
   102  
   103  type categoryIcon struct {
   104  	Prefix string
   105  	Suffix string
   106  }