Class: Plz::Commands::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/plz/commands/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(headers: nil, params: nil, method: nil, base_url: nil, path: nil, options: nil) ⇒ Request

Returns a new instance of Request.

Parameters:

  • headers (Hash) (defaults to: nil)
  • params (Hash) (defaults to: nil)
  • method (String) (defaults to: nil)
  • base_url (String) (defaults to: nil)
  • path (String) (defaults to: nil)
  • options (Hash) (defaults to: nil)


10
11
12
13
14
15
16
17
# File 'lib/plz/commands/request.rb', line 10

def initialize(headers: nil, params: nil, method: nil, base_url: nil, path: nil, options: nil)
  @headers = headers
  @params = params
  @method = method
  @base_url = base_url
  @path = path
  @options = options
end

Instance Method Details

#callObject

Sends an HTTP request and logs out the response



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/plz/commands/request.rb', line 20

def call
  response = client.send(@method.downcase, @path, @params, @headers)
  print ResponseRenderer.call(
    status: response.status,
    headers: response.headers,
    body: response.body,
    response_header: flag_to_show_response_header,
    response_body: flag_to_show_response_body,
    color: flag_to_color_response,
  )
rescue Faraday::ConnectionFailed => exception
  puts exception
end