From 6be4ca78842a7e2c35d3b104ce53faf663e59776 Mon Sep 17 00:00:00 2001 From: Matt Mueller Date: Sat, 9 Nov 2013 07:07:01 -0600 Subject: [PATCH] Add fallback default version of current date. Fixes #69 --- lib/foursquare2/client.rb | 2 +- test/test_campaigns.rb | 8 +++---- test/test_checkins.rb | 8 +++---- test/test_client.rb | 6 +++++ test/test_events.rb | 4 ++-- test/test_lists.rb | 16 ++++++------- test/test_pages.rb | 6 ++--- test/test_photos.rb | 2 +- test/test_specials.rb | 6 ++--- test/test_tips.rb | 4 ++-- test/test_users.rb | 32 ++++++++++++------------- test/test_venuegroups.rb | 6 ++--- test/test_venues.rb | 50 +++++++++++++++++++-------------------- 13 files changed, 78 insertions(+), 72 deletions(-) diff --git a/lib/foursquare2/client.rb b/lib/foursquare2/client.rb index 6d9811c..7035cb5 100644 --- a/lib/foursquare2/client.rb +++ b/lib/foursquare2/client.rb @@ -42,7 +42,7 @@ def initialize(options={}) @client_id = options[:client_id] || Foursquare2.client_id @client_secret = options[:client_secret] || Foursquare2.client_secret @oauth_token = options[:oauth_token] - @api_version = options[:api_version] || Foursquare2.api_version + @api_version = options[:api_version] || Foursquare2.api_version || Time.now.strftime('%Y%m%d') @locale = options[:locale] || Foursquare2.locale @ssl = options[:ssl] || Foursquare2.ssl || Hash.new @connection_middleware = options[:connection_middleware] || Foursquare2.connection_middleware || [] diff --git a/test/test_campaigns.rb b/test/test_campaigns.rb index 4fd1503..29f756b 100644 --- a/test/test_campaigns.rb +++ b/test/test_campaigns.rb @@ -10,25 +10,25 @@ class TestCampaigns < Test::Unit::TestCase end should "get a campaign" do - stub_get("https://api.foursquare.com/v2/campaigns/4e0deba2922e6f94b1410b79?oauth_token=#{@client.oauth_token}", "campaigns/campaign.json") + stub_get("https://api.foursquare.com/v2/campaigns/4e0deba2922e6f94b1410b79?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "campaigns/campaign.json") campaign = @client.campaign('4e0deba2922e6f94b1410b79') campaign.id == "4e0deba2922e6f94b1410b79" end should "add a campaign" do - stub_post("https://api.foursquare.com/v2/campaigns/add?oauth_token=#{@client.oauth_token}&specialId=4bd876f886ba62b58a6e88b3", "campaigns/campaign_created.json") + stub_post("https://api.foursquare.com/v2/campaigns/add?oauth_token=#{@client.oauth_token}&specialId=4bd876f886ba62b58a6e88b3&v=#{@client.api_version}", "campaigns/campaign_created.json") campaign = @client.add_campaign(:specialId => '4bd876f886ba62b58a6e88b3') campaign.special.id == "4bd876f886ba62b58a6e88b3" end should "list all campaigns" do - stub_get("https://api.foursquare.com/v2/campaigns/list?oauth_token=#{@client.oauth_token}&status=active", "campaigns/campaigns_list.json") + stub_get("https://api.foursquare.com/v2/campaigns/list?oauth_token=#{@client.oauth_token}&status=active&v=#{@client.api_version}", "campaigns/campaigns_list.json") campaigns = @client.list_campaigns(:status => 'active') campaigns.first.id.should == "4e0deba2922e6f94b1410b79" end should "list campaigns of specialId" do - stub_get("https://api.foursquare.com/v2/campaigns/list?oauth_token=#{@client.oauth_token}&specialId=4e0debea922e6f94b1410bb7", "campaigns/campaigns_list.json") + stub_get("https://api.foursquare.com/v2/campaigns/list?oauth_token=#{@client.oauth_token}&specialId=4e0debea922e6f94b1410bb7&v=#{@client.api_version}", "campaigns/campaigns_list.json") campaigns = @client.list_campaigns(:specialId => '4e0debea922e6f94b1410bb7') campaigns.first['specialId'].should == "4e0debea922e6f94b1410bb7" end diff --git a/test/test_checkins.rb b/test/test_checkins.rb index e730eb6..49c9c50 100644 --- a/test/test_checkins.rb +++ b/test/test_checkins.rb @@ -8,14 +8,14 @@ class TestCheckins < Test::Unit::TestCase end should "fetch info for a single checkin" do - stub_get("https://api.foursquare.com/v2/checkins/4d572bcc9e508cfab975189b?oauth_token=#{@client.oauth_token}", "checkins/checkin.json") + stub_get("https://api.foursquare.com/v2/checkins/4d572bcc9e508cfab975189b?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "checkins/checkin.json") checkin = @client.checkin('4d572bcc9e508cfab975189b') checkin.venue.name.should == 'Bridgestone Arena' checkin.user.firstName.should == 'Matt' end should "fetch recent checkins from friends"do - stub_get("https://api.foursquare.com/v2/checkins/recent?oauth_token=#{@client.oauth_token}&limit=2", "checkins/friend_checkins.json") + stub_get("https://api.foursquare.com/v2/checkins/recent?oauth_token=#{@client.oauth_token}&limit=2&v=#{@client.api_version}", "checkins/friend_checkins.json") checkins = @client.recent_checkins(:limit => 2) checkins.count.should == 2 checkins.first.venue.name.should == 'Buffalo Billiards' @@ -23,13 +23,13 @@ class TestCheckins < Test::Unit::TestCase end should "add a post to an existing checkin" do - stub_post("https://api.foursquare.com/v2/checkins/5041335de4b08d95c1591453/addpost?oauth_token=#{@client.oauth_token}&text=Test", "checkins/post_created.json") + stub_post("https://api.foursquare.com/v2/checkins/5041335de4b08d95c1591453/addpost?oauth_token=#{@client.oauth_token}&text=Test&v=#{@client.api_version}", "checkins/post_created.json") post = @client.add_checkin_post('5041335de4b08d95c1591453', :text => "Test") post.text.should == "Test" end should "add a reply to an existing checkin" do - stub_post("https://api.foursquare.com/v2/checkins/5041eda9e4b0133020c2292c/reply?oauth_token=#{@client.oauth_token}&text=Test", "checkins/checkin_reply.json") + stub_post("https://api.foursquare.com/v2/checkins/5041eda9e4b0133020c2292c/reply?oauth_token=#{@client.oauth_token}&text=Test&v=#{@client.api_version}", "checkins/checkin_reply.json") reply = @client.add_checkin_reply('5041eda9e4b0133020c2292c', :text => "Test") reply.text.should == "Test" end diff --git a/test/test_client.rb b/test/test_client.rb index 87e5555..650cd78 100644 --- a/test/test_client.rb +++ b/test/test_client.rb @@ -76,6 +76,12 @@ class TestClient < Test::Unit::TestCase @client.ssl[:ca_file].should == 'path_to_ca_file' end + should "default to the current date for versioning" do + @client = Foursquare2::Client.new + @client.api_version.should == Time.now.strftime('%Y%m%d') + end + + should "apply the middleware to the connection" do middleware = [FaradayMiddleware::Instrumentation, [FaradayMiddleware::ParseJson, {:content_type => /\bjson$/}]] diff --git a/test/test_events.rb b/test/test_events.rb index 75ed10b..90ff89c 100644 --- a/test/test_events.rb +++ b/test/test_events.rb @@ -8,13 +8,13 @@ class TestEvents < Test::Unit::TestCase end should "fetch list of event categories" do - stub_get("https://api.foursquare.com/v2/events/categories?oauth_token=#{@client.oauth_token}", "events/event_categories.json") + stub_get("https://api.foursquare.com/v2/events/categories?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "events/event_categories.json") event_categories = @client.event_categories() event_categories.first.name.should == "Movies" end should "fetch info for a single event" do - stub_get("https://api.foursquare.com/v2/events/4f98d496f6903e7ae2a3628c?oauth_token=#{@client.oauth_token}", "events/event.json") + stub_get("https://api.foursquare.com/v2/events/4f98d496f6903e7ae2a3628c?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "events/event.json") event = @client.event('4f98d496f6903e7ae2a3628c') event.name.should == "Marvel's The Avengers" end diff --git a/test/test_lists.rb b/test/test_lists.rb index 2056b41..c20dc86 100644 --- a/test/test_lists.rb +++ b/test/test_lists.rb @@ -9,46 +9,46 @@ class TestLists < Test::Unit::TestCase end should "fetch info for a single list" do - stub_get("https://api.foursquare.com/v2/lists/#{@list_id}?oauth_token=#{@client.oauth_token}", "lists/list.json") + stub_get("https://api.foursquare.com/v2/lists/#{@list_id}?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "lists/list.json") list = @client.list(@list_id) list.name.should == 'Restaurants to Try' list.venueCount.should == 8 end should "add a list" do - stub_post("https://api.foursquare.com/v2/lists/add?oauth_token=#{@client.oauth_token}&name=Ramen+Spots", "lists/list_created.json") + stub_post("https://api.foursquare.com/v2/lists/add?oauth_token=#{@client.oauth_token}&name=Ramen+Spots&v=#{@client.api_version}", "lists/list_created.json") list = @client.add_list(:name => "Ramen Spots") list.name.should == "Ramen Spots" end should "follow a list" do - stub_post("https://api.foursquare.com/v2/lists/#{@list_id}/follow?oauth_token=#{@client.oauth_token}", "lists/list_followed.json") + stub_post("https://api.foursquare.com/v2/lists/#{@list_id}/follow?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "lists/list_followed.json") list = @client.follow_list(@list_id) list.following.should == true end should "unfollow a list" do - stub_post("https://api.foursquare.com/v2/lists/#{@list_id}/unfollow?oauth_token=#{@client.oauth_token}", "lists/list.json") + stub_post("https://api.foursquare.com/v2/lists/#{@list_id}/unfollow?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "lists/list.json") list = @client.unfollow_list(@list_id) list.following.should == false end should "update a list" do - stub_post("https://api.foursquare.com/v2/lists/#{@list_id}/update?oauth_token=#{@client.oauth_token}&name=Ramen+Sports", "lists/list_updated.json") + stub_post("https://api.foursquare.com/v2/lists/#{@list_id}/update?oauth_token=#{@client.oauth_token}&name=Ramen+Sports&v=#{@client.api_version}", "lists/list_updated.json") list = @client.update_list(@list_id, :name => "Ramen Sports") list.name.should == "Ramen Sports" end should "add an item to a list" do venue_id = '4ba19cb0f964a520c2c337e3' - stub_post("https://api.foursquare.com/v2/lists/#{@list_id}/additem?oauth_token=#{@client.oauth_token}&venueId=#{venue_id}", "lists/list_item.json") + stub_post("https://api.foursquare.com/v2/lists/#{@list_id}/additem?oauth_token=#{@client.oauth_token}&venueId=#{venue_id}&v=#{@client.api_version}", "lists/list_item.json") item = @client.add_list_item(@list_id, :venueId => venue_id) item.venue.id.should == venue_id end should "delete an item from a list" do item_id = 'v4ba19cb0f964a520c2c337e3' - stub_post("https://api.foursquare.com/v2/lists/#{@list_id}/deleteitem?oauth_token=#{@client.oauth_token}&itemId=#{item_id}", "lists/list_item.json") + stub_post("https://api.foursquare.com/v2/lists/#{@list_id}/deleteitem?oauth_token=#{@client.oauth_token}&itemId=#{item_id}&v=#{@client.api_version}", "lists/list_item.json") item = @client.delete_list_item(@list_id, item_id) item.id.should == item_id end @@ -56,7 +56,7 @@ class TestLists < Test::Unit::TestCase should "move an item on a list" do item_id = 't4d404fc934f42d43b2624385' before_id = 'v4a01c477f964a520f9701fe3' - stub_post("https://api.foursquare.com/v2/lists/#{@list_id}/moveitem?oauth_token=#{@client.oauth_token}&itemId=#{item_id}&beforeId=#{before_id}", "lists/list_moved_item.json") + stub_post("https://api.foursquare.com/v2/lists/#{@list_id}/moveitem?oauth_token=#{@client.oauth_token}&itemId=#{item_id}&beforeId=#{before_id}&v=#{@client.api_version}", "lists/list_moved_item.json") list = @client.move_list_item(@list_id, item_id, :beforeId => before_id) list.listItems.items[0].id.should == item_id list.listItems.items[1].id.should == before_id diff --git a/test/test_pages.rb b/test/test_pages.rb index 15052fc..f972850 100644 --- a/test/test_pages.rb +++ b/test/test_pages.rb @@ -8,20 +8,20 @@ class TestPages < Test::Unit::TestCase end should "fetch info for a single page" do - stub_get("https://api.foursquare.com/v2/pages/14046309?oauth_token=#{@client.oauth_token}", "pages/page.json") + stub_get("https://api.foursquare.com/v2/pages/14046309?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "pages/page.json") page = @client.page('14046309') page.firstName.should == "Nashville Geeks" page.type.should == "page" end should "fetch results when searching for a page" do - stub_get("https://api.foursquare.com/v2/pages/search?name=NashvilleGeeks&oauth_token=#{@client.oauth_token}", "pages/search_pages.json") + stub_get("https://api.foursquare.com/v2/pages/search?name=NashvilleGeeks&oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "pages/search_pages.json") pages = @client.search_pages(:name => 'NashvilleGeeks') pages.results.first.firstName.should == "Nashville Geeks" end should "fetch venues for a given page" do - stub_get("https://api.foursquare.com/v2/pages/1070527/venues?limit=2&oauth_token=#{@client.oauth_token}", "pages/page_venues.json") + stub_get("https://api.foursquare.com/v2/pages/1070527/venues?limit=2&oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "pages/page_venues.json") venues = @client.page_venues(1070527, :limit => 2) venues['count'].should == 11051 venues.items.length.should == 2 diff --git a/test/test_photos.rb b/test/test_photos.rb index 821c5da..9eac684 100644 --- a/test/test_photos.rb +++ b/test/test_photos.rb @@ -8,7 +8,7 @@ class TestPhotos < Test::Unit::TestCase end should "fetch info for a single photo" do - stub_get("https://api.foursquare.com/v2/photos/4d0fb8162d39a340637dc42b?oauth_token=#{@client.oauth_token}", "photos/photo.json") + stub_get("https://api.foursquare.com/v2/photos/4d0fb8162d39a340637dc42b?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "photos/photo.json") photo = @client.photo('4d0fb8162d39a340637dc42b') photo.sizes.items.count.should == 4 photo.sizes.items.first.url.should == "http://playfoursquare.s3.amazonaws.com/pix/UYU54GYOCURPAUYXH5V2U3EOM4DCX4VZPT3YOMN43H555KU2.jpg" diff --git a/test/test_specials.rb b/test/test_specials.rb index 6becb16..6aaacf5 100644 --- a/test/test_specials.rb +++ b/test/test_specials.rb @@ -8,20 +8,20 @@ class TestSpecials < Test::Unit::TestCase end should "fetch info for a single special" do - stub_get("https://api.foursquare.com/v2/specials/4bd876f886ba62b58a6e88b3?oauth_token=#{@client.oauth_token}", "specials/special.json") + stub_get("https://api.foursquare.com/v2/specials/4bd876f886ba62b58a6e88b3?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "specials/special.json") special = @client.special('4bd876f886ba62b58a6e88b3') special.message.should == "$10 off for the mayor!" end should "fetch results when searching for nearby specials" do - stub_get("https://api.foursquare.com/v2/specials/search?ll=40.7%2C-73.9&oauth_token=#{@client.oauth_token}", "specials/search_specials.json") + stub_get("https://api.foursquare.com/v2/specials/search?ll=40.7%2C-73.9&oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "specials/search_specials.json") specials = @client.search_specials(:ll => '40.7,-73.9') specials.count.should == 1 specials.first.message.should == "Buy 1 Get 1 40% Off All Video Games (priced up to $19.99)\r\n\r\nItems must be of equal or lesser value to the lowest priced item purchased\r\n\r\nEnds 2/12/2011" end should "add a special for a venue with given params" do - stub_post("https://api.foursquare.com/v2/specials/add?text=Test&unlockedText=Congrats&oauth_token=#{@client.oauth_token}", "specials/special_created.json") + stub_post("https://api.foursquare.com/v2/specials/add?text=Test&unlockedText=Congrats&oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "specials/special_created.json") special = @client.add_special(:text => 'Test', :unlockedText => 'Congrats') special.message.should == "Test" end diff --git a/test/test_tips.rb b/test/test_tips.rb index e45c36c..6053dde 100644 --- a/test/test_tips.rb +++ b/test/test_tips.rb @@ -8,7 +8,7 @@ class TestTips < Test::Unit::TestCase end should "fetch info for a single tip" do - stub_get("https://api.foursquare.com/v2/tips/4b5e662a70c603bba7d790b4?oauth_token=#{@client.oauth_token}", "tips/tip.json") + stub_get("https://api.foursquare.com/v2/tips/4b5e662a70c603bba7d790b4?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "tips/tip.json") tip = @client.tip('4b5e662a70c603bba7d790b4') tip.done.groups.first['count'].should == 0 tip.done.groups.last['count'].should == 6 @@ -17,7 +17,7 @@ class TestTips < Test::Unit::TestCase end should "fetch results when searching for nearby tips" do - stub_get("https://api.foursquare.com/v2/tips/search?ll=40.7%2C-73.9&oauth_token=#{@client.oauth_token}&limit=3", "tips/search_tips.json") + stub_get("https://api.foursquare.com/v2/tips/search?ll=40.7%2C-73.9&oauth_token=#{@client.oauth_token}&limit=3&v=#{@client.api_version}", "tips/search_tips.json") tips = @client.search_tips(:ll => '40.7,-73.9', :limit => 3) tips.count.should == 3 tips.first.text.should == "If you want a soda go to the vending machine next to the ice Cream place near the music barge it's only $2 for a 20oz bottle instead of $2 for a can at one of the carts." diff --git a/test/test_users.rb b/test/test_users.rb index 54ce0cc..5808f12 100644 --- a/test/test_users.rb +++ b/test/test_users.rb @@ -8,40 +8,40 @@ class TestUsers < Test::Unit::TestCase end should "fetch user's leaderboard" do - stub_get("https://api.foursquare.com/v2/users/leaderboard?oauth_token=#{@client.oauth_token}&neighbors=2", "users/leaderboard.json", ) + stub_get("https://api.foursquare.com/v2/users/leaderboard?oauth_token=#{@client.oauth_token}&neighbors=2&v=#{@client.api_version}", "users/leaderboard.json", ) leaderboard = @client.leaderboard(:neighbors => 2) leaderboard.leaderboard['count'].should == 3 end should "fetch info for a single user" do - stub_get("https://api.foursquare.com/v2/users/self?oauth_token=#{@client.oauth_token}", "users/user.json") + stub_get("https://api.foursquare.com/v2/users/self?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "users/user.json") user = @client.user('self') user.firstName.should == 'Matt' user.checkins['count'].should == 669 end should "fetch results when searching for users" do - stub_get("https://api.foursquare.com/v2/users/search?oauth_token=#{@client.oauth_token}&twitter=matt_mueller", "users/search_users.json") + stub_get("https://api.foursquare.com/v2/users/search?oauth_token=#{@client.oauth_token}&twitter=matt_mueller&v=#{@client.api_version}", "users/search_users.json") users = @client.search_users(:twitter => 'matt_mueller') users.results.count.should == 1 users.results.first.lastName.should == 'Mueller' end should "fetch tips" do - stub_get("https://api.foursquare.com/v2/users/self/tips?oauth_token=#{@client.oauth_token}", "users/user_tips.json") + stub_get("https://api.foursquare.com/v2/users/self/tips?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "users/user_tips.json") tips = @client.user_tips('self') tips.items.first.text.should == "Encontrei mesas e chao sujos." tips.items.size.should == 12 end should "fetch tips and filter with term #{QUERY}" do - stub_get("https://api.foursquare.com/v2/users/self/tips?oauth_token=#{@client.oauth_token}&query=#{QUERY}", "users/user_tips.json") + stub_get("https://api.foursquare.com/v2/users/self/tips?oauth_token=#{@client.oauth_token}&query=#{QUERY}&v=#{@client.api_version}", "users/user_tips.json") tips = @client.user_tips('self', {:query => QUERY}) tips.items.size.should == 1 end should "fetch lists for a single user" do - stub_get("https://api.foursquare.com/v2/users/self/lists?oauth_token=#{@client.oauth_token}", "users/user_lists.json") + stub_get("https://api.foursquare.com/v2/users/self/lists?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "users/user_lists.json") lists = @client.user_lists('self') lists.items.size.should == 21 end @@ -49,39 +49,39 @@ class TestUsers < Test::Unit::TestCase #TODO refactoring all call to method stub_get should "list only user with tip #{QUERY}" do - stub_get("https://api.foursquare.com/v2/tips/search?oauth_token=#{@client.oauth_token}&ll=77.7%2C-77.7&query=#{QUERY}&limit=500", "tips/search_tips.json") + stub_get("https://api.foursquare.com/v2/tips/search?oauth_token=#{@client.oauth_token}&ll=77.7%2C-77.7&query=#{QUERY}&limit=500&v=#{@client.api_version}", "tips/search_tips.json") users = @client.search_users_by_tip({:name => 'developer', :ll =>'77.7,-77.7', :query => QUERY}) users.first.id.should == "2227298" users.size.should == 1 end should "find by name not case sensitive" do - stub_get("https://api.foursquare.com/v2/tips/search?oauth_token=#{@client.oauth_token}&ll=77.7%2C-77.7&query=#{QUERY}&limit=500", "tips/search_tips.json") + stub_get("https://api.foursquare.com/v2/tips/search?oauth_token=#{@client.oauth_token}&ll=77.7%2C-77.7&query=#{QUERY}&limit=500&v=#{@client.api_version}", "tips/search_tips.json") users = @client.search_users_by_tip({:name => 'Developer', :ll =>'77.7,-77.7', :query => QUERY}) users.first.id.should == "2227298" users.size.should == 1 end should "haven't user with name anonymous with tip #{QUERY}" do - stub_get("https://api.foursquare.com/v2/tips/search?oauth_token=#{@client.oauth_token}&ll=77.7%2C-77.7&query=#{QUERY}&limit=500", "tips/search_tips.json") + stub_get("https://api.foursquare.com/v2/tips/search?oauth_token=#{@client.oauth_token}&ll=77.7%2C-77.7&query=#{QUERY}&limit=500&v=#{@client.api_version}", "tips/search_tips.json") users = @client.search_users_by_tip({:name => 'anonymous', :ll =>'77.7,-77.7', :query => QUERY}) users.size.should == 0 end should "find a users mayorships" do - stub_get("https://api.foursquare.com/v2/users/self/mayorships?oauth_token=#{@client.oauth_token}", "users/user_mayorships.json") + stub_get("https://api.foursquare.com/v2/users/self/mayorships?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "users/user_mayorships.json") mayorships = @client.user_mayorships('self') mayorships.items.size.should == 2 end should "find a users checkins - plain (without optional params)" do - stub_get("https://api.foursquare.com/v2/users/self/checkins?oauth_token=#{@client.oauth_token}", "users/user_checkins_plain.json") + stub_get("https://api.foursquare.com/v2/users/self/checkins?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "users/user_checkins_plain.json") checkins = @client.user_checkins checkins.items.size.should == 20 end should "find a users checkins with afterTimestamp param" do - stub_get("https://api.foursquare.com/v2/users/self/checkins?oauth_token=#{@client.oauth_token}&limit=10&offset=2&sort=newestfirst&afterTimestamp=1279044824", "users/user_checkins_aftertimestamp.json") + stub_get("https://api.foursquare.com/v2/users/self/checkins?oauth_token=#{@client.oauth_token}&limit=10&offset=2&sort=newestfirst&afterTimestamp=1279044824&v=#{@client.api_version}", "users/user_checkins_aftertimestamp.json") checkins_after = @client.user_checkins({:limit => 10, :offset => 2, :sort => 'newestfirst', :afterTimestamp => 1279044824}) checkins_after.items.size.should == 10 checkins_after.items.reject { |ci| ci.createdAt > 1279044824 }.empty?.should == true @@ -89,7 +89,7 @@ class TestUsers < Test::Unit::TestCase end should "find a users checkins with beforeTimestamp param" do - stub_get("https://api.foursquare.com/v2/users/self/checkins?oauth_token=#{@client.oauth_token}&limit=5&offset=20&sort=oldestfirst&beforeTimestamp=1355867689", "users/user_checkins_beforetimestamp.json") + stub_get("https://api.foursquare.com/v2/users/self/checkins?oauth_token=#{@client.oauth_token}&limit=5&offset=20&sort=oldestfirst&beforeTimestamp=1355867689&v=#{@client.api_version}", "users/user_checkins_beforetimestamp.json") checkins_before = @client.user_checkins({:limit => 5, :offset => 20, :sort => 'oldestfirst', :beforeTimestamp => 1355867689}) checkins_before.items.size.should == 5 checkins_before.items.reject { |ci| ci.createdAt < 1355867689 }.empty?.should == true @@ -97,21 +97,21 @@ class TestUsers < Test::Unit::TestCase end should "find a users venuestats by self" do - stub_get("https://api.foursquare.com/v2/users/self/venuestats?oauth_token=#{@client.oauth_token}", "users/user_venuestats.json") + stub_get("https://api.foursquare.com/v2/users/self/venuestats?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "users/user_venuestats.json") venuestats = @client.venuestats venuestats.venues.size.should == 5 venuestats.categories.size.should == 10 end should "find a users venuestats by inputting friends user_id" do - stub_get("https://api.foursquare.com/v2/users/555555/venuestats?oauth_token=#{@client.oauth_token}", "users/user_venuestats_friend_id.json") + stub_get("https://api.foursquare.com/v2/users/555555/venuestats?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "users/user_venuestats_friend_id.json") friends_venuestats = @client.venuestats(555555) friends_venuestats.venues.size.should == 5 friends_venuestats.categories.size.should == 8 end should "fetch photos" do - stub_get("https://api.foursquare.com/v2/users/self/photos?oauth_token=#{@client.oauth_token}", "users/user_photos.json") + stub_get("https://api.foursquare.com/v2/users/self/photos?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "users/user_photos.json") photos = @client.user_photos photos.items.size.should == 2 photos.items.first.suffix.should == "/308098_MgBNEkeVohBBWDO3eQVMbUWJFmm-7R5kEEWjhq77xIQ.jpg" diff --git a/test/test_venuegroups.rb b/test/test_venuegroups.rb index b7800d2..c4963a7 100644 --- a/test/test_venuegroups.rb +++ b/test/test_venuegroups.rb @@ -8,19 +8,19 @@ class TestVenuegroups < Test::Unit::TestCase end should "get a venuegroup" do - stub_get("https://api.foursquare.com/v2/venuegroups/4e15cd13b61c42e7c54e5bb6?oauth_token=#{@client.oauth_token}", "venuegroups/venuegroup.json") + stub_get("https://api.foursquare.com/v2/venuegroups/4e15cd13b61c42e7c54e5bb6?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venuegroups/venuegroup.json") venuegroup = @client.venuegroup('4e15cd13b61c42e7c54e5bb6') venuegroup.id == "4e15cd13b61c42e7c54e5bb6" end should "add a venuegroup" do - stub_post("https://api.foursquare.com/v2/venuegroups/add?oauth_token=#{@client.oauth_token}&name=Venues&venueId=4b8c3d87f964a520f7c532e3", "venuegroups/venuegroup_add.json") + stub_post("https://api.foursquare.com/v2/venuegroups/add?oauth_token=#{@client.oauth_token}&name=Venues&venueId=4b8c3d87f964a520f7c532e3&v=#{@client.api_version}", "venuegroups/venuegroup_add.json") venuegroup = @client.add_venuegroup(:name => 'Venues', :venueId => '4b8c3d87f964a520f7c532e3') venuegroup.name == "Venues" end should "update a venuegroup" do - stub_post("https://api.foursquare.com/v2/venuegroups/4e15cd13b61c42e7c54e5bb6/update?oauth_token=#{@client.oauth_token}?venueId=4b8c3d87f964a520f7c532e3,4d572bcc9e508cfab975189b", "venuegroups/venuegroup_update.json") + stub_post("https://api.foursquare.com/v2/venuegroups/4e15cd13b61c42e7c54e5bb6/update?oauth_token=#{@client.oauth_token}?venueId=4b8c3d87f964a520f7c532e3,4d572bcc9e508cfab975189b&v=#{@client.api_version}", "venuegroups/venuegroup_update.json") venuegroup = @client.venuegroup('4e15cd13b61c42e7c54e5bb6') venuegroup.venues.count == 2 end diff --git a/test/test_venues.rb b/test/test_venues.rb index fd849d4..f9ce804 100644 --- a/test/test_venues.rb +++ b/test/test_venues.rb @@ -8,20 +8,20 @@ class TestVenues < Test::Unit::TestCase end should "fetch info for a single venue" do - stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3?oauth_token=#{@client.oauth_token}", "venues/venue.json") + stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue.json") venue = @client.venue('4b8c3d87f964a520f7c532e3') venue.name.should == 'Bridgestone Arena' venue.location.address.should == '501 Broadway' end should "search for venues based on passed criteria" do - stub_get("https://api.foursquare.com/v2/venues/search?ll=36.142064%2C-86.816086&oauth_token=#{@client.oauth_token}&query=coffee", "venues/search_venues.json") + stub_get("https://api.foursquare.com/v2/venues/search?ll=36.142064%2C-86.816086&oauth_token=#{@client.oauth_token}&query=coffee&v=#{@client.api_version}", "venues/search_venues.json") venues = @client.search_venues(:ll => "36.142064,-86.816086", :query => "coffee") venues.groups.first.items.first.name.should == 'Ugly Mugs' end should "search for trending venues around a certain position" do - stub_get("https://api.foursquare.com/v2/venues/trending?ll=36.132832%2C-115.151827&radius=10000&oauth_token=#{@client.oauth_token}", "venues/trending_venues.json") + stub_get("https://api.foursquare.com/v2/venues/trending?ll=36.132832%2C-115.151827&radius=10000&oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/trending_venues.json") venues = @client.trending_venues("36.132832,-115.151827", { :radius => 10000 }) venues.venues.count.should == 2 @@ -29,33 +29,33 @@ class TestVenues < Test::Unit::TestCase end should "search for venues from a tip search" do - stub_get("https://api.foursquare.com/v2/tips/search?ll=-23.013968%2C-45.550802&oauth_token=#{@client.oauth_token}&query=rodoviaria", "venues/search_venues_by_tip.json") + stub_get("https://api.foursquare.com/v2/tips/search?ll=-23.013968%2C-45.550802&oauth_token=#{@client.oauth_token}&query=rodoviaria&v=#{@client.api_version}", "venues/search_venues_by_tip.json") venues = @client.search_venues_by_tip(:ll => "-23.013968,-45.550802", :query => "rodoviaria") venues.first.name.should == "Santa Barbara" end should "not find venues from a tip search" do - stub_get("https://api.foursquare.com/v2/tips/search?ll=-23.013968%2C-45.550802&oauth_token=#{@client.oauth_token}&query=loremlpsun", "venues/no_venues_by_tip.json") + stub_get("https://api.foursquare.com/v2/tips/search?ll=-23.013968%2C-45.550802&oauth_token=#{@client.oauth_token}&query=loremlpsun&v=#{@client.api_version}", "venues/no_venues_by_tip.json") venues = @client.search_venues_by_tip(:ll => "-23.013968,-45.550802", :query => "loremlpsun") venues.size.should == 0 end should "get tips from a venue" do - stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/tips?oauth_token=#{@client.oauth_token}", "venues/venue_tips.json") + stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/tips?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_tips.json") tips = @client.venue_tips('4b8c3d87f964a520f7c532e3') tips.items.first.id.should == "4c94a45c82b56dcb47cad0aa" tips.items.size.should == 4 end should "get tips from a venue only with some term" do - stub_get("https://api.foursquare.com/v2/venues/4c94a45c82b56dcb47cad0aa/tips?oauth_token=#{@client.oauth_token}", "venues/venue_tips.json") + stub_get("https://api.foursquare.com/v2/venues/4c94a45c82b56dcb47cad0aa/tips?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_tips.json") tips = @client.venue_tips('4c94a45c82b56dcb47cad0aa', {:query => "legal"}) tips[:count].should == 1 tips.items.first.id.should == "4c94a45c82b56dcb47cad0aa" end should "get tips from a venue only with some term case sensitive" do - stub_get("https://api.foursquare.com/v2/venues/4c94a45c82b56dcb47cad0aa/tips?oauth_token=#{@client.oauth_token}", "venues/venue_tips.json") + stub_get("https://api.foursquare.com/v2/venues/4c94a45c82b56dcb47cad0aa/tips?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_tips.json") tips = @client.venue_tips('4c94a45c82b56dcb47cad0aa', {:query => "LEGAL"}) tips.items.size.should == 1 @@ -63,20 +63,20 @@ class TestVenues < Test::Unit::TestCase end should "no tips from a venue with term lorem" do - stub_get("https://api.foursquare.com/v2/venues/4c94a45c82b56dcb47cad0aa/tips?oauth_token=#{@client.oauth_token}", "venues/venue_tips.json") + stub_get("https://api.foursquare.com/v2/venues/4c94a45c82b56dcb47cad0aa/tips?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_tips.json") tips = @client.venue_tips('4c94a45c82b56dcb47cad0aa', {:query => "lorem"}) tips[:items].size.should == 0 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=#{@client.oauth_token}&limit=2", "venues/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&v=#{@client.api_version}", "venues/explore_venues.json") venues = @client.explore_venues(:ll => '40.7,-74', :section => 'food', :limit => '2') venues.groups.first.items.count.should == 2 end should "get links for a venue" do - stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/links?oauth_token=#{@client.oauth_token}", "venues/venue_links.json") + stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/links?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_links.json") links = @client.venue_links('4b8c3d87f964a520f7c532e3') links.items.first.linkedId.should == "2513467" links.items.size == links.count @@ -84,7 +84,7 @@ class TestVenues < Test::Unit::TestCase end should "get photos for a venue" do - stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/photos?group=venue&oauth_token=#{@client.oauth_token}&limit=3", "venues/venue_photos.json") + stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/photos?group=venue&oauth_token=#{@client.oauth_token}&limit=3&v=#{@client.api_version}", "venues/venue_photos.json") photos = @client.venue_photos('4b8c3d87f964a520f7c532e3', { :group => 'venue', :limit => 3 }) photos.items.first.id.should == "4edc309e46907c1b44d25ab2" photos['count'].should == 222 @@ -92,20 +92,20 @@ class TestVenues < Test::Unit::TestCase 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", "venues/suggest_completion_venues.json") + stub_get("https://api.foursquare.com/v2/venues/suggestCompletion?oauth_token=#{@client.oauth_token}&ll=40.7%2C-74&query=coffee&v=#{@client.api_version}", "venues/suggest_completion_venues.json") venues = @client.suggest_completion_venues(:ll => "40.7,-74", :query => "coffee") venues.minivenues.first.id.should == '44dc96e4f964a520b0361fe3' end should "fetch venue for manager" do - stub_get("https://api.foursquare.com/v2/venues/managed?oauth_token=#{@client.oauth_token}", "venues/managed_venues.json") + stub_get("https://api.foursquare.com/v2/venues/managed?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/managed_venues.json") venues = @client.managed_venues() venues.first.name.should == 'Black Founders Startup Ventures' venues.first.location.address.should == '625 2nd St' end should "get menus for a venue" do - stub_get("https://api.foursquare.com/v2/venues/4b2a544ff964a5204ca724e3/menu?oauth_token=#{@client.oauth_token}", "venues/venue_menus.json") + stub_get("https://api.foursquare.com/v2/venues/4b2a544ff964a5204ca724e3/menu?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_menus.json") response = @client.venue_menus('4b2a544ff964a5204ca724e3') response.menu.menus.items.count.should == 1 response.menu.menus.items.first.name.should == "Main Menu" @@ -113,7 +113,7 @@ class TestVenues < Test::Unit::TestCase end should "get currently checked in users for a venue" do - stub_get("https://api.foursquare.com/v2/venues/4a1c8506f964a520457b1fe3/herenow?oauth_token=#{@client.oauth_token}", "venues/venue_herenow.json") + stub_get("https://api.foursquare.com/v2/venues/4a1c8506f964a520457b1fe3/herenow?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_herenow.json") response = @client.herenow('4a1c8506f964a520457b1fe3') response.hereNow.count.should == 2 response.hereNow.items.first.user.firstName.should == "Sabine" @@ -121,53 +121,53 @@ class TestVenues < Test::Unit::TestCase end should "get detailed stats for a venue managed by user" do - stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/stats?oauth_token=#{@client.oauth_token}", "venues/venue_stats.json") + stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/stats?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_stats.json") response = @client.managed_venue_stats('4b8c3d87f964a520f7c532e3') response.stats.totalCheckins.should == 1 end should "get a subset of detailed stats for a venue managed by user when passing in options" do - stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/stats?oauth_token=#{@client.oauth_token}&startAt=1343085269&endAt=1343171627", "venues/venue_stats.json") + stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/stats?oauth_token=#{@client.oauth_token}&startAt=1343085269&endAt=1343171627&v=#{@client.api_version}", "venues/venue_stats.json") response = @client.managed_venue_stats('4b8c3d87f964a520f7c532e3', { :startAt => 1343085269, :endAt => 1343171627}) response.stats.totalCheckins.should == 1 end should "get hours from a venue" do - stub_get("https://api.foursquare.com/v2/venues/49d68c61f964a520e65c1fe3/hours?oauth_token=#{@client.oauth_token}", "venues/venue_hours.json") + stub_get("https://api.foursquare.com/v2/venues/49d68c61f964a520e65c1fe3/hours?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_hours.json") response = @client.venue_hours('49d68c61f964a520e65c1fe3') response.hours.timeframes.first.days.should == [1, 2, 3, 4, 5, 6] end should "get events from a venue" do - stub_get("https://api.foursquare.com/v2/venues/40afe980f964a5203bf31ee3/events?oauth_token=#{@client.oauth_token}", "venues/venue_events.json") + stub_get("https://api.foursquare.com/v2/venues/40afe980f964a5203bf31ee3/events?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_events.json") response = @client.venue_events('40afe980f964a5203bf31ee3') response.events.items.first.name.should == 'Nautanki Saala!' response.events.items.size == response.events.count end should "get likes for a venue" do - stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/likes?oauth_token=#{@client.oauth_token}", "venues/venue_likes.json") + stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/likes?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_likes.json") response = @client.venue_likes('4b8c3d87f964a520f7c532e3') response.likes.groups.first.items.first.id.should == '53698158' response.likes.count == 140 end should "get lists for a venue" do - stub_get("https://api.foursquare.com/v2/venues/4989af90f964a5207f521fe3/listed?oauth_token=#{@client.oauth_token}&group=other&limit=4&offset=0", "venues/venue_listed.json") + stub_get("https://api.foursquare.com/v2/venues/4989af90f964a5207f521fe3/listed?oauth_token=#{@client.oauth_token}&group=other&limit=4&offset=0&v=#{@client.api_version}", "venues/venue_listed.json") response = @client.venue_listed('4989af90f964a5207f521fe3', { :group => 'other', :limit => 4, :offset => 0}) response.lists.items.first.id == '4e5b95beb61c4aaa3e182d8d' response.lists.count == 4 end should "get next venues for a venue" do - stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/nextvenues?oauth_token=#{@client.oauth_token}", "venues/venue_nextvenues.json") + stub_get("https://api.foursquare.com/v2/venues/4b8c3d87f964a520f7c532e3/nextvenues?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_nextvenues.json") response = @client.venue_nextvenues('4b8c3d87f964a520f7c532e3') response.nextVenues.items.first.id.should == '4b06a391f964a5200aee22e3' response.nextVenues.count == 5 end should "get similar venues for a venue" do - stub_get("https://api.foursquare.com/v2/venues/40a55d80f964a52020f31ee3/similar?oauth_token=#{@client.oauth_token}", "venues/venue_similar.json") + stub_get("https://api.foursquare.com/v2/venues/40a55d80f964a52020f31ee3/similar?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", "venues/venue_similar.json") response = @client.venue_similar('40a55d80f964a52020f31ee3') response.similarVenues.items.first.id.should == '4b61cec9f964a52023242ae3' response.similarVenues.count == 5 @@ -175,7 +175,7 @@ class TestVenues < Test::Unit::TestCase context "and getting detailed stats for a venue not managed by user" do should "raise a 'not authorized' API error" do - stub_get("https://api.foursquare.com/v2/venues/4ad4c04af964a52065f220e3/stats?oauth_token=#{@client.oauth_token}", nil, + stub_get("https://api.foursquare.com/v2/venues/4ad4c04af964a52065f220e3/stats?oauth_token=#{@client.oauth_token}&v=#{@client.api_version}", nil, :error => { :code => '403', :type => 'not_authorized', :message => 'User is not authorized to view venue stats' }) assert_raises(Foursquare2::APIError) do @client.managed_venue_stats('4ad4c04af964a52065f220e3')