Class: Yt::Models::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/yt/models/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

Returns a new instance of Request.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/yt/models/request.rb', line 15

def initialize(options = {})
  @auth = options[:auth]
  @body = options[:body]
  @body_type = options.fetch :body_type, :json
  @expected_response = options.fetch :expected_response, Net::HTTPSuccess
  @format = options.fetch :format, :json
  @headers = options.fetch :headers, {}
  @host = options.fetch :host, google_api_host
  @method = options.fetch :method, :get
  @path = options[:path]
  @query = options.fetch(:params, {}).to_param
end

Instance Method Details

#runObject



28
29
30
31
32
33
34
# File 'lib/yt/models/request.rb', line 28

def run
  if response.is_a? @expected_response
    response.tap{|response| response.body = parse_format response.body}
  else
    run_again? ? run : raise(error_for(response), request_error_message)
  end
end