Class: Proc::Http::Client

Inherits:
Object
  • Object
show all
Includes:
Is::Async
Defined in:
lib/proc/http/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



18
19
20
# File 'lib/proc/http/client.rb', line 18

def initialize
  @internet = Async::HTTP::Internet.new
end

Instance Method Details

#call(method, uri, params: {}, headers: {}, body: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/proc/http/client.rb', line 22

def call(method, uri, params: {}, headers: {}, body: nil)
  request = Request.new(method: method, uri: uri, params: params, headers: headers, body: body)

  await {
    begin
      response = make_request(request)

      yield response
    ensure
      response&.close
    end
  }
end

#closeObject



36
37
38
# File 'lib/proc/http/client.rb', line 36

def close
  @internet.close
end