Home Download Docs Code Community
     1	/*
     2	Copyright 2014 The Perkeep 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 Swarm's JSON API.
    18	
    19	package swarm
    20	
    21	type user struct {
    22		Id        string
    23		FirstName string
    24		LastName  string
    25		Photo     photoItem
    26	}
    27	
    28	type userInfo struct {
    29		Response struct {
    30			User user
    31		}
    32	}
    33	
    34	type checkinsList struct {
    35		Response struct {
    36			Checkins struct {
    37				Items []*checkinItem
    38			}
    39		}
    40	}
    41	
    42	type checkinItem struct {
    43		Id             string
    44		CreatedAt      int64  // unix time in seconds from 4sq
    45		TimeZoneOffset int    // offset in minutes. positive is east.
    46		Shout          string // "Message from check-in, if present and visible to the acting user."
    47		Venue          venueItem
    48		With           []*user // list of friends checked in together
    49	}
    50	
    51	type venueItem struct {
    52		Id         string // eg 42474900f964a52087201fe3 from 4sq
    53		Name       string
    54		Location   *venueLocationItem
    55		Categories []*venueCategory
    56	}
    57	
    58	type photosList struct {
    59		Response struct {
    60			Photos struct {
    61				Items []*photoItem
    62			}
    63		}
    64	}
    65	
    66	type photoItem struct {
    67		Id     string
    68		Prefix string
    69		Suffix string
    70		Width  int
    71		Height int
    72	}
    73	
    74	func (vi *venueItem) primaryCategory() *venueCategory {
    75		for _, c := range vi.Categories {
    76			if c.Primary {
    77				return c
    78			}
    79		}
    80		return nil
    81	}
    82	
    83	func (vi *venueItem) icon() string {
    84		c := vi.primaryCategory()
    85		if c == nil || c.Icon == nil || c.Icon.Prefix == "" {
    86			return ""
    87		}
    88		return c.Icon.Prefix + "bg_88" + c.Icon.Suffix
    89	}
    90	
    91	func (user *user) icon() string {
    92		if user.Photo.Prefix == "" || user.Photo.Suffix == "" {
    93			return ""
    94		}
    95		return user.Photo.Prefix + "500x500" + user.Photo.Suffix
    96	}
    97	
    98	type venueLocationItem struct {
    99		Address    string
   100		City       string
   101		PostalCode string
   102		State      string
   103		Country    string // 4sq provides "US"
   104		Lat        float64
   105		Lng        float64
   106	}
   107	
   108	type venueCategory struct {
   109		Primary bool
   110		Name    string
   111		Icon    *categoryIcon
   112	}
   113	
   114	type categoryIcon struct {
   115		Prefix string
   116		Suffix string
   117	}
Website layout inspired by memcached.
Content by the authors.