Class: Rester::Client::Adapters::HttpAdapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/rester/client/adapters/http_adapter.rb

Defined Under Namespace

Classes: Connection

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Adapter

#headers, #initialize, #request

Constructor Details

This class inherits a constructor from Rester::Client::Adapters::Adapter

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/rester/client/adapters/http_adapter.rb', line 6

def connection
  @connection
end

Class Method Details

.can_connect_to?(service) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
# 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

Instance Method Details

#connect(*args) ⇒ Object

Class Methods



20
21
22
# File 'lib/rester/client/adapters/http_adapter.rb', line 20

def connect(*args)
  nil.tap { @connection = Connection.new(*args) }
end

#connected?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rester/client/adapters/http_adapter.rb', line 24

def connected?
  !!connection
end

#delete!(path, params = {}) ⇒ Object



33
34
35
36
# File 'lib/rester/client/adapters/http_adapter.rb', line 33

def delete!(path, params={})
  _require_connection
  _prepare_response(connection.delete(path, headers: headers, query: params))
end

#get!(path, params = {}) ⇒ Object



28
29
30
31
# File 'lib/rester/client/adapters/http_adapter.rb', line 28

def get!(path, params={})
  _require_connection
  _prepare_response(connection.get(path, headers: headers, query: params))
end

#post!(path, params = {}) ⇒ Object



43
44
45
46
# File 'lib/rester/client/adapters/http_adapter.rb', line 43

def post!(path, params={})
  _require_connection
  _prepare_response(connection.post(path, headers: headers, data: params))
end

#put!(path, params = {}) ⇒ Object



38
39
40
41
# File 'lib/rester/client/adapters/http_adapter.rb', line 38

def put!(path, params={})
  _require_connection
  _prepare_response(connection.put(path, headers: headers, data: params))
end