Class: Phaxio::Resource::Collection
- Inherits:
-
Object
- Object
- Phaxio::Resource::Collection
- Includes:
- Enumerable
- Defined in:
- lib/phaxio/resource.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
The raw response data.
-
#page ⇒ Object
The raw response data.
-
#per_page ⇒ Object
The raw response data.
-
#raw_data ⇒ Object
The raw response data.
-
#total ⇒ Object
The raw response data.
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(response_data, resource) ⇒ Collection
constructor
Returns a new collection of resource instances for this data.
- #length ⇒ Object
- #size ⇒ Object
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
#collection ⇒ Object
The raw response data
135 136 137 |
# File 'lib/phaxio/resource.rb', line 135 def collection @collection end |
#page ⇒ Object
The raw response data
135 136 137 |
# File 'lib/phaxio/resource.rb', line 135 def page @page end |
#per_page ⇒ Object
The raw response data
135 136 137 |
# File 'lib/phaxio/resource.rb', line 135 def per_page @per_page end |
#raw_data ⇒ Object
The raw response data
135 136 137 |
# File 'lib/phaxio/resource.rb', line 135 def raw_data @raw_data end |
#total ⇒ Object
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 |
#length ⇒ Object
159 160 161 |
# File 'lib/phaxio/resource.rb', line 159 def length collection.length end |
#size ⇒ Object
163 164 165 |
# File 'lib/phaxio/resource.rb', line 163 def size length end |