virtengine_api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,121 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class BalancesCollection
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
attr_reader :iterator
|
|
6
|
+
def initialize
|
|
7
|
+
@balance = Array.new
|
|
8
|
+
@balance_by_name = Hash.new
|
|
9
|
+
@insert_after_idx = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def all_balance
|
|
13
|
+
@balance
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def [](index)
|
|
17
|
+
@balance[index]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def []=(index, arg)
|
|
21
|
+
is_megam_balance(arg)
|
|
22
|
+
@balance[index] = arg
|
|
23
|
+
@balance_by_name[arg.id] = index
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def <<(*args)
|
|
27
|
+
args.flatten.each do |a|
|
|
28
|
+
is_megam_balance(a)
|
|
29
|
+
@balance << a
|
|
30
|
+
@balance_by_name[a.id] =@balance.length - 1
|
|
31
|
+
end
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# 'push' is an alias method to <<
|
|
36
|
+
alias_method :push, :<<
|
|
37
|
+
|
|
38
|
+
def insert(balance)
|
|
39
|
+
is_megam_balance(balance)
|
|
40
|
+
if @insert_after_idx
|
|
41
|
+
# in the middle of executing a run, so any predefs inserted now should
|
|
42
|
+
# be placed after the most recent addition done by the currently executing
|
|
43
|
+
# balance
|
|
44
|
+
@balance.insert(@insert_after_idx + 1, balance)
|
|
45
|
+
# update id -> location mappings and register new balance
|
|
46
|
+
@balance_by_name.each_key do |key|
|
|
47
|
+
@balance_by_name[key] += 1 if@balance_by_name[key] > @insert_after_idx
|
|
48
|
+
end
|
|
49
|
+
@balance_by_name[balance.id] = @insert_after_idx + 1
|
|
50
|
+
@insert_after_idx += 1
|
|
51
|
+
else
|
|
52
|
+
@balance << balance
|
|
53
|
+
@balance_by_name[balance.id] =@balance.length - 1
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def each
|
|
58
|
+
@balance.each do |balance|
|
|
59
|
+
yield balance
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def each_index
|
|
64
|
+
@balance.each_index do |i|
|
|
65
|
+
yield i
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def empty?
|
|
70
|
+
@balance.empty?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def lookup(balance)
|
|
74
|
+
lookup_by = nil
|
|
75
|
+
if balance.kind_of?(Megam::Balances)
|
|
76
|
+
lookup_by = balance.id
|
|
77
|
+
elsif balance.kind_of?(String)
|
|
78
|
+
lookup_by = balance
|
|
79
|
+
else
|
|
80
|
+
raise ArgumentError, "Must pass a Megam::Balance or String to lookup"
|
|
81
|
+
end
|
|
82
|
+
res =@balance_by_name[lookup_by]
|
|
83
|
+
unless res
|
|
84
|
+
raise ArgumentError, "Cannot find a balance matching #{lookup_by} (did you define it first?)"
|
|
85
|
+
end
|
|
86
|
+
@balance[res]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def to_s
|
|
90
|
+
@balance.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 |balance_list|
|
|
104
|
+
balance_array = balance_list.kind_of?(Array) ? balance_list : [ balance_list ]
|
|
105
|
+
balance_array.each do |balance|
|
|
106
|
+
collection.insert(balance)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
collection
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
def is_megam_balance(arg)
|
|
115
|
+
unless arg.kind_of?(Megam::Balances)
|
|
116
|
+
raise ArgumentError, "Members must be Megam::balance's"
|
|
117
|
+
end
|
|
118
|
+
true
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class Billedhistories < Megam::RestAdapter
|
|
3
|
+
def initialize(o)
|
|
4
|
+
@id = nil
|
|
5
|
+
@accounts_id = nil
|
|
6
|
+
@assembly_id = nil
|
|
7
|
+
@bill_type = nil
|
|
8
|
+
@billing_amount = nil
|
|
9
|
+
@currency_type = nil
|
|
10
|
+
@created_at = nil
|
|
11
|
+
@some_msg = {}
|
|
12
|
+
super(o)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def billedhistories
|
|
16
|
+
self
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def id(arg=nil)
|
|
20
|
+
if arg != nil
|
|
21
|
+
@id = arg
|
|
22
|
+
else
|
|
23
|
+
@id
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def accounts_id(arg=nil)
|
|
28
|
+
if arg != nil
|
|
29
|
+
@accounts_id= arg
|
|
30
|
+
else
|
|
31
|
+
@accounts_id
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def assembly_id(arg=nil)
|
|
36
|
+
if arg != nil
|
|
37
|
+
@assembly_id = arg
|
|
38
|
+
else
|
|
39
|
+
@assembly_id
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def bill_type(arg=nil)
|
|
44
|
+
if arg != nil
|
|
45
|
+
@bill_type = arg
|
|
46
|
+
else
|
|
47
|
+
@bill_type
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def billing_amount(arg=nil)
|
|
52
|
+
if arg != nil
|
|
53
|
+
@billing_amount= arg
|
|
54
|
+
else
|
|
55
|
+
@billing_amount
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def currency_type(arg=nil)
|
|
60
|
+
if arg != nil
|
|
61
|
+
@currency_type = arg
|
|
62
|
+
else
|
|
63
|
+
@currency_type
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def created_at(arg=nil)
|
|
68
|
+
if arg != nil
|
|
69
|
+
@created_at = arg
|
|
70
|
+
else
|
|
71
|
+
@created_at
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def some_msg(arg=nil)
|
|
76
|
+
if arg != nil
|
|
77
|
+
@some_msg = arg
|
|
78
|
+
else
|
|
79
|
+
@some_msg
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def error?
|
|
84
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Transform the ruby obj -> to a Hash
|
|
88
|
+
def to_hash
|
|
89
|
+
index_hash = Hash.new
|
|
90
|
+
index_hash["json_claz"] = self.class.name
|
|
91
|
+
index_hash["id"] = id
|
|
92
|
+
index_hash["accounts_id"] = accounts_id
|
|
93
|
+
index_hash["assembly_id"] = assembly_id
|
|
94
|
+
index_hash["bill_type"] = bill_type
|
|
95
|
+
index_hash["billing_amount"] = billing_amount
|
|
96
|
+
index_hash["currency_type"] = currency_type
|
|
97
|
+
index_hash["created_at"] = created_at
|
|
98
|
+
index_hash
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Serialize this object as a hash: called from JsonCompat.
|
|
102
|
+
# Verify if this called from JsonCompat during testing.
|
|
103
|
+
def to_json(*a)
|
|
104
|
+
for_json.to_json(*a)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def for_json
|
|
108
|
+
result = {
|
|
109
|
+
"id" => id,
|
|
110
|
+
"accounts_id" => accounts_id,
|
|
111
|
+
"assembly_id" => assembly_id,
|
|
112
|
+
"bill_type" => bill_type,
|
|
113
|
+
"billing_amount" => billing_amount,
|
|
114
|
+
"currency_type" => currency_type,
|
|
115
|
+
"created_at" => created_at
|
|
116
|
+
}
|
|
117
|
+
result
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
#
|
|
121
|
+
def self.json_create(o)
|
|
122
|
+
bal = new({})
|
|
123
|
+
bal.id(o["id"]) if o.has_key?("id")
|
|
124
|
+
bal.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
|
|
125
|
+
bal.assembly_id(o["assembly_id"]) if o.has_key?("assembly_id")
|
|
126
|
+
bal.bill_type(o["bill_type"]) if o.has_key?("bill_type")
|
|
127
|
+
bal.billing_amount(o["billing_amount"]) if o.has_key?("billing_amount")
|
|
128
|
+
bal.currency_type(o["currency_type"]) if o.has_key?("currency_type")
|
|
129
|
+
bal.created_at(o["created_at"]) if o.has_key?("created_at")
|
|
130
|
+
#success or error
|
|
131
|
+
bal.some_msg[:code] = o["code"] if o.has_key?("code")
|
|
132
|
+
bal.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
|
133
|
+
bal.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
|
134
|
+
bal.some_msg[:links] = o["links"] if o.has_key?("links")
|
|
135
|
+
bal
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
|
139
|
+
bal = self.new(tmp_email, tmp_api_key, tmp_host)
|
|
140
|
+
bal.from_hash(o)
|
|
141
|
+
bal
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def from_hash(o)
|
|
145
|
+
@id = o[:id] if o.has_key?(:id)
|
|
146
|
+
@accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
|
|
147
|
+
@assembly_id = o[:assembly_id] if o.has_key?(:assembly_id)
|
|
148
|
+
@bill_type = o[:bill_type] if o.has_key?(:bill_type)
|
|
149
|
+
@billing_amount = o[:billing_amount] if o.has_key?(:billing_amount)
|
|
150
|
+
@currency_type = o[:currency_type] if o.has_key?(:currency_type)
|
|
151
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
|
152
|
+
self
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def self.create(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
|
156
|
+
acct = from_hash(o,tmp_email, tmp_api_key, tmp_host)
|
|
157
|
+
acct.create
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Create the billing histories via the REST API
|
|
161
|
+
def create
|
|
162
|
+
megam_rest.post_billedhistories(to_hash)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Load all billing histories -
|
|
166
|
+
# returns a BillingHistoriesCollection
|
|
167
|
+
# don't return self. check if the Megam::BillingHistoriesCollection is returned.
|
|
168
|
+
def self.list(params)
|
|
169
|
+
billhistory = self.new(params["email"], params["api_key"], params["host"])
|
|
170
|
+
billhistory.megam_rest.get_billedhistories
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# Show a particular billing history by name,
|
|
174
|
+
# Megam::BillingHistory
|
|
175
|
+
def self.show(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
|
176
|
+
pre = self.new(tmp_email,tmp_api_key, tmp_host)
|
|
177
|
+
pre.megam_rest.get_billedhistory(p_name)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def self.delete(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
|
181
|
+
pre = self.new(tmp_email,tmp_api_key, tmp_host)
|
|
182
|
+
pre.megam_rest.delete_billedhistory(p_name)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def to_s
|
|
186
|
+
Megam::Stuff.styled_hash(to_hash)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
end
|
|
190
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class BilledhistoriesCollection
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
attr_reader :iterator
|
|
6
|
+
def initialize
|
|
7
|
+
@billedhistories = Array.new
|
|
8
|
+
@billedhistories_by_name = Hash.new
|
|
9
|
+
@insert_after_idx = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def all_billedhistories
|
|
13
|
+
@billedhistories
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def [](index)
|
|
17
|
+
@billedhistories[index]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def []=(index, arg)
|
|
21
|
+
is_megam_billedhistories(arg)
|
|
22
|
+
@billedhistories[index] = arg
|
|
23
|
+
@billedhistories_by_name[arg.accounts_id] = index
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def <<(*args)
|
|
27
|
+
args.flatten.each do |a|
|
|
28
|
+
is_megam_billedhistories(a)
|
|
29
|
+
@billedhistories << a
|
|
30
|
+
@billedhistories_by_name[a.accounts_id] =@billedhistories.length - 1
|
|
31
|
+
end
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# 'push' is an alias method to <<
|
|
36
|
+
alias_method :push, :<<
|
|
37
|
+
|
|
38
|
+
def insert(billedhistories)
|
|
39
|
+
is_megam_billedhistories(billedhistories)
|
|
40
|
+
if @insert_after_idx
|
|
41
|
+
# in the middle of executing a run, so any predefs inserted now should
|
|
42
|
+
# be placed after the most recent addition done by the currently executing
|
|
43
|
+
# billedhistories
|
|
44
|
+
@billedhistories.insert(@insert_after_idx + 1, billedhistories)
|
|
45
|
+
# update name -> location mappings and register new billedhistories
|
|
46
|
+
@billedhistories_by_name.each_key do |key|
|
|
47
|
+
@billedhistories_by_name[key] += 1 if@billedhistories_by_name[key] > @insert_after_idx
|
|
48
|
+
end
|
|
49
|
+
@billedhistories_by_name[billedhistories.accounts_id] = @insert_after_idx + 1
|
|
50
|
+
@insert_after_idx += 1
|
|
51
|
+
else
|
|
52
|
+
@billedhistories << billedhistories
|
|
53
|
+
@billedhistories_by_name[billedhistories.accounts_id] =@billedhistories.length - 1
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def each
|
|
58
|
+
@billedhistories.each do |billedhistories|
|
|
59
|
+
yield billedhistories
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def each_index
|
|
64
|
+
@billedhistories.each_index do |i|
|
|
65
|
+
yield i
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def empty?
|
|
70
|
+
@billedhistories.empty?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def lookup(billedhistories)
|
|
74
|
+
lookup_by = nil
|
|
75
|
+
if Billedhistories.kind_of?(Megam::Billedhistories)
|
|
76
|
+
lookup_by = billedhistories.accounts_id
|
|
77
|
+
elsif billedhistories.kind_of?(String)
|
|
78
|
+
lookup_by = billedhistories
|
|
79
|
+
else
|
|
80
|
+
raise ArgumentError, "Must pass a Megam::billedhistories or String to lookup"
|
|
81
|
+
end
|
|
82
|
+
res =@billedhistories_by_name[lookup_by]
|
|
83
|
+
unless res
|
|
84
|
+
raise ArgumentError, "Cannot find a billedhistories matching #{lookup_by} (did you define it first?)"
|
|
85
|
+
end
|
|
86
|
+
@billedhistories[res]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def to_s
|
|
90
|
+
@billedhistories.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 |billedhistories_list|
|
|
104
|
+
billedhistories_array = billedhistories_list.kind_of?(Array) ? billedhistories_list : [ billedhistories_list ]
|
|
105
|
+
billedhistories_array.each do |billedhistories|
|
|
106
|
+
collection.insert(billedhistories)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
collection
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
def is_megam_billedhistories(arg)
|
|
115
|
+
unless arg.kind_of?(Megam::Billedhistories)
|
|
116
|
+
raise ArgumentError, "Members must be Megam::billedhistories's"
|
|
117
|
+
end
|
|
118
|
+
true
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class Billingtransactions < Megam::RestAdapter
|
|
3
|
+
def initialize(o)
|
|
4
|
+
@id = nil
|
|
5
|
+
@accounts_id = nil
|
|
6
|
+
@gateway = nil
|
|
7
|
+
@amountin = nil
|
|
8
|
+
@amountout = nil
|
|
9
|
+
@fees = nil
|
|
10
|
+
@tranid = nil
|
|
11
|
+
@trandate = nil
|
|
12
|
+
@currency_type = nil
|
|
13
|
+
@created_at = nil
|
|
14
|
+
@some_msg = {}
|
|
15
|
+
super(o)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def
|
|
19
|
+
self
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def id(arg=nil)
|
|
23
|
+
if arg != nil
|
|
24
|
+
@id = arg
|
|
25
|
+
else
|
|
26
|
+
@id
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def accounts_id(arg=nil)
|
|
31
|
+
if arg != nil
|
|
32
|
+
@accounts_id= arg
|
|
33
|
+
else
|
|
34
|
+
@accounts_id
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def gateway(arg=nil)
|
|
39
|
+
if arg != nil
|
|
40
|
+
@gateway= arg
|
|
41
|
+
else
|
|
42
|
+
@gateway
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def amountin(arg=nil)
|
|
47
|
+
if arg != nil
|
|
48
|
+
@amountin= arg
|
|
49
|
+
else
|
|
50
|
+
@amountin
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def amountout(arg=nil)
|
|
55
|
+
if arg != nil
|
|
56
|
+
@amountout= arg
|
|
57
|
+
else
|
|
58
|
+
@amountout
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def fees(arg=nil)
|
|
63
|
+
if arg != nil
|
|
64
|
+
@fees = arg
|
|
65
|
+
else
|
|
66
|
+
@fees
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def tranid(arg=nil)
|
|
71
|
+
if arg != nil
|
|
72
|
+
@tranid = arg
|
|
73
|
+
else
|
|
74
|
+
@tranid
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def trandate(arg=nil)
|
|
79
|
+
if arg != nil
|
|
80
|
+
@trandate = arg
|
|
81
|
+
else
|
|
82
|
+
@trandate
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def currency_type(arg=nil)
|
|
87
|
+
if arg != nil
|
|
88
|
+
@currency_type = arg
|
|
89
|
+
else
|
|
90
|
+
@currency_type
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def created_at(arg=nil)
|
|
95
|
+
if arg != nil
|
|
96
|
+
@created_at = arg
|
|
97
|
+
else
|
|
98
|
+
@created_at
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def some_msg(arg=nil)
|
|
103
|
+
if arg != nil
|
|
104
|
+
@some_msg = arg
|
|
105
|
+
else
|
|
106
|
+
@some_msg
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def error?
|
|
111
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Transform the ruby obj -> to a Hash
|
|
115
|
+
def to_hash
|
|
116
|
+
index_hash = Hash.new
|
|
117
|
+
index_hash["json_claz"] = self.class.name
|
|
118
|
+
index_hash["id"] = id
|
|
119
|
+
index_hash["accounts_id"] = accounts_id
|
|
120
|
+
index_hash["gateway"] = gateway
|
|
121
|
+
index_hash["amountin"] = amountin
|
|
122
|
+
index_hash["amountout"] = amountout
|
|
123
|
+
index_hash["fees"] = fees
|
|
124
|
+
index_hash["tranid"] = tranid
|
|
125
|
+
index_hash["trandate"] = trandate
|
|
126
|
+
index_hash["currency_type"] = currency_type
|
|
127
|
+
index_hash["created_at"] = created_at
|
|
128
|
+
index_hash
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Serialize this object as a hash: called from JsonCompat.
|
|
132
|
+
# Verify if this called from JsonCompat during testing.
|
|
133
|
+
def to_json(*a)
|
|
134
|
+
for_json.to_json(*a)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def for_json
|
|
138
|
+
result = {
|
|
139
|
+
"id" => id,
|
|
140
|
+
"accounts_id" => accounts_id,
|
|
141
|
+
"gateway" => gateway,
|
|
142
|
+
"amountin" => amountin,
|
|
143
|
+
"amountout" => amountout,
|
|
144
|
+
"fees" => fees,
|
|
145
|
+
"tranid" => tranid,
|
|
146
|
+
"trandate" => trandate,
|
|
147
|
+
"currency_type" => currency_type,
|
|
148
|
+
"created_at" => created_at
|
|
149
|
+
}
|
|
150
|
+
result
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
#
|
|
154
|
+
def self.json_create(o)
|
|
155
|
+
bal = new({})
|
|
156
|
+
bal.id(o["id"]) if o.has_key?("id")
|
|
157
|
+
bal.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
|
|
158
|
+
bal.gateway(o["gateway"]) if o.has_key?("gateway")
|
|
159
|
+
bal.amountin(o["amountin"]) if o.has_key?("amountin")
|
|
160
|
+
bal.amountout(o["amountout"]) if o.has_key?("amountout")
|
|
161
|
+
bal.fees(o["fees"]) if o.has_key?("fees")
|
|
162
|
+
bal.tranid(o["tranid"]) if o.has_key?("tranid")
|
|
163
|
+
bal.trandate(o["trandate"]) if o.has_key?("trandate")
|
|
164
|
+
bal.currency_type(o["currency_type"]) if o.has_key?("currency_type")
|
|
165
|
+
bal.created_at(o["created_at"]) if o.has_key?("created_at")
|
|
166
|
+
#success or error
|
|
167
|
+
bal.some_msg[:code] = o["code"] if o.has_key?("code")
|
|
168
|
+
bal.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
|
169
|
+
bal.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
|
170
|
+
bal.some_msg[:links] = o["links"] if o.has_key?("links")
|
|
171
|
+
bal
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def self.from_hash(o)
|
|
175
|
+
bal = self.new(o)
|
|
176
|
+
bal.from_hash(o)
|
|
177
|
+
bal
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def from_hash(o)
|
|
181
|
+
@id = o[:id] if o.has_key?(:id)
|
|
182
|
+
@accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
|
|
183
|
+
@gateway = o[:gateway] if o.has_key?(:gateway)
|
|
184
|
+
@amountin = o[:amountin] if o.has_key?(:amountin)
|
|
185
|
+
@amountout = o[:amountout] if o.has_key?(:amountout)
|
|
186
|
+
@fees = o[:fees] if o.has_key?(:fees)
|
|
187
|
+
@tranid = o[:tranid] if o.has_key?(:tranid)
|
|
188
|
+
@trandate = o[:trandate] if o.has_key?(:trandate)
|
|
189
|
+
@currency_type = o[:currency_type] if o.has_key?(:currency_type)
|
|
190
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
|
191
|
+
self
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def self.create(params)
|
|
195
|
+
acct = from_hash(params)
|
|
196
|
+
acct.create
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def create
|
|
200
|
+
megam_rest.post_billedhistories(to_hash)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def self.list(params)
|
|
204
|
+
bill = self.new(params)
|
|
205
|
+
bill.megam_rest.get_billingtransactions
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def to_s
|
|
210
|
+
Megam::Stuff.styled_hash(to_hash)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
end
|
|
214
|
+
end
|