Class: Yt::Models::Request
- Inherits:
-
Object
- Object
- Yt::Models::Request
- Defined in:
- lib/yt/models/request.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Request
constructor
A new instance of Request.
- #request_error_message ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Request
Returns a new instance of Request.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/yt/models/request.rb', line 16 def initialize( = {}) @auth = [:auth] @body = [:body] @file = [:file] @body_type = .fetch :body_type, :json @expected_response = .fetch :expected_response, Net::HTTPSuccess @format = .fetch :format, :json @headers = .fetch :headers, gzip_headers @host = .fetch :host, google_api_host @method = .fetch :method, :get @path = [:path] @query = .fetch(:params, {}).to_param end |
Instance Method Details
#request_error_message ⇒ Object
38 39 40 41 42 43 |
# File 'lib/yt/models/request.rb', line 38 def {}.tap do || [:request_curl] = as_curl [:response_body] = JSON(response.body) rescue response.inspect end.to_json end |
#run ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/yt/models/request.rb', line 30 def run if response.is_a? @expected_response response.tap{|response| response.body = parse_format response.body} else run_again? ? run : raise(response_error, ) end end |