megam_api 1.7.6 → 1.7.8
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 +4 -4
- data/lib/megam/api.rb +20 -11
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/json_compat.rb +1 -7
- data/lib/megam/core/rest_adapter.rb +9 -6
- metadata +29 -6
- data/lib/megam/api/eventsall.rb +0 -36
- data/lib/megam/core/eventsall.rb +0 -186
- data/lib/megam/core/eventsall_collection.rb +0 -122
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e688fbe4d9c65ce6d84c379b41be88be58c7465a
|
4
|
+
data.tar.gz: afca3ba773c8004115c796df39fdf440594225fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a56e9fdf4d5d752466c1824bc917e853e675180f3f1f9d61c4be5b831fcb903b7b34eb3c538f352783692cc0919deb22d7f3dfbd9f8ef4c70b455e9f9f2d4dd
|
7
|
+
data.tar.gz: 46ab486c5ff99f3c0705c995d7f2deed5077e94ad0e9592e039a6cbf746727fad28be2e0fbb1adc4fe1772f81ed8bff52137bbcd991b1bd71321c040e4a7da63
|
data/lib/megam/api.rb
CHANGED
@@ -23,7 +23,6 @@ require 'megam/api/promos'
|
|
23
23
|
require 'megam/api/requests'
|
24
24
|
require 'megam/api/sensors'
|
25
25
|
require 'megam/api/sshkeys'
|
26
|
-
require 'megam/api/eventsall'
|
27
26
|
require 'megam/api/eventsvm'
|
28
27
|
require 'megam/api/eventscontainer'
|
29
28
|
require 'megam/api/eventsbilling'
|
@@ -53,9 +52,7 @@ require 'megam/core/request'
|
|
53
52
|
require 'megam/core/request_collection'
|
54
53
|
require 'megam/core/sshkey'
|
55
54
|
require 'megam/core/sshkey_collection'
|
56
|
-
require 'megam/core/eventsall'
|
57
55
|
require 'megam/core/eventsvm'
|
58
|
-
require 'megam/core/eventsall_collection'
|
59
56
|
require 'megam/core/eventsvm_collection'
|
60
57
|
require 'megam/core/eventscontainer'
|
61
58
|
require 'megam/core/eventscontainer_collection'
|
@@ -99,6 +96,7 @@ module Megam
|
|
99
96
|
attr_accessor :text
|
100
97
|
attr_accessor :email, :api_key, :password_hash, :org_id
|
101
98
|
attr_accessor :api_url, :api_version
|
99
|
+
attr_accessor :master_key
|
102
100
|
attr_reader :last_response
|
103
101
|
|
104
102
|
API_VERSION2 = '/v2'.freeze
|
@@ -108,6 +106,7 @@ module Megam
|
|
108
106
|
X_Megam_OTTAI = 'X-Megam-OTTAI'.freeze
|
109
107
|
X_Megam_ORG = 'X-Megam-ORG'.freeze
|
110
108
|
X_Megam_PUTTUSAVI = 'X-Megam-PUTTUSAVI'.freeze
|
109
|
+
X_Megam_MASTERKEY = 'X-Megam-MASTERKEY'.freeze
|
111
110
|
|
112
111
|
HEADERS = {
|
113
112
|
'Accept' => 'application/json',
|
@@ -191,10 +190,11 @@ module Megam
|
|
191
190
|
private
|
192
191
|
|
193
192
|
def assign_credentials
|
194
|
-
@api_key = @options.delete(:api_key) || ENV['
|
195
|
-
@email = @options.delete(:email)
|
193
|
+
@api_key = @options.delete(:api_key) || ENV['VERTICE_API_KEY']
|
194
|
+
@email = @options.delete(:email) || ENV['VERTICE_EMAIL']
|
196
195
|
@password_hash = @options.delete(:password_hash)
|
197
196
|
@org_id = @options.delete(:org_id)
|
197
|
+
@master_key = @options.delete(:master_key) || ENV['VERTICE_MASTER_KEY']
|
198
198
|
end
|
199
199
|
|
200
200
|
def ensure_host_is_flattened
|
@@ -216,7 +216,7 @@ module Megam
|
|
216
216
|
end
|
217
217
|
|
218
218
|
def ensure_authkeys
|
219
|
-
if !api_combo_missing? && !pw_combo_missing?
|
219
|
+
if !api_combo_missing? && !pw_combo_missing? && !masterkey_combo_missing?
|
220
220
|
fail Megam::API::Errors::AuthKeysMissing
|
221
221
|
end
|
222
222
|
end
|
@@ -225,15 +225,16 @@ module Megam
|
|
225
225
|
(!@email.nil? && !@api_key.nil?)
|
226
226
|
end
|
227
227
|
|
228
|
-
|
229
|
-
|
230
228
|
def pw_combo_missing?
|
231
229
|
(!@email.nil? && !@password_hash.nil?)
|
232
230
|
end
|
233
231
|
|
232
|
+
def masterkey_combo_missing?
|
233
|
+
(!@email.nil? && !@master_key.nil?)
|
234
|
+
end
|
235
|
+
|
234
236
|
def turn_off_ssl_verify
|
235
237
|
Excon.defaults[:ssl_verify_peer] = false unless @api_url.include?("https")
|
236
|
-
|
237
238
|
end
|
238
239
|
|
239
240
|
def just_color_debug(path)
|
@@ -258,6 +259,8 @@ module Megam
|
|
258
259
|
|
259
260
|
|
260
261
|
build_header_puttusavi
|
262
|
+
|
263
|
+
build_header_masterkey
|
261
264
|
end
|
262
265
|
|
263
266
|
def encode_header
|
@@ -273,8 +276,8 @@ module Megam
|
|
273
276
|
hash = OpenSSL::HMAC.hexdigest(digest, Base64.strict_decode64(@password_hash), movingFactor)
|
274
277
|
elsif api_combo_missing?
|
275
278
|
hash = OpenSSL::HMAC.hexdigest(digest, @api_key, movingFactor)
|
276
|
-
|
277
|
-
hash = OpenSSL::HMAC.hexdigest(digest,
|
279
|
+
elsif master_key_combo_missing?
|
280
|
+
hash = OpenSSL::HMAC.hexdigest(digest, @master_key, movingFactor)
|
278
281
|
end
|
279
282
|
|
280
283
|
{ hmac: (@email + ':' + hash), date: current_date }
|
@@ -286,5 +289,11 @@ module Megam
|
|
286
289
|
end
|
287
290
|
end
|
288
291
|
|
292
|
+
def build_header_masterkey
|
293
|
+
if masterkey_combo_missing? && !is_passthru?
|
294
|
+
@options[:headers] = @options[:headers].merge(X_Megam_MASTERKEY => "true")
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
289
298
|
end
|
290
299
|
end
|
data/lib/megam/api/version.rb
CHANGED
@@ -6,7 +6,7 @@ require "json"
|
|
6
6
|
|
7
7
|
module Megam
|
8
8
|
class JSONCompat
|
9
|
-
|
9
|
+
|
10
10
|
JSON_MAX_NESTING = 1000
|
11
11
|
|
12
12
|
JSON_CLAZ = 'json_claz'.freeze
|
@@ -41,8 +41,6 @@ module Megam
|
|
41
41
|
MEGAM_DISKSCOLLECTION = 'Megam::DisksCollection'.freeze
|
42
42
|
MEGAM_SSHKEY = 'Megam::SshKey'.freeze
|
43
43
|
MEGAM_SSHKEYCOLLECTION = 'Megam::SshKeyCollection'.freeze
|
44
|
-
MEGAM_EVENTSALL = 'Megam::EventsAll'.freeze
|
45
|
-
MEGAM_EVENTSALLCOLLECTION = 'Megam::EventsAllCollection'.freeze
|
46
44
|
MEGAM_EVENTSVM = 'Megam::EventsVm'.freeze
|
47
45
|
MEGAM_EVENTSVMCOLLECTION = 'Megam::EventsVmCollection'.freeze
|
48
46
|
MEGAM_EVENTSCONTAINER = 'Megam::EventsContainer'.freeze
|
@@ -166,10 +164,6 @@ module Megam
|
|
166
164
|
Megam::EventsVm
|
167
165
|
when MEGAM_EVENTSVMCOLLECTION
|
168
166
|
Megam::EventsVmCollection
|
169
|
-
when MEGAM_EVENTSALL
|
170
|
-
Megam::EventsAll
|
171
|
-
when MEGAM_EVENTSALLCOLLECTION
|
172
|
-
Megam::EventsAllCollection
|
173
167
|
when MEGAM_EVENTSCONTAINER
|
174
168
|
Megam::EventsContainer
|
175
169
|
when MEGAM_EVENTSCONTAINERCOLLECTION
|
@@ -6,18 +6,20 @@ module Megam
|
|
6
6
|
# the name :password is used as attr_accessor in accounts,
|
7
7
|
# hence we use gpassword
|
8
8
|
attr_reader :password_hash
|
9
|
+
attr_reader :master_key
|
9
10
|
attr_reader :org_id
|
10
11
|
attr_reader :headers
|
11
12
|
|
12
13
|
|
13
14
|
## clean up this module later.
|
14
15
|
def initialize(o)
|
15
|
-
@email
|
16
|
-
@api_key
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
16
|
+
@email = o[:email]
|
17
|
+
@api_key = o[:api_key] || nil
|
18
|
+
@master_key = o[:master_key] || nil
|
19
|
+
@host = o[:host]
|
20
|
+
@password_hash = o[:password_hash] || nil
|
21
|
+
@org_id = o[:org_id]
|
22
|
+
@headers = o[:headers]
|
21
23
|
end
|
22
24
|
|
23
25
|
# Build a megam api client
|
@@ -30,6 +32,7 @@ module Megam
|
|
30
32
|
:api_key => api_key,
|
31
33
|
:org_id => org_id,
|
32
34
|
:password_hash => password_hash,
|
35
|
+
:master_key => master_key,
|
33
36
|
:host => host
|
34
37
|
}
|
35
38
|
if headers
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: megam_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajthilak, Kishorekumar Neelamegam, Ranjitha R, Vinodhini V, Rathish VBR, Rajesh
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-09-
|
12
|
+
date: 2016-09-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: excon
|
@@ -148,7 +148,6 @@ files:
|
|
148
148
|
- lib/megam/api/disks.rb
|
149
149
|
- lib/megam/api/domains.rb
|
150
150
|
- lib/megam/api/errors.rb
|
151
|
-
- lib/megam/api/eventsall.rb
|
152
151
|
- lib/megam/api/eventsbilling.rb
|
153
152
|
- lib/megam/api/eventscontainer.rb
|
154
153
|
- lib/megam/api/eventsstorage.rb
|
@@ -182,8 +181,6 @@ files:
|
|
182
181
|
- lib/megam/core/domain_collection.rb
|
183
182
|
- lib/megam/core/domains.rb
|
184
183
|
- lib/megam/core/error.rb
|
185
|
-
- lib/megam/core/eventsall.rb
|
186
|
-
- lib/megam/core/eventsall_collection.rb
|
187
184
|
- lib/megam/core/eventsbilling.rb
|
188
185
|
- lib/megam/core/eventsbilling_collection.rb
|
189
186
|
- lib/megam/core/eventscontainer.rb
|
@@ -274,4 +271,30 @@ rubygems_version: 2.5.1
|
|
274
271
|
signing_key:
|
275
272
|
specification_version: 4
|
276
273
|
summary: Ruby Client for the Megam Vertice
|
277
|
-
test_files:
|
274
|
+
test_files:
|
275
|
+
- test/mixins/test_assemblies.rb
|
276
|
+
- test/mixins/test_assembly.rb
|
277
|
+
- test/mixins/test_component.rb
|
278
|
+
- test/test_accounts.rb
|
279
|
+
- test/test_addons.rb
|
280
|
+
- test/test_assemblies.rb
|
281
|
+
- test/test_assembly.rb
|
282
|
+
- test/test_balances.rb
|
283
|
+
- test/test_billedhistories.rb
|
284
|
+
- test/test_billingtranscations.rb
|
285
|
+
- test/test_components.rb
|
286
|
+
- test/test_disks.rb
|
287
|
+
- test/test_domains.rb
|
288
|
+
- test/test_eventsbilling.rb
|
289
|
+
- test/test_eventscontainer.rb
|
290
|
+
- test/test_eventsstorage.rb
|
291
|
+
- test/test_eventsvm.rb
|
292
|
+
- test/test_helper.rb
|
293
|
+
- test/test_marketplaces.rb
|
294
|
+
- test/test_organizations.rb
|
295
|
+
- test/test_promos.rb
|
296
|
+
- test/test_requests.rb
|
297
|
+
- test/test_sensors.rb
|
298
|
+
- test/test_snapshots.rb
|
299
|
+
- test/test_sshkeys.rb
|
300
|
+
- test/test_subscriptions.rb
|
data/lib/megam/api/eventsall.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module Megam
|
2
|
-
class API
|
3
|
-
# GET /nodes
|
4
|
-
def list_eventsall(limit)
|
5
|
-
@options = {:path => "/eventsvm/#{limit}",:body => ""}.merge(@options)
|
6
|
-
|
7
|
-
request(
|
8
|
-
:expects => 200,
|
9
|
-
:method => :get,
|
10
|
-
:body => @options[:body]
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
def get_eventsall(limit, new_events)
|
16
|
-
@options = {:path => "/eventsall/show/#{limit}",
|
17
|
-
:body => Megam::JSONCompat.to_json(new_events)}.merge(@options)
|
18
|
-
request(
|
19
|
-
:expects => 200,
|
20
|
-
:method => :post,
|
21
|
-
:body => @options[:body]
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
def index_eventsall
|
27
|
-
@options = {:path => "/eventsall",:body => ""}.merge(@options)
|
28
|
-
|
29
|
-
request(
|
30
|
-
:expects => 200,
|
31
|
-
:method => :get,
|
32
|
-
:body => @options[:body]
|
33
|
-
)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/megam/core/eventsall.rb
DELETED
@@ -1,186 +0,0 @@
|
|
1
|
-
module Megam
|
2
|
-
class EventsAll < 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 eventsall
|
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.id(o["id"]) if o.has_key?("id")
|
127
|
-
evt.assembly_id(o["assembly_id"]) if o.has_key?("assembly_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
|
-
def self.show(o)
|
167
|
-
evt = from_hash(o)
|
168
|
-
evt.megam_rest.get_eventsall(o[:limit], evt.from_hash(o).for_json)
|
169
|
-
end
|
170
|
-
|
171
|
-
def self.list(params)
|
172
|
-
asm = self.new(params)
|
173
|
-
asm.megam_rest.list_eventsall(params[:limit])
|
174
|
-
end
|
175
|
-
|
176
|
-
def self.index(params)
|
177
|
-
asm = self.new(params)
|
178
|
-
asm.megam_rest.index_eventsall
|
179
|
-
end
|
180
|
-
|
181
|
-
def to_s
|
182
|
-
Megam::Stuff.styled_hash(to_hash)
|
183
|
-
end
|
184
|
-
|
185
|
-
end
|
186
|
-
end
|
@@ -1,122 +0,0 @@
|
|
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
|