Class: Yt::HTTPRequest Private
- Inherits:
-
Object
- Object
- Yt::HTTPRequest
- Defined in:
- lib/yt/http_request.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A wrapper around Net::HTTP
to send HTTP requests to any web API and return their result or raise an error if the result is unexpected. The basic way to use Request is by calling run
on an instance.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ HTTPRequest
constructor
private
Initializes a Request object.
-
#run ⇒ Net::HTTPResponse
private
Sends the request and returns the response with the body parsed from JSON.
Constructor Details
#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.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/yt/http_request.rb', line 33 def initialize( = {}) @method = .fetch :method, :get @host = .fetch :host, 'www.googleapis.com' @path = [:path] @params = .fetch :params, {} @headers = .fetch :headers, {} @body = [:body] @request_format = .fetch :request_format, :json @error_message = .fetch :error_message, ->(body) {"Error: #{body}"} end |
Instance Method Details
#run ⇒ Net::HTTPResponse
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.
Sends the request and returns the response with the body parsed from JSON.
47 48 49 50 51 52 53 54 55 |
# File 'lib/yt/http_request.rb', line 47 def run if response.is_a? Net::HTTPSuccess response.tap do parse_response! end else raise Yt::HTTPError.new(, response: response) end end |