Class: Megam::Balances
Instance Attribute Summary
Attributes inherited from ServerAPI
#api_key, #email, #host, #org_id, #password
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from ServerAPI
#megam_rest
Constructor Details
#initialize(o) ⇒ Balances
Returns a new instance of Balances.
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/megam/core/balances.rb', line 18
def initialize(o)
@id = nil
@accounts_id = nil
@name = nil
@credit = nil
@created_at = nil
@updated_at = nil
@some_msg = {}
super(o)
end
|
Class Method Details
.create(params) ⇒ Object
156
157
158
159
|
# File 'lib/megam/core/balances.rb', line 156
def self.create(params)
acct = from_hash(params,params["email"], params["api_key"], params["host"])
acct.create
end
|
.delete(p_name, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
181
182
183
184
|
# File 'lib/megam/core/balances.rb', line 181
def self.delete(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
pre = self.new(tmp_email,tmp_api_key,tmp_host)
pre.megam_rest.delete_balance(p_name)
end
|
.from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
140
141
142
143
144
|
# File 'lib/megam/core/balances.rb', line 140
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
balances = self.new(tmp_email, tmp_api_key, tmp_host)
balances.from_hash(o)
balances
end
|
.json_create(o) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/megam/core/balances.rb', line 124
def self.json_create(o)
balances = new({})
balances.id(o["id"]) if o.has_key?("id")
balances.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
balances.name(o["name"]) if o.has_key?("name")
balances.credit(o["credit"]) if o.has_key?("credit")
balances.created_at(o["created_at"]) if o.has_key?("created_at")
balances.updated_at(o["updated_at"]) if o.has_key?("updated_at")
balances.some_msg[:code] = o["code"] if o.has_key?("code")
balances.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
balances.some_msg[:msg]= o["msg"] if o.has_key?("msg")
balances.some_msg[:links] = o["links"] if o.has_key?("links")
balances
end
|
.list(params) ⇒ Object
Load all balances - returns a BalanceCollection don’t return self. check if the Megam::BalanceCollection is returned.
169
170
171
172
|
# File 'lib/megam/core/balances.rb', line 169
def self.list(params)
balance = self.new(params["email"], params["api_key"], params["host"])
balance.megam_rest.get_balances
end
|
.show(params) ⇒ Object
Show a particular balance by name, Megam::Balance
176
177
178
179
|
# File 'lib/megam/core/balances.rb', line 176
def self.show(params)
pre = self.new(params["email"], params["api_key"], params["host"])
pre.megam_rest.get_balance(params["email"])
end
|
.update(params) ⇒ Object
186
187
188
189
|
# File 'lib/megam/core/balances.rb', line 186
def self.update(params)
asm = from_hash(params, params["email"], params["api_key"], params["host"])
asm.update
end
|
Instance Method Details
#accounts_id(arg = nil) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/megam/core/balances.rb', line 41
def accounts_id(arg=nil)
if arg != nil
@accounts_id= arg
else
@accounts_id
end
end
|
#balances ⇒ Object
29
30
31
|
# File 'lib/megam/core/balances.rb', line 29
def balances
self
end
|
#create ⇒ Object
Create the predef via the REST API
162
163
164
|
# File 'lib/megam/core/balances.rb', line 162
def create
megam_rest.post_balances(to_hash)
end
|
#created_at(arg = nil) ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/megam/core/balances.rb', line 65
def created_at(arg=nil)
if arg != nil
@created_at = arg
else
@created_at
end
end
|
#credit(arg = nil) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/megam/core/balances.rb', line 57
def credit(arg=nil)
if arg != nil
@credit = arg
else
@credit
end
end
|
#error? ⇒ Boolean
89
90
91
|
# File 'lib/megam/core/balances.rb', line 89
def error?
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end
|
#for_json ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/megam/core/balances.rb', line 112
def for_json
result = {
"id" => id,
"accounts_id" => accounts_id,
"name" => name,
"credit" => credit,
"created_at" => created_at,
"updated_at" => updated_at
}
result
end
|
#from_hash(o) ⇒ Object
146
147
148
149
150
151
152
153
154
|
# File 'lib/megam/core/balances.rb', line 146
def from_hash(o)
@id = o[:id] if o.has_key?(:id)
@accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
@name = o[:name] if o.has_key?(:name)
@credit = o[:credit] if o.has_key?(:credit)
@created_at = o[:created_at] if o.has_key?(:created_at)
@updated_at = o[:updated_at] if o.has_key?(:updated_at)
self
end
|
#id(arg = nil) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/megam/core/balances.rb', line 33
def id(arg=nil)
if arg != nil
@id = arg
else
@id
end
end
|
#name(arg = nil) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/megam/core/balances.rb', line 49
def name(arg=nil)
if arg != nil
@name = arg
else
@name
end
end
|
#some_msg(arg = nil) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/megam/core/balances.rb', line 81
def some_msg(arg=nil)
if arg != nil
@some_msg = arg
else
@some_msg
end
end
|
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/megam/core/balances.rb', line 94
def to_hash
index_hash = Hash.new
index_hash["json_claz"] = self.class.name
index_hash["id"] = id
index_hash["accounts_id"] = accounts_id
index_hash["name"] = name
index_hash["credit"] = credit
index_hash["created_at"] = created_at
index_hash["updated_at"] = updated_at
index_hash
end
|
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.
108
109
110
|
# File 'lib/megam/core/balances.rb', line 108
def to_json(*a)
for_json.to_json(*a)
end
|
#update ⇒ Object
Create the node via the REST API
192
193
194
|
# File 'lib/megam/core/balances.rb', line 192
def update
megam_rest.update_balance(to_hash)
end
|
#updated_at(arg = nil) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/megam/core/balances.rb', line 73
def updated_at(arg=nil)
if arg != nil
@updated_at = arg
else
@updated_at
end
end
|