foursquarego

package module
v2.0.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2016 License: MIT Imports: 6 Imported by: 1

README

Foursquarego

Foursquarego is a simple Go package for accessing the Foursquare API.

If you find any errors please create an issue, the foursquare API has different types even for things with the same name. I tested as much as I could and right now this fits my needs.

This code is largely based off of Anaconda and I have included their LICENSE in with mine.

Examples

Authentication

Creating a client is simple:

api := foursquarego.NewFoursquareApi("your client id", "your client secret")

If you have a user oauth token you can assign that to the api too:

api.SetOauthToken("your oauth token")
Queries

Queries are conducted using a pointer to an authenticated FoursquareApi struct.

venue, _ := api.GetVenue(venueID)
fmt.Println(venue.Name)

Certain endpoints allow separate optional parameter; if desired, these can be passed as the final parameter.

//Perhaps we want 200 values instead of the default
uv := url.Values{}
uv.Set("limit", "200")
p, err := api.GetVenuePhotos(venueID, uv)

(Remember that url.Values is equivalent to a map[string][]string, if you find that more convenient notation when specifying values). Otherwise, nil suffices.

Error Handling

Errors are returned as an ApiError, which satisfies the error interface and can be treated as a vanilla error. However, it also contains the additional information that may be useful in deciding how to proceed after encountering an error.

License

Foursquarego is free software licensed under the MIT license. Details provided in the LICENSE file.

Documentation

Index

Constants

View Source
const (
	InvalidAuth       = 401
	ParamError        = 400
	EndPointError     = 404
	NotAuthorized     = 403
	RateLimitExceeded = 403
	Depreciated       = 200
)
View Source
const (
	API_URL = "https://api.foursquare.com/v2/"
	VERSION = "20150813"
	MODE    = "foursquare"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiError

type ApiError struct {
	StatusCode int
	Meta       Meta
	Url        *url.URL
}

func (ApiError) Error

func (aerr ApiError) Error() string

type Attribute

type Attribute struct {
	Type    string `json:"type"`
	Name    string `json:"name"`
	Summary string `json:"summary"`
	Count   int    `json:"count"`
	Items   []Omit `json:"-"`
}

type Attributes

type Attributes struct {
	Groups []Attribute `json:"groups"`
}

type Category

type Category struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	PluralName string `json:"pluralName"`
	ShortName  string `json:"shortName"`
	Icon       Icon   `json:"icon"`
	Primary    bool   `json:"primary"`
}

type Contact

type Contact struct {
	Phone          string `json:"phone"`
	FormattedPhone string `json:"formattedPhone"`
	Twitter        string `json:"twitter"`
}

type Entitie

type Entitie struct {
	Indicies []int  `json:"indicies"`
	Type     string `json:"type"`
}

type Entries

type Entries struct {
	Count int         `json:"count"`
	Items []EntryItem `json:"items"`
}

type EntryItem

type EntryItem struct {
	EntryID     string   `json:"entryId"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Prices      []string `json:"prices"`
	Price       string   `json:"price"`
	Options     Omit     `json:"-"`
	Additions   Omit     `json:"-"`
}

type Event

type Event struct {
	ID         string     `json:"id"`
	Name       string     `json:"name"`
	Categories []Category `json:"categories"`
	HereNow    HereNow    `json:"hereNow"`
	AllDay     bool       `json:"allDay"`
	Date       int        `json:"date"`
	TimeZone   string     `json:"timeZone"`
	Stats      Stats      `json:"stats"`
	Url        string     `json:"url"`
}

type EventsResponse

type EventsResponse struct {
	Count   int     `json:"count"`
	Summary string  `json:"summary"`
	Items   []Event `json:"items"`
}

type Followers

type Followers struct {
	Count int `json:"count"`
}

type FoursquareApi

type FoursquareApi struct {
	HttpClient *http.Client
	// contains filtered or unexported fields
}

func NewFoursquareApi

func NewFoursquareApi(clientID string, clientSecret string) *FoursquareApi

func (*FoursquareApi) Close

func (a *FoursquareApi) Close()

func (FoursquareApi) GetCategories

func (a FoursquareApi) GetCategories() (categories []Category, err error)

func (FoursquareApi) GetVenue

func (a FoursquareApi) GetVenue(id string) (venue Venue, err error)

func (FoursquareApi) GetVenueEvents

func (a FoursquareApi) GetVenueEvents(id string) (events []Event, err error)

func (FoursquareApi) GetVenueHereNow

func (a FoursquareApi) GetVenueHereNow(id string, uv url.Values) (hereNow HereNow, err error)

valid url.Values are: limit, offset This is reqlly a swarm endpoint

func (FoursquareApi) GetVenueHours

func (a FoursquareApi) GetVenueHours(id string) (hours HoursResponse, err error)

func (FoursquareApi) GetVenueLikes

func (a FoursquareApi) GetVenueLikes(id string) (likes LikesResponse, err error)
func (a FoursquareApi) GetVenueLinks(id string) (links LinksResponse, err error)

func (FoursquareApi) GetVenueListed

func (a FoursquareApi) GetVenueListed(id string, uv url.Values) (lists Listed, err error)

valid url.Values are: group, limit, offset

func (FoursquareApi) GetVenueMenu

func (a FoursquareApi) GetVenueMenu(id string) (menu MenuResponse, err error)

func (FoursquareApi) GetVenuePhotos

func (a FoursquareApi) GetVenuePhotos(id string, uv url.Values) (photos []Photo, err error)

valid url.Values are: group, limit, offset

func (FoursquareApi) GetVenueSimilar

func (a FoursquareApi) GetVenueSimilar(id string, uv url.Values) (venues SimilarVenueResponse, err error)

func (FoursquareApi) Search

func (a FoursquareApi) Search(uv url.Values) (venues []Venue, err error)

type HereNow

type HereNow struct {
	Count   int           `json:"count"`
	Summary string        `json:"summary"`
	Groups  Omit          `json:"groups,omitempty"` //TODO: take care fo this later
	Items   []HereNowItem `json:"items,omitempty"`  // I dunno sometimes it has groups or Items
}

type HereNowItem

type HereNowItem struct {
	ID             string `json:"id"`
	CreatedAt      int    `json:"createdAt"`
	Type           string `json:"type"`
	TimeZoneOffset int    `json:"timeZoneOffset"`
	User           User   `json:"user"`
	Likes          Likes  `json:"likes"`
	Like           bool   `json:"like"`
}

type Hours

type Hours struct {
	Status     string           `json:"status,omitempty"`
	IsOpen     bool             `json:"isOpen,ommitempty"`
	Timeframes []TimeFrameHours `json:"timeframes,omitempty"`
}

type HoursResponse

type HoursResponse struct {
	Hours   Hours `json:"hours"`
	Popular Hours `json:"popular"`
}

type HoursVenue

type HoursVenue struct {
	Status     string      `json:"status,omitempty"`
	IsOpen     bool        `json:"isOpen,ommitempty"`
	Timeframes []TimeFrame `json:"timeframes,omitempty"`
}

type Icon

type Icon struct {
	Prefix string `json:"prefix"`
	Suffix string `json:"suffix"`
}

type Interaction

type Interaction struct {
	EntryUrl string `json:"entryUrl"`
}

type Likes

type Likes struct {
	Count   int    `json:"count"`
	Groups  Omit   `json:"-"` //TODO: take care fo this later
	Items   []User `json:"items"`
	Summary string `json:"summary"`
}

type LikesResponse

type LikesResponse struct {
	Likes Likes `json:"likes"`
	Like  bool  `json:"like"`
}
type Link struct {
	Provider Provider `json:"provider"`
	LinkedID string   `json:"linkedId"`
	Url      string   `json:"url"`
}

type LinksResponse

type LinksResponse struct {
	Count int    `json:"count"`
	Items []Link `json:"items"`
}

type List

type List struct {
	ID            string      `json:"id"`
	Name          string      `json:"name"`
	Description   string      `json:"description"`
	Type          string      `json:"type"`
	User          User        `json:"user"`
	Editable      bool        `json:"editable"`
	Public        bool        `json:"public"`
	Collaborative bool        `json:"collaborative"`
	Url           string      `json:"url"`
	CanonicalUrl  string      `json:"canonicalUrl"`
	CreatedAt     int         `json:"createdAt"`
	UpdatedAt     int         `json:"updatedAt"`
	Photo         Photo       `json:"photo"`
	Followers     Followers   `json:"followers"`
	ListItems     []ListItems `json:"listItems"`
}

type ListGroup

type ListGroup struct {
	Type  string `json:"type"`
	Name  string `json:"name"`
	Count int    `json:"count"`
	Items []List `json:"items"`
}

type ListItem

type ListItem struct {
	ID        string `json:"id"`
	CreatedAt int    `json:"createdAt"`
	Tip       Tip    `json:"tip"`
	Photo     Photo  `json:"photo"`
}

type ListItems

type ListItems struct {
	Count int        `json:"count"`
	Items []ListItem `json:"items"`
}

type Listed

type Listed struct {
	Count  int         `json:"count"`
	Groups []ListGroup `json:"groups"`
}

type Location

type Location struct {
	Address          string  `json:"address"`
	CrossStreet      string  `json:"crossStreet"`
	Lat              float64 `json:"lat"`
	Lng              float64 `json:"lng"`
	Distance         int     `json:"distance"`
	PostalCode       string  `json:"postalCode"`
	Cc               string  `json:"cc"`
	City             string  `json:"city"`
	State            string  `json:"state"`
	Country          string  `json:"country"`
	FormattedAddress string  `json:"formattedAddress"`
	IsFuzzed         bool    `json:"isFuzzed"`
}
type Menu struct {
	MenuID  string  `json:"menuId"`
	Name    string  `json:"name"`
	Entries Entries `json:"entries"`
}
type MenuResponse struct {
	Provider Provider `json:"provider"`
	Menus    Menus    `json:"menus"`
}
type Menus struct {
	Count int    `json:"count"`
	Items []Menu `json:"items"`
}

type Meta

type Meta struct {
	Code        int    `json:"code"`
	ErrorType   string `json:"errorType"`
	ErrorDetail string `json:"errorDetail"`
}

type Omit

type Omit struct{}

type Open

type Open struct {
	Start        string `json:"start"`
	End          string `json:"end"`
	RenderedTime string `json:"renderedTime"`
}

type Photo

type Photo struct {
	ID         string      `json:"id"`
	CreatedAt  int         `json:"createdAt"`
	Source     PhotoSource `json:"source"`
	Prefix     string      `json:"prefix"`
	Suffix     string      `json:"suffix"`
	Width      int         `json:"width"`
	Height     int         `json:"height"`
	User       User        `json:"user"`
	Visibility string      `json:"visibility"`
}

type PhotoGroup

type PhotoGroup struct {
	Type  string  `json:"type"`
	Name  string  `json:"name"`
	Count int     `json:"count"`
	Items []Photo `json:"items"`
}

type PhotoSource

type PhotoSource struct {
	Name string `json:"name"`
	Url  string `json:"url"`
}

type Photos

type Photos struct {
	Count  int          `json:"count"`
	Groups []PhotoGroup `json:"groups"`
}

type PhotosResponse

type PhotosResponse struct {
	Count        int     `json:"count"`
	Items        []Photo `json:"items"`
	DupesRemoved int     `json:"dupesRemoved"`
}

type Phrase

type Phrase struct {
	Phrase string `json:"phrase"`
	Sample Sample `json:"sample"`
	Count  int    `json:"count"`
}
type Popular struct {
	Status     string      `json:"status"`
	IsOpen     bool        `json:"isOpen"`
	TimeFrames []TimeFrame `json:"timeFrames"`
}

type Price

type Price struct {
	Tier     int    `json:"tier"`
	Message  string `json:"message"`
	Currency string `json:"currency"`
}

type Provider

type Provider struct {
	ID               string `json:"id"`
	Name             string `json:"name"`
	AttributionImage string `json:"attributionImage"`
	AttributionLink  string `json:"attributionLink"`
	AttributionText  string `json:"attributionText"`
}

type Reason

type Reason struct {
	Summary    string `json:"summary"`
	Type       string `json:"type"`
	ReasonName string `json:"reasonName"`
}

type Reasons

type Reasons struct {
	Count int      `json:"count"`
	Items []Reason `json:"items"`
}

type Sample

type Sample struct {
	Entities []Entitie `json:"entities"`
	Text     string    `json:"text"`
	Count    int       `json:"count"`
}

type ShortMenu

type ShortMenu struct {
	Type      string `json:"type"`
	Label     string `json:"lablel"`
	Anchor    string `json:"anchor"`
	Url       string `json:"url"`
	MobileUrl string `json:"mobileUrl"`
}

type SimilarVenueResponse

type SimilarVenueResponse struct {
	Count int     `json:"count"`
	Items []Venue `json:"items"`
}

type SpecialItem

type SpecialItem struct {
	Type                string      `json:"type"`
	Message             string      `json:"message"`
	Description         string      `json:"description"`
	FinePrint           string      `json:"finePrint"`
	Unlocked            bool        `json:"unlocked"`
	Icon                string      `json:"icon"`
	Title               string      `json:"title"`
	State               string      `json:"state"`
	Provider            string      `json:"provider"`
	Redemption          string      `json:"redemption"`
	Interaction         Interaction `json:"interaction"`
	Progress            int         `json:"progress"`
	ProgressDescription string      `json:"progressDescription"`
	Detail              int         `json:"detail"`
	Target              int         `json:"target"`
	FriendsHere         []User      `json:"friendsHere"`
	// contains filtered or unexported fields
}

type Specials

type Specials struct {
	Count int           `json:"count"`
	Items []SpecialItem `json:"items"`
}

type Stats

type Stats struct {
	CheckinsCount int `json:"checkinsCount"`
	UsersCount    int `json:"usersCount"`
	TipCount      int `json:"tipCount"`
	VisitsCount   int `json:"visitsCount"`
}

type TimeFrame

type TimeFrame struct {
	Days          string `json:"days"`
	IncludesToday bool   `json:"includesToday"`
	Open          []Open `json:"open"`
	Segments      Omit   `json:"-"` //TODO:  take care fo this later
}

This is used in the main Hours struct for the entire venu

type TimeFrameHours

type TimeFrameHours struct {
	Days          []int  `json:"days"`
	IncludesToday bool   `json:"includesToday"`
	Open          []Open `json:"open"`
	Segements     Omit   `json:"-"`
}

This is used for the hours endpoint

type Tip

type Tip struct {
	ID           string `json:"id"`
	CreatedAt    int    `json:"createdAt"`
	Text         string `json:"text"`
	Type         string `json:"type"`
	Url          string `json:"url"`
	CanonicalUrl string `json:"canonicalurl"`
	Photo        Photo  `json:"photo"`
	PhotoUrl     string `json:"photoUrl"`
	Flags        Omit   `json:"flags"` //TODO:  take care fo this later
	Likes        Likes  `json:"likes"`
	Like         bool   `json:"like"`
	LogView      bool   `json:"logView"`
	EditedAt     int    `json:"editedAt"`
	Todo         Omit   `json:"todo"` //TODO:  take care fo this later
	User         User   `json:"user"`
}

type TipGroup

type TipGroup struct {
	Type  string `json:"type"`
	Name  string `json:"name"`
	Count int    `json:"count"`
	Items []Tip  `json:"items"`
}

type Tips

type Tips struct {
	Count  int        `json:"count"`
	Groups []TipGroup `json:"groups"`
}

type User

type User struct {
	ID           string    `json:"id"`
	FirstName    string    `json:"firstName"`
	LastName     string    `json:"lastName"`
	Gender       string    `json:"gender"`
	RelationShip string    `json:"relationship"`
	Photo        UserPhoto `json:"photo"`
}

type UserPhoto

type UserPhoto struct {
	Prefix string `json:"prefix"`
	Suffix string `json:"suffix"`
}

type Venue

type Venue struct {
	ID            string     `json:"id"`
	Name          string     `json:"name"`
	Contact       Contact    `json:"contact"`
	Location      Location   `json:"location"`
	CanonicalUrl  string     `json:"canonicalUrl"`
	Categories    []Category `json:"categories"`
	Verified      bool       `json:"verified"`
	Stats         Stats      `json:"stats"`
	Url           string     `json:"url"`
	Price         Price      `json:"price"`
	HasMenu       bool       `json:"hasMenu"`
	Likes         Likes      `json:"likes"`
	Like          bool       `json:"like"`
	Dislike       bool       `json:"dislike"`
	Ok            bool       `json:"ok"`
	Rating        float32    `json:"rating"`
	RatingColor   string     `json:"ratingColor"`
	RatingSignals int        `json:"ratingSignals"`
	Menu          ShortMenu  `json:"menu"`
	Specials      Specials   `json:"specials"`
	Photos        Photos     `json:"photos"`
	Reasons       Reasons    `json:"reasons"`
	CreatedAt     int        `json:"createdAt"`
	Tips          Tips       `json:"tips"`
	Tags          []string   `json:"tags"`
	ShortUrl      string     `json:"shortUrl"`
	TimeZone      string     `json:"timeZone"`
	Listed        Listed     `json:"listed"`
	Phrases       []Phrase   `json:"phrases"`
	Hours         HoursVenue `json:"hours"`
	Popular       Popular    `json:"popular"`
	PageUpdates   Omit       `json:"-"`
	Inbox         Omit       `json:"-"`
	VenueChains   Omit       `json:"-"`
	Attributes    Attributes `json:"attributes"`
	BestPhoto     Photo      `json:"bestPhoto"`
}

func (*Venue) HasCategory

func (v *Venue) HasCategory(cat string) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL