megam_api 1.5.rc5 → 1.5.rc7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/LICENSE +21 -202
- data/README.md +3 -20
- data/lib/megam/api.rb +154 -169
- data/lib/megam/api/accounts.rb +0 -15
- data/lib/megam/api/assemblies.rb +0 -15
- data/lib/megam/api/assembly.rb +0 -15
- data/lib/megam/api/balances.rb +0 -15
- data/lib/megam/api/billedhistories.rb +0 -15
- data/lib/megam/api/billingtransactions.rb +0 -15
- data/lib/megam/api/components.rb +0 -15
- data/lib/megam/api/domains.rb +0 -15
- data/lib/megam/api/errors.rb +0 -15
- data/lib/megam/api/eventsbilling.rb +0 -15
- data/lib/megam/api/eventscontainer.rb +0 -15
- data/lib/megam/api/eventsstorage.rb +0 -15
- data/lib/megam/api/eventsvm.rb +0 -15
- data/lib/megam/api/marketplaces.rb +0 -15
- data/lib/megam/api/organizations.rb +0 -15
- data/lib/megam/api/promos.rb +0 -15
- data/lib/megam/api/requests.rb +0 -15
- data/lib/megam/api/sensors.rb +0 -15
- data/lib/megam/api/snapshots.rb +0 -15
- data/lib/megam/api/sshkeys.rb +0 -15
- data/lib/megam/api/version.rb +1 -16
- data/lib/megam/core/account.rb +241 -60
- data/lib/megam/core/assemblies.rb +0 -16
- data/lib/megam/core/assemblies_collection.rb +101 -116
- data/lib/megam/core/assembly.rb +201 -218
- data/lib/megam/core/assembly_collection.rb +101 -116
- data/lib/megam/core/balances.rb +182 -197
- data/lib/megam/core/balances_collection.rb +101 -116
- data/lib/megam/core/billedhistories.rb +186 -201
- data/lib/megam/core/billedhistories_collection.rb +101 -116
- data/lib/megam/core/billingtransactions.rb +0 -15
- data/lib/megam/core/billingtransactions_collection.rb +0 -15
- data/lib/megam/core/components.rb +300 -316
- data/lib/megam/core/components_collection.rb +0 -15
- data/lib/megam/core/domain_collection.rb +1 -16
- data/lib/megam/core/domains.rb +115 -131
- data/lib/megam/core/error.rb +55 -70
- data/lib/megam/core/eventsbilling.rb +0 -16
- data/lib/megam/core/eventsbilling_collection.rb +101 -116
- data/lib/megam/core/eventscontainer.rb +0 -16
- data/lib/megam/core/eventscontainer_collection.rb +101 -116
- data/lib/megam/core/eventsstorage.rb +0 -16
- data/lib/megam/core/eventsstorage_collection.rb +0 -15
- data/lib/megam/core/eventsvm.rb +0 -16
- data/lib/megam/core/eventsvm_collection.rb +101 -116
- data/lib/megam/core/json_compat.rb +0 -12
- data/lib/megam/core/konipai.rb +0 -15
- data/lib/megam/core/log.rb +0 -15
- data/lib/megam/core/marketplace.rb +224 -241
- data/lib/megam/core/marketplace_collection.rb +0 -15
- data/lib/megam/core/organizations.rb +0 -16
- data/lib/megam/core/organizations_collection.rb +0 -15
- data/lib/megam/core/promos.rb +0 -15
- data/lib/megam/core/request.rb +0 -15
- data/lib/megam/core/request_collection.rb +0 -15
- data/lib/megam/core/rest_adapter.rb +0 -15
- data/lib/megam/core/sensors.rb +138 -154
- data/lib/megam/core/sensors_collection.rb +0 -15
- data/lib/megam/core/snapshots.rb +0 -16
- data/lib/megam/core/snapshots_collection.rb +0 -15
- data/lib/megam/core/sshkey.rb +169 -184
- data/lib/megam/core/sshkey_collection.rb +0 -15
- data/lib/megam/core/stuff.rb +17 -32
- data/lib/megam/core/text.rb +82 -97
- data/lib/megam/mixins/assemblies.rb +10 -25
- data/lib/megam/mixins/assembly.rb +33 -49
- data/lib/megam/mixins/common_deployable.rb +64 -79
- data/lib/megam/mixins/components.rb +160 -175
- data/lib/megam/mixins/megam_attributes.rb +22 -37
- data/lib/megam/mixins/outputs.rb +14 -29
- data/lib/megam/mixins/policies.rb +21 -36
- data/lib/megam_api.rb +0 -15
- data/test/mixins/test_assemblies.rb +1 -2
- data/test/test_accounts.rb +84 -29
- data/test/test_billingtranscations.rb +17 -21
- data/test/test_eventscontainer.rb +19 -23
- data/test/test_eventsstorage.rb +8 -10
- data/test/test_eventsvm.rb +19 -23
- data/test/test_helper.rb +30 -30
- data/test/test_snapshots.rb +16 -22
- metadata +2 -2
@@ -1,137 +1,122 @@
|
|
1
|
-
# Copyright:: Copyright (c) 2013-2016 Megam Systems
|
2
|
-
# License:: Apache License, Version 2.0
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
1
|
module Megam
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
2
|
+
class AssemblyCollection
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :iterator
|
6
|
+
def initialize
|
7
|
+
@assemblys = Array.new
|
8
|
+
@assemblys_by_name = Hash.new
|
9
|
+
@insert_after_idx = nil
|
10
|
+
end
|
26
11
|
|
27
|
-
|
28
|
-
|
29
|
-
|
12
|
+
def all_assemblys
|
13
|
+
@assemblys
|
14
|
+
end
|
30
15
|
|
31
|
-
|
32
|
-
|
33
|
-
|
16
|
+
def [](index)
|
17
|
+
@assemblys[index]
|
18
|
+
end
|
34
19
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
20
|
+
def []=(index, arg)
|
21
|
+
is_megam_assemblys(arg)
|
22
|
+
@assemblys[index] = arg
|
23
|
+
@assemblys_by_name[arg.name] = index
|
24
|
+
end
|
40
25
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
26
|
+
def <<(*args)
|
27
|
+
args.flatten.each do |a|
|
28
|
+
is_megam_assemblys(a)
|
29
|
+
@assemblys << a
|
30
|
+
@assemblys_by_name[a.name] = @assemblys.length - 1
|
31
|
+
end
|
32
|
+
self
|
33
|
+
end
|
49
34
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
35
|
+
# 'push' is an alias method to <<
|
36
|
+
alias_method :push, :<<
|
37
|
+
|
38
|
+
def insert(assemblys)
|
39
|
+
is_megam_assemblys(assemblys)
|
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
|
+
@assemblys.insert(@insert_after_idx + 1, assemblys)
|
45
|
+
# update name -> location mappings and register new node
|
46
|
+
@assemblys_by_name.each_key do |key|
|
47
|
+
@assemblys_by_name[key] += 1 if @assemblys_by_name[key] > @insert_after_idx
|
48
|
+
end
|
49
|
+
@assemblys_by_name[assemblys.name] = @insert_after_idx + 1
|
50
|
+
@insert_after_idx += 1
|
51
|
+
else
|
52
|
+
@assemblys << assemblys
|
53
|
+
@assemblys_by_name[assemblys.name] = @assemblys.length - 1
|
54
|
+
end
|
63
55
|
end
|
64
|
-
@assemblys_by_name[assemblys.name] = @insert_after_idx + 1
|
65
|
-
@insert_after_idx += 1
|
66
|
-
else
|
67
|
-
@assemblys << assemblys
|
68
|
-
@assemblys_by_name[assemblys.name] = @assemblys.length - 1
|
69
|
-
end
|
70
|
-
end
|
71
56
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
57
|
+
def each
|
58
|
+
@assemblys.each do |assemblys|
|
59
|
+
yield assemblys
|
60
|
+
end
|
61
|
+
end
|
77
62
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
63
|
+
def each_index
|
64
|
+
@assemblys.each_index do |i|
|
65
|
+
yield i
|
66
|
+
end
|
67
|
+
end
|
83
68
|
|
84
|
-
|
85
|
-
|
86
|
-
|
69
|
+
def empty?
|
70
|
+
@assemblys.empty?
|
71
|
+
end
|
87
72
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
73
|
+
def lookup(assemblys)
|
74
|
+
lookup_by = nil
|
75
|
+
if assemblys.kind_of?(Megam::Assembly)
|
76
|
+
lookup_by = assemblys.name
|
77
|
+
elsif assemblys.kind_of?(String)
|
78
|
+
lookup_by = assemblys
|
79
|
+
else
|
80
|
+
raise ArgumentError, "Must pass a Megam::Assemblies or String to lookup"
|
81
|
+
end
|
82
|
+
res = @assemblys_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
|
+
@assemblys[res]
|
87
|
+
end
|
103
88
|
|
104
|
-
|
105
|
-
|
106
|
-
|
89
|
+
def to_s
|
90
|
+
@assemblys.join(", ")
|
91
|
+
end
|
107
92
|
|
108
|
-
|
109
|
-
|
110
|
-
|
93
|
+
def for_json
|
94
|
+
to_a.map { |item| item.to_s }
|
95
|
+
end
|
111
96
|
|
112
|
-
|
113
|
-
|
114
|
-
|
97
|
+
def to_json(*a)
|
98
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
99
|
+
end
|
115
100
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
101
|
+
def self.json_create(o)
|
102
|
+
collection = self.new()
|
103
|
+
o["results"].each do |assemblys_list|
|
104
|
+
assemblys_array = assemblys_list.kind_of?(Array) ? assemblys_list : [ assemblys_list ]
|
105
|
+
assemblys_array.each do |assemblys|
|
106
|
+
collection.insert(assemblys)
|
122
107
|
|
108
|
+
end
|
109
|
+
end
|
110
|
+
collection
|
123
111
|
end
|
124
|
-
end
|
125
|
-
collection
|
126
|
-
end
|
127
112
|
|
128
|
-
|
113
|
+
private
|
129
114
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
115
|
+
def is_megam_assemblys(arg)
|
116
|
+
unless arg.kind_of?(Megam::Assembly)
|
117
|
+
raise ArgumentError, "Members must be Megam::Assembly's"
|
118
|
+
end
|
119
|
+
true
|
120
|
+
end
|
135
121
|
end
|
136
|
-
end
|
137
122
|
end
|
data/lib/megam/core/balances.rb
CHANGED
@@ -1,201 +1,186 @@
|
|
1
|
-
##
|
2
|
-
## Copyright 2013-2016 Megam Systems
|
3
|
-
##
|
4
|
-
## Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
## you may not use this file except in compliance with the License.
|
6
|
-
## You may obtain a copy of the License at
|
7
|
-
##
|
8
|
-
## http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
##
|
10
|
-
## Unless required by applicable law or agreed to in writing, software
|
11
|
-
## distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
## See the License for the specific language governing permissions and
|
14
|
-
## limitations under the License.
|
15
|
-
##
|
16
1
|
module Megam
|
17
|
-
|
18
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
2
|
+
class Balances < Megam::RestAdapter
|
3
|
+
def initialize(o)
|
4
|
+
@id = nil
|
5
|
+
@accounts_id = nil
|
6
|
+
@name = nil
|
7
|
+
@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 accounts_id(arg=nil)
|
27
|
+
if arg != nil
|
28
|
+
@accounts_id= arg
|
29
|
+
else
|
30
|
+
@accounts_id
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def name(arg=nil)
|
35
|
+
if arg != nil
|
36
|
+
@name = arg
|
37
|
+
else
|
38
|
+
@name
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def credit(arg=nil)
|
43
|
+
if arg != nil
|
44
|
+
@credit = arg
|
45
|
+
else
|
46
|
+
@credit
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def created_at(arg=nil)
|
51
|
+
if arg != nil
|
52
|
+
@created_at = arg
|
53
|
+
else
|
54
|
+
@created_at
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def updated_at(arg=nil)
|
59
|
+
if arg != nil
|
60
|
+
@updated_at = arg
|
61
|
+
else
|
62
|
+
@updated_at
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def some_msg(arg=nil)
|
67
|
+
if arg != nil
|
68
|
+
@some_msg = arg
|
69
|
+
else
|
70
|
+
@some_msg
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def error?
|
75
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
76
|
+
end
|
77
|
+
|
78
|
+
# Transform the ruby obj -> to a Hash
|
79
|
+
def to_hash
|
80
|
+
index_hash = Hash.new
|
81
|
+
index_hash["json_claz"] = self.class.name
|
82
|
+
index_hash["id"] = id
|
83
|
+
index_hash["accounts_id"] = accounts_id
|
84
|
+
index_hash["name"] = name
|
85
|
+
index_hash["credit"] = credit
|
86
|
+
index_hash["created_at"] = created_at
|
87
|
+
index_hash["updated_at"] = updated_at
|
88
|
+
index_hash
|
89
|
+
end
|
90
|
+
|
91
|
+
# Serialize this object as a hash: called from JsonCompat.
|
92
|
+
# Verify if this called from JsonCompat during testing.
|
93
|
+
def to_json(*a)
|
94
|
+
for_json.to_json(*a)
|
95
|
+
end
|
96
|
+
|
97
|
+
def for_json
|
98
|
+
result = {
|
99
|
+
"id" => id,
|
100
|
+
"accounts_id" => accounts_id,
|
101
|
+
"name" => name,
|
102
|
+
"credit" => credit,
|
103
|
+
"created_at" => created_at,
|
104
|
+
"updated_at" => updated_at
|
105
|
+
}
|
106
|
+
result
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.json_create(o)
|
110
|
+
balances = new({})
|
111
|
+
balances.id(o["id"]) if o.has_key?("id")
|
112
|
+
balances.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
|
113
|
+
balances.name(o["name"]) if o.has_key?("name")
|
114
|
+
balances.credit(o["credit"]) if o.has_key?("credit")
|
115
|
+
balances.created_at(o["created_at"]) if o.has_key?("created_at")
|
116
|
+
balances.updated_at(o["updated_at"]) if o.has_key?("updated_at")
|
117
|
+
#success or error
|
118
|
+
balances.some_msg[:code] = o["code"] if o.has_key?("code")
|
119
|
+
balances.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
120
|
+
balances.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
121
|
+
balances.some_msg[:links] = o["links"] if o.has_key?("links")
|
122
|
+
balances
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
126
|
+
balances = self.new(tmp_email, tmp_api_key, tmp_host)
|
127
|
+
balances.from_hash(o)
|
128
|
+
balances
|
129
|
+
end
|
130
|
+
|
131
|
+
def from_hash(o)
|
132
|
+
@id = o[:id] if o.has_key?(:id)
|
133
|
+
@accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
|
134
|
+
@name = o[:name] if o.has_key?(:name)
|
135
|
+
@credit = o[:credit] if o.has_key?(:credit)
|
136
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
137
|
+
@updated_at = o[:updated_at] if o.has_key?(:updated_at)
|
138
|
+
self
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.create(params)
|
142
|
+
acct = from_hash(params,params["email"], params["api_key"], params["host"])
|
143
|
+
acct.create
|
144
|
+
end
|
145
|
+
|
146
|
+
# Create the predef via the REST API
|
147
|
+
def create
|
148
|
+
megam_rest.post_balances(to_hash)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Load all balances -
|
152
|
+
# returns a BalanceCollection
|
153
|
+
# don't return self. check if the Megam::BalanceCollection is returned.
|
154
|
+
def self.list(params)
|
155
|
+
balance = self.new(params["email"], params["api_key"], params["host"])
|
156
|
+
balance.megam_rest.get_balances
|
157
|
+
end
|
158
|
+
|
159
|
+
# Show a particular balance by name,
|
160
|
+
# Megam::Balance
|
161
|
+
def self.show(params)
|
162
|
+
pre = self.new(params["email"], params["api_key"], params["host"])
|
163
|
+
pre.megam_rest.get_balance(params["email"])
|
164
|
+
end
|
165
|
+
|
166
|
+
def self.delete(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
167
|
+
pre = self.new(tmp_email,tmp_api_key,tmp_host)
|
168
|
+
pre.megam_rest.delete_balance(p_name)
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.update(params)
|
172
|
+
asm = from_hash(params, params["email"], params["api_key"], params["host"])
|
173
|
+
asm.update
|
174
|
+
end
|
175
|
+
|
176
|
+
# Create the node via the REST API
|
177
|
+
def update
|
178
|
+
megam_rest.update_balance(to_hash)
|
179
|
+
end
|
180
|
+
|
181
|
+
def to_s
|
182
|
+
Megam::Stuff.styled_hash(to_hash)
|
183
|
+
end
|
111
184
|
|
112
|
-
def for_json
|
113
|
-
result = {
|
114
|
-
"id" => id,
|
115
|
-
"accounts_id" => accounts_id,
|
116
|
-
"name" => name,
|
117
|
-
"credit" => credit,
|
118
|
-
"created_at" => created_at,
|
119
|
-
"updated_at" => updated_at
|
120
|
-
}
|
121
|
-
result
|
122
185
|
end
|
123
|
-
|
124
|
-
def self.json_create(o)
|
125
|
-
balances = new({})
|
126
|
-
balances.id(o["id"]) if o.has_key?("id")
|
127
|
-
balances.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
|
128
|
-
balances.name(o["name"]) if o.has_key?("name")
|
129
|
-
balances.credit(o["credit"]) if o.has_key?("credit")
|
130
|
-
balances.created_at(o["created_at"]) if o.has_key?("created_at")
|
131
|
-
balances.updated_at(o["updated_at"]) if o.has_key?("updated_at")
|
132
|
-
#success or error
|
133
|
-
balances.some_msg[:code] = o["code"] if o.has_key?("code")
|
134
|
-
balances.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
135
|
-
balances.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
136
|
-
balances.some_msg[:links] = o["links"] if o.has_key?("links")
|
137
|
-
balances
|
138
|
-
end
|
139
|
-
|
140
|
-
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
141
|
-
balances = self.new(tmp_email, tmp_api_key, tmp_host)
|
142
|
-
balances.from_hash(o)
|
143
|
-
balances
|
144
|
-
end
|
145
|
-
|
146
|
-
def from_hash(o)
|
147
|
-
@id = o[:id] if o.has_key?(:id)
|
148
|
-
@accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
|
149
|
-
@name = o[:name] if o.has_key?(:name)
|
150
|
-
@credit = o[:credit] if o.has_key?(:credit)
|
151
|
-
@created_at = o[:created_at] if o.has_key?(:created_at)
|
152
|
-
@updated_at = o[:updated_at] if o.has_key?(:updated_at)
|
153
|
-
self
|
154
|
-
end
|
155
|
-
|
156
|
-
def self.create(params)
|
157
|
-
acct = from_hash(params,params["email"], params["api_key"], params["host"])
|
158
|
-
acct.create
|
159
|
-
end
|
160
|
-
|
161
|
-
# Create the predef via the REST API
|
162
|
-
def create
|
163
|
-
megam_rest.post_balances(to_hash)
|
164
|
-
end
|
165
|
-
|
166
|
-
# Load all balances -
|
167
|
-
# returns a BalanceCollection
|
168
|
-
# don't return self. check if the Megam::BalanceCollection is returned.
|
169
|
-
def self.list(params)
|
170
|
-
balance = self.new(params["email"], params["api_key"], params["host"])
|
171
|
-
balance.megam_rest.get_balances
|
172
|
-
end
|
173
|
-
|
174
|
-
# Show a particular balance by name,
|
175
|
-
# Megam::Balance
|
176
|
-
def self.show(params)
|
177
|
-
pre = self.new(params["email"], params["api_key"], params["host"])
|
178
|
-
pre.megam_rest.get_balance(params["email"])
|
179
|
-
end
|
180
|
-
|
181
|
-
def self.delete(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
182
|
-
pre = self.new(tmp_email,tmp_api_key,tmp_host)
|
183
|
-
pre.megam_rest.delete_balance(p_name)
|
184
|
-
end
|
185
|
-
|
186
|
-
def self.update(params)
|
187
|
-
asm = from_hash(params, params["email"], params["api_key"], params["host"])
|
188
|
-
asm.update
|
189
|
-
end
|
190
|
-
|
191
|
-
# Create the node via the REST API
|
192
|
-
def update
|
193
|
-
megam_rest.update_balance(to_hash)
|
194
|
-
end
|
195
|
-
|
196
|
-
def to_s
|
197
|
-
Megam::Stuff.styled_hash(to_hash)
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
186
|
end
|