Class: SynapsePay::APIList
- Inherits:
-
APIResource
show all
- Includes:
- Enumerable
- Defined in:
- lib/synapse_pay/apibits/api_list.rb
Instance Attribute Summary collapse
Attributes inherited from APIResource
#api_method, #json
Instance Method Summary
collapse
Methods inherited from APIResource
api_attribute_names, #api_attributes, api_subclass_fetch, api_subclasses, #changed_api_attributes, #clear_api_attributes, #determine_api_attribute_value, determine_api_attribute_value, #inspect_api_attributes, #inspect_nested, register_api_subclass, #to_json
Constructor Details
#initialize(klass, json = {}, api_method = nil, client = nil) ⇒ APIList
Returns a new instance of APIList.
9
10
11
12
13
14
15
16
17
|
# File 'lib/synapse_pay/apibits/api_list.rb', line 9
def initialize(klass, json={}, api_method=nil, client=nil)
if klass.is_a?(Class)
@klass = klass
else
@klass = Util.constantize(klass)
end
refresh_from(json, api_method, client)
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
7
8
9
|
# File 'lib/synapse_pay/apibits/api_list.rb', line 7
def client
@client
end
|
#data ⇒ Object
Returns the value of attribute data.
5
6
7
|
# File 'lib/synapse_pay/apibits/api_list.rb', line 5
def data
@data
end
|
#klass ⇒ Object
Returns the value of attribute klass.
6
7
8
|
# File 'lib/synapse_pay/apibits/api_list.rb', line 6
def klass
@klass
end
|
Instance Method Details
#[](k) ⇒ Object
47
48
49
|
# File 'lib/synapse_pay/apibits/api_list.rb', line 47
def [](k)
data[k]
end
|
#[]=(k, v) ⇒ Object
51
52
53
|
# File 'lib/synapse_pay/apibits/api_list.rb', line 51
def []=(k, v)
data[k]=v
end
|
#each(&blk) ⇒ Object
63
64
65
|
# File 'lib/synapse_pay/apibits/api_list.rb', line 63
def each(&blk)
data.each(&blk)
end
|
#inspect ⇒ Object
67
68
69
|
# File 'lib/synapse_pay/apibits/api_list.rb', line 67
def inspect
"#<#{self.class}[#{@klass}]:0x#{self.object_id.to_s(16)}> Data: " + JSON.pretty_generate(inspect_data)
end
|
#inspect_data ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/synapse_pay/apibits/api_list.rb', line 71
def inspect_data
ret = []
data.each do |d|
if d.respond_to?(:inspect_nested)
ret << d.inspect_nested
else
ret << d
end
end
ret
end
|
#last ⇒ Object
55
56
57
|
# File 'lib/synapse_pay/apibits/api_list.rb', line 55
def last
data.last
end
|
#length ⇒ Object
59
60
61
|
# File 'lib/synapse_pay/apibits/api_list.rb', line 59
def length
data.length
end
|
#refresh_from(json, api_method = nil, client = nil) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/synapse_pay/apibits/api_list.rb', line 19
def refresh_from(json, api_method=nil, client=nil)
unless json.is_a?(Hash)
json = {
:data => json
}
end
json = Util.symbolize_keys(json)
clear_api_attributes
@api_method = api_method
@client = client
@data = []
@json = Util.sorta_deep_clone(json)
json.each do |k, v|
if k.to_sym == :data
if v.respond_to?(:map)
instance_variable_set("@#{k}", v.map{ |i| @klass.new(i, @api_method, @client) })
else
instance_variable_set("@#{k}", v || [])
end
elsif self.class.api_attribute_names.include?(k)
instance_variable_set("@#{k}", determine_api_attribute_value(k, v))
end
end
self
end
|