Class: Syntropy::HTTP::Client

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

Overview

HTTP Client class.

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ Client

Initializes an HTTP client.



11
12
13
# File 'lib/syntropy/http/client.rb', line 11

def initialize(machine)
  @machine = machine
end

Instance Method Details

#get(url, **headers) ⇒ Array

Performs a GET request.

Parameters:

  • url (String)

    URL

  • headers (Hash)

    request headers

Returns:

  • (Array)

    array containing response headers and body



20
21
22
23
24
25
26
27
# File 'lib/syntropy/http/client.rb', line 20

def get(url, **headers, &)
  uri = URI.parse(url)
  headers = headers.merge(
    ':method' => 'GET',
    ':path' => uri.request_uri
  )
  req(uri, **headers, &)
end