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.
14 15 16 17 18 |
# File 'lib/youku/v2/request.rb', line 14 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.
8 9 10 |
# File 'lib/youku/v2/request.rb', line 8 def params @params end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/youku/v2/request.rb', line 8 def response @response end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/youku/v2/request.rb', line 8 def url @url end |
Instance Method Details
#body ⇒ Object
Public: Get body.
Returns the instance of Hashie::Mash.
49 50 51 |
# File 'lib/youku/v2/request.rb', line 49 def body @body ||= Hashie::Mash.new(MultiJson.load response.body || '') end |
#code ⇒ Object
Public: Get response code.
Returns Integer code of response.
35 36 37 |
# File 'lib/youku/v2/request.rb', line 35 def code response.code end |
#next_page ⇒ Object
Public: Get next page.
Returns the instance of Youku::V2::Request.
23 24 25 |
# File 'lib/youku/v2/request.rb', line 23 def next_page Request.new url, params.merge(page: params[:page] + 1) end |
#ok? ⇒ Boolean
Returns true at successful request , false otherwise.
28 29 30 |
# File 'lib/youku/v2/request.rb', line 28 def ok? response.code == 200 end |
#return_code ⇒ Object
Public: Get return code.
Returns Integer return code.
42 43 44 |
# File 'lib/youku/v2/request.rb', line 42 def return_code response.return_code end |