Class: BasisTheory::Collection
- Inherits:
-
Object
- Object
- BasisTheory::Collection
- Defined in:
- lib/basis_theory/collection.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#page_number ⇒ Object
readonly
Returns the value of attribute page_number.
-
#page_size ⇒ Object
readonly
Returns the value of attribute page_size.
-
#total_items ⇒ Object
readonly
Returns the value of attribute total_items.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data:, total_items:, page_number:, page_size:, total_pages:) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(data:, total_items:, page_number:, page_size:, total_pages:) ⇒ Collection
Returns a new instance of Collection.
18 19 20 21 22 23 24 |
# File 'lib/basis_theory/collection.rb', line 18 def initialize(data:, total_items:, page_number:, page_size:, total_pages:) @data = data @total_items = total_items @page_number = page_number @page_size = page_size @total_pages = total_pages end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/basis_theory/collection.rb', line 5 def data @data end |
#page_number ⇒ Object (readonly)
Returns the value of attribute page_number.
5 6 7 |
# File 'lib/basis_theory/collection.rb', line 5 def page_number @page_number end |
#page_size ⇒ Object (readonly)
Returns the value of attribute page_size.
5 6 7 |
# File 'lib/basis_theory/collection.rb', line 5 def page_size @page_size end |
#total_items ⇒ Object (readonly)
Returns the value of attribute total_items.
5 6 7 |
# File 'lib/basis_theory/collection.rb', line 5 def total_items @total_items end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
5 6 7 |
# File 'lib/basis_theory/collection.rb', line 5 def total_pages @total_pages end |
Class Method Details
.from_response(response, type:) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/basis_theory/collection.rb', line 7 def self.from_response(response, type:) body = response.body new( data: body['data'].map { |attrs| type.new(attrs) }, total_items: body.dig('pagination', 'total_items'), page_number: body.dig('pagination', 'page_number'), page_size: body.dig('pagination', 'page_size'), total_pages: body.dig('pagination', 'total_pages') ) end |