This commit is contained in:
Martin Donnelly 2024-02-27 10:37:21 +00:00
commit ed50572dc2
9 changed files with 746 additions and 0 deletions

90
.gitignore vendored Normal file
View File

@ -0,0 +1,90 @@
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
*.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Go template
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module git.caliban.io/martin/go-foursquare
go 1.22.0
require github.com/google/go-querystring v1.1.0

5
go.sum Normal file
View File

@ -0,0 +1,5 @@
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

290
model.go Normal file
View File

@ -0,0 +1,290 @@
package foursquare
import (
"time"
)
type (
Options struct {
LatLong string `url:"ll"`
Radius int64 `url:"radius"`
Category string `url:"categories,omitempty"`
Key string `url:"-"`
}
)
type CustomTime struct {
time.Time
}
type (
FoursquarePlaces struct {
Results []Results4sqPlaces `json:"results"`
}
Results4sqPlaces struct {
FsqId string `json:"fsq_id"`
Categories []Categories4sqPlaces `json:"categories"`
Chains []Chains4sqPlaces `json:"chains,omitempty"`
ClosedBucket string `json:"closed_bucket,omitempty"`
DateClosed CustomTime `json:"date_closed,omitempty"`
Description string `json:"description,omitempty"`
Distance int64 `json:"distance,omitempty"`
Email string `json:"email,omitempty"`
Fax string `json:"fax,omitempty"`
Features Features4sqPlaces `json:"features,omitempty"`
Geocodes Geocodes4sqPlaces `json:"geocodes,omitempty"`
Hours Hours4sqPlaces `json:"hours,omitempty"`
HoursPopular []HoursSlots4sqPlaces `json:"hours_popular,omitempty"`
Link string `json:"link,omitempty"`
Location Location4sqPlaces `json:"location,omitempty"`
Photos []Photos4sqPlaces `json:"photos,omitempty"`
Popularity int64 `json:"popularity,omitempty"`
Price int64 `json:"price,omitempty"`
Rating int64 `json:"rating,omitempty"`
Name string `json:"name,omitempty"`
RelatedPlaces struct{} `json:"related_places,omitempty"`
SocialMedia SocialMedia4sqPlaces `json:"social_media,omitempty"`
Stats Stats4sqPlaces `json:"stats,omitempty"`
StoreId string `json:"store_id,omitempty"`
Tastes []string `json:"tastes,omitempty"`
Tel string `json:"tel,omitempty"`
Timezone string `json:"timezone,omitempty"`
Tips []Tips4sqPlaces `json:"tips,omitempty"`
VenueRealityBucket string `json:"venue_reality_bucket,omitempty"`
Verified bool `json:"verified,omitempty"`
Website string `json:"website,omitempty"`
}
)
type Categories4sqPlaces struct {
Id int64 `json:"id"`
Name string `json:"name"`
ShortName string `json:"short_name,omitempty"`
PluralName string `json:"plural_name,omitempty"`
Icon Icon4sqPlaces `json:"icon,omitempty"`
}
type Icon4sqPlaces struct {
Id string `json:"id,omitempty"`
CreateAt CustomTime `json:"create_at,omitempty"`
Prefix string `json:"prefix"`
Suffix string `json:"suffix"`
Width int64 `json:"width,omitempty"`
Height int64 `json:"height,omitempty"`
Classifications []string `json:"classifications,omitempty"`
Tip Tip4sqPlaces `json:"tip,omitempty"`
}
type Chains4sqPlaces struct {
Id string `json:"id"`
Name string `json:"name"`
}
type Tip4sqPlaces struct {
Id string `json:"id"`
CreatedAt CustomTime `json:"created_at,omitempty"`
Text string `json:"text"`
Url string `json:"url,omitempty"`
Lang string `json:"lang,omitempty"`
AgreeCount int64 `json:"agree_count,omitempty"`
DisagreeCount int64 `json:"disagree_count,omitempty"`
}
type Features4sqPlaces struct {
Payment Payment4sqPlaces `json:"payment,omitempty"`
FoodAndDrink FoodAndDrink4sqPlaces `json:"food_and_drink,omitempty"`
Services Services4sqPlaces `json:"services,omitempty"`
Amenities Amenities4sqPlaces `json:"amenities,omitempty"`
Attributes Attributes4sqPlaces `json:"attributes,omitempty"`
}
type Payment4sqPlaces struct {
CreditCards CreditCards4sqPlaces `json:"credit_cards,omitempty"`
DigitalWallet DigitalWallet4sqPlaces `json:"digital_wallet,omitempty"`
}
type CreditCards4sqPlaces struct {
AcceptsCreditCards struct{} `json:"accepts_credit_cards,omitempty"`
Amex struct{} `json:"amex,omitempty"`
Discover struct{} `json:"discover,omitempty"`
Visa struct{} `json:"visa,omitempty"`
DinersClub struct{} `json:"diners_club,omitempty"`
MasterCard struct{} `json:"master_card,omitempty"`
UnionPay struct{} `json:"union_pay,omitempty"`
}
type DigitalWallet4sqPlaces struct {
AcceptsNfc struct{} `json:"accepts_nfc,omitempty"`
}
type FoodAndDrink4sqPlaces struct {
Alcohol Alcohol4sqPlaces `json:"alcohol,omitempty"`
Meals Meals4sqPlaces `json:"meals,omitempty"`
}
type Alcohol4sqPlaces struct {
BarService struct{} `json:"bar_service,omitempty"`
Beer struct{} `json:"beer,omitempty"`
Byo struct{} `json:"byo,omitempty"`
Cocktails struct{} `json:"cocktails,omitempty"`
FullBar struct{} `json:"full_bar,omitempty"`
Wine struct{} `json:"wine,omitempty"`
}
type Meals4sqPlaces struct {
BarSnacks struct{} `json:"bar_snacks,omitempty"`
Breakfast struct{} `json:"breakfast,omitempty"`
Brunch struct{} `json:"brunch,omitempty"`
Lunch struct{} `json:"lunch,omitempty"`
HappyHour struct{} `json:"happy_hour,omitempty"`
Dessert struct{} `json:"dessert,omitempty"`
Dinner struct{} `json:"dinner,omitempty"`
TastingMenu struct{} `json:"tasting_menu,omitempty"`
}
type Services4sqPlaces struct {
Delivery struct{} `json:"delivery,omitempty"`
Takeout struct{} `json:"takeout,omitempty"`
DriveThrough struct{} `json:"drive_through,omitempty"`
DineIn DineIn4sqPlaces `json:"dine_in,omitempty"`
}
type DineIn4sqPlaces struct {
Reservations struct{} `json:"reservations,omitempty"`
OnlineReservations struct{} `json:"online_reservations,omitempty"`
GroupsOnlyReservations struct{} `json:"groups_only_reservations,omitempty"`
EssentialReservations struct{} `json:"essential_reservations,omitempty"`
}
type Amenities4sqPlaces struct {
Restroom struct{} `json:"restroom,omitempty"`
Smoking struct{} `json:"smoking,omitempty"`
Jukebox struct{} `json:"jukebox,omitempty"`
Music struct{} `json:"music,omitempty"`
LiveMusic struct{} `json:"live_music,omitempty"`
PrivateRoom struct{} `json:"private_room,omitempty"`
OutdoorSeating struct{} `json:"outdoor_seating,omitempty"`
Tvs struct{} `json:"tvs,omitempty"`
Atm struct{} `json:"atm,omitempty"`
CoatCheck struct{} `json:"coat_check,omitempty"`
WheelchairAccessible struct{} `json:"wheelchair_accessible,omitempty"`
Parking Parking4sqPlaces `json:"parking,omitempty"`
SitDownDining struct{} `json:"sit_down_dining,omitempty"`
Wifi string `json:"wifi,omitempty"`
}
type Parking4sqPlaces struct {
Parking struct{} `json:"parking,omitempty"`
StreetParking struct{} `json:"street_parking,omitempty"`
ValetParking struct{} `json:"valet_parking,omitempty"`
PublicLot struct{} `json:"public_lot,omitempty"`
PrivateLot struct{} `json:"private_lot,omitempty"`
}
type Attributes4sqPlaces struct {
BusinessMeeting string `json:"business_meeting,omitempty"`
Clean string `json:"clean,omitempty"`
Crowded string `json:"crowded,omitempty"`
DatesPopular string `json:"dates_popular,omitempty"`
FamiliesPopular string `json:"families_popular,omitempty"`
GlutenFreeDiet string `json:"gluten_free_diet,omitempty"`
GoodForDogs string `json:"good_for_dogs,omitempty"`
GroupsPopular string `json:"groups_popular,omitempty"`
HealthyDiet string `json:"healthy_diet,omitempty"`
LateNight string `json:"late_night,omitempty"`
Noisy string `json:"noisy,omitempty"`
QuickBite string `json:"quick_bite,omitempty"`
Romantic string `json:"romantic,omitempty"`
ServiceQuality string `json:"service_quality,omitempty"`
SinglesPopular string `json:"singles_popular,omitempty"`
SpecialOccasion string `json:"special_occasion,omitempty"`
Trendy string `json:"trendy,omitempty"`
ValueForMoney string `json:"value_for_money,omitempty"`
VeganDiet string `json:"vegan_diet,omitempty"`
VegetarianDiet string `json:"vegetarian_diet,omitempty"`
}
type Geocodes4sqPlaces struct {
DropOff LatLong4sqPlaces `json:"drop_off,omitempty"`
FrontDoor LatLong4sqPlaces `json:"front_door,omitempty"`
Main LatLong4sqPlaces `json:"main,omitempty"`
Road LatLong4sqPlaces `json:"road,omitempty"`
Roof LatLong4sqPlaces `json:"roof,omitempty"`
}
type LatLong4sqPlaces struct {
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
}
type Hours4sqPlaces struct {
Display string `json:"display,omitempty"`
IsLocalHoliday bool `json:"is_local_holiday,omitempty"`
OpenNow bool `json:"open_now,omitempty"`
Regular []HoursSlots4sqPlaces `json:"regular,omitempty"`
}
type HoursSlots4sqPlaces struct {
Close string `json:"close,omitempty"`
Day int64 `json:"day,omitempty"`
Open string `json:"open,omitempty"`
}
type Location4sqPlaces struct {
Address string `json:"address,omitempty"`
AddressExtended string `json:"address_extended,omitempty"`
AdminRegion string `json:"admin_region,omitempty"`
CensusBlock string `json:"census_block,omitempty"`
Country string `json:"country,omitempty"`
CrossStreet string `json:"cross_street,omitempty"`
Dma string `json:"dma,omitempty"`
FormattedAddress string `json:"formatted_address,omitempty"`
Locality string `json:"locality,omitempty"`
Neighborhood []string `json:"neighborhood,omitempty"`
PoBox string `json:"po_box,omitempty"`
PostTown string `json:"post_town,omitempty"`
Region string `json:"region,omitempty"`
}
type Photos4sqPlaces struct {
Id string `json:"id,omitempty"`
CreatedAt CustomTime `json:"created_at,omitempty"`
Prefix string `json:"prefix,omitempty"`
Suffix string `json:"suffix,omitempty"`
Width int64 `json:"width,omitempty"`
Height int64 `json:"height,omitempty"`
Classifications []string `json:"classifications,omitempty"`
Tip PhotosTip4sqPlaces `json:"tip,omitempty"`
}
type PhotosTip4sqPlaces struct {
Id string `json:"id,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
Text string `json:"text,omitempty"`
Url string `json:"url,omitempty"`
Lang string `json:"lang,omitempty"`
AgreeCount int64 `json:"agree_count,omitempty"`
DisagreeCount int64 `json:"disagree_count,omitempty"`
}
type SocialMedia4sqPlaces struct {
FacebookId string `json:"facebook_id,omitempty"`
Instagram string `json:"instagram,omitempty"`
Twitter string `json:"twitter,omitempty"`
}
type Stats4sqPlaces struct {
TotalPhotos int64 `json:"total_photos,omitempty"`
TotalRatings int64 `json:"total_ratings,omitempty"`
TotalTips int64 `json:"total_tips,omitempty"`
}
type Tips4sqPlaces struct {
Id string `json:"id,omitempty"`
CreatedAt CustomTime `json:"created_at,omitempty"`
Text string `json:"text,omitempty"`
Url string `json:"url,omitempty"`
Lang string `json:"lang,omitempty"`
AgreeCount int64 `json:"agree_count,omitempty"`
DisagreeCount int64 `json:"disagree_count,omitempty"`
}

213
modelv2.go Normal file
View File

@ -0,0 +1,213 @@
package foursquare
type (
FoursquarePlacesv2 struct {
Results []struct {
FsqId string `json:"fsq_id"`
Categories []Categories4sqPlaces `json:"categories"`
Chains []struct {
Id string `json:"id"`
Name string `json:"name"`
} `json:"chains,omitempty"`
ClosedBucket string `json:"closed_bucket,omitempty"`
DateClosed CustomTime `json:"date_closed,omitempty"`
Description string `json:"description,omitempty"`
Distance int64 `json:"distance,omitempty"`
Email string `json:"email,omitempty"`
Fax string `json:"fax,omitempty"`
Features struct {
Payment struct {
CreditCards struct {
AcceptsCreditCards struct{} `json:"accepts_credit_cards,omitempty"`
Amex struct{} `json:"amex,omitempty"`
Discover struct{} `json:"discover,omitempty"`
Visa struct{} `json:"visa,omitempty"`
DinersClub struct{} `json:"diners_club,omitempty"`
MasterCard struct{} `json:"master_card,omitempty"`
UnionPay struct{} `json:"union_pay,omitempty"`
} `json:"credit_cards,omitempty"`
DigitalWallet struct {
AcceptsNfc struct{} `json:"accepts_nfc,omitempty"`
} `json:"digital_wallet,omitempty"`
} `json:"payment,omitempty"`
FoodAndDrink struct {
Alcohol struct {
BarService struct{} `json:"bar_service,omitempty"`
Beer struct{} `json:"beer,omitempty"`
Byo struct{} `json:"byo,omitempty"`
Cocktails struct{} `json:"cocktails,omitempty"`
FullBar struct{} `json:"full_bar,omitempty"`
Wine struct{} `json:"wine,omitempty"`
} `json:"alcohol,omitempty"`
Meals struct {
BarSnacks struct{} `json:"bar_snacks,omitempty"`
Breakfast struct{} `json:"breakfast,omitempty"`
Brunch struct{} `json:"brunch,omitempty"`
Lunch struct{} `json:"lunch,omitempty"`
HappyHour struct{} `json:"happy_hour,omitempty"`
Dessert struct{} `json:"dessert,omitempty"`
Dinner struct{} `json:"dinner,omitempty"`
TastingMenu struct{} `json:"tasting_menu,omitempty"`
} `json:"meals,omitempty"`
} `json:"food_and_drink,omitempty"`
Services struct {
Delivery struct{} `json:"delivery,omitempty"`
Takeout struct{} `json:"takeout,omitempty"`
DriveThrough struct{} `json:"drive_through,omitempty"`
DineIn struct {
Reservations struct{} `json:"reservations,omitempty"`
OnlineReservations struct{} `json:"online_reservations,omitempty"`
GroupsOnlyReservations struct{} `json:"groups_only_reservations,omitempty"`
EssentialReservations struct{} `json:"essential_reservations,omitempty"`
} `json:"dine_in,omitempty"`
} `json:"services,omitempty"`
Amenities struct {
Restroom struct{} `json:"restroom,omitempty"`
Smoking struct{} `json:"smoking,omitempty"`
Jukebox struct{} `json:"jukebox,omitempty"`
Music struct{} `json:"music,omitempty"`
LiveMusic struct{} `json:"live_music,omitempty"`
PrivateRoom struct{} `json:"private_room,omitempty"`
OutdoorSeating struct{} `json:"outdoor_seating,omitempty"`
Tvs struct{} `json:"tvs,omitempty"`
Atm struct{} `json:"atm,omitempty"`
CoatCheck struct{} `json:"coat_check,omitempty"`
WheelchairAccessible struct{} `json:"wheelchair_accessible,omitempty"`
Parking struct {
Parking struct{} `json:"parking,omitempty"`
StreetParking struct{} `json:"street_parking,omitempty"`
ValetParking struct{} `json:"valet_parking,omitempty"`
PublicLot struct{} `json:"public_lot,omitempty"`
PrivateLot struct{} `json:"private_lot,omitempty"`
} `json:"parking,omitempty"`
SitDownDining struct{} `json:"sit_down_dining,omitempty"`
Wifi string `json:"wifi,omitempty"`
} `json:"amenities,omitempty"`
Attributes struct {
BusinessMeeting string `json:"business_meeting,omitempty"`
Clean string `json:"clean,omitempty"`
Crowded string `json:"crowded,omitempty"`
DatesPopular string `json:"dates_popular,omitempty"`
FamiliesPopular string `json:"families_popular,omitempty"`
GlutenFreeDiet string `json:"gluten_free_diet,omitempty"`
GoodForDogs string `json:"good_for_dogs,omitempty"`
GroupsPopular string `json:"groups_popular,omitempty"`
HealthyDiet string `json:"healthy_diet,omitempty"`
LateNight string `json:"late_night,omitempty"`
Noisy string `json:"noisy,omitempty"`
QuickBite string `json:"quick_bite,omitempty"`
Romantic string `json:"romantic,omitempty"`
ServiceQuality string `json:"service_quality,omitempty"`
SinglesPopular string `json:"singles_popular,omitempty"`
SpecialOccasion string `json:"special_occasion,omitempty"`
Trendy string `json:"trendy,omitempty"`
ValueForMoney string `json:"value_for_money,omitempty"`
VeganDiet string `json:"vegan_diet,omitempty"`
VegetarianDiet string `json:"vegetarian_diet,omitempty"`
} `json:"attributes,omitempty"`
} `json:"features,omitempty"`
Geocodes struct {
DropOff struct {
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
} `json:"drop_off,omitempty"`
FrontDoor struct {
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
} `json:"front_door,omitempty"`
Main struct {
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
} `json:"main,omitempty"`
Road struct {
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
} `json:"road,omitempty"`
Roof struct {
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
} `json:"roof,omitempty"`
} `json:"geocodes,omitempty"`
Hours struct {
Display string `json:"display,omitempty"`
IsLocalHoliday bool `json:"is_local_holiday,omitempty"`
OpenNow bool `json:"open_now,omitempty"`
Regular []struct {
Close string `json:"close,omitempty"`
Day int64 `json:"day,omitempty"`
Open string `json:"open,omitempty"`
} `json:"regular,omitempty"`
} `json:"hours,omitempty"`
HoursPopular []struct {
Close string `json:"close,omitempty"`
Day int64 `json:"day,omitempty"`
Open string `json:"open,omitempty"`
} `json:"hours_popular,omitempty"`
Link string `json:"link,omitempty"`
Location struct {
Address string `json:"address,omitempty"`
AddressExtended string `json:"address_extended,omitempty"`
AdminRegion string `json:"admin_region,omitempty"`
CensusBlock string `json:"census_block,omitempty"`
Country string `json:"country,omitempty"`
CrossStreet string `json:"cross_street,omitempty"`
Dma string `json:"dma,omitempty"`
FormattedAddress string `json:"formatted_address,omitempty"`
Locality string `json:"locality,omitempty"`
Neighborhood []string `json:"neighborhood,omitempty"`
PoBox string `json:"po_box,omitempty"`
PostTown string `json:"post_town,omitempty"`
Region string `json:"region,omitempty"`
} `json:"location,omitempty"`
Photos []struct {
Id string `json:"id,omitempty"`
CreatedAt CustomTime `json:"created_at,omitempty"`
Prefix string `json:"prefix,omitempty"`
Suffix string `json:"suffix,omitempty"`
Width int64 `json:"width,omitempty"`
Height int64 `json:"height,omitempty"`
Classifications []string `json:"classifications,omitempty"`
Tip struct {
Id string `json:"id,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
Text string `json:"text,omitempty"`
Url string `json:"url,omitempty"`
Lang string `json:"lang,omitempty"`
AgreeCount int64 `json:"agree_count,omitempty"`
DisagreeCount int64 `json:"disagree_count,omitempty"`
} `json:"tip,omitempty"`
} `json:"photos,omitempty"`
Popularity int64 `json:"popularity,omitempty"`
Price int64 `json:"price,omitempty"`
Rating int64 `json:"rating,omitempty"`
Name string `json:"name,omitempty"`
RelatedPlaces struct{} `json:"related_places,omitempty"`
SocialMedia struct {
FacebookId string `json:"facebook_id,omitempty"`
Instagram string `json:"instagram,omitempty"`
Twitter string `json:"twitter,omitempty"`
} `json:"social_media,omitempty"`
Stats struct {
TotalPhotos int64 `json:"total_photos,omitempty"`
TotalRatings int64 `json:"total_ratings,omitempty"`
TotalTips int64 `json:"total_tips,omitempty"`
} `json:"stats,omitempty"`
StoreId string `json:"store_id,omitempty"`
Tastes []string `json:"tastes,omitempty"`
Tel string `json:"tel,omitempty"`
Timezone string `json:"timezone,omitempty"`
Tips []struct {
Id string `json:"id,omitempty"`
CreatedAt CustomTime `json:"created_at,omitempty"`
Text string `json:"text,omitempty"`
Url string `json:"url,omitempty"`
Lang string `json:"lang,omitempty"`
AgreeCount int64 `json:"agree_count,omitempty"`
DisagreeCount int64 `json:"disagree_count,omitempty"`
} `json:"tips,omitempty"`
VenueRealityBucket string `json:"venue_reality_bucket,omitempty"`
Verified bool `json:"verified,omitempty"`
Website string `json:"website,omitempty"`
} `json:"results"`
}
)

29
nearbyModel.go Normal file
View File

@ -0,0 +1,29 @@
package foursquare
type (
ReduceResponse struct {
Response struct {
Groups []ReduceGroup `json:"groups"`
} `json:"response"`
}
)
type (
ReduceVenue struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Category []Categories4sqPlaces `json:"category,omitempty"`
Location struct {
Distance int64 `json:"distance,omitempty"`
} `json:"location,omitempty"`
}
)
type ReduceItems struct {
Venue ReduceVenue `json:"venue,omitempty"`
}
type ReduceGroup struct {
Items []ReduceItems `json:"items,omitempty"`
}

89
query.go Normal file
View File

@ -0,0 +1,89 @@
package foursquare
import (
"encoding/json"
"fmt"
"github.com/google/go-querystring/query"
"io"
"net/http"
)
type Query struct {
APIKey string
Query string
Categories string
Chains string
}
/*func NewQueryForLocation(apiKey string, lat string, lon string, modifierType string, modifier string) Query {
category := ""
chain := ""
if modifierType == "chain" {
chain = modifier
}
if modifierType == "category" {
category = modifier
}
return Query{
APIKey: apiKey,
Query: lat + "," + lon,
Categories: category,
Chains: chain,
}
}
*/
// go run main.go -key "fsq3ksL8PkGBLhDJ6Bydixoa9Lah6djwvm5a5LIWrtmFexc=" -ll "51.507351,-0.1277" -category "13303"
func (options *Options) NewQueryForLocation() (*FoursquarePlacesv2, error) {
fmt.Println("Foursquare")
//url := "https://api.foursquare.com/v3/places/search?ll=51.507351%2C-0.127758&radius=800&categories=13303"
v, _ := query.Values(options)
fmt.Println(v.Encode())
url := "https://api.foursquare.com/v3/places/search?" + v.Encode()
fmt.Println(url)
req, err := http.NewRequest("GET", url, nil)
req.Header.Add("accept", "application/json")
req.Header.Add("Authorization",options.Key )
res, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Http failed")
return nil, err
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
fmt.Println(string(body))
if err != nil {
fmt.Println("io readall failed")
return nil, err
}
dataPtr := &FoursquarePlacesv2{}
err = json.Unmarshal(body, dataPtr)
if err != nil {
fmt.Println("Unmarshal failed")
return nil, err
}
return dataPtr, err
}

20
query_test.go Normal file
View File

@ -0,0 +1,20 @@
package foursquare
import (
"testing"
)
func TestNewQueryForLocation(t *testing.T) {
apiKey := "key"
lat := "54.000"
lon := "-4.000"
modifierType := "chain"
modifier := "ab4bee40"
q := NewQueryForLocation(apiKey, lat, lon, modifierType, modifier)
if q.APIKey != apiKey {
t.Fatalf("Something broke")
}
}

5
readme.md Normal file
View File

@ -0,0 +1,5 @@
# Go-Foursquare
Work in progress...