restful_resource 0.9.3 → 0.9.4
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/lib/restful_resource/http_client.rb +12 -10
 - data/lib/restful_resource/version.rb +1 -1
 - data/spec/restful_resource/http_client_spec.rb +4 -0
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c6a47ee146d262a5463d3cf10f49318a5dab35e5
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: f693fe236ef58a22e5bc3472ad98b6f28d487b54
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 711c0c2caf73eb09d702d2be0d84a714d5bfa5b51ff200a0f89efa91e64a69a82d1f9c039082cf50ae617221bb58b1d8033c8156e68f8c3e832eb8388f53edce
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 4adece4f69337c12fabab85a888cf13d41f97f2d508491e3382ef94df9e19cbc34b78210b32c281b9070f6bc9d220df7f71d803663f395b64d68541f4225de9d
         
     | 
| 
         @@ -51,20 +51,20 @@ module RestfulResource 
     | 
|
| 
       51 
51 
     | 
    
         
             
                  end
         
     | 
| 
       52 
52 
     | 
    
         
             
                end
         
     | 
| 
       53 
53 
     | 
    
         | 
| 
       54 
     | 
    
         
            -
                def get(url)
         
     | 
| 
       55 
     | 
    
         
            -
                  http_request(method: :get, url: url)
         
     | 
| 
      
 54 
     | 
    
         
            +
                def get(url, accept: 'application/json')
         
     | 
| 
      
 55 
     | 
    
         
            +
                  http_request(method: :get, url: url, accept: accept)
         
     | 
| 
       56 
56 
     | 
    
         
             
                end
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
                def delete(url)
         
     | 
| 
       59 
     | 
    
         
            -
                  http_request(method: :delete, url: url)
         
     | 
| 
      
 58 
     | 
    
         
            +
                def delete(url, accept: 'application/json')
         
     | 
| 
      
 59 
     | 
    
         
            +
                  http_request(method: :delete, url: url, accept: accept)
         
     | 
| 
       60 
60 
     | 
    
         
             
                end
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
       62 
     | 
    
         
            -
                def put(url, data: {})
         
     | 
| 
       63 
     | 
    
         
            -
                  http_request(method: :put, url: url, data: data)
         
     | 
| 
      
 62 
     | 
    
         
            +
                def put(url, data: {}, accept: 'application/json')
         
     | 
| 
      
 63 
     | 
    
         
            +
                  http_request(method: :put, url: url, data: data, accept: accept)
         
     | 
| 
       64 
64 
     | 
    
         
             
                end
         
     | 
| 
       65 
65 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
                def post(url, data: {})
         
     | 
| 
       67 
     | 
    
         
            -
                  http_request(method: :post, url: url, data: data)
         
     | 
| 
      
 66 
     | 
    
         
            +
                def post(url, data: {}, accept: 'application/json')
         
     | 
| 
      
 67 
     | 
    
         
            +
                  http_request(method: :post, url: url, data: data, accept: accept)
         
     | 
| 
       68 
68 
     | 
    
         
             
                end
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
                private
         
     | 
| 
         @@ -78,9 +78,11 @@ module RestfulResource 
     | 
|
| 
       78 
78 
     | 
    
         
             
                    end
         
     | 
| 
       79 
79 
     | 
    
         
             
                  end
         
     | 
| 
       80 
80 
     | 
    
         
             
                  Response.new(body: response.body, headers: response.headers, status: response.status)
         
     | 
| 
       81 
     | 
    
         
            -
                rescue Faraday:: 
     | 
| 
      
 81 
     | 
    
         
            +
                rescue Faraday::ResourceNotFound
         
     | 
| 
       82 
82 
     | 
    
         
             
                  raise HttpClient::ResourceNotFound
         
     | 
| 
       83 
     | 
    
         
            -
                rescue Faraday:: 
     | 
| 
      
 83 
     | 
    
         
            +
                rescue Faraday::ConnectionFailed
         
     | 
| 
      
 84 
     | 
    
         
            +
                  raise
         
     | 
| 
      
 85 
     | 
    
         
            +
                rescue Faraday::ClientError => e
         
     | 
| 
       84 
86 
     | 
    
         
             
                  response = e.response
         
     | 
| 
       85 
87 
     | 
    
         
             
                  if response[:status] == 422
         
     | 
| 
       86 
88 
     | 
    
         
             
                    raise HttpClient::UnprocessableEntity.new(response)
         
     | 
| 
         @@ -41,6 +41,10 @@ describe RestfulResource::HttpClient do 
     | 
|
| 
       41 
41 
     | 
    
         
             
                  expect { @http_client.put('http://httpbin.org/status/404', data: { name: 'Mad cow' }) }.to raise_error(RestfulResource::HttpClient::ResourceNotFound)
         
     | 
| 
       42 
42 
     | 
    
         
             
                  expect { @http_client.post('http://httpbin.org/status/404', data: { name: 'Mad cow' }) }.to raise_error(RestfulResource::HttpClient::ResourceNotFound)
         
     | 
| 
       43 
43 
     | 
    
         
             
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                it 'should raise normal exception' do
         
     | 
| 
      
 46 
     | 
    
         
            +
                  expect { @http_client.get('https://localhost:3005') }.to raise_error(Faraday::ConnectionFailed)
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
       44 
48 
     | 
    
         
             
              end
         
     | 
| 
       45 
49 
     | 
    
         | 
| 
       46 
50 
     | 
    
         
             
              describe 'Authentication' do
         
     |