Class: Proc::Http::Client

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

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



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

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

Instance Method Details

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



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

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

  if task
    make_request(request)
  else
    Async(logger: NullLogger) {
      make_request(request)
    }.wait
  end
end

#closeObject



33
34
35
36
37
38
39
# File 'lib/proc/http/client.rb', line 33

def close
  # TODO: Make sure this works. We should also close / clear after accumulating some amount.
  #
  @responses.each_value(&:close)
  @responses.clear
  @internet.close
end

#countObject



41
42
43
# File 'lib/proc/http/client.rb', line 41

def count
  @responses.count
end