Sha256: 8240cb7820763ac0d503fa3f04b6f9795baa335ad1c98bd27bed859819c052e9

Contents?: true

Size: 899 Bytes

Versions: 8

Compression:

Stored size: 899 Bytes

Contents

require 'restfully/http/adapters/abstract_adapter'
require 'restclient'

module Restfully
  module HTTP
    module Adapters
      class RestClientAdapter < AbstractAdapter
        def initialize(base_uri, options = {})
          super(base_uri, options)
          @options[:user] = @options.delete(:username)
        end
        def get(request)
          begin
            resource = RestClient::Resource.new(request.uri.to_s, @options)
            response = resource.get(request.headers)
            headers = response.headers
            body = response.to_s
            headers.delete(:status)
            status = response.code
          rescue RestClient::ExceptionWithResponse => e
            body = e.http_body
            headers = e.response.to_hash
            status = e.http_code
          end
          Response.new(status, headers, body)
        end
      end
    
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
crohr-restfully-0.2.1 lib/restfully/http/adapters/rest_client_adapter.rb
crohr-restfully-0.2.2 lib/restfully/http/adapters/rest_client_adapter.rb
restfully-0.3.2 lib/restfully/http/adapters/rest_client_adapter.rb
restfully-0.3.1 lib/restfully/http/adapters/rest_client_adapter.rb
restfully-0.3.0 lib/restfully/http/adapters/rest_client_adapter.rb
restfully-0.2.3 lib/restfully/http/adapters/rest_client_adapter.rb
restfully-0.2.2 lib/restfully/http/adapters/rest_client_adapter.rb
restfully-0.2.1 lib/restfully/http/adapters/rest_client_adapter.rb