raca 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09f97899c1e739f1f0e14a11a4a6ef9d42dd516f
4
- data.tar.gz: a2955d1c12e809dc132be52d9564f9e23cdf677d
3
+ metadata.gz: 1c290f2dd6af19a5ab076f84c52b27387d5f3fd4
4
+ data.tar.gz: 8040a35b98a4fdb5998c7720e6dc8eed505ef5eb
5
5
  SHA512:
6
- metadata.gz: d743838723bf414aae9716e8eb87173a814cb0c70fd2dfd3ef60a61c732de574e2111733b1aba69e30f27310d9f02a98bb62b1651824f53903e3c8c32cf4735b
7
- data.tar.gz: d16ab2778fe4ae974808015c56be1cc9a4d6463d494c7e591ca949d74b7fa36fb5fea20bb640b0ae400c1df5b66d43fc2b6a7b806dcd9c20cf9833cdd420f51c
6
+ metadata.gz: 69beeb3f67228cb2a6eeb2a44bd8fc95864c53222698925d45699471b1c7ce796d6822edf49cafbd6fe5a9ae97834f0efdaab1d0c94588802c2f6d2987a8446b
7
+ data.tar.gz: 3cbb4a824710d81018e40d465603165976ac365eefe470c207f09314f0659ebd903f88c8fb4cd46a74511a5a182193efcd0cf3a019e7b55b4f8f8740b6885f75
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ v0.3.2 (23rd April 2014)
2
+ * Bugfix: correctly handle a 401 response when a stale token is used for
3
+ a streaming PUT
4
+
1
5
  v0.3.1(14th April 2014)
2
6
  * Add the rackspace transaction ID to HTTP exceptions
3
7
 
data/README.markdown CHANGED
@@ -155,7 +155,8 @@ As of version 1.20.0, fog supports dozens of providers, contains ~152000 lines
155
155
  of ruby and adds ~500ms to the boot time of our rails apps. raca is a
156
156
  lightweight, rackspace-only alternative with minimal dependencies that should
157
157
  have a negligable impact on application boot times. Version 0.3 has ~700 lines of
158
- ruby (excluding specs).
158
+ ruby (excluding specs). It also does *much* less than fog. We can't have our cake
159
+ and eat it too.
159
160
 
160
161
  ## Compatibility
161
162
 
data/lib/raca/account.rb CHANGED
@@ -121,6 +121,7 @@ module Raca
121
121
  def raise_on_error(response)
122
122
  error_klass = case response.code.to_i
123
123
  when 400 then BadRequestError
124
+ when 401 then UnauthorizedError
124
125
  when 404 then NotFoundError
125
126
  when 500 then ServerError
126
127
  else
data/lib/raca/errors.rb CHANGED
@@ -5,6 +5,9 @@ module Raca
5
5
  # for 400 responses from rackspace
6
6
  class BadRequestError < HTTPError; end
7
7
 
8
+ # for 401 responses from rackspace
9
+ class UnauthorizedError < HTTPError; end
10
+
8
11
  # for 404 responses from rackspace
9
12
  class NotFoundError < HTTPError; end
10
13
 
@@ -21,35 +21,60 @@ module Raca
21
21
 
22
22
  def get(path, headers = {}, &block)
23
23
  cloud_request(Net::HTTP::Get.new(path, headers), &block)
24
+ rescue Raca::UnauthorizedError
25
+ @account.refresh_cache
26
+ cloud_request(Net::HTTP::Get.new(path, headers), &block)
24
27
  end
25
28
 
26
29
  def head(path, headers = {})
27
30
  cloud_request(Net::HTTP::Head.new(path, headers))
31
+ rescue Raca::UnauthorizedError
32
+ @account.refresh_cache
33
+ cloud_request(Net::HTTP::Head.new(path, headers))
28
34
  end
29
35
 
30
36
  def delete(path, headers = {})
31
37
  cloud_request(Net::HTTP::Delete.new(path, headers))
38
+ rescue Raca::UnauthorizedError
39
+ @account.refresh_cache
40
+ cloud_request(Net::HTTP::Delete.new(path, headers))
32
41
  end
33
42
 
34
43
  def put(path, headers = {})
35
44
  cloud_request(Net::HTTP::Put.new(path, headers))
45
+ rescue Raca::UnauthorizedError
46
+ @account.refresh_cache
47
+ cloud_request(Net::HTTP::Put.new(path, headers))
36
48
  end
37
49
 
38
50
  def streaming_put(path, io, byte_count, headers = {})
39
- request = Net::HTTP::Put.new(path, headers)
40
- request.body_stream = io
41
- request.content_length = byte_count
42
- cloud_request(request)
51
+ cloud_request(build_streaming_put_request(path, io, byte_count, headers))
52
+ rescue Raca::UnauthorizedError
53
+ @account.refresh_cache
54
+ io.rewind if io.respond_to?(:rewind)
55
+ cloud_request(build_streaming_put_request(path, io, byte_count, headers))
43
56
  end
44
57
 
45
58
  def post(path, body, headers = {})
46
59
  request = Net::HTTP::Post.new(path, headers)
47
60
  request.body = body if body
48
61
  cloud_request(request)
62
+ rescue Raca::UnauthorizedError
63
+ @account.refresh_cache
64
+ request = Net::HTTP::Post.new(path, headers)
65
+ request.body = body if body
66
+ cloud_request(request)
49
67
  end
50
68
 
51
69
  private
52
70
 
71
+ def build_streaming_put_request(path, io, byte_count, headers)
72
+ request = Net::HTTP::Put.new(path, headers)
73
+ request.body_stream = io
74
+ request.content_length = byte_count
75
+ request
76
+ end
77
+
53
78
  # perform an HTTP request to rackpsace.
54
79
  #
55
80
  # request is a Net::HTTP request object.
@@ -83,16 +108,8 @@ module Raca
83
108
  end
84
109
 
85
110
  def cloud_http(&block)
86
- Net::HTTP.new(@hostname, 443).tap {|http|
87
- http.use_ssl = true
88
- http.read_timeout = 70
89
- }.start do |http|
90
- response = block.call http
91
- if response.is_a?(Net::HTTPUnauthorized)
92
- log "Rackspace returned HTTP 401; refreshing auth before retrying."
93
- @account.refresh_cache
94
- response = block.call http
95
- end
111
+ Net::HTTP.start(@hostname, 443, use_ssl: true, read_timeout: 70) do |http|
112
+ response = block.call(http)
96
113
  if response.is_a?(Net::HTTPSuccess)
97
114
  response
98
115
  else
@@ -104,6 +121,7 @@ module Raca
104
121
  def raise_on_error(response)
105
122
  error_klass = case response.code.to_i
106
123
  when 400 then BadRequestError
124
+ when 401 then UnauthorizedError
107
125
  when 404 then NotFoundError
108
126
  when 500 then ServerError
109
127
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Healy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-14 00:00:00.000000000 Z
11
+ date: 2014-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake