Class: BasisTheory::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/basis_theory/collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/basis_theory/collection.rb', line 5

def data
  @data
end

#page_numberObject (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_sizeObject (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_itemsObject (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_pagesObject (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