Skip to content

Commit

Permalink
Merge branch 'master' of github.com:twoism/foursquare2
Browse files Browse the repository at this point in the history
  • Loading branch information
Hirurg103 committed Oct 7, 2017
2 parents e32a563 + 9d8183f commit 5f24396
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/foursquare2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def configure
require 'foursquare2/pages'
require 'foursquare2/lists'
require 'foursquare2/events'
require 'foursquare2/multi'
require 'foursquare2/client'
require 'foursquare2/api_error'

Expand Down
1 change: 1 addition & 0 deletions lib/foursquare2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Client
include Campaigns
include Lists
include Events
include Multi

attr_reader :client_id, :client_secret, :oauth_token, :api_version, :locale

Expand Down
19 changes: 19 additions & 0 deletions lib/foursquare2/multi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Foursquare2
module Multi

# Retrieve multiple requests
#
# param [Array] queries the uri encoded request urls

def multi(requests, options = {})
escaped_requests = requests.map {|r| CGI.escape(r) }.join(",")

options.merge!(requests: escaped_requests)

response = connection.post do |req|
req.url "multi", options
end
return_error_or_body(response, response.body.response.responses)
end
end
end
Empty file added test/fixtures/multi/multi.json
Empty file.
23 changes: 23 additions & 0 deletions test/test_multi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'helper'

class TestMulti < Test::Unit::TestCase

context "When using the foursquare API and working with multiple requests" do
setup do
@client = foursquare_test_client
end

should "fetch cw for a single venue" do
stub_post("https://api.foursquare.com/v2/multi?oauth_token=#{@client.oauth_token}", "multi/multi.json")
requests = [
"/venues/4b8c3d87f964a520f7c532e3",
"/venues/4b8c3d87f964a520f7c532e3",
]
responses = @client.multi(requests, v: 20150101)

responses.first.response.venue.id.should == "4b8c3d87f964a520f7c532e3"
end

end

end

0 comments on commit 5f24396

Please sign in to comment.