Class: Square::ListResponse
- Inherits:
-
Object
- Object
- Square::ListResponse
- Includes:
- Enumerable
- Defined in:
- lib/square/list_response.rb
Constant Summary collapse
- LINK_REGEXP =
RegExp used for parsing Link headers when the API paginates data. Don’t care about rel attributes right now because this is the only thing this is used for.
/^<([ -~]+)>;/i
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Each.
-
#has_more? ⇒ Boolean
Check if there are more pages.
-
#initialize(response, data_type) ⇒ ListResponse
constructor
Initialize.
-
#method_missing(name, *args, &block) ⇒ Object
Pass through methods to the original response object.
-
#more ⇒ Array
Get more records.
Constructor Details
#initialize(response, data_type) ⇒ ListResponse
Initialize.
18 19 20 21 22 23 |
# File 'lib/square/list_response.rb', line 18 def initialize(response, data_type) @response = response @data_type = data_type @values = {} parse_response(@response) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Pass through methods to the original response object.
52 53 54 |
# File 'lib/square/list_response.rb', line 52 def method_missing(name, *args, &block) @response.send(name, *args, &block) end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/square/list_response.rb', line 5 def response @response end |
Instance Method Details
#each(&block) ⇒ Object
Each.
28 29 30 |
# File 'lib/square/list_response.rb', line 28 def each(&block) @values.each(&block) end |
#has_more? ⇒ Boolean
Check if there are more pages.
47 48 49 |
# File 'lib/square/list_response.rb', line 47 def has_more? !@next_link.nil? end |
#more ⇒ Array
Get more records.
35 36 37 38 39 40 41 42 |
# File 'lib/square/list_response.rb', line 35 def more if !has_more? return nil end @response = Square.make_request(url: @next_link) self.class.new(@response, @data_type) end |