instagram 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
data/instagram.gemspec CHANGED
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
5
5
  s.add_development_dependency('rspec', '~> 2.4')
6
6
  s.add_development_dependency('webmock', '~> 1.6')
7
7
  s.add_development_dependency('bluecloth', '~> 2.0.11')
8
- s.add_runtime_dependency('faraday', '~> 0.5.4')
9
- s.add_runtime_dependency('faraday_middleware', '~> 0.3.1')
8
+ s.add_runtime_dependency('faraday', '~> 0.7')
9
+ s.add_runtime_dependency('faraday_middleware', '~> 0.8')
10
10
  s.add_runtime_dependency('multi_json', '~> 1.0.3')
11
11
  s.add_runtime_dependency('hashie', '>= 0.4.0')
12
12
  s.authors = ["Shayne Sweeney"]
@@ -1,13 +1,14 @@
1
1
  require 'faraday'
2
2
 
3
3
  # @private
4
- module Faraday
4
+ module FaradayMiddleware
5
5
  # @private
6
- class Request::OAuth2 < Faraday::Middleware
6
+ class OAuth2 < Faraday::Middleware
7
7
  def call(env)
8
8
 
9
9
  if env[:method] == :get or env[:method] == :delete
10
10
  env[:url].query_values = {} if env[:url].query_values.nil?
11
+
11
12
  if @access_token and not env[:url].query_values["client_secret"]
12
13
  env[:url].query_values = env[:url].query_values.merge(:access_token => @access_token)
13
14
  env[:request_headers] = env[:request_headers].merge('Authorization' => "Token token=\"#{@access_token}\"")
@@ -24,6 +25,8 @@ module Faraday
24
25
  end
25
26
  end
26
27
 
28
+ env[:url].query_values = nil if env[:url].query_values == {}
29
+
27
30
  @app.call env
28
31
  end
29
32
 
@@ -0,0 +1,45 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module FaradayMiddleware
5
+ # @private
6
+ class RaiseHttpException < Faraday::Middleware
7
+ def call(env)
8
+ @app.call(env).on_complete do |response|
9
+ case response[:status].to_i
10
+ when 400
11
+ raise Instagram::BadRequest, error_message_400(response)
12
+ when 404
13
+ raise Instagram::NotFound, error_message_400(response)
14
+ when 500
15
+ raise Instagram::InternalServerError, error_message_500(response, "Something is technically wrong.")
16
+ when 503
17
+ raise Instagram::ServiceUnavailable, error_message_500(response, "Instagram is rate limiting your requests.")
18
+ end
19
+ end
20
+ end
21
+
22
+ def initialize(app)
23
+ super app
24
+ @parser = nil
25
+ end
26
+
27
+ private
28
+
29
+ def error_message_400(response)
30
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
31
+ end
32
+
33
+ def error_body(body)
34
+ if body.nil?
35
+ nil
36
+ elsif body['meta'] and body['meta']['error_message'] and not body['meta']['error_message'].empty?
37
+ ": #{body['meta']['error_message']}"
38
+ end
39
+ end
40
+
41
+ def error_message_500(response, body=nil)
42
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
43
+ end
44
+ end
45
+ end
@@ -1,4 +1,5 @@
1
1
  require 'openssl'
2
+ require 'multi_json'
2
3
 
3
4
  module Instagram
4
5
  class Client
@@ -15,16 +15,16 @@ module Instagram
15
15
  }
16
16
 
17
17
  Faraday::Connection.new(options) do |connection|
18
- connection.use Faraday::Request::OAuth2, client_id, access_token
18
+ connection.use FaradayMiddleware::OAuth2, client_id, access_token
19
+ connection.use Faraday::Request::UrlEncoded
19
20
  connection.adapter(adapter)
20
- connection.use Faraday::Response::RaiseHttp5xx
21
+ connection.use FaradayMiddleware::Mashify unless raw
21
22
  unless raw
22
23
  case format.to_s.downcase
23
24
  when 'json' then connection.use Faraday::Response::ParseJson
24
25
  end
25
26
  end
26
- connection.use Faraday::Response::RaiseHttp4xx
27
- connection.use Faraday::Response::Mashify unless raw
27
+ connection.use FaradayMiddleware::RaiseHttpException
28
28
  end
29
29
  end
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module Instagram
2
- VERSION = '0.8.2'.freeze unless defined?(::Instagram::VERSION)
2
+ VERSION = '0.8.3'.freeze unless defined?(::Instagram::VERSION)
3
3
  end
@@ -5,7 +5,7 @@ describe Instagram::Client do
5
5
  client = Instagram::Client.new
6
6
  endpoint = URI.parse(client.endpoint)
7
7
  connection = client.send(:connection).build_url(nil).to_s
8
- connection.should == endpoint.to_s
8
+ (connection + '/').should == endpoint.to_s
9
9
  end
10
10
 
11
11
  it "should not cache the user account across clients" do
@@ -14,8 +14,7 @@ describe Instagram do
14
14
 
15
15
  it "should get the correct resource" do
16
16
  Instagram.user_media_feed()
17
- a_get("users/self/feed.json").
18
- should have_been_made
17
+ a_get("users/self/feed.json").should have_been_made
19
18
  end
20
19
 
21
20
  it "should return the same results as a client" do
@@ -94,4 +93,4 @@ describe Instagram do
94
93
  end
95
94
  end
96
95
  end
97
- end
96
+ 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.2
4
+ version: 0.8.3
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-02-15 00:00:00.000000000Z
12
+ date: 2012-02-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70334758094220 !ruby/object:Gem::Requirement
16
+ requirement: &70311601093360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.4'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70334758094220
24
+ version_requirements: *70311601093360
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: webmock
27
- requirement: &70334758093000 !ruby/object:Gem::Requirement
27
+ requirement: &70311601092260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.6'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70334758093000
35
+ version_requirements: *70311601092260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bluecloth
38
- requirement: &70334758091900 !ruby/object:Gem::Requirement
38
+ requirement: &70311601091380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,32 +43,32 @@ dependencies:
43
43
  version: 2.0.11
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70334758091900
46
+ version_requirements: *70311601091380
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faraday
49
- requirement: &70334758090960 !ruby/object:Gem::Requirement
49
+ requirement: &70311601090160 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 0.5.4
54
+ version: '0.7'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70334758090960
57
+ version_requirements: *70311601090160
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: faraday_middleware
60
- requirement: &70334758088740 !ruby/object:Gem::Requirement
60
+ requirement: &70311601089040 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
64
64
  - !ruby/object:Gem::Version
65
- version: 0.3.1
65
+ version: '0.8'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70334758088740
68
+ version_requirements: *70311601089040
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: multi_json
71
- requirement: &70334758086720 !ruby/object:Gem::Requirement
71
+ requirement: &70311601087820 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.0.3
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70334758086720
79
+ version_requirements: *70311601087820
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: hashie
82
- requirement: &70334758084100 !ruby/object:Gem::Requirement
82
+ requirement: &70311601086700 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: 0.4.0
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70334758084100
90
+ version_requirements: *70311601086700
91
91
  description: A Ruby wrapper for the Instagram REST and Search APIs
92
92
  email:
93
93
  - shayne@instagr.am
@@ -104,8 +104,7 @@ files:
104
104
  - Rakefile
105
105
  - instagram.gemspec
106
106
  - lib/faraday/oauth2.rb
107
- - lib/faraday/raise_http_4xx.rb
108
- - lib/faraday/raise_http_5xx.rb
107
+ - lib/faraday/raise_http_exception.rb
109
108
  - lib/instagram.rb
110
109
  - lib/instagram/api.rb
111
110
  - lib/instagram/client.rb
@@ -190,7 +189,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
189
  version: '0'
191
190
  segments:
192
191
  - 0
193
- hash: -1332548355430204884
192
+ hash: -68303577616785186
194
193
  required_rubygems_version: !ruby/object:Gem::Requirement
195
194
  none: false
196
195
  requirements:
@@ -1,37 +0,0 @@
1
- require 'faraday'
2
-
3
- # @private
4
- module Faraday
5
- # @private
6
- class Response::RaiseHttp4xx < Response::Middleware
7
- def self.register_on_complete(env)
8
- env[:response].on_complete do |response|
9
- case response[:status].to_i
10
- when 400
11
- raise Instagram::BadRequest, error_message(response)
12
- when 404
13
- raise Instagram::NotFound, error_message(response)
14
- end
15
- end
16
- end
17
-
18
- def initialize(app)
19
- super
20
- @parser = nil
21
- end
22
-
23
- private
24
-
25
- def self.error_message(response)
26
- "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
27
- end
28
-
29
- def self.error_body(body)
30
- if body.nil?
31
- nil
32
- elsif body['meta'] and body['meta']['error_message'] and not body['meta']['error_message'].empty?
33
- ": #{body['meta']['error_message']}"
34
- end
35
- end
36
- end
37
- end
@@ -1,29 +0,0 @@
1
- require 'faraday'
2
-
3
- # @private
4
- module Faraday
5
- # @private
6
- class Response::RaiseHttp5xx < Response::Middleware
7
- def self.register_on_complete(env)
8
- env[:response].on_complete do |response|
9
- case response[:status].to_i
10
- when 500
11
- raise Instagram::InternalServerError, error_message(response, "Something is technically wrong.")
12
- when 503
13
- raise Instagram::ServiceUnavailable, error_message(response, "Instagram is rate limiting your requests.")
14
- end
15
- end
16
- end
17
-
18
- def initialize(app)
19
- super
20
- @parser = nil
21
- end
22
-
23
- private
24
-
25
- def self.error_message(response, body=nil)
26
- "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
27
- end
28
- end
29
- end