Class: Yt::Request

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

Returns a new instance of Request.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/yt/actions/request.rb', line 11

def initialize(options = {})
  options[:query] ||= options[:params].to_param
  @uri = URI::HTTPS.build options.slice(:host, :path, :query)
  @method = options[:method]
  @format = options[:format]
  @scope = options[:scope]
  @body = options[:body]
  @body_type = options[:body_type]
  @auth = options[:auth]
  @headers = {}
end

Class Method Details

.default_paramsObject



32
33
34
35
36
37
38
39
# File 'lib/yt/actions/request.rb', line 32

def self.default_params
  {}.tap do |params|
    params[:format] = :json
    params[:host] = 'www.googleapis.com'
    params[:scope] = 'https://www.googleapis.com/auth/youtube'
    params[:body_type] = :json
  end
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
# File 'lib/yt/actions/request.rb', line 23

def run
  add_authorization_to_request!
  fetch_response.tap do |response|
    response.body = parse_format response.body if response.body
    # puts "You can try again running #{to_curl}"
    raise RequestError, response.body unless response.is_a? Net::HTTPSuccess
  end
end