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,122 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class EventsAllCollection
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
attr_reader :iterator
|
|
6
|
+
def initialize
|
|
7
|
+
@eventsall = Array.new
|
|
8
|
+
@eventsall_by_name = Hash.new
|
|
9
|
+
@insert_after_idx = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def all_eventsall
|
|
13
|
+
@eventsall
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def [](index)
|
|
17
|
+
@eventsall[index]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def []=(index, arg)
|
|
21
|
+
is_megam_eventsall(arg)
|
|
22
|
+
@eventsall[index] = arg
|
|
23
|
+
@eventsall_by_name[arg.account_id] = index
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def <<(*args)
|
|
27
|
+
args.flatten.each do |a|
|
|
28
|
+
is_megam_events(a)
|
|
29
|
+
@eventsall << a
|
|
30
|
+
@eventsall_by_name[a.account_id] = @eventsall.length - 1
|
|
31
|
+
end
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# 'push' is an alias method to <<
|
|
36
|
+
alias_method :push, :<<
|
|
37
|
+
|
|
38
|
+
def insert(eventsall)
|
|
39
|
+
is_megam_eventsall(eventsall)
|
|
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
|
+
@eventsall.insert(@insert_after_idx + 1, eventsall)
|
|
45
|
+
# update name -> location mappings and register new node
|
|
46
|
+
@eventsall_by_name.each_key do |key|
|
|
47
|
+
@eventsall_by_name[key] += 1 if @eventsall_by_name[key] > @insert_after_idx
|
|
48
|
+
end
|
|
49
|
+
@eventsall_by_name[eventsall.account_id] = @insert_after_idx + 1
|
|
50
|
+
@insert_after_idx += 1
|
|
51
|
+
else
|
|
52
|
+
@eventsall << eventsall
|
|
53
|
+
@eventsall_by_name[eventsall.account_id] = @eventsall.length - 1
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def each
|
|
58
|
+
@eventsall.each do |eventsall|
|
|
59
|
+
yield eventsall
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def each_index
|
|
64
|
+
@eventsall.each_index do |i|
|
|
65
|
+
yield i
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def empty?
|
|
70
|
+
@eventsall.empty?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def lookup(eventsall)
|
|
74
|
+
lookup_by = nil
|
|
75
|
+
if events.kind_of?(Megam::EventsAll)
|
|
76
|
+
lookup_by = eventsall.account_id
|
|
77
|
+
elsif events.kind_of?(String)
|
|
78
|
+
lookup_by = eventsall
|
|
79
|
+
else
|
|
80
|
+
raise ArgumentError, "Must pass a Megam::EventsAll or String to lookup"
|
|
81
|
+
end
|
|
82
|
+
res = @eventsall_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
|
+
@eventsall[res]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def to_s
|
|
90
|
+
@eventsall.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 |eventsall_list|
|
|
104
|
+
eventsall_array = eventsall_list.kind_of?(Array) ? eventsall_list : [ eventsall_list ]
|
|
105
|
+
eventsall_array.each do |eventsall|
|
|
106
|
+
collection.insert(eventsall)
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
collection
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
|
|
115
|
+
def is_megam_eventsall(arg)
|
|
116
|
+
unless arg.kind_of?(Megam::EventsAll)
|
|
117
|
+
raise ArgumentError, "Members must be Megam::EventsAll's"
|
|
118
|
+
end
|
|
119
|
+
true
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class EventsBilling < Megam::RestAdapter
|
|
3
|
+
def initialize(o)
|
|
4
|
+
@account_id = nil
|
|
5
|
+
@assembly_id = nil
|
|
6
|
+
@event_type = nil
|
|
7
|
+
@data = []
|
|
8
|
+
@created_at = nil
|
|
9
|
+
@limit = nil
|
|
10
|
+
@some_msg = {}
|
|
11
|
+
super(o)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def eventsbilling
|
|
15
|
+
self
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def account_id(arg=nil)
|
|
19
|
+
if arg != nil
|
|
20
|
+
@account_id = arg
|
|
21
|
+
else
|
|
22
|
+
@account_id
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def assembly_id(arg=nil)
|
|
27
|
+
if arg != nil
|
|
28
|
+
@assembly_id = arg
|
|
29
|
+
else
|
|
30
|
+
@assembly_id
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def event_type(arg=nil)
|
|
35
|
+
if arg != nil
|
|
36
|
+
@event_type = arg
|
|
37
|
+
else
|
|
38
|
+
@event_type
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def data(arg=[])
|
|
44
|
+
if arg != []
|
|
45
|
+
@data = arg
|
|
46
|
+
else
|
|
47
|
+
@data
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def limit(arg=[])
|
|
52
|
+
if arg != []
|
|
53
|
+
@limit = arg
|
|
54
|
+
else
|
|
55
|
+
@limit
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
def created_at(arg=nil)
|
|
59
|
+
if arg != nil
|
|
60
|
+
@created_at = arg
|
|
61
|
+
else
|
|
62
|
+
@created_at
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def error?
|
|
67
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def some_msg(arg=nil)
|
|
72
|
+
if arg != nil
|
|
73
|
+
@some_msg = arg
|
|
74
|
+
else
|
|
75
|
+
@some_msg
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# Transform the ruby obj -> to a Hash
|
|
81
|
+
def to_hash
|
|
82
|
+
index_hash = Hash.new
|
|
83
|
+
index_hash["json_claz"] = self.class.name
|
|
84
|
+
index_hash["account_id"] = account_id
|
|
85
|
+
index_hash["assembly_id"] = assembly_id
|
|
86
|
+
index_hash["event_type"] = event_type
|
|
87
|
+
index_hash["data"] = data
|
|
88
|
+
index_hash["limit"] = limit
|
|
89
|
+
index_hash["created_at"] = created_at
|
|
90
|
+
index_hash["some_msg"] = some_msg
|
|
91
|
+
index_hash
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Serialize this object as a hash: called from JsonCompat.
|
|
95
|
+
# Verify if this called from JsonCompat during testing.
|
|
96
|
+
def to_json(*a)
|
|
97
|
+
for_json.to_json(*a)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def for_json
|
|
101
|
+
result = {
|
|
102
|
+
"account_id" => account_id,
|
|
103
|
+
"assembly_id" => assembly_id,
|
|
104
|
+
"event_type" => event_type,
|
|
105
|
+
"data" => data,
|
|
106
|
+
"limit" => limit,
|
|
107
|
+
"created_at" => created_at
|
|
108
|
+
}
|
|
109
|
+
result
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def self.json_create(o)
|
|
113
|
+
evt = new({})
|
|
114
|
+
evt.account_id(o["account_id"]) if o.has_key?("account_id")
|
|
115
|
+
evt.assembly_id(o["assembly_id"]) if o.has_key?("assembly_id")
|
|
116
|
+
evt.event_type(o["event_type"]) if o.has_key?("event_type") #this will be an array? can hash store array?
|
|
117
|
+
evt.data(o["data"]) if o.has_key?("data")
|
|
118
|
+
evt.limit(o["limit"]) if o.has_key?("limit")
|
|
119
|
+
evt.created_at(o["created_at"]) if o.has_key?("created_at")
|
|
120
|
+
evt.some_msg[:code] = o["code"] if o.has_key?("code")
|
|
121
|
+
evt.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
|
122
|
+
evt.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
|
123
|
+
evt.some_msg[:links] = o["links"] if o.has_key?("links")
|
|
124
|
+
evt
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def self.from_hash(o)
|
|
128
|
+
evt = self.new(o)
|
|
129
|
+
evt.from_hash(o)
|
|
130
|
+
evt
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def from_hash(o)
|
|
134
|
+
@account_id = o[:account_id] if o.has_key?(:account_id)
|
|
135
|
+
@assembly_id = o[:assembly_id] if o.has_key?(:assembly_id)
|
|
136
|
+
@event_type = o[:event_type] if o.has_key?(:event_type)
|
|
137
|
+
@data = o[:data] if o.has_key?(:data)
|
|
138
|
+
@limit = o[:limit] if o.has_key?(:limit)
|
|
139
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
|
140
|
+
self
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def self.create(params)
|
|
144
|
+
evt = from_hash(params)
|
|
145
|
+
evt.create
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Create the node via the REST API
|
|
149
|
+
def create
|
|
150
|
+
megam_rest.post_events(to_hash)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Load a account by email_p
|
|
154
|
+
def self.show(o)
|
|
155
|
+
evt = self.new(o)
|
|
156
|
+
evt.megam_rest.get_eventsbilling(o[:limit], to_hash)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def self.list(params)
|
|
160
|
+
asm = self.new(params)
|
|
161
|
+
asm.megam_rest.list_eventsbilling(params[:limit])
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def self.index(params)
|
|
165
|
+
asm = self.new(params)
|
|
166
|
+
asm.megam_rest.index_eventsbilling
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def to_s
|
|
170
|
+
Megam::Stuff.styled_hash(to_hash)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
end
|
|
174
|
+
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class EventsBillingCollection
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
attr_reader :iterator
|
|
6
|
+
def initialize
|
|
7
|
+
@eventsbilling = Array.new
|
|
8
|
+
@eventsbilling_by_name = Hash.new
|
|
9
|
+
@insert_after_idx = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def all_eventsbilling
|
|
13
|
+
@eventsbilling
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def [](index)
|
|
17
|
+
@eventsbilling[index]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def []=(index, arg)
|
|
21
|
+
is_megam_eventsbilling(arg)
|
|
22
|
+
@eventsbilling[index] = arg
|
|
23
|
+
@eventsbilling_by_name[arg.account_id] = index
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def <<(*args)
|
|
27
|
+
args.flatten.each do |a|
|
|
28
|
+
is_megam_events(a)
|
|
29
|
+
@eventsbilling << a
|
|
30
|
+
@eventsbilling_by_name[a.account_id] = @eventsbilling.length - 1
|
|
31
|
+
end
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# 'push' is an alias method to <<
|
|
36
|
+
alias_method :push, :<<
|
|
37
|
+
|
|
38
|
+
def insert(eventsbilling)
|
|
39
|
+
is_megam_eventsbilling(eventsbilling)
|
|
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
|
+
@eventsbilling.insert(@insert_after_idx + 1, eventsbilling)
|
|
45
|
+
# update name -> location mappings and register new node
|
|
46
|
+
@eventsbilling_by_name.each_key do |key|
|
|
47
|
+
@eventsbilling_by_name[key] += 1 if @eventsbilling_by_name[key] > @insert_after_idx
|
|
48
|
+
end
|
|
49
|
+
@eventsbilling_by_name[eventsbilling.account_id] = @insert_after_idx + 1
|
|
50
|
+
@insert_after_idx += 1
|
|
51
|
+
else
|
|
52
|
+
@eventsbilling << eventsbilling
|
|
53
|
+
@eventsbilling_by_name[eventsbilling.account_id] = @eventsbilling.length - 1
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def each
|
|
58
|
+
@eventsbilling.each do |eventsbilling|
|
|
59
|
+
yield eventsbilling
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def each_index
|
|
64
|
+
@eventsbilling.each_index do |i|
|
|
65
|
+
yield i
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def empty?
|
|
70
|
+
@eventsbilling.empty?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def lookup(eventsbilling)
|
|
74
|
+
lookup_by = nil
|
|
75
|
+
if events.kind_of?(Megam::EventsBilling)
|
|
76
|
+
lookup_by = eventsbilling.account_id
|
|
77
|
+
elsif events.kind_of?(String)
|
|
78
|
+
lookup_by = eventsbilling
|
|
79
|
+
else
|
|
80
|
+
raise ArgumentError, "Must pass a Megam::EventsBilling or String to lookup"
|
|
81
|
+
end
|
|
82
|
+
res = @eventsbilling_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
|
+
@eventsbilling[res]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def to_s
|
|
90
|
+
@eventsbilling.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 |eventsbilling_list|
|
|
104
|
+
eventsbilling_array = eventsbilling_list.kind_of?(Array) ? eventsbilling_list : [ eventsbilling_list ]
|
|
105
|
+
eventsbilling_array.each do |eventsbilling|
|
|
106
|
+
collection.insert(eventsbilling)
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
collection
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
|
|
115
|
+
def is_megam_eventsbilling(arg)
|
|
116
|
+
unless arg.kind_of?(Megam::EventsBilling)
|
|
117
|
+
raise ArgumentError, "Members must be Megam::EventsBilling's"
|
|
118
|
+
end
|
|
119
|
+
true
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
module Megam
|
|
2
|
+
class EventsContainer < Megam::RestAdapter
|
|
3
|
+
def initialize(o)
|
|
4
|
+
@account_id = nil
|
|
5
|
+
@assembly_id = nil
|
|
6
|
+
@event_type = nil
|
|
7
|
+
@data = []
|
|
8
|
+
@created_at = nil
|
|
9
|
+
@id = nil
|
|
10
|
+
@limit = nil
|
|
11
|
+
@some_msg = {}
|
|
12
|
+
super(o)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def eventscontainer
|
|
16
|
+
self
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def account_id(arg=nil)
|
|
20
|
+
if arg != nil
|
|
21
|
+
@account_id = arg
|
|
22
|
+
else
|
|
23
|
+
@account_id
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def id(arg=nil)
|
|
28
|
+
if arg != nil
|
|
29
|
+
@id = arg
|
|
30
|
+
else
|
|
31
|
+
@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 event_type(arg=nil)
|
|
44
|
+
if arg != nil
|
|
45
|
+
@event_type = arg
|
|
46
|
+
else
|
|
47
|
+
@event_type
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def data(arg=[])
|
|
53
|
+
if arg != []
|
|
54
|
+
@data = arg
|
|
55
|
+
else
|
|
56
|
+
@data
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def limit(arg=[])
|
|
61
|
+
if arg != []
|
|
62
|
+
@limit = arg
|
|
63
|
+
else
|
|
64
|
+
@limit
|
|
65
|
+
end
|
|
66
|
+
end
|
|
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 error?
|
|
76
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def some_msg(arg=nil)
|
|
81
|
+
if arg != nil
|
|
82
|
+
@some_msg = arg
|
|
83
|
+
else
|
|
84
|
+
@some_msg
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# Transform the ruby obj -> to a Hash
|
|
90
|
+
def to_hash
|
|
91
|
+
index_hash = Hash.new
|
|
92
|
+
index_hash["json_claz"] = self.class.name
|
|
93
|
+
index_hash["account_id"] = account_id
|
|
94
|
+
index_hash["assembly_id"] = assembly_id
|
|
95
|
+
index_hash["event_type"] = event_type
|
|
96
|
+
index_hash["data"] = data
|
|
97
|
+
index_hash["limit"] = limit
|
|
98
|
+
index_hash["created_at"] = created_at
|
|
99
|
+
index_hash["id"] = id
|
|
100
|
+
index_hash["some_msg"] = some_msg
|
|
101
|
+
index_hash
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Serialize this object as a hash: called from JsonCompat.
|
|
105
|
+
# Verify if this called from JsonCompat during testing.
|
|
106
|
+
def to_json(*a)
|
|
107
|
+
for_json.to_json(*a)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def for_json
|
|
111
|
+
result = {
|
|
112
|
+
"account_id" => account_id,
|
|
113
|
+
"assembly_id" => assembly_id,
|
|
114
|
+
"event_type" => event_type,
|
|
115
|
+
"data" => data,
|
|
116
|
+
"limit" => limit,
|
|
117
|
+
"created_at" => created_at,
|
|
118
|
+
"id" => id
|
|
119
|
+
}
|
|
120
|
+
result
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def self.json_create(o)
|
|
124
|
+
evt = new({})
|
|
125
|
+
evt.account_id(o["account_id"]) if o.has_key?("account_id")
|
|
126
|
+
evt.assembly_id(o["assembly_id"]) if o.has_key?("assembly_id")
|
|
127
|
+
evt.id(o["id"]) if o.has_key?("id")
|
|
128
|
+
evt.event_type(o["event_type"]) if o.has_key?("event_type") #this will be an array? can hash store array?
|
|
129
|
+
evt.data(o["data"]) if o.has_key?("data")
|
|
130
|
+
evt.limit(o["limit"]) if o.has_key?("limit")
|
|
131
|
+
evt.created_at(o["created_at"]) if o.has_key?("created_at")
|
|
132
|
+
evt.some_msg[:code] = o["code"] if o.has_key?("code")
|
|
133
|
+
evt.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
|
134
|
+
evt.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
|
135
|
+
evt.some_msg[:links] = o["links"] if o.has_key?("links")
|
|
136
|
+
evt
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def self.from_hash(o)
|
|
140
|
+
evt = self.new(o)
|
|
141
|
+
evt.from_hash(o)
|
|
142
|
+
evt
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def from_hash(o)
|
|
146
|
+
@account_id = o[:account_id] if o.has_key?(:account_id)
|
|
147
|
+
@assembly_id = o[:assembly_id] if o.has_key?(:assembly_id)
|
|
148
|
+
@event_type = o[:event_type] if o.has_key?(:event_type)
|
|
149
|
+
@data = o[:data] if o.has_key?(:data)
|
|
150
|
+
@limit = o[:limit] if o.has_key?(:limit)
|
|
151
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
|
152
|
+
@id = o[:id] if o.has_key?(:id)
|
|
153
|
+
self
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def self.create(params)
|
|
157
|
+
evt = from_hash(params)
|
|
158
|
+
evt.create
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# Create the node via the REST API
|
|
162
|
+
def create
|
|
163
|
+
megam_rest.post_events(to_hash)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Load a account by email_p
|
|
167
|
+
def self.show(o)
|
|
168
|
+
evt = from_hash(o)
|
|
169
|
+
evt.megam_rest.get_eventscontainer(o[:limit], evt.from_hash(o).for_json)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def self.list(params)
|
|
173
|
+
asm = self.new(params)
|
|
174
|
+
asm.megam_rest.list_eventscontainer(params[:limit])
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def self.index(params)
|
|
178
|
+
asm = self.new(params)
|
|
179
|
+
asm.megam_rest.index_eventscontainer
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def to_s
|
|
183
|
+
Megam::Stuff.styled_hash(to_hash)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
end
|
|
187
|
+
end
|