class Rester::Client::Adapters::HttpAdapter
Attributes
connection[R]
Public Class Methods
can_connect_to?(service)
click to toggle source
# File lib/rester/client/adapters/http_adapter.rb, line 9 def can_connect_to?(service) if service.is_a?(URI) uri = service elsif service.is_a?(String) && URI::regexp.match(service) uri = URI(service) end !!uri && ['http', 'https'].include?(uri.scheme) end
Public Instance Methods
connect(url)
click to toggle source
# File lib/rester/client/adapters/http_adapter.rb, line 20 def connect(url) nil.tap { @connection = Connection.new(url, timeout: timeout) } end
connected?()
click to toggle source
# File lib/rester/client/adapters/http_adapter.rb, line 24 def connected? !!connection end
request!(verb, path, encoded_data)
click to toggle source
# File lib/rester/client/adapters/http_adapter.rb, line 28 def request!(verb, path, encoded_data) _require_connection data_key = [:get, :delete].include?(verb) ? :query : :data response = connection.request(verb, path, headers: headers, data_key => encoded_data) _prepare_response(response) end
Private Instance Methods
_prepare_response(response)
click to toggle source
# File lib/rester/client/adapters/http_adapter.rb, line 40 def _prepare_response(response) # We want to format the header keys in the way we would expect it in our # client: X-Rester-Header-Key. # # http://ruby-doc.org/stdlib-2.1.1/libdoc/net/http/rdoc/Net/HTTPHeader.html headers = {}.tap { |h| response.each_capitalized { |k,v| h[k] = v } } [response.code.to_i, headers, response.body] end
_require_connection()
click to toggle source
# File lib/rester/client/adapters/http_adapter.rb, line 49 def _require_connection raise "not connected" unless connected? end