Skip to content

Commit

Permalink
Add fallback default version of current date.
Browse files Browse the repository at this point in the history
Fixes #69
  • Loading branch information
mattmueller committed Nov 9, 2013
1 parent c8263f7 commit 6be4ca7
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 72 deletions.
2 changes: 1 addition & 1 deletion lib/foursquare2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 || []
Expand Down
8 changes: 4 additions & 4 deletions test/test_campaigns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/test_checkins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ 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'
checkins.last.user.firstName.should == 'David'
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
Expand Down
6 changes: 6 additions & 0 deletions test/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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$/}]]
Expand Down
4 changes: 2 additions & 2 deletions test/test_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions test/test_lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,54 @@ 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

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
Expand Down
6 changes: 3 additions & 3 deletions test/test_pages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_photos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions test/test_specials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test_tips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."
Expand Down
Loading

0 comments on commit 6be4ca7

Please sign in to comment.