Sha256: 428ebbcc32d4eab6bbc14c5896b31c4c8b2ec1780b12c23f0729e015c7b430aa

Contents?: true

Size: 920 Bytes

Versions: 8

Compression:

Stored size: 920 Bytes

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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
restful_resource-0.8.13 lib/restful_resource/http_client.rb
restful_resource-0.8.12 lib/restful_resource/http_client.rb
restful_resource-0.8.11 lib/restful_resource/http_client.rb
restful_resource-0.8.10 lib/restful_resource/http_client.rb
restful_resource-0.8.9 lib/restful_resource/http_client.rb
restful_resource-0.8.8 lib/restful_resource/http_client.rb
restful_resource-0.8.7 lib/restful_resource/http_client.rb
restful_resource-0.8.6 lib/restful_resource/http_client.rb