Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added venue suggestion function

  • Loading branch information...
commit 73fbf6515e5c2c27979f1a3706609118d5a9f581 1 parent 522fc7a
@cbrauchli authored
View
20 lib/foursquare2/venues.rb
@@ -136,7 +136,8 @@ def propose_venue_edit(venue_id, options={})
# @option options String :section - One of food, drinks, coffee, shops, or arts. Choosing one of these limits results to venues with categories matching these terms.
# @option options String :query - Query to match venues on.
# @option options Integer :limit - The limit of results to return.
- # @option options String :basis - If present and set to friends or me, limits results to only places where friends have visited or user has visited, respectively.
+ # @option options String :intent - Limit results to venues with specials.
+ # @option options String :novelty - Pass new or old to limit results to places the acting user hasn't been or has been, respectively. Omitting this parameter returns a mixture.
def explore_venues(options={})
response = connection.get do |req|
@@ -144,5 +145,22 @@ def explore_venues(options={})
end
return_error_or_body(response, response.body.response)
end
+
+ # Suggest venue completions. Returns a list of mini-venues partially matching the search term, near the location.
+ #
+ # @param [Hash] options
+ # @option options String :ll - Latitude and longitude in format LAT,LON
+ # @option options Integer :llAcc - Accuracy of the lat/lon in meters.
+ # @option options Integer :alt - Altitude in meters
+ # @option options Integer :altAcc - Accuracy of the altitude in meters
+ # @option options String :query - Query to match venues on.
+ # @option options Integer :limit - The limit of results to return.
+
+ def suggest_completion_venues(options={})
+ response = connection.get do |req|
+ req.url "venues/suggestCompletion", options
+ end
+ return_error_or_body(response, response.body.response)
+ end
end
end
View
1  test/fixtures/suggest_completion_venues.json
@@ -0,0 +1 @@
+{"meta":{"code":200},"notifications":[{"type":"notificationTray","item":{"unreadCount":0}}],"response":{"minivenues":[{"id":"44dc96e4f964a520b0361fe3","name":"think coffee","location":{"address":"248 Mercer St","crossStreet":"btw 4th & Washington Square Village","city":"New York","state":"NY","postalCode":"10012","country":"USA","lat":40.728395,"lng":-73.995489,"distance":3183},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4ae33a3df964a520f99121e3","name":"Think Coffee","location":{"address":"123 4th Ave","crossStreet":"btw 12th & 13th St","city":"New York","state":"NY","postalCode":"10003","country":"USA","lat":40.733029,"lng":-73.990038,"distance":3771},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4075e780f964a52059f21ee3","name":"Gorilla Coffee","location":{"address":"97 5th Ave","crossStreet":"at Park Pl","city":"Brooklyn","state":"NY","postalCode":"11217","country":"USA","lat":40.679668384825625,"lng":-73.97820175,"distance":2916},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"491ada01f964a52072521fe3","name":"Think Coffee","location":{"address":"1 Bleecker St.","crossStreet":"at Bowery","city":"New York","state":"NY","postalCode":"10003","country":"USA","lat":40.725292088686246,"lng":-73.99214602821085,"distance":2892},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4aeedbe6f964a5206cd421e3","name":"Birch Coffee","location":{"address":"5 E 27th St","crossStreet":"btw 5th Ave & Madison","city":"New York","state":"NY","postalCode":"10016","country":"USA","lat":40.743906,"lng":-73.98717,"distance":5005},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"49d7b51ff964a520515d1fe3","name":"Gimme! Coffee","location":{"address":"228 Mott St","crossStreet":"btw Prince & Spring","city":"New York","state":"NY","postalCode":"10012","country":"USA","lat":40.722279576782924,"lng":-73.99517675668822,"distance":2513},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"41214a80f964a520300c1fe3","name":"Coffee Pot","location":{"address":"350 W 49th St","crossStreet":"btw 8th & 9th Aves","city":"New York","state":"NY","postalCode":"10019","country":"USA","lat":40.762803,"lng":-73.989232,"distance":7049},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4ecc046b0e61aaf0384f19c4","name":"Think Coffee","location":{"address":"73 8th Ave.","crossStreet":"14th St.","city":"New York","state":"NY","postalCode":"10014","lat":40.73946479913673,"lng":-74.00265603689895,"distance":4398},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"460ab8cdf964a520f1441fe3","name":"Gregory's Coffee","location":{"address":"327 Park Ave. S.","crossStreet":"btwn E. 24th & 25th","city":"New York","state":"NY","postalCode":"10010-2934","country":"USA","lat":40.740923,"lng":-73.985996,"distance":4706},"category":{"id":"4bf58dd8d48988d16d941735","name":"Café","pluralName":"Cafés","shortName":"Café","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/cafe_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4ed39cda0aafd18692a48b5e","name":"Coffee","location":{"city":"New York","state":"NY","postalCode":"10005","lat":40.706789,"lng":-74.010902,"distance":1190},"category":{"id":"4bf58dd8d48988d16d941735","name":"Café","pluralName":"Cafés","shortName":"Café","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/cafe_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4d1266ff12916dcb8daad58a","name":"Bourbon Coffee","location":{"address":"43 W 14th St","crossStreet":"6th Ave","city":"New York","state":"NY","postalCode":"10011","country":"USA","lat":40.736893,"lng":-73.99573,"distance":4122},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4e9d9e599a5262f9812fed9e","name":"Bowery Coffee","location":{"address":"89 E Houston St","crossStreet":"btwn Bowery & Elizabeth","city":"New York","state":"NY","postalCode":"10012","lat":40.7242915,"lng":-73.99289022,"distance":2769},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"44ca1c8af964a520f6351fe3","name":"Gimme Coffee","location":{"address":"495 Lorimer St","crossStreet":"Grand St","city":"Brooklyn","state":"NY","postalCode":"11211","country":"USA","lat":40.711812,"lng":-73.949068,"distance":4494},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4e720243c65bae37845e6951","name":"Coffee","location":{"state":"NY","lat":40.672019,"lng":-73.972279,"distance":3895},"category":{"id":"4bf58dd8d48988d16d941735","name":"Café","pluralName":"Cafés","shortName":"Café","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/cafe_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4876216df964a52011511fe3","name":"Jack's Coffee","location":{"address":"138 W 10th St","crossStreet":"btw Greenwich & Waverly","city":"New York","state":"NY","postalCode":"10014","country":"USA","lat":40.734653,"lng":-74.000575,"distance":3857},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4b0ea0f0f964a520175923e3","name":"Gregory's Coffee","location":{"address":"58 W 44th St","crossStreet":"6th Ave","city":"New York","state":"NY","postalCode":"10036-6604","country":"USA","lat":40.756172,"lng":-73.982775,"distance":6419},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4cd3704eb74860fc56a76e49","name":"Pushcart Coffee","location":{"address":"221 E. Broadway","crossStreet":"at Clinton St.","city":"New York","state":"NY","postalCode":"10002","country":"USA","lat":40.71423232033,"lng":-73.98693859577179,"distance":1930},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4e3db0dfae60454236694c6b","name":"Joe Coffee","location":{"address":"332 Flatbush Ave","crossStreet":"Willoughby St","city":"Brooklyn","state":"NY","postalCode":"11201","lat":40.691756,"lng":-73.98292,"distance":1708},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"49be6964f964a520aa541fe3","name":"Mojo Coffee","location":{"address":"128 Charles St","crossStreet":"btw Greenwich St & Washington St","city":"New York","state":"NY","postalCode":"10014","country":"USA","lat":40.734186,"lng":-74.007496,"distance":3857},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4a69c95df964a52008cc1fe3","name":"Oslo Coffee","location":{"address":"133 Roebling St.","crossStreet":"at Metropolitan","city":"New York","state":"NY","postalCode":"11211","country":"USA","lat":40.714736512395255,"lng":-73.95685493946075,"distance":3993},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4f044f5993ad64af7ace411b","name":"Prodigy Coffee","location":{"city":"New York","state":"NY","postalCode":"10014","lat":40.73005893543017,"lng":-74.00303437785037,"distance":3355},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4bcefda6cc8cd13a7821c5cf","name":"myWayCup Coffee","location":{"address":"102 E 23rd St","crossStreet":"btw Park & Lexington Ave","city":"New York","state":"NY","postalCode":"10010","country":"USA","lat":40.740281,"lng":-73.986155,"distance":4633},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4cdb13064006a1433ef2d5b2","name":"Roastown Coffee","location":{"address":"133 2nd Ave.","crossStreet":"St. Marks","city":"New York","state":"NY","postalCode":"10003","country":"USA","lat":40.728683,"lng":-73.987674,"distance":3358},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4d53548e2f638cfa759e616a","name":"Coffee","location":{"lat":40.760543,"lng":-73.996448,"distance":6746},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4e6fe48c1fc7d3fc71285ec2","name":"Gregorys Coffee","location":{"address":"12 East 46th St.","crossStreet":"btwn 5th Ave and Madison","city":"New York","state":"NY","postalCode":"10176","lat":40.75557768724385,"lng":-73.97818048527262,"distance":6454},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4c6d9ca4a437224b8e932db1","name":"Roastown Coffee","location":{"address":"793 6th Ave","crossStreet":"W 27th St","city":"New York","state":"NY","postalCode":"10001","country":"USA","lat":40.745496,"lng":-73.990971,"distance":5121},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4c24b32cf7ced13a0b33236d","name":"Gregory's Coffee","location":{"address":"551 Fashion Ave","crossStreet":"at 39th St","city":"New York","state":"NY","postalCode":"10018","country":"USA","lat":40.75437,"lng":-73.988181,"distance":6133},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4c4dcfb2fb742d7f792a592d","name":"Gimme! Coffee","location":{"address":"107 Roebling St","crossStreet":"btw n5th & n6th St","city":"Brooklyn","state":"New York","postalCode":"11211","country":"USA","lat":40.715666,"lng":-73.955944,"distance":4106},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4d02a26b9d33a14317b6ae78","name":"Starbucks Coffee","location":{"address":"511 Lexington Ave","crossStreet":"50th Street","city":"New York","state":"NY","postalCode":"10017","lat":40.75691691768806,"lng":-73.97210685714634,"distance":6758},"category":{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"}}},{"id":"4d988ee8e07ea35d046af402","name":"Coffee","location":{"address":"broadway","crossStreet":"63","state":"New York","postalCode":"10023","lat":40.773141,"lng":-73.982027,"distance":8281}}]}}
View
8 test/test_venues.rb
@@ -62,7 +62,7 @@ class TestVenues < Test::Unit::TestCase
end
should "allow venues to be explored" do
- stub_get("https://api.foursquare.com/v2/venues/explore?section=food&ll=40.7%2C-74&oauth_token=yeehaw&limit=2", "explore_venues.json")
+ stub_get("https://api.foursquare.com/v2/venues/explore?section=food&ll=40.7%2C-74&oauth_token=#{@client.oauth_token}&limit=2", "explore_venues.json")
venues = @client.explore_venues(:ll => '40.7,-74', :section => 'food', :limit => '2')
venues.groups.first.items.count.should == 2
end
@@ -83,6 +83,12 @@ class TestVenues < Test::Unit::TestCase
photos.items.size.should == 3
end
+ should "should suggest venues based on passed criteria" do
+ stub_get("https://api.foursquare.com/v2/venues/suggestCompletion?oauth_token=#{@client.oauth_token}&ll=40.7%2C-74&query=coffee", "suggest_completion_venues.json")
+ venues = @client.suggest_completion_venues(:ll => "40.7,-74", :query => "coffee")
+ venues.minivenues.first.id.should == '44dc96e4f964a520b0361fe3'
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.