instagram 0.8.5 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -68,6 +68,13 @@ API Usage Examples
68
68
  ------------------
69
69
  require "rubygems"
70
70
  require "instagram"
71
+
72
+ # All methods require authentication (either by client ID or access token).
73
+ # To get your Instagram OAuth credentials, register an app at http://instagr.am/oauth/client/register/
74
+ Instagram.configure do |config|
75
+ config.client_id = YOUR_CLIENT_KEY
76
+ config.access_token = YOUR_ACCESS_TOKEN
77
+ end
71
78
 
72
79
  # Get a list of a user's most recent media
73
80
  puts Instagram.user_recent_media(777)
@@ -78,16 +85,6 @@ API Usage Examples
78
85
  # Get a list of recent media at a given location, in this case, the Instagram office
79
86
  puts Instagram.location_recent_media(514276)
80
87
 
81
- # All methods require authentication (either by client ID or access token).
82
- # To get your Instagram OAuth credentials, register an app at http://instagr.am/oauth/client/register/
83
- Instagram.configure do |config|
84
- config.client_id = YOUR_CLIENT_KEY
85
- config.access_token = YOUR_ACCESS_TOKEN
86
- end
87
-
88
- # Get a list of all the users you're following
89
- puts Instagram.follows
90
-
91
88
  # Get a list of media close to a given latitude and longitude
92
89
  puts Instagram.media_search("37.7808851","-122.3948632")
93
90
 
@@ -97,6 +94,14 @@ API Usage Examples
97
94
  # Search for users on instagram, by name or username
98
95
  puts Instagram.user_search("shayne sweeney")
99
96
 
97
+ # Search for a location by lat/lng
98
+ puts Instagram.location_search("37.7808851","-122.3948632")
99
+
100
+ # Search for a location by Fousquare ID (v2)
101
+ puts Instagram.location_search("3fd66200f964a520c5f11ee3")
102
+
103
+
104
+
100
105
 
101
106
  Contributing
102
107
  ------------
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.post_install_message =<<eos
15
15
  ********************************************************************************
16
16
 
17
- Follow @instagram on Twitter for announcements, updates, and news.
17
+ Follow @instagramapi on Twitter for announcements, updates, and news.
18
18
  https://twitter.com/instagramapi
19
19
 
20
20
  Join the mailing list!
@@ -3,7 +3,7 @@ require 'faraday'
3
3
  # @private
4
4
  module FaradayMiddleware
5
5
  # @private
6
- class OAuth2 < Faraday::Middleware
6
+ class InstagramOAuth2 < Faraday::Middleware
7
7
  def call(env)
8
8
 
9
9
  if env[:method] == :get or env[:method] == :delete
@@ -16,5 +16,6 @@ module Instagram
16
16
  include Instagram::Client::Comments
17
17
  include Instagram::Client::Likes
18
18
  include Instagram::Client::Subscriptions
19
+ include Instagram::Client::Embedding
19
20
  end
20
- end
21
+ end
@@ -0,0 +1,11 @@
1
+ module Instagram
2
+ class Client
3
+ module Embedding
4
+ def oembed(*args)
5
+ url = args.first
6
+ return nil unless url
7
+ get("oembed?url=#{url}", {}, false, true)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -38,20 +38,32 @@ module Instagram
38
38
  response
39
39
  end
40
40
 
41
- # Returns Instagram locations within proximity of given lat,lng
41
+ # Returns Instagram locations within proximity of given lat,lng or foursquare venue id
42
42
  #
43
- # @param lat [String] A given latitude in decimal format
44
- # @param lng [String] A given longitude in decimal format
45
- # @option options [Integer] :count The number of media items to retrieve.
46
- # @return [Array]
47
- # @example Return locations around 37.7808851, -122.3948632 (164 S Park, SF, CA USA)
48
- # Instagram.location_search("37.7808851", "-122.3948632")
43
+ # @overload location_search(options={})
44
+ # @param foursquare_v2_id [String] A valid Foursquare Venue ID (v2)
45
+ # @param lat [String] A given latitude in decimal format
46
+ # @param lng [String] A given longitude in decimal format
47
+ # @option options [Integer] :count The number of media items to retrieve.
48
+ # @return [Array]
49
+ # @example 1: Return a location with the Foursquare Venue ID = ()
50
+ # Instagram.location_search("3fd66200f964a520c5f11ee3") (Schiller's Liquor Bar, 131 Rivington St., NY, NY 10002)
51
+ # @example 2: Return locations around 37.7808851, -122.3948632 (164 S Park, SF, CA USA)
52
+ # Instagram.location_search("37.7808851", "-122.3948632")
49
53
  # @see TODO:doc url
50
54
  # @format :json
51
55
  # @authenticated false
52
56
  # @rate_limited true
53
- def location_search(lat, lng, options={})
54
- response = get('locations/search', options.merge(:lat => lat, :lng => lng))
57
+ def location_search(*args)
58
+ options = args.last.is_a?(Hash) ? args.pop : {}
59
+ case args.size
60
+ when 1
61
+ foursquare_v2_id = args.first
62
+ response = get('locations/search', options.merge(:foursquare_v2_id => foursquare_v2_id))
63
+ when 2
64
+ lat, lng = args
65
+ response = get('locations/search', options.merge(:lat => lat, :lng => lng))
66
+ end
55
67
  response["data"]
56
68
  end
57
69
  end
@@ -15,7 +15,7 @@ module Instagram
15
15
  }
16
16
 
17
17
  Faraday::Connection.new(options) do |connection|
18
- connection.use FaradayMiddleware::OAuth2, client_id, access_token
18
+ connection.use FaradayMiddleware::InstagramOAuth2, client_id, access_token
19
19
  connection.use Faraday::Request::UrlEncoded
20
20
  connection.use FaradayMiddleware::Mashify unless raw
21
21
  unless raw
@@ -4,7 +4,7 @@ module Instagram
4
4
  # Return URL for OAuth authorization
5
5
  def authorize_url(options={})
6
6
  options[:response_type] ||= "code"
7
- params = access_token_params.merge(options)
7
+ params = authorization_params.merge(options)
8
8
  connection.build_url("/oauth/authorize/", params).to_s
9
9
  end
10
10
 
@@ -17,6 +17,12 @@ module Instagram
17
17
 
18
18
  private
19
19
 
20
+ def authorization_params
21
+ {
22
+ :client_id => client_id
23
+ }
24
+ end
25
+
20
26
  def access_token_params
21
27
  {
22
28
  :client_id => client_id,
@@ -1,3 +1,3 @@
1
1
  module Instagram
2
- VERSION = '0.8.5'.freeze unless defined?(::Instagram::VERSION)
2
+ VERSION = '0.9.0'.freeze unless defined?(::Instagram::VERSION)
3
3
  end
@@ -36,7 +36,7 @@ describe Faraday::Response do
36
36
  it "should return the body error message" do
37
37
  expect do
38
38
  @client.user_media_feed()
39
- end.should raise_error(Instagram::BadRequest, /Bad words are bad./)
39
+ end.to raise_error(Instagram::BadRequest, /Bad words are bad./)
40
40
  end
41
41
  end
42
42
  end
@@ -0,0 +1 @@
1
+ {"meta": {"code": 200}, "data": [{"latitude": 40.719607, "longitude": -73.986764, "id": "1075772", "name": "Schiller's Liquor Bar"}]}
@@ -0,0 +1,14 @@
1
+ {
2
+ "provider_url": "http:\/\/instagram.com\/",
3
+ "media_id": "123657555223544123_41812344",
4
+ "title": "I like this title #hash",
5
+ "url": "http:\/\/distilleryimage4.s3.amazonaws.com\/7.jpg",
6
+ "author_name": "my_name",
7
+ "height": 612,
8
+ "width": 612,
9
+ "version": "1.0",
10
+ "author_url": "http:\/\/instagram.com\/",
11
+ "author_id": 1234,
12
+ "type": "photo",
13
+ "provider_name": "Instagram"
14
+ }
@@ -75,13 +75,24 @@ describe Instagram::API do
75
75
  redirect_uri = 'http://localhost:4567/oauth/callback'
76
76
  url = client.authorize_url(:redirect_uri => redirect_uri)
77
77
 
78
- params2 = client.send(:access_token_params).merge(params)
79
- params2[:redirect_uri] = redirect_uri
80
- params2[:response_type] = "code"
78
+ options = {
79
+ :redirect_uri => redirect_uri,
80
+ :response_type => "code"
81
+ }
82
+ params2 = client.send(:authorization_params).merge(options)
83
+
81
84
  url2 = client.send(:connection).build_url("/oauth/authorize/", params2).to_s
82
85
 
83
86
  url2.should == url
84
87
  end
88
+
89
+ it "should not include client secret in URL params" do
90
+ params = { :client_id => "CID", :client_secret => "CS" }
91
+ client = Instagram::Client.new(params)
92
+ redirect_uri = 'http://localhost:4567/oauth/callback'
93
+ url = client.authorize_url(:redirect_uri => redirect_uri)
94
+ url.should_not include("client_secret")
95
+ end
85
96
  end
86
97
 
87
98
  describe ".get_access_token" do
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe Instagram::Client do
4
+ Instagram::Configuration::VALID_FORMATS.each do |format|
5
+ context ".new(:format => '#{format}')" do
6
+ before do
7
+ @client = Instagram::Client.new(:format => format, :client_id => 'CID', :client_secret => 'CS', :access_token => 'AT')
8
+ end
9
+
10
+ describe ".oembed" do
11
+ before do
12
+ stub_get("oembed").
13
+ with(:query => {:access_token => @client.access_token, :url => "http://instagram.com/p/abcdef"}).
14
+ to_return(:body => fixture("oembed.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
15
+ end
16
+
17
+ it "should get the correct resource" do
18
+ @client.oembed("http://instagram.com/p/abcdef")
19
+ a_get("oembed?url=http://instagram.com/p/abcdef").
20
+ with(:query => {:access_token => @client.access_token}).
21
+ should have_been_made
22
+ end
23
+
24
+ it "should return the oembed information for an instagram media url" do
25
+ oembed = @client.oembed("http://instagram.com/p/abcdef")
26
+ oembed.media_id.should == "123657555223544123_41812344"
27
+ end
28
+
29
+ it "should return nil if a URL is not provided" do
30
+ oembed = @client.oembed
31
+ oembed.should be_nil
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -50,7 +50,7 @@ describe Instagram::Client do
50
50
  end
51
51
  end
52
52
 
53
- describe ".location_search" do
53
+ describe ".location_search_lat_lng" do
54
54
 
55
55
  before do
56
56
  stub_get("locations/search.#{format}").
@@ -59,7 +59,7 @@ describe Instagram::Client do
59
59
  to_return(:body => fixture("location_search.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
60
60
  end
61
61
 
62
- it "should get the correct resource" do
62
+ it "should get the correct resource by lat/lng" do
63
63
  @client.location_search("37.7808851", "-122.3948632")
64
64
  a_get("locations/search.#{format}").
65
65
  with(:query => {:access_token => @client.access_token}).
@@ -73,6 +73,31 @@ describe Instagram::Client do
73
73
  locations.first.name.should == "Instagram"
74
74
  end
75
75
  end
76
+
77
+ describe ".location_search_foursquare_v2_id" do
78
+
79
+ before do
80
+ stub_get("locations/search.#{format}").
81
+ with(:query => {:access_token => @client.access_token}).
82
+ with(:query => {:foursquare_v2_id => "3fd66200f964a520c5f11ee3"}).
83
+ to_return(:body => fixture("location_search_fsq.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
84
+ end
85
+
86
+ it "should get the correct resource by foursquare_v2_id" do
87
+ @client.location_search("3fd66200f964a520c5f11ee3")
88
+ a_get("locations/search.#{format}").
89
+ with(:query => {:access_token => @client.access_token}).
90
+ with(:query => {:foursquare_v2_id => "3fd66200f964a520c5f11ee3"}).
91
+ should have_been_made
92
+ end
93
+
94
+ it "should return an array of user search results" do
95
+ locations = @client.location_search("3fd66200f964a520c5f11ee3")
96
+ locations.should be_a Array
97
+ locations.first.name.should == "Schiller's Liquor Bar"
98
+ end
99
+ end
100
+
76
101
  end
77
102
  end
78
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instagram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-13 00:00:00.000000000Z
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70311845220480 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '2.4'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70311845220480
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.4'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: webmock
27
- requirement: &70311845218780 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '1.6'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70311845218780
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.6'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: bluecloth
38
- requirement: &70311845217920 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 2.0.11
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70311845217920
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.11
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: faraday
49
- requirement: &70311845217080 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -57,10 +72,18 @@ dependencies:
57
72
  version: '0.9'
58
73
  type: :runtime
59
74
  prerelease: false
60
- version_requirements: *70311845217080
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0.7'
81
+ - - <
82
+ - !ruby/object:Gem::Version
83
+ version: '0.9'
61
84
  - !ruby/object:Gem::Dependency
62
85
  name: faraday_middleware
63
- requirement: &70311845215700 !ruby/object:Gem::Requirement
86
+ requirement: !ruby/object:Gem::Requirement
64
87
  none: false
65
88
  requirements:
66
89
  - - ~>
@@ -68,10 +91,15 @@ dependencies:
68
91
  version: '0.8'
69
92
  type: :runtime
70
93
  prerelease: false
71
- version_requirements: *70311845215700
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ~>
98
+ - !ruby/object:Gem::Version
99
+ version: '0.8'
72
100
  - !ruby/object:Gem::Dependency
73
101
  name: multi_json
74
- requirement: &70311845214840 !ruby/object:Gem::Requirement
102
+ requirement: !ruby/object:Gem::Requirement
75
103
  none: false
76
104
  requirements:
77
105
  - - ! '>='
@@ -82,10 +110,18 @@ dependencies:
82
110
  version: '1.0'
83
111
  type: :runtime
84
112
  prerelease: false
85
- version_requirements: *70311845214840
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: 1.0.3
119
+ - - ~>
120
+ - !ruby/object:Gem::Version
121
+ version: '1.0'
86
122
  - !ruby/object:Gem::Dependency
87
123
  name: hashie
88
- requirement: &70311845213800 !ruby/object:Gem::Requirement
124
+ requirement: !ruby/object:Gem::Requirement
89
125
  none: false
90
126
  requirements:
91
127
  - - ! '>='
@@ -93,7 +129,12 @@ dependencies:
93
129
  version: 0.4.0
94
130
  type: :runtime
95
131
  prerelease: false
96
- version_requirements: *70311845213800
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: 0.4.0
97
138
  description: A Ruby wrapper for the Instagram REST and Search APIs
98
139
  email:
99
140
  - shayne@instagr.am
@@ -115,6 +156,7 @@ files:
115
156
  - lib/instagram/api.rb
116
157
  - lib/instagram/client.rb
117
158
  - lib/instagram/client/comments.rb
159
+ - lib/instagram/client/embedding.rb
118
160
  - lib/instagram/client/geographies.rb
119
161
  - lib/instagram/client/likes.rb
120
162
  - lib/instagram/client/locations.rb
@@ -142,6 +184,7 @@ files:
142
184
  - spec/fixtures/location.json
143
185
  - spec/fixtures/location_recent_media.json
144
186
  - spec/fixtures/location_search.json
187
+ - spec/fixtures/location_search_fsq.json
145
188
  - spec/fixtures/media.json
146
189
  - spec/fixtures/media_comment.json
147
190
  - spec/fixtures/media_comment_deleted.json
@@ -152,6 +195,7 @@ files:
152
195
  - spec/fixtures/media_search.json
153
196
  - spec/fixtures/media_unliked.json
154
197
  - spec/fixtures/mikeyk.json
198
+ - spec/fixtures/oembed.json
155
199
  - spec/fixtures/recent_media.json
156
200
  - spec/fixtures/relationship.json
157
201
  - spec/fixtures/requested_by.json
@@ -169,6 +213,7 @@ files:
169
213
  - spec/fixtures/user_search.json
170
214
  - spec/instagram/api_spec.rb
171
215
  - spec/instagram/client/comments_spec.rb
216
+ - spec/instagram/client/embedding_spec.rb
172
217
  - spec/instagram/client/geography_spec.rb
173
218
  - spec/instagram/client/likes_spec.rb
174
219
  - spec/instagram/client/locations_spec.rb
@@ -182,7 +227,7 @@ files:
182
227
  homepage: https://github.com/Instagram/instagram-ruby-gem
183
228
  licenses: []
184
229
  post_install_message: ! "********************************************************************************\n\n
185
- \ Follow @instagram on Twitter for announcements, updates, and news.\n https://twitter.com/instagramapi\n\n
230
+ \ Follow @instagramapi on Twitter for announcements, updates, and news.\n https://twitter.com/instagramapi\n\n
186
231
  \ Join the mailing list!\n https://groups.google.com/group/instagram-ruby-gem\n\n********************************************************************************\n"
187
232
  rdoc_options: []
188
233
  require_paths:
@@ -195,7 +240,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
240
  version: '0'
196
241
  segments:
197
242
  - 0
198
- hash: -1111246945157108473
243
+ hash: 3320943877353398037
199
244
  required_rubygems_version: !ruby/object:Gem::Requirement
200
245
  none: false
201
246
  requirements:
@@ -204,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
249
  version: 1.3.6
205
250
  requirements: []
206
251
  rubyforge_project: instagram
207
- rubygems_version: 1.8.10
252
+ rubygems_version: 1.8.23
208
253
  signing_key:
209
254
  specification_version: 3
210
255
  summary: Ruby wrapper for the Instagram API
@@ -222,6 +267,7 @@ test_files:
222
267
  - spec/fixtures/location.json
223
268
  - spec/fixtures/location_recent_media.json
224
269
  - spec/fixtures/location_search.json
270
+ - spec/fixtures/location_search_fsq.json
225
271
  - spec/fixtures/media.json
226
272
  - spec/fixtures/media_comment.json
227
273
  - spec/fixtures/media_comment_deleted.json
@@ -232,6 +278,7 @@ test_files:
232
278
  - spec/fixtures/media_search.json
233
279
  - spec/fixtures/media_unliked.json
234
280
  - spec/fixtures/mikeyk.json
281
+ - spec/fixtures/oembed.json
235
282
  - spec/fixtures/recent_media.json
236
283
  - spec/fixtures/relationship.json
237
284
  - spec/fixtures/requested_by.json
@@ -249,6 +296,7 @@ test_files:
249
296
  - spec/fixtures/user_search.json
250
297
  - spec/instagram/api_spec.rb
251
298
  - spec/instagram/client/comments_spec.rb
299
+ - spec/instagram/client/embedding_spec.rb
252
300
  - spec/instagram/client/geography_spec.rb
253
301
  - spec/instagram/client/likes_spec.rb
254
302
  - spec/instagram/client/locations_spec.rb