Class: IGMarkets::RequestFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/ig_markets/request_formatter.rb

Overview

This class contains methods for formatting a REST request and its response for inspection and debugging.

Class Method Summary collapse

Class Method Details

.format_request(options) ⇒ String

Formats a request options hash that is ready to be passed to ‘Excon`.

Parameters:

  • options (Hash)

    The request options.

Returns:

  • (String)

    The formatted request.



12
13
14
15
16
17
18
19
# File 'lib/ig_markets/request_formatter.rb', line 12

def format_request(options)
  result = "#{options[:method].to_s.upcase} #{options[:url]}\n"

  result += format_request_headers options[:headers]
  result += format_request_body options[:body]

  result
end

.format_response(response) ⇒ String

Formats a response received from ‘Excon`.

Parameters:

  • response (#headers, #body)

    The response.

Returns:

  • (String)

    The formatted response.



26
27
28
29
30
31
32
33
# File 'lib/ig_markets/request_formatter.rb', line 26

def format_response(response)
  result = "  Response:\n"

  result += format_response_headers response.headers
  result += format_response_body response.body

  result
end