dropbox-api 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1474a34de5bf86752d2a0fc373aa9d556e80cc6
4
+ data.tar.gz: dc33512fa9132a5e9c12f36156328294309f2cb5
5
+ SHA512:
6
+ metadata.gz: ece9abc626bfcd3f8920614b8db8de0ead7004713e33c80190ae34b47f20740ea5d9800d3fb4abb19202b1712ba2b07a5a5a3118b690dba3971056119c41b215
7
+ data.tar.gz: 9ec8f8012d2a3b3967fa2d1973b9eb9dfc317abfb3f515439ed7ba3c1609468e6e365758ae2ccba5789dff1bd7855030c9e3067fbfbb94274ee290e97047a5fb
@@ -10,20 +10,36 @@ module Dropbox
10
10
  raise Dropbox::API::Error::ConnectionFailed if !response
11
11
  status = response.code.to_i
12
12
  case status
13
+ when 400
14
+ parsed = MultiJson.decode(response.body)
15
+ raise Dropbox::API::Error::BadInput.new("400 - Bad input parameter - #{parsed['error']}")
13
16
  when 401
14
- raise Dropbox::API::Error::Unauthorized
17
+ raise Dropbox::API::Error::Unauthorized.new("401 - Bad or expired token")
15
18
  when 403
16
19
  parsed = MultiJson.decode(response.body)
17
- raise Dropbox::API::Error::Forbidden.new(parsed["error"])
20
+ raise Dropbox::API::Error::Forbidden.new('403 - Bad OAuth request')
18
21
  when 404
19
- raise Dropbox::API::Error::NotFound
20
- when 400, 406
22
+ raise Dropbox::API::Error::NotFound.new("404 - Not found")
23
+ when 405
24
+ parsed = MultiJson.decode(response.body)
25
+ raise Dropbox::API::Error::WrongMethod.new("405 - Request method not expected - #{parsed['error']}")
26
+ when 406
21
27
  parsed = MultiJson.decode(response.body)
22
- raise Dropbox::API::Error.new(parsed["error"])
28
+ raise Dropbox::API::Error.new("#{status} - #{parsed['error']}")
29
+ when 429
30
+ raise Dropbox::API::Error::RateLimit.new('429 - Rate Limiting in affect')
23
31
  when 300..399
24
- raise Dropbox::API::Error::Redirect
25
- when 500..599
26
- raise Dropbox::API::Error
32
+ raise Dropbox::API::Error::Redirect.new("#{status} - Redirect Error")
33
+ when 503
34
+ parsed = MultiJson.decode(response.body)
35
+ header_parse = MultiJson.decode(response.headers)
36
+ error_message = "#{parsed["error"]}. Retry after: #{header_parse['Retry-After']}"
37
+ raise Dropbox::API::Error.new("503 - #{error_message}")
38
+ when 507
39
+ raise Dropbox::API::Error::StorageQuota.new("507 - Dropbox storage quota exceeded.")
40
+ when 500..502, 504..506, 508..599
41
+ parsed = MultiJson.decode(response.body)
42
+ raise Dropbox::API::Error.new("#{status} - Server error. Check http://status.dropbox.com/")
27
43
  else
28
44
  options[:raw] ? response.body : MultiJson.decode(response.body)
29
45
  end
@@ -3,12 +3,16 @@ module Dropbox
3
3
 
4
4
  class Error < StandardError
5
5
 
6
+ class BadInput < Error; end
6
7
  class ConnectionFailed < Error; end
7
8
  class Config < Error; end
8
9
  class Unauthorized < Error; end
9
10
  class Forbidden < Error; end
10
11
  class NotFound < Error; end
11
12
  class Redirect < Error; end
13
+ class WrongMethod < Error; end
14
+ class RateLimit < Error; end
15
+ class StorageQuota < Error; end
12
16
 
13
17
  end
14
18
 
@@ -1,5 +1,5 @@
1
1
  module Dropbox
2
2
  module API
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.2"
4
4
  end
5
5
  end
@@ -10,62 +10,91 @@ describe Dropbox::API::Connection do
10
10
  describe "#request" do
11
11
 
12
12
  it "returns a parsed response when the response is a 200" do
13
- response = mock :code => 200, :body => '{ "a":1}'
13
+ response = double :code => 200, :body => '{ "a":1}'
14
14
  response = @connection.request { response }
15
15
  response.should be_an_instance_of(Hash)
16
16
  end
17
17
 
18
18
  it "raises a Dropbox::API::Error::Unauthorized when the response is a 401" do
19
- response = mock :code => 401, :body => '{ "a":1}'
19
+ response = double :code => 401, :body => '{ "a":1}'
20
20
  lambda do
21
21
  @connection.request { response }
22
- end.should raise_error(Dropbox::API::Error::Unauthorized)
22
+ end.should raise_error(Dropbox::API::Error::Unauthorized, '401 - Bad or expired token')
23
23
  end
24
24
 
25
25
  it "raises a Dropbox::API::Error::Forbidden when the response is a 403" do
26
- response = mock :code => 403, :body => '{ "a":1}'
26
+ response = double :code => 403, :body => '{ "a":1}'
27
27
  lambda do
28
28
  @connection.request { response }
29
- end.should raise_error(Dropbox::API::Error::Forbidden)
29
+ end.should raise_error(Dropbox::API::Error::Forbidden, '403 - Bad OAuth request')
30
30
  end
31
31
 
32
32
  it "raises a Dropbox::API::Error::NotFound when the response is a 404" do
33
- response = mock :code => 404, :body => '{ "a":1}'
33
+ response = double :code => 404, :body => '{ "a":1}'
34
34
  lambda do
35
35
  @connection.request { response }
36
- end.should raise_error(Dropbox::API::Error::NotFound)
36
+ end.should raise_error(Dropbox::API::Error::NotFound, '404 - Not found')
37
+ end
38
+
39
+ it "raises a Dropbox::API::Error::WrongMethod when the response is a 405" do
40
+ response = double :code => 405, :body => '{ "error": "The requested method GET is not allowed for the URL /foo/." }'
41
+ lambda do
42
+ @connection.request { response }
43
+ end.should raise_error(Dropbox::API::Error::WrongMethod, '405 - Request method not expected - The requested method GET is not allowed for the URL /foo/.')
37
44
  end
38
45
 
39
46
  it "raises a Dropbox::API::Error when the response is a 3xx" do
40
- response = mock :code => 301, :body => '{ "a":1}'
47
+ response = double :code => 301, :body => '{ "a":1}'
41
48
  lambda do
42
49
  @connection.request { response }
43
- end.should raise_error(Dropbox::API::Error::Redirect)
50
+ end.should raise_error(Dropbox::API::Error::Redirect, '301 - Redirect Error')
44
51
  end
45
52
 
46
53
  it "raises a Dropbox::API::Error when the response is a 5xx" do
47
- response = mock :code => 500, :body => '{ "a":1}'
54
+ response = double :code => 500, :body => '{ "a":1}'
48
55
  lambda do
49
56
  @connection.request { response }
50
- end.should raise_error(Dropbox::API::Error)
57
+ end.should raise_error(Dropbox::API::Error, '500 - Server error. Check http://status.dropbox.com/')
51
58
  end
52
59
 
53
60
  it "raises a Dropbox::API::Error when the response is a 400" do
54
- response = mock :code => 400, :body => '{ "error": "bad request" }'
61
+ response = double :code => 400, :body => '{ "error": "bad request foo" }'
62
+ lambda do
63
+ @connection.request { response }
64
+ end.should raise_error(Dropbox::API::Error::BadInput, '400 - Bad input parameter - bad request foo')
65
+ end
66
+
67
+ it "raises a Dropbox::API::Error when the response is a 406" do
68
+ response = double :code => 406, :body => '{ "error": "bad request bar" }'
55
69
  lambda do
56
70
  @connection.request { response }
57
- end.should raise_error(Dropbox::API::Error)
71
+ end.should raise_error(Dropbox::API::Error, '406 - bad request bar')
58
72
  end
59
73
 
60
74
  it "raises a Dropbox::API::Error when the response is a 406" do
61
- response = mock :code => 406, :body => '{ "error": "bad request" }'
75
+ response = double :code => 429, :body => '{ "error": "rate limited" }'
76
+ lambda do
77
+ @connection.request { response }
78
+ end.should raise_error(Dropbox::API::Error::RateLimit, '429 - Rate Limiting in affect')
79
+ end
80
+
81
+ it "raises a Dropbox::API::Error when the response is a 503" do
82
+ response = double :code => 503, :body => '{ "error": "rate limited" }', :headers => '{ "Retry-After": "50" }'
83
+ lambda do
84
+ @connection.request { response }
85
+ end.should raise_error(Dropbox::API::Error, '503 - rate limited. Retry after: 50')
86
+ end
87
+
88
+ it "raises a Dropbox::API::Error::StorageQuota when the response is a 507" do
89
+ response = double :code => 507, :body => '{ "error": "quote limit" }'
62
90
  lambda do
63
91
  @connection.request { response }
64
- end.should raise_error(Dropbox::API::Error)
92
+ end.should raise_error(Dropbox::API::Error, '507 - Dropbox storage quota exceeded.')
65
93
  end
66
94
 
95
+
67
96
  it "returns the raw response if :raw => true is provided" do
68
- response = mock :code => 200, :body => '{ "something": "more" }'
97
+ response = double :code => 200, :body => '{ "something": "more" }'
69
98
  response = @connection.request(:raw => true) { response }
70
99
  response.should == '{ "something": "more" }'
71
100
  end
@@ -83,7 +112,7 @@ describe Dropbox::API::Connection do
83
112
  describe "errors" do
84
113
 
85
114
  it "recovers error with rescue statement modifier" do
86
- expect { raise Dropbox::API::Error rescue nil }.to_not raise_error(Dropbox::API::Error)
115
+ expect { raise Dropbox::API::Error rescue nil }.to_not raise_error
87
116
  end
88
117
 
89
118
  it "recovers any kind of errors with the generic error" do
@@ -5,7 +5,7 @@ describe Dropbox::API::OAuth do
5
5
  describe ".consumer" do
6
6
 
7
7
  it "raises an error if config options are not provided" do
8
- Dropbox::API::Config.stub!(:app_key).and_return(nil)
8
+ Dropbox::API::Config.stub(:app_key).and_return(nil)
9
9
  lambda {
10
10
  Dropbox::API::OAuth.consumer :main
11
11
  }.should raise_error(Dropbox::API::Error::Config)
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropbox-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
5
- prerelease:
4
+ version: 0.4.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Marcin Bunsch
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-16 00:00:00.000000000 Z
11
+ date: 2014-02-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: multi_json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: oauth
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: hashie
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: To deliver a more Rubyesque experience when using the DropBox API.
@@ -103,33 +96,26 @@ files:
103
96
  - spec/support/jpeg.rb
104
97
  homepage: http://github.com/futuresimple/dropbox-api
105
98
  licenses: []
99
+ metadata: {}
106
100
  post_install_message:
107
101
  rdoc_options: []
108
102
  require_paths:
109
103
  - lib
110
104
  required_ruby_version: !ruby/object:Gem::Requirement
111
- none: false
112
105
  requirements:
113
- - - ! '>='
106
+ - - '>='
114
107
  - !ruby/object:Gem::Version
115
108
  version: '0'
116
- segments:
117
- - 0
118
- hash: -720354913055572093
119
109
  required_rubygems_version: !ruby/object:Gem::Requirement
120
- none: false
121
110
  requirements:
122
- - - ! '>='
111
+ - - '>='
123
112
  - !ruby/object:Gem::Version
124
113
  version: '0'
125
- segments:
126
- - 0
127
- hash: -720354913055572093
128
114
  requirements: []
129
115
  rubyforge_project: dropbox-api
130
- rubygems_version: 1.8.25
116
+ rubygems_version: 2.0.5
131
117
  signing_key:
132
- specification_version: 3
118
+ specification_version: 4
133
119
  summary: A Ruby client for the DropBox REST API.
134
120
  test_files:
135
121
  - spec/connection.sample.yml
@@ -143,3 +129,4 @@ test_files:
143
129
  - spec/spec_helper.rb
144
130
  - spec/support/config.rb
145
131
  - spec/support/jpeg.rb
132
+ has_rdoc: