Class: Square::ListResponse

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/square/list_response.rb

Constant Summary collapse

/^<([ -~]+)>;/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, data_type) ⇒ ListResponse

Initialize.

Parameters:

  • response (RestClient::Response)

    Raw resonse object.

  • data_type (Square::DataType)

    Data type to new up records.


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

#responseObject

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.

Parameters:

  • block (Block)

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.

Returns:

  • (Boolean)

47
48
49
# File 'lib/square/list_response.rb', line 47

def has_more?
  !@next_link.nil?
end

#moreArray

Get more records.

Returns:

  • (Array)

    parsed 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