Class: Amdapi::Collection

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, current_page:, next_page:, is_last_page:) ⇒ Collection

Returns a new instance of Collection.



16
17
18
19
20
21
# File 'lib/amdapi/collection.rb', line 16

def initialize(data:, current_page:, next_page:, is_last_page:)
  @current_page = current_page
  @next_page = next_page
  @is_last_page = is_last_page
  @data = data
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



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

def current_page
  @current_page
end

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#is_last_pageObject (readonly)

Returns the value of attribute is_last_page.



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

def is_last_page
  @is_last_page
end

#next_pageObject (readonly)

Returns the value of attribute next_page.



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

def next_page
  @next_page
end

Class Method Details

.from_response(response, key: "calls", type: Call) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/amdapi/collection.rb', line 7

def self.from_response(response, key: "calls", type: Call)
  new(
    data: response[key].map { |attrs| type.new(attrs, call_uuid: attrs["call_uuid"]) },
    current_page: response["current_page"],
    next_page: response["next_page"],
    is_last_page: response["is_last_page"]
  )
end