Class: Youku::V2::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/youku/v2/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, params) ⇒ Request

Public: Constructor.

url - The String url. params - The Hash query params.



12
13
14
15
16
# File 'lib/youku/v2/request.rb', line 12

def initialize(url, params)
  @url      = url
  @params   = params
  @response = Typhoeus::Request.new(url, params: params, connecttimeout: 5, timeout: 10).run
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/youku/v2/request.rb', line 6

def params
  @params
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/youku/v2/request.rb', line 6

def response
  @response
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/youku/v2/request.rb', line 6

def url
  @url
end

Instance Method Details

#bodyObject

Public: Get body.

Returns the instance of Hashie::Mash.



47
48
49
# File 'lib/youku/v2/request.rb', line 47

def body
  @body ||= Hashie::Mash.new(MultiJson.load response.body || '')
end

#codeObject

Public: Get response code.

Returns Integer code of response.



33
34
35
# File 'lib/youku/v2/request.rb', line 33

def code
  response.code
end

#next_pageObject

Public: Get next page.

Returns the instance of Youku::V2::Request.



21
22
23
# File 'lib/youku/v2/request.rb', line 21

def next_page
  Request.new url, params.merge(page: params[:page] + 1)
end

#ok?Boolean

Returns true at successful request , false otherwise.

Returns:

  • (Boolean)


26
27
28
# File 'lib/youku/v2/request.rb', line 26

def ok?
  response.code == 200
end

#return_codeObject

Public: Get return code.

Returns Integer return code.



40
41
42
# File 'lib/youku/v2/request.rb', line 40

def return_code
  response.return_code
end