Class: Youku::V2::Request
- Inherits:
-
Object
- Object
- Youku::V2::Request
- Defined in:
- lib/youku/v2/request.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#body ⇒ Object
Public: Get body.
-
#code ⇒ Object
Public: Get response code.
-
#initialize(url, params) ⇒ Request
constructor
Public: Constructor.
-
#next_page ⇒ Object
Public: Get next page.
-
#ok? ⇒ Boolean
Returns true at successful request , false otherwise.
-
#return_code ⇒ Object
Public: Get return code.
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
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/youku/v2/request.rb', line 6 def params @params end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/youku/v2/request.rb', line 6 def response @response end |
#url ⇒ Object (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
#body ⇒ Object
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 |
#code ⇒ Object
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_page ⇒ Object
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.
26 27 28 |
# File 'lib/youku/v2/request.rb', line 26 def ok? response.code == 200 end |
#return_code ⇒ Object
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 |