virtengine_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +11 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/Rakefile +10 -0
- data/lib/megam/api.rb +329 -0
- data/lib/megam/api/accounts.rb +96 -0
- data/lib/megam/api/addons.rb +27 -0
- data/lib/megam/api/assemblies.rb +49 -0
- data/lib/megam/api/assembly.rb +56 -0
- data/lib/megam/api/backups.rb +57 -0
- data/lib/megam/api/balances.rb +45 -0
- data/lib/megam/api/billedhistories.rb +35 -0
- data/lib/megam/api/billingtransactions.rb +25 -0
- data/lib/megam/api/components.rb +24 -0
- data/lib/megam/api/credits.rb +34 -0
- data/lib/megam/api/disks.rb +44 -0
- data/lib/megam/api/domains.rb +25 -0
- data/lib/megam/api/errors.rb +29 -0
- data/lib/megam/api/eventsall.rb +36 -0
- data/lib/megam/api/eventsbilling.rb +35 -0
- data/lib/megam/api/eventscontainer.rb +35 -0
- data/lib/megam/api/eventsmarketplace.rb +35 -0
- data/lib/megam/api/eventsstorage.rb +24 -0
- data/lib/megam/api/eventsvm.rb +35 -0
- data/lib/megam/api/flavors.rb +56 -0
- data/lib/megam/api/license.rb +26 -0
- data/lib/megam/api/marketplaces.rb +68 -0
- data/lib/megam/api/organizations.rb +50 -0
- data/lib/megam/api/promos.rb +18 -0
- data/lib/megam/api/quotas.rb +47 -0
- data/lib/megam/api/rawimages.rb +36 -0
- data/lib/megam/api/reports.rb +24 -0
- data/lib/megam/api/requests.rb +36 -0
- data/lib/megam/api/sensors.rb +35 -0
- data/lib/megam/api/snapshots.rb +46 -0
- data/lib/megam/api/sshkeys.rb +35 -0
- data/lib/megam/api/subscriptions.rb +26 -0
- data/lib/megam/api/version.rb +6 -0
- data/lib/megam/core/account.rb +245 -0
- data/lib/megam/core/account_collection.rb +122 -0
- data/lib/megam/core/addons.rb +169 -0
- data/lib/megam/core/addons_collection.rb +121 -0
- data/lib/megam/core/assemblies.rb +191 -0
- data/lib/megam/core/assemblies_collection.rb +122 -0
- data/lib/megam/core/assembly.rb +226 -0
- data/lib/megam/core/assembly_collection.rb +122 -0
- data/lib/megam/core/backups.rb +259 -0
- data/lib/megam/core/backups_collection.rb +122 -0
- data/lib/megam/core/balances.rb +187 -0
- data/lib/megam/core/balances_collection.rb +121 -0
- data/lib/megam/core/billedhistories.rb +190 -0
- data/lib/megam/core/billedhistories_collection.rb +121 -0
- data/lib/megam/core/billingtransactions.rb +214 -0
- data/lib/megam/core/billingtransactions_collection.rb +122 -0
- data/lib/megam/core/components.rb +326 -0
- data/lib/megam/core/components_collection.rb +123 -0
- data/lib/megam/core/credits.rb +146 -0
- data/lib/megam/core/credits_collection.rb +121 -0
- data/lib/megam/core/disks.rb +199 -0
- data/lib/megam/core/disks_collection.rb +122 -0
- data/lib/megam/core/domain_collection.rb +122 -0
- data/lib/megam/core/domains.rb +118 -0
- data/lib/megam/core/error.rb +70 -0
- data/lib/megam/core/eventsall.rb +186 -0
- data/lib/megam/core/eventsall_collection.rb +122 -0
- data/lib/megam/core/eventsbilling.rb +174 -0
- data/lib/megam/core/eventsbilling_collection.rb +122 -0
- data/lib/megam/core/eventscontainer.rb +187 -0
- data/lib/megam/core/eventscontainer_collection.rb +122 -0
- data/lib/megam/core/eventsmarketplace.rb +187 -0
- data/lib/megam/core/eventsmarketplace_collection.rb +122 -0
- data/lib/megam/core/eventsstorage.rb +156 -0
- data/lib/megam/core/eventsstorage_collection.rb +122 -0
- data/lib/megam/core/eventsvm.rb +187 -0
- data/lib/megam/core/eventsvm_collection.rb +122 -0
- data/lib/megam/core/flavors.rb +294 -0
- data/lib/megam/core/flavors_collection.rb +121 -0
- data/lib/megam/core/json_compat.rb +289 -0
- data/lib/megam/core/konipai.rb +42 -0
- data/lib/megam/core/license.rb +101 -0
- data/lib/megam/core/license_collection.rb +122 -0
- data/lib/megam/core/log.rb +19 -0
- data/lib/megam/core/marketplace.rb +308 -0
- data/lib/megam/core/marketplace_collection.rb +123 -0
- data/lib/megam/core/monologger.rb +89 -0
- data/lib/megam/core/organizations.rb +142 -0
- data/lib/megam/core/organizations_collection.rb +121 -0
- data/lib/megam/core/promos.rb +145 -0
- data/lib/megam/core/quotas.rb +215 -0
- data/lib/megam/core/quotas_collection.rb +121 -0
- data/lib/megam/core/rawimages.rb +194 -0
- data/lib/megam/core/rawimages_collection.rb +121 -0
- data/lib/megam/core/reports.rb +176 -0
- data/lib/megam/core/reports_collection.rb +121 -0
- data/lib/megam/core/request.rb +197 -0
- data/lib/megam/core/request_collection.rb +121 -0
- data/lib/megam/core/rest_adapter.rb +44 -0
- data/lib/megam/core/sensors.rb +141 -0
- data/lib/megam/core/sensors_collection.rb +121 -0
- data/lib/megam/core/snapshots.rb +268 -0
- data/lib/megam/core/snapshots_collection.rb +122 -0
- data/lib/megam/core/sshkey.rb +173 -0
- data/lib/megam/core/sshkey_collection.rb +122 -0
- data/lib/megam/core/stuff.rb +22 -0
- data/lib/megam/core/subscriptions.rb +167 -0
- data/lib/megam/core/subscriptions_collection.rb +121 -0
- data/lib/megam/core/text.rb +87 -0
- data/lib/megam/core/text_formatter.rb +64 -0
- data/lib/megam/mixins/assemblies.rb +16 -0
- data/lib/megam/mixins/assembly.rb +59 -0
- data/lib/megam/mixins/common_deployable.rb +78 -0
- data/lib/megam/mixins/components.rb +182 -0
- data/lib/megam/mixins/megam_attributes.rb +30 -0
- data/lib/megam/mixins/outputs.rb +23 -0
- data/lib/megam/mixins/policies.rb +27 -0
- data/lib/megam_api.rb +1 -0
- data/megam_api.gemspec +26 -0
- data/test/mixins/test_assemblies.rb +113 -0
- data/test/mixins/test_assembly.rb +74 -0
- data/test/mixins/test_component.rb +19 -0
- data/test/test_accounts.rb +127 -0
- data/test/test_addons.rb +26 -0
- data/test/test_assemblies.rb +88 -0
- data/test/test_assembly.rb +37 -0
- data/test/test_backups.rb +29 -0
- data/test/test_balances.rb +38 -0
- data/test/test_billedhistories.rb +30 -0
- data/test/test_billingtranscations.rb +35 -0
- data/test/test_components.rb +42 -0
- data/test/test_credits.rb +28 -0
- data/test/test_disks.rb +25 -0
- data/test/test_domains.rb +29 -0
- data/test/test_eventsbilling.rb +30 -0
- data/test/test_eventscontainer.rb +26 -0
- data/test/test_eventsstorage.rb +12 -0
- data/test/test_eventsvm.rb +26 -0
- data/test/test_helper.rb +77 -0
- data/test/test_marketplaces.rb +38 -0
- data/test/test_organizations.rb +45 -0
- data/test/test_promos.rb +11 -0
- data/test/test_quotas.rb +33 -0
- data/test/test_reports.rb +32 -0
- data/test/test_requests.rb +95 -0
- data/test/test_sensors.rb +50 -0
- data/test/test_snapshots.rb +30 -0
- data/test/test_sshkeys.rb +50 -0
- data/test/test_subscriptions.rb +22 -0
- metadata +325 -0
@@ -0,0 +1,259 @@
|
|
1
|
+
module Megam
|
2
|
+
class Backups < Megam::RestAdapter
|
3
|
+
def initialize(o)
|
4
|
+
@id = nil
|
5
|
+
@account_id = nil
|
6
|
+
@asm_id = nil
|
7
|
+
@org_id = nil
|
8
|
+
@tosca_type = nil
|
9
|
+
@inputs = []
|
10
|
+
@outputs = []
|
11
|
+
@labels = []
|
12
|
+
@name= nil
|
13
|
+
@status=nil
|
14
|
+
@image_id=nil
|
15
|
+
@created_at = nil
|
16
|
+
@some_msg = {}
|
17
|
+
super(o)
|
18
|
+
end
|
19
|
+
|
20
|
+
def backups
|
21
|
+
self
|
22
|
+
end
|
23
|
+
def id(arg=nil)
|
24
|
+
if arg != nil
|
25
|
+
@id = arg
|
26
|
+
else
|
27
|
+
@id
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def account_id(arg=nil)
|
32
|
+
if arg != nil
|
33
|
+
@account_id = arg
|
34
|
+
else
|
35
|
+
@account_id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def asm_id(arg=nil)
|
40
|
+
if arg != nil
|
41
|
+
@asm_id = arg
|
42
|
+
else
|
43
|
+
@asm_id
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def org_id(arg=nil)
|
48
|
+
if arg != nil
|
49
|
+
@org_id = arg
|
50
|
+
else
|
51
|
+
@org_id
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def tosca_type(arg = nil)
|
56
|
+
if !arg.nil?
|
57
|
+
@tosca_type = arg
|
58
|
+
else
|
59
|
+
@tosca_type
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def inputs(arg = [])
|
64
|
+
if arg != []
|
65
|
+
@inputs = arg
|
66
|
+
else
|
67
|
+
@inputs
|
68
|
+
end
|
69
|
+
end
|
70
|
+
def labels(arg=[])
|
71
|
+
if arg != []
|
72
|
+
@labels=arg
|
73
|
+
else
|
74
|
+
@labels
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def outputs(arg = [])
|
79
|
+
if arg != []
|
80
|
+
@outputs = arg
|
81
|
+
else
|
82
|
+
@outputs
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def name(arg=nil)
|
87
|
+
if arg != nil
|
88
|
+
@name = arg
|
89
|
+
else
|
90
|
+
@name
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def status(arg=nil)
|
95
|
+
if arg != nil
|
96
|
+
@status = arg
|
97
|
+
else
|
98
|
+
@status
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def image_id(arg=nil)
|
103
|
+
if arg != nil
|
104
|
+
@image_id = arg
|
105
|
+
else
|
106
|
+
@image_id
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def created_at(arg=nil)
|
111
|
+
if arg != nil
|
112
|
+
@created_at = arg
|
113
|
+
else
|
114
|
+
@created_at
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def error?
|
119
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
def some_msg(arg=nil)
|
124
|
+
if arg != nil
|
125
|
+
@some_msg = arg
|
126
|
+
else
|
127
|
+
@some_msg
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
# Transform the ruby obj -> to a Hash
|
133
|
+
def to_hash
|
134
|
+
index_hash = Hash.new
|
135
|
+
index_hash["json_claz"] = self.class.name
|
136
|
+
index_hash["id"] = id
|
137
|
+
index_hash["account_id"] = account_id
|
138
|
+
index_hash["asm_id"] = asm_id
|
139
|
+
index_hash["org_id"] = org_id
|
140
|
+
index_hash["labels"] = labels
|
141
|
+
index_hash["tosca_type"] = tosca_type
|
142
|
+
index_hash["inputs"] = inputs
|
143
|
+
index_hash["outputs"] = outputs
|
144
|
+
index_hash["name"] = name
|
145
|
+
index_hash["status"] = status
|
146
|
+
index_hash["image_id"] = image_id
|
147
|
+
index_hash["created_at"] = created_at
|
148
|
+
index_hash["some_msg"] = some_msg
|
149
|
+
index_hash
|
150
|
+
end
|
151
|
+
|
152
|
+
# Serialize this object as a hash: called from JsonCompat.
|
153
|
+
# Verify if this called from JsonCompat during testing.
|
154
|
+
def to_json(*a)
|
155
|
+
for_json.to_json(*a)
|
156
|
+
end
|
157
|
+
|
158
|
+
def for_json
|
159
|
+
result = {
|
160
|
+
"id" => id,
|
161
|
+
"account_id" => account_id,
|
162
|
+
"asm_id" => asm_id,
|
163
|
+
"org_id" => org_id,
|
164
|
+
"tosca_type" => tosca_type,
|
165
|
+
"inputs" => inputs,
|
166
|
+
"outputs" => outputs,
|
167
|
+
"name" => name,
|
168
|
+
"status" => status,
|
169
|
+
"image_id" => image_id,
|
170
|
+
"created_at" => created_at,
|
171
|
+
"labels" =>labels,
|
172
|
+
}
|
173
|
+
result
|
174
|
+
end
|
175
|
+
|
176
|
+
def self.json_create(o)
|
177
|
+
sps = new({})
|
178
|
+
sps.id(o["id"]) if o.has_key?("id")
|
179
|
+
sps.account_id(o["account_id"]) if o.has_key?("account_id")
|
180
|
+
sps.asm_id(o["asm_id"]) if o.has_key?("asm_id")
|
181
|
+
sps.org_id(o["org_id"]) if o.has_key?("org_id") #this will be an array? can hash store array?
|
182
|
+
sps.tosca_type(o['tosca_type']) if o.key?('tosca_type')
|
183
|
+
sps.inputs(o['inputs']) if o.key?('inputs')
|
184
|
+
sps.outputs(o['outputs']) if o.key?('outputs')
|
185
|
+
sps.name(o["name"]) if o.has_key?("name")
|
186
|
+
sps.status(o["status"]) if o.has_key?("status")
|
187
|
+
sps.image_id(o["image_id"]) if o.has_key?("image_id")
|
188
|
+
sps.created_at(o["created_at"]) if o.has_key?("created_at")
|
189
|
+
sps.labels(o["labels"]) if o.key?("labels")
|
190
|
+
sps.some_msg[:code] = o["code"] if o.has_key?("code")
|
191
|
+
sps.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
192
|
+
sps.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
193
|
+
sps.some_msg[:links] = o["links"] if o.has_key?("links")
|
194
|
+
sps
|
195
|
+
end
|
196
|
+
|
197
|
+
def self.from_hash(o)
|
198
|
+
sps = self.new(o)
|
199
|
+
sps.from_hash(o)
|
200
|
+
sps
|
201
|
+
end
|
202
|
+
|
203
|
+
def from_hash(o)
|
204
|
+
@id = o[:id] if o.has_key?(:id)
|
205
|
+
@account_id = o[:account_id] if o.has_key?(:account_id)
|
206
|
+
@asm_id = o[:asm_id] if o.has_key?(:asm_id)
|
207
|
+
@org_id = o[:org_id] if o.has_key?(:org_id)
|
208
|
+
@tosca_type = o[:tosca_type] if o.key?(:tosca_type)
|
209
|
+
@inputs = o[:inputs] if o.key?(:inputs)
|
210
|
+
@outputs = o[:outputs] if o.key?(:outputs)
|
211
|
+
@name = o[:name] if o.has_key?(:name)
|
212
|
+
@status = o[:status] if o.has_key?(:status)
|
213
|
+
@image_id = o[:image_id] if o.has_key?(:image_id)
|
214
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
215
|
+
@labels = o[:labels] if o.key?(:labels)
|
216
|
+
self
|
217
|
+
end
|
218
|
+
|
219
|
+
def self.create(params)
|
220
|
+
sps = from_hash(params)
|
221
|
+
sps.create
|
222
|
+
end
|
223
|
+
|
224
|
+
def self.update(params)
|
225
|
+
sps = from_hash(params)
|
226
|
+
sps.update
|
227
|
+
end
|
228
|
+
|
229
|
+
# Create the node via the REST API
|
230
|
+
def create
|
231
|
+
megam_rest.post_backups(to_hash)
|
232
|
+
end
|
233
|
+
|
234
|
+
def self.listall(params)
|
235
|
+
sps = self.new(params)
|
236
|
+
sps.megam_rest.list_backups
|
237
|
+
end
|
238
|
+
|
239
|
+
# Load a account by email_p
|
240
|
+
def self.list(o)
|
241
|
+
sps = self.new(o)
|
242
|
+
sps.megam_rest.get_backups(o[:id])
|
243
|
+
end
|
244
|
+
|
245
|
+
def self.show(o)
|
246
|
+
sps = self.new(o)
|
247
|
+
sps.megam_rest.get_one_backup(o[:id])
|
248
|
+
end
|
249
|
+
|
250
|
+
def update
|
251
|
+
megam_rest.update_backups(to_hash)
|
252
|
+
end
|
253
|
+
|
254
|
+
def to_s
|
255
|
+
Megam::Stuff.styled_hash(to_hash)
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module Megam
|
2
|
+
class BackupsCollection
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :iterator
|
6
|
+
def initialize
|
7
|
+
@backups = Array.new
|
8
|
+
@backups_by_name = Hash.new
|
9
|
+
@insert_after_idx = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def all_backups
|
13
|
+
@backups
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](index)
|
17
|
+
@backups[index]
|
18
|
+
end
|
19
|
+
|
20
|
+
def []=(index, arg)
|
21
|
+
is_megam_backups(arg)
|
22
|
+
@backups[index] = arg
|
23
|
+
@backups_by_name[arg.account_id] = index
|
24
|
+
end
|
25
|
+
|
26
|
+
def <<(*args)
|
27
|
+
args.flatten.each do |a|
|
28
|
+
is_megam_backups(a)
|
29
|
+
@backups << a
|
30
|
+
@backups_by_name[a.account_id] = @backups.length - 1
|
31
|
+
end
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# 'push' is an alias method to <<
|
36
|
+
alias_method :push, :<<
|
37
|
+
|
38
|
+
def insert(backups)
|
39
|
+
is_megam_backups(backups)
|
40
|
+
if @insert_after_idx
|
41
|
+
# in the middle of executing a run, so any nodes inserted now should
|
42
|
+
# be placed after the most recent addition done by the currently executing
|
43
|
+
# node
|
44
|
+
@backups.insert(@insert_after_idx + 1, backups)
|
45
|
+
# update name -> location mappings and register new node
|
46
|
+
@backups_by_name.each_key do |key|
|
47
|
+
@backups_by_name[key] += 1 if @backups_by_name[key] > @insert_after_idx
|
48
|
+
end
|
49
|
+
@backups_by_name[backups.account_id] = @insert_after_idx + 1
|
50
|
+
@insert_after_idx += 1
|
51
|
+
else
|
52
|
+
@backups << backups
|
53
|
+
@backups_by_name[backups.account_id] = @backups.length - 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def each
|
58
|
+
@backups.each do |backups|
|
59
|
+
yield backups
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def each_index
|
64
|
+
@backups.each_index do |i|
|
65
|
+
yield i
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def empty?
|
70
|
+
@backups.empty?
|
71
|
+
end
|
72
|
+
|
73
|
+
def lookup(backups)
|
74
|
+
lookup_by = nil
|
75
|
+
if events.kind_of?(Megam::Backups)
|
76
|
+
lookup_by = backups.account_id
|
77
|
+
elsif backups.kind_of?(String)
|
78
|
+
lookup_by = backups
|
79
|
+
else
|
80
|
+
raise ArgumentError, "Must pass a Megam::Backups or String to lookup"
|
81
|
+
end
|
82
|
+
res = @backups_by_name[lookup_by]
|
83
|
+
unless res
|
84
|
+
raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
|
85
|
+
end
|
86
|
+
@backups[res]
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_s
|
90
|
+
@backups.join(", ")
|
91
|
+
end
|
92
|
+
|
93
|
+
def for_json
|
94
|
+
to_a.map { |item| item.to_s }
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_json(*a)
|
98
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.json_create(o)
|
102
|
+
collection = self.new()
|
103
|
+
o["results"].each do |backups_list|
|
104
|
+
backups_array = backups_list.kind_of?(Array) ? backups_list : [ backups_list ]
|
105
|
+
backups_array.each do |backups|
|
106
|
+
collection.insert(backups)
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
collection
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def is_megam_backups(arg)
|
116
|
+
unless arg.kind_of?(Megam::Backups)
|
117
|
+
raise ArgumentError, "Members must be Megam::Backups's"
|
118
|
+
end
|
119
|
+
true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
module Megam
|
2
|
+
class Balances < Megam::RestAdapter
|
3
|
+
def initialize(o)
|
4
|
+
@id = nil
|
5
|
+
@account_id = nil
|
6
|
+
@credit = nil
|
7
|
+
@biller_credit = nil
|
8
|
+
@created_at = nil
|
9
|
+
@updated_at = nil
|
10
|
+
@some_msg = {}
|
11
|
+
super(o)
|
12
|
+
end
|
13
|
+
|
14
|
+
def balances
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def id(arg=nil)
|
19
|
+
if arg != nil
|
20
|
+
@id = arg
|
21
|
+
else
|
22
|
+
@id
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def account_id(arg=nil)
|
27
|
+
if arg != nil
|
28
|
+
@account_id= arg
|
29
|
+
else
|
30
|
+
@account_id
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def credit(arg=nil)
|
36
|
+
if arg != nil
|
37
|
+
@credit = arg
|
38
|
+
else
|
39
|
+
@credit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def biller_credit(arg=nil)
|
44
|
+
if arg != nil
|
45
|
+
@biller_credit = arg
|
46
|
+
else
|
47
|
+
@biller_credit
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def created_at(arg=nil)
|
52
|
+
if arg != nil
|
53
|
+
@created_at = arg
|
54
|
+
else
|
55
|
+
@created_at
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def updated_at(arg=nil)
|
60
|
+
if arg != nil
|
61
|
+
@updated_at = arg
|
62
|
+
else
|
63
|
+
@updated_at
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def some_msg(arg=nil)
|
68
|
+
if arg != nil
|
69
|
+
@some_msg = arg
|
70
|
+
else
|
71
|
+
@some_msg
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def error?
|
76
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
77
|
+
end
|
78
|
+
|
79
|
+
# Transform the ruby obj -> to a Hash
|
80
|
+
def to_hash
|
81
|
+
index_hash = Hash.new
|
82
|
+
index_hash["json_claz"] = self.class.name
|
83
|
+
index_hash["id"] = id
|
84
|
+
index_hash["account_id"] = account_id
|
85
|
+
index_hash["credit"] = credit
|
86
|
+
index_hash["biller_credit"] = biller_credit
|
87
|
+
index_hash["created_at"] = created_at
|
88
|
+
index_hash["updated_at"] = updated_at
|
89
|
+
index_hash
|
90
|
+
end
|
91
|
+
|
92
|
+
# Serialize this object as a hash: called from JsonCompat.
|
93
|
+
# Verify if this called from JsonCompat during testing.
|
94
|
+
def to_json(*a)
|
95
|
+
for_json.to_json(*a)
|
96
|
+
end
|
97
|
+
|
98
|
+
def for_json
|
99
|
+
result = {
|
100
|
+
"id" => id,
|
101
|
+
"account_id" => account_id,
|
102
|
+
"credit" => credit,
|
103
|
+
"biller_credit" => biller_credit,
|
104
|
+
"created_at" => created_at,
|
105
|
+
"updated_at" => updated_at
|
106
|
+
}
|
107
|
+
result
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.json_create(o)
|
111
|
+
balances = new({})
|
112
|
+
balances.id(o["id"]) if o.has_key?("id")
|
113
|
+
balances.account_id(o["account_id"]) if o.has_key?("account_id")
|
114
|
+
balances.credit(o["credit"]) if o.has_key?("credit")
|
115
|
+
balances.biller_credit(o["biller_credit"]) if o.has_key?("biller_credit")
|
116
|
+
balances.created_at(o["created_at"]) if o.has_key?("created_at")
|
117
|
+
balances.updated_at(o["updated_at"]) if o.has_key?("updated_at")
|
118
|
+
#success or error
|
119
|
+
balances.some_msg[:code] = o["code"] if o.has_key?("code")
|
120
|
+
balances.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
121
|
+
balances.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
122
|
+
balances.some_msg[:links] = o["links"] if o.has_key?("links")
|
123
|
+
balances
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.from_hash(o)
|
127
|
+
balances = self.new(o)
|
128
|
+
balances.from_hash(o)
|
129
|
+
balances
|
130
|
+
end
|
131
|
+
|
132
|
+
def from_hash(o)
|
133
|
+
@id = o[:id] if o.has_key?(:id)
|
134
|
+
@account_id = o[:account_id] if o.has_key?(:account_id)
|
135
|
+
@credit = o[:credit] if o.has_key?(:credit)
|
136
|
+
@biller_credit = o[:biller_credit] if o.has_key?(:biller_credit)
|
137
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
138
|
+
@updated_at = o[:updated_at] if o.has_key?(:updated_at)
|
139
|
+
self
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.create(params)
|
143
|
+
acct = from_hash(params,params["email"], params["api_key"], params["host"])
|
144
|
+
acct.create
|
145
|
+
end
|
146
|
+
|
147
|
+
# Create the predef via the REST API
|
148
|
+
def create
|
149
|
+
megam_rest.post_balances(to_hash)
|
150
|
+
end
|
151
|
+
|
152
|
+
# Load all balances -
|
153
|
+
# returns a BalanceCollection
|
154
|
+
# don't return self. check if the Megam::BalanceCollection is returned.
|
155
|
+
def self.list(params)
|
156
|
+
balance = self.new(params)
|
157
|
+
balance.megam_rest.get_balances
|
158
|
+
end
|
159
|
+
|
160
|
+
# Show a particular balance by name,
|
161
|
+
# Megam::Balance
|
162
|
+
def self.show(params)
|
163
|
+
pre = self.new(params)
|
164
|
+
pre.megam_rest.get_balance(params["email"])
|
165
|
+
end
|
166
|
+
|
167
|
+
def self.delete(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
168
|
+
pre = self.new(tmp_email,tmp_api_key,tmp_host)
|
169
|
+
pre.megam_rest.delete_balance(p_name)
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.update(params)
|
173
|
+
asm = from_hash(params)
|
174
|
+
asm.update
|
175
|
+
end
|
176
|
+
|
177
|
+
# Create the node via the REST API
|
178
|
+
def update
|
179
|
+
megam_rest.update_balance(to_hash)
|
180
|
+
end
|
181
|
+
|
182
|
+
def to_s
|
183
|
+
Megam::Stuff.styled_hash(to_hash)
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
end
|