Method: Yt::HTTPRequest#initialize

Defined in:
lib/yt/http_request.rb

#initialize(options = {}) ⇒ HTTPRequest

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes a Request object.

Parameters:

  • options (Hash) (defaults to: {})

    the options for the request.

Options Hash (options):

  • :method (Symbol) — default: :get

    The HTTP method to use.

  • :host (String)

    The host of the request URI.

  • :path (String)

    The path of the request URI.

  • :params (Hash) — default: {}

    The params to use as the query component of the request URI, for instance the Hash {a: 1, b: 2} corresponds to the query parameters “a=1&b=2”.

  • :headers (Hash) — default: {}

    The headers of the request.

  • :body (#size)

    The body of the request.

  • :request_format (Hash) — default: :json

    The format of the requesty body. If a request body is passed, it will be parsed according to this format before sending it in the request.

  • :error_message (Proc)

    The block that will be invoked when a request fails.



33
34
35
36
37
38
39
40
41
42
# File 'lib/yt/http_request.rb', line 33

def initialize(options = {})
  @method = options.fetch :method, :get
  @host = options.fetch :host, 'www.googleapis.com'
  @path = options[:path]
  @params = options.fetch :params, {}
  @headers = options.fetch :headers, {}
  @body = options[:body]
  @request_format = options.fetch :request_format, :json
  @error_message = options.fetch :error_message, ->(code) {"Error: #{code}"}
end