Class: Hactor::HTTP::Client

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/hactor/http/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/hactor/http/client.rb', line 9

def initialize(options={})
  @response_class = options.fetch(:response_class) { Hactor::HTTP::Response }
  @backend = options.fetch(:backend) { Faraday.new }
  super(@backend)
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



7
8
9
# File 'lib/hactor/http/client.rb', line 7

def backend
  @backend
end

#response_classObject (readonly)

Returns the value of attribute response_class.



7
8
9
# File 'lib/hactor/http/client.rb', line 7

def response_class
  @response_class
end

Instance Method Details

#follow(link, options = {}) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/hactor/http/client.rb', line 15

def follow(link, options = {})
  actor = options.fetch(:actor)
  context_url = options.fetch(:context_url)

  url = context_url.merge(link.href)
  get(url: url, actor: actor)
end

#get(options) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/hactor/http/client.rb', line 23

def get(options)
  url = options.fetch :url
  actor = options.fetch :actor

  response = response_class.new(backend.get(url),
                                http_client: self)
  actor.call response
end