Class: Hactor::HTTP::Client
- Inherits:
-
Delegator
- Object
- Delegator
- Hactor::HTTP::Client
- Defined in:
- lib/hactor/http/client.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#response_class ⇒ Object
readonly
Returns the value of attribute response_class.
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #follow(link, options) ⇒ Object
- #get(url, options) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #traverse(link, options) ⇒ Object
Constructor Details
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
8 9 10 |
# File 'lib/hactor/http/client.rb', line 8 def backend @backend end |
#response_class ⇒ Object (readonly)
Returns the value of attribute response_class.
8 9 10 |
# File 'lib/hactor/http/client.rb', line 8 def response_class @response_class end |
Instance Method Details
#__getobj__ ⇒ Object
44 45 46 |
# File 'lib/hactor/http/client.rb', line 44 def __getobj__ backend end |
#follow(link, options) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/hactor/http/client.rb', line 15 def follow(link, ) context_url = .fetch(:context_url) url = context_url.merge(link.href([:expand_with])) get(url, ) end |
#get(url, options) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/hactor/http/client.rb', line 36 def get(url, ) actor = [:actor] || Hactor::NullActor.new headers = [:headers] response = response_class.new backend.get(url, nil, headers), http_client: self actor.call response end |
#traverse(link, options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/hactor/http/client.rb', line 22 def traverse(link, ) context_url = .fetch(:context_url) method = .fetch(:method).to_s.downcase actor = [:actor] || Hactor::NullActor.new headers = [:headers] body = [:body] url = context_url.merge link.href([:expand_with]) response = response_class.new backend.send(method, url, body, headers), http_client: self actor.call response end |