Class: MultiSafePay::List
- Inherits:
-
Base
- Object
- Base
- MultiSafePay::List
show all
- Includes:
- Enumerable
- Defined in:
- lib/multisafepay/list.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#attributes
Instance Method Summary
collapse
Methods inherited from Base
all, #assign_attributes, cancel, create, #delete, delete, get, id_param, parent_id, request, resource_name, update, #update
Constructor Details
#initialize(list_attributes, klass) ⇒ List
Returns a new instance of List.
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/multisafepay/list.rb', line 7
def initialize(list_attributes, klass)
@klass = klass
@pager = list_attributes['pager'] || {}
list_attributes['items'] ||= list_attributes['data'] || []
super list_attributes
@items = items.map do |attributes|
klass.new attributes
end
end
|
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
5
6
7
|
# File 'lib/multisafepay/list.rb', line 5
def items
@items
end
|
#klass ⇒ Object
Returns the value of attribute klass.
5
6
7
|
# File 'lib/multisafepay/list.rb', line 5
def klass
@klass
end
|
Returns the value of attribute pager.
5
6
7
|
# File 'lib/multisafepay/list.rb', line 5
def
@pager
end
|
Instance Method Details
#[](index) ⇒ Object
19
20
21
|
# File 'lib/multisafepay/list.rb', line 19
def [](index)
@items[index]
end
|
#each(&block) ⇒ Object
27
28
29
|
# File 'lib/multisafepay/list.rb', line 27
def each(&block)
@items.each(&block)
end
|
#next(options = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/multisafepay/list.rb', line 39
def next(options = {})
return self.class.new({}, klass) if ['after'].nil?
href = URI.parse(['after'])
query = URI.decode_www_form(href.query).to_h
response = MultiSafePay::Client.instance.perform_http_call('GET', ['after'], nil, {}, options.merge(query))
self.class.new(response, klass)
end
|
#next? ⇒ Boolean
31
32
33
|
# File 'lib/multisafepay/list.rb', line 31
def next?
!['after'].nil?
end
|
#previous(options = {}) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/multisafepay/list.rb', line 49
def previous(options = {})
return self.class.new({}, klass) if ['before'].nil?
href = URI.parse(['before'])
query = URI.decode_www_form(href.query).to_h
response = MultiSafePay::Client.instance.perform_http_call('GET', ['before'], nil, {}, options.merge(query))
self.class.new(response, klass)
end
|
#previous? ⇒ Boolean
35
36
37
|
# File 'lib/multisafepay/list.rb', line 35
def previous?
!['before'].nil?
end
|
#size ⇒ Object
23
24
25
|
# File 'lib/multisafepay/list.rb', line 23
def size
@items.size
end
|