box_view 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDNiODM0YTdhMjdiMTk4ODg2ZDQ5ZjgzNjdhZTU2M2FmMWNiOTI5ZA==
4
+ ZTlkMjY2ODQzYjJlYjNkYTFkMWZjMzg1ZWU0MDNhYzY1NmRkMTUwNQ==
5
5
  data.tar.gz: !binary |-
6
- NTRhYWVlNmE1MTEzODM0NmE1N2RkN2RhOWI2MDU3OGVjN2NiYWM4OA==
6
+ MTVjZjc4OTBkNDdhZjNhNGFkNjdkNGJiZDhmNDA3Y2M4YzMzYzA5Zg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NTBmZjViZmI4YzQwOTI1OGVmNGRkOGY2NzRkM2JhYzZjYjE2MDRjOTEzMTk3
10
- NjJmZjExNzIxYjM0NGM5NWQyYmFiZTQ2YTk2ZjU1YjhhZDg2NmY4ZWI3ZWFi
11
- MDE3NDExMTg1NWNlODlhYTczZTgxNDg4ZGZiMDU1Y2JkYzJlMDA=
9
+ N2Q5ZGNiMGU2YWJiYzM3MDg2N2RkYjVkOGQ3YzJhNjJiMjU1YzRiNDY0NTFl
10
+ MmMwNmFjMWI3MDUyMGMyZWMyMzNjNTM3OGYzYTFlM2YwNDIxMWFmODJjNDY3
11
+ YWIxNWNhNTA4MzhkNzk3ZDU3NzZiMzYxNWU3ODQwNTA2ZTc3MWY=
12
12
  data.tar.gz: !binary |-
13
- YWQ3MDljNjhlMDBlYWE1Y2JjNjg2Y2JlMDE4NGFjMWI3MjljZDA4NjJkMDEz
14
- ZmMzNGJkMmY5NmU2MTQ4M2NlMzAyNGM5YWUxZDJmMTI0OTI0MTI0OTBjMzhj
15
- Y2I2NGUyM2M5MGYzNzExNDc2NTY5ZjYwNGVhMzA5NzM5NjE5NTQ=
13
+ MzQ3NDk3ZmJhNzgzZDJjMDg5NTM2Zjk3ZTAxMDk2Y2QwYmM2MmM5NGJiYThl
14
+ MjBjODQ1OGNiZTM1NmFkZjM2ODdhYThhYTcxMmNlMDY1MDI5NTA0NTFjMjI5
15
+ YTE0NjNhNGI4OTQyZGE0Y2JmNDI3MWIyZmEwMTlmYmFiNmVmMDI=
data/lib/box_view/http.rb CHANGED
@@ -14,6 +14,7 @@ module BoxView
14
14
  super(msg)
15
15
  end
16
16
  end
17
+ class RequestThrottledError < BoxView::Http::RetryNeededError; end
17
18
 
18
19
  def base_uri(path, params = {})
19
20
  uri = URI.parse("https://view-api.box.com")
@@ -69,18 +70,20 @@ module BoxView
69
70
  end
70
71
 
71
72
  def check_for_error(res)
72
- case res
73
- when Net::HTTPAccepted
73
+ case res.code.to_s
74
+ when '202' # Accepted
74
75
  if res['Retry-After']
75
76
  raise BoxView::Http::RetryNeededError.new('Retry Needed', res['Retry-After'])
76
77
  end
77
- when Net::HTTPBadRequest
78
+ when '400' # Bad Request
78
79
  msg = 'Bad Request'
79
80
  if err_dets = error_details(res)
80
81
  msg += " (#{err_dets})"
81
82
  end
82
83
 
83
84
  raise BoxView::Http::BadRequestError.new(msg)
85
+ when '429' # Too Many Requests
86
+ raise BoxView::Http::RequestThrottledError.new('Request Throttled', res['Retry-After'])
84
87
  end
85
88
  end
86
89
 
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module BoxView
2
4
  module Models
3
5
 
@@ -1,3 +1,3 @@
1
1
  module BoxView
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/spec/http_spec.rb CHANGED
@@ -66,5 +66,24 @@ describe BoxView::Http do
66
66
  end
67
67
  end
68
68
  end
69
+
70
+ context 'given a 429 response' do
71
+ let(:body) do
72
+ '{"message": "Request was throttled. Try again in 2 seconds", "type": "error",
73
+ "request_id": "5b296c69f9f94c0eace43a5912fcbb41"}'
74
+ end
75
+ let(:response) do
76
+ Net::HTTPClientError.new('1.1', '429', 'TOO MANY REQUESTS').tap do |r|
77
+ r['Retry-After'] == '2'
78
+ r.stub(:body).and_return(body)
79
+ end
80
+ end
81
+
82
+ it 'should raise a BoxView::Http:BadRequest with a message indicating the problem' do
83
+ expect { subject }.to raise_error(BoxView::Http::RequestThrottledError) do |error|
84
+ error.retry_after.should == '2'
85
+ end
86
+ end
87
+ end
69
88
  end
70
89
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: box_view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reilly Forshaw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-20 00:00:00.000000000 Z
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler