Class: Phaxio::Resource::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/phaxio/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_data, resource) ⇒ Collection

Returns a new collection of resource instances for this data. Generally this is not called directly.


141
142
143
144
145
146
147
148
149
# File 'lib/phaxio/resource.rb', line 141

def initialize response_data, resource
  if response_data.key? 'paging'
    self.total = response_data['paging']['total']
    self.per_page = response_data['paging']['per_page']
    self.page = response_data['paging']['page']
  end
  self.raw_data = response_data['data']
  self.collection = raw_data.map { |record_data| resource.response_record record_data }
end

Instance Attribute Details

#collectionObject

The raw response data


135
136
137
# File 'lib/phaxio/resource.rb', line 135

def collection
  @collection
end

#pageObject

The raw response data


135
136
137
# File 'lib/phaxio/resource.rb', line 135

def page
  @page
end

#per_pageObject

The raw response data


135
136
137
# File 'lib/phaxio/resource.rb', line 135

def per_page
  @per_page
end

#raw_dataObject

The raw response data


135
136
137
# File 'lib/phaxio/resource.rb', line 135

def raw_data
  @raw_data
end

#totalObject

The raw response data


135
136
137
# File 'lib/phaxio/resource.rb', line 135

def total
  @total
end

Instance Method Details

#[](idx) ⇒ Object


151
152
153
# File 'lib/phaxio/resource.rb', line 151

def [] idx
  collection[idx]
end

#each(&block) ⇒ Object


155
156
157
# File 'lib/phaxio/resource.rb', line 155

def each(&block)
  collection.each(&block)
end

#lengthObject


159
160
161
# File 'lib/phaxio/resource.rb', line 159

def length
  collection.length
end

#sizeObject


163
164
165
# File 'lib/phaxio/resource.rb', line 163

def size
  length
end