Sha256: 26891b4e569e66525f19edea243167a07618aaf7d2944318bb6d2aecd6a6a267

Contents?: true

Size: 1.25 KB

Versions: 12

Compression:

Stored size: 1.25 KB

Contents

module RestfulResource
  class HttpClient
    class UnprocessableEntity < RuntimeError
      attr_reader :response

      def initialize(response)
        @response = Response.new(body: response.body, headers: response.headers, status: response.code)
      end
    end

    def initialize(authorization: nil)
      @authorization = authorization
    end

    def get(url)
      response = RestClient.get(url, :accept => :json, authorization: @authorization)
      Response.new(body: response.body, headers: response.headers, status: response.code)
    end

    def put(url, data: {})
      begin
        response = RestClient.put(url, data, :accept => :json, authorization: @authorization)
      rescue RestClient::UnprocessableEntity => e
        raise HttpClient::UnprocessableEntity.new(e.response)
      end
      Response.new(body: response.body, headers: response.headers, status: response.code)
    end

    def post(url, data: {})
      begin
        response = RestClient.post(url, data, :accept => :json, authorization: @authorization)
      rescue RestClient::UnprocessableEntity => e
        raise HttpClient::UnprocessableEntity.new(e.response)
      end
      Response.new(body: response.body, headers: response.headers, status: response.code)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
restful_resource-0.8.25 lib/restful_resource/http_client.rb
restful_resource-0.8.24 lib/restful_resource/http_client.rb
restful_resource-0.8.23 lib/restful_resource/http_client.rb
restful_resource-0.8.22 lib/restful_resource/http_client.rb
restful_resource-0.8.21 lib/restful_resource/http_client.rb
restful_resource-0.8.20 lib/restful_resource/http_client.rb
restful_resource-0.8.19 lib/restful_resource/http_client.rb
restful_resource-0.8.18 lib/restful_resource/http_client.rb
restful_resource-0.8.17 lib/restful_resource/http_client.rb
restful_resource-0.8.16 lib/restful_resource/http_client.rb
restful_resource-0.8.15 lib/restful_resource/http_client.rb
restful_resource-0.8.14 lib/restful_resource/http_client.rb