Permalink
Browse files

Merge pull request #52 from roomnoise/search_by_foursquare_v2_id

Locations search by Foursquare V2 ID
  • Loading branch information...
2 parents 65f723a + b8ff86f commit 33dd945f22c0e5f62e4359ed068d38258d7bde71 @shayne shayne committed Feb 21, 2013
Showing with 57 additions and 11 deletions.
  1. +8 −0 README.md
  2. +21 −9 lib/instagram/client/locations.rb
  3. +1 −0 spec/fixtures/location_search_fsq.json
  4. +27 −2 spec/instagram/client/locations_spec.rb
View
@@ -97,6 +97,14 @@ API Usage Examples
# Search for users on instagram, by name or username
puts Instagram.user_search("shayne sweeney")
+ # Search for a location by lat/lng
+ puts Instagram.location_search("37.7808851","-122.3948632")
+
+ # Search for a location by Fousquare ID (v2)
+ puts Instagram.location_search("3fd66200f964a520c5f11ee3")
+
+
+
Contributing
------------
@@ -38,20 +38,32 @@ def location_recent_media(id, *args)
response
end
- # Returns Instagram locations within proximity of given lat,lng
+ # Returns Instagram locations within proximity of given lat,lng or foursquare venue id
#
- # @param lat [String] A given latitude in decimal format
- # @param lng [String] A given longitude in decimal format
- # @option options [Integer] :count The number of media items to retrieve.
- # @return [Array]
- # @example Return locations around 37.7808851, -122.3948632 (164 S Park, SF, CA USA)
- # Instagram.location_search("37.7808851", "-122.3948632")
+ # @overload location_search(options={})
+ # @param foursquare_v2_id [String] A valid Foursquare Venue ID (v2)
+ # @param lat [String] A given latitude in decimal format
+ # @param lng [String] A given longitude in decimal format
+ # @option options [Integer] :count The number of media items to retrieve.
+ # @return [Array]
+ # @example 1: Return a location with the Foursquare Venue ID = ()
+ # Instagram.location_search("3fd66200f964a520c5f11ee3") (Schiller's Liquor Bar, 131 Rivington St., NY, NY 10002)
+ # @example 2: Return locations around 37.7808851, -122.3948632 (164 S Park, SF, CA USA)
+ # Instagram.location_search("37.7808851", "-122.3948632")
# @see TODO:doc url
# @format :json
# @authenticated false
# @rate_limited true
- def location_search(lat, lng, options={})
- response = get('locations/search', options.merge(:lat => lat, :lng => lng))
+ def location_search(*args)
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ case args.size
+ when 1
+ foursquare_v2_id = args.first
+ response = get('locations/search', options.merge(:foursquare_v2_id => foursquare_v2_id))
+ when 2
+ lat, lng = args
+ response = get('locations/search', options.merge(:lat => lat, :lng => lng))
+ end
response["data"]
end
end
@@ -0,0 +1 @@
+{"meta": {"code": 200}, "data": [{"latitude": 40.719607, "longitude": -73.986764, "id": "1075772", "name": "Schiller's Liquor Bar"}]}
@@ -50,7 +50,7 @@
end
end
- describe ".location_search" do
+ describe ".location_search_lat_lng" do
before do
stub_get("locations/search.#{format}").
@@ -59,7 +59,7 @@
to_return(:body => fixture("location_search.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end
- it "should get the correct resource" do
+ it "should get the correct resource by lat/lng" do
@client.location_search("37.7808851", "-122.3948632")
a_get("locations/search.#{format}").
with(:query => {:access_token => @client.access_token}).
@@ -73,6 +73,31 @@
locations.first.name.should == "Instagram"
end
end
+
+ describe ".location_search_foursquare_v2_id" do
+
+ before do
+ stub_get("locations/search.#{format}").
+ with(:query => {:access_token => @client.access_token}).
+ with(:query => {:foursquare_v2_id => "3fd66200f964a520c5f11ee3"}).
+ to_return(:body => fixture("location_search_fsq.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
+ end
+
+ it "should get the correct resource by foursquare_v2_id" do
+ @client.location_search("3fd66200f964a520c5f11ee3")
+ a_get("locations/search.#{format}").
+ with(:query => {:access_token => @client.access_token}).
+ with(:query => {:foursquare_v2_id => "3fd66200f964a520c5f11ee3"}).
+ should have_been_made
+ end
+
+ it "should return an array of user search results" do
+ locations = @client.location_search("3fd66200f964a520c5f11ee3")
+ locations.should be_a Array
+ locations.first.name.should == "Schiller's Liquor Bar"
+ end
+ end
+
end
end
end

0 comments on commit 33dd945

Please sign in to comment.