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 150 151 152 153 154 155 |
# File 'lib/phaxio/resource.rb', line 141 def initialize response_data, resource # For some endpoints we'll get a hash with `paging` and `data` attributes. # For others, just an array. if response_data.is_a? Hash 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'] else self.raw_data = response_data end 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
157 158 159 |
# File 'lib/phaxio/resource.rb', line 157 def [] idx collection[idx] end |
#each(&block) ⇒ Object
161 162 163 |
# File 'lib/phaxio/resource.rb', line 161 def each(&block) collection.each(&block) end |
#length ⇒ Object
165 166 167 |
# File 'lib/phaxio/resource.rb', line 165 def length collection.length end |
#size ⇒ Object
169 170 171 |
# File 'lib/phaxio/resource.rb', line 169 def size length end |