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 +4 -4
 - data/CHANGELOG +4 -0
 - data/README.markdown +2 -1
 - data/lib/raca/account.rb +1 -0
 - data/lib/raca/errors.rb +3 -0
 - data/lib/raca/http_client.rb +32 -14
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1c290f2dd6af19a5ab076f84c52b27387d5f3fd4
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8040a35b98a4fdb5998c7720e6dc8eed505ef5eb
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 69beeb3f67228cb2a6eeb2a44bd8fc95864c53222698925d45699471b1c7ce796d6822edf49cafbd6fe5a9ae97834f0efdaab1d0c94588802c2f6d2987a8446b
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 3cbb4a824710d81018e40d465603165976ac365eefe470c207f09314f0659ebd903f88c8fb4cd46a74511a5a182193efcd0cf3a019e7b55b4f8f8740b6885f75
         
     | 
    
        data/CHANGELOG
    CHANGED
    
    
    
        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
    
    
    
        data/lib/raca/errors.rb
    CHANGED
    
    
    
        data/lib/raca/http_client.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
                   
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                   
     | 
| 
       42 
     | 
    
         
            -
                   
     | 
| 
      
 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. 
     | 
| 
       87 
     | 
    
         
            -
                     
     | 
| 
       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. 
     | 
| 
      
 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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-04-23 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rake
         
     |