megam_api 1.5.rc1 → 1.5.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/megam/api.rb +18 -3
- data/lib/megam/api/billingtranscations.rb +40 -0
- data/lib/megam/api/eventsbilling.rb +50 -0
- data/lib/megam/api/eventscontainer.rb +50 -0
- data/lib/megam/api/{events.rb → eventsstorage.rb} +4 -5
- data/lib/megam/api/eventsvm.rb +50 -0
- data/lib/megam/api/snapshots.rb +50 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/billingtranscations.rb +244 -0
- data/lib/megam/core/billingtranscations_collection.rb +136 -0
- data/lib/megam/core/{events.rb → eventsbilling.rb} +10 -18
- data/lib/megam/core/eventsbilling_collection.rb +137 -0
- data/lib/megam/core/eventscontainer.rb +190 -0
- data/lib/megam/core/eventscontainer_collection.rb +137 -0
- data/lib/megam/core/eventsstorage.rb +172 -0
- data/lib/megam/core/eventsstorage_collection.rb +137 -0
- data/lib/megam/core/eventsvm.rb +190 -0
- data/lib/megam/core/{events_collection.rb → eventsvm_collection.rb} +38 -38
- data/lib/megam/core/json_compat.rb +36 -6
- data/lib/megam/core/snapshots.rb +184 -0
- data/lib/megam/core/snapshots_collection.rb +137 -0
- data/test/test_billingtranscations.rb +33 -0
- data/test/test_eventsbilling.rb +30 -0
- data/test/test_eventscontainer.rb +30 -0
- data/test/test_eventsstorage.rb +14 -0
- data/test/test_eventsvm.rb +30 -0
- data/test/test_snapshots.rb +32 -0
- metadata +32 -7
- data/test/test_events.rb +0 -17
@@ -0,0 +1,137 @@
|
|
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
|
+
module Megam
|
17
|
+
class EventsContainerCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
attr_reader :iterator
|
21
|
+
def initialize
|
22
|
+
@eventscontainer = Array.new
|
23
|
+
@eventscontainer_by_name = Hash.new
|
24
|
+
@insert_after_idx = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_eventscontainer
|
28
|
+
@eventscontainer
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](index)
|
32
|
+
@eventscontainer[index]
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, arg)
|
36
|
+
is_megam_eventsvm(arg)
|
37
|
+
@eventscontainer[index] = arg
|
38
|
+
@eventscontainer_by_name[arg.account_id] = index
|
39
|
+
end
|
40
|
+
|
41
|
+
def <<(*args)
|
42
|
+
args.flatten.each do |a|
|
43
|
+
is_megam_events(a)
|
44
|
+
@eventscontainer << a
|
45
|
+
@eventscontainer_by_name[a.account_id] = @eventscontainer.length - 1
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# 'push' is an alias method to <<
|
51
|
+
alias_method :push, :<<
|
52
|
+
|
53
|
+
def insert(eventscontainer)
|
54
|
+
is_megam_eventscontainer(eventscontainer)
|
55
|
+
if @insert_after_idx
|
56
|
+
# in the middle of executing a run, so any nodes inserted now should
|
57
|
+
# be placed after the most recent addition done by the currently executing
|
58
|
+
# node
|
59
|
+
@eventscontainer.insert(@insert_after_idx + 1, eventscontainer)
|
60
|
+
# update name -> location mappings and register new node
|
61
|
+
@eventscontainer_by_name.each_key do |key|
|
62
|
+
@eventscontainer_by_name[key] += 1 if @eventscontainer_by_name[key] > @insert_after_idx
|
63
|
+
end
|
64
|
+
@eventscontainer_by_name[eventscontainer.account_id] = @insert_after_idx + 1
|
65
|
+
@insert_after_idx += 1
|
66
|
+
else
|
67
|
+
@eventscontainer << eventscontainer
|
68
|
+
@eventscontainer_by_name[eventscontainer.account_id] = @eventscontainer.length - 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def each
|
73
|
+
@eventscontainer.each do |eventscontainer|
|
74
|
+
yield eventscontainer
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def each_index
|
79
|
+
@eventscontainer.each_index do |i|
|
80
|
+
yield i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def empty?
|
85
|
+
@eventscontainer.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def lookup(eventscontainer)
|
89
|
+
lookup_by = nil
|
90
|
+
if events.kind_of?(Megam::EventsContainer)
|
91
|
+
lookup_by = eventscontainer.account_id
|
92
|
+
elsif eventscontainer.kind_of?(String)
|
93
|
+
lookup_by = eventscontainer
|
94
|
+
else
|
95
|
+
raise ArgumentError, "Must pass a Megam::EventsContainer or String to lookup"
|
96
|
+
end
|
97
|
+
res = @eventscontainer_by_name[lookup_by]
|
98
|
+
unless res
|
99
|
+
raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
|
100
|
+
end
|
101
|
+
@eventscontainer[res]
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_s
|
105
|
+
@eventscontainer.join(", ")
|
106
|
+
end
|
107
|
+
|
108
|
+
def for_json
|
109
|
+
to_a.map { |item| item.to_s }
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_json(*a)
|
113
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.json_create(o)
|
117
|
+
collection = self.new()
|
118
|
+
o["results"].each do |eventscontainer_list|
|
119
|
+
eventscontainer_array = eventscontainer_list.kind_of?(Array) ? eventscontainer_list : [ eventscontainer_list ]
|
120
|
+
eventscontainer_array.each do |eventscontainer|
|
121
|
+
collection.insert(eventscontainer)
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
collection
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def is_megam_eventscontainer(arg)
|
131
|
+
unless arg.kind_of?(Megam::EventsContainer)
|
132
|
+
raise ArgumentError, "Members must be Megam::EventsContainer's"
|
133
|
+
end
|
134
|
+
true
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,172 @@
|
|
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
|
+
|
17
|
+
module Megam
|
18
|
+
class EventsStorage < Megam::RestAdapter
|
19
|
+
def initialize(o)
|
20
|
+
@account_id = nil
|
21
|
+
@event_type = nil
|
22
|
+
@data = []
|
23
|
+
@created_at = nil
|
24
|
+
@limit = nil
|
25
|
+
@some_msg = {}
|
26
|
+
super(o)
|
27
|
+
end
|
28
|
+
|
29
|
+
def eventsstorage
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def account_id(arg=nil)
|
34
|
+
if arg != nil
|
35
|
+
@account_id = arg
|
36
|
+
else
|
37
|
+
@account_id
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def event_type(arg=nil)
|
42
|
+
if arg != nil
|
43
|
+
@event_type = arg
|
44
|
+
else
|
45
|
+
@event_type
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def data(arg=[])
|
50
|
+
if arg != []
|
51
|
+
@data = arg
|
52
|
+
else
|
53
|
+
@data
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def limit(arg=[])
|
58
|
+
if arg != []
|
59
|
+
@limit = arg
|
60
|
+
else
|
61
|
+
@limit
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def created_at(arg=nil)
|
66
|
+
if arg != nil
|
67
|
+
@created_at = arg
|
68
|
+
else
|
69
|
+
@created_at
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def error?
|
74
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def some_msg(arg=nil)
|
79
|
+
if arg != nil
|
80
|
+
@some_msg = arg
|
81
|
+
else
|
82
|
+
@some_msg
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
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["account_id"] = account_id
|
92
|
+
index_hash["event_type"] = event_type
|
93
|
+
index_hash["data"] = data
|
94
|
+
index_hash["limit"] = limit
|
95
|
+
index_hash["created_at"] = created_at
|
96
|
+
index_hash["some_msg"] = some_msg
|
97
|
+
index_hash
|
98
|
+
end
|
99
|
+
|
100
|
+
# Serialize this object as a hash: called from JsonCompat.
|
101
|
+
# Verify if this called from JsonCompat during testing.
|
102
|
+
def to_json(*a)
|
103
|
+
for_json.to_json(*a)
|
104
|
+
end
|
105
|
+
|
106
|
+
def for_json
|
107
|
+
result = {
|
108
|
+
"account_id" => account_id,
|
109
|
+
"event_type" => event_type,
|
110
|
+
"data" => data,
|
111
|
+
"limit" => limit,
|
112
|
+
"created_at" => created_at
|
113
|
+
}
|
114
|
+
result
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.json_create(o)
|
118
|
+
evt = new({})
|
119
|
+
evt.account_id(o["account_id"]) if o.has_key?("account_id")
|
120
|
+
evt.event_type(o["event_type"]) if o.has_key?("event_type") #this will be an array? can hash store array?
|
121
|
+
evt.data(o["data"]) if o.has_key?("data")
|
122
|
+
evt.limit(o["limit"]) if o.has_key?("limit")
|
123
|
+
evt.created_at(o["created_at"]) if o.has_key?("created_at")
|
124
|
+
evt.some_msg[:code] = o["code"] if o.has_key?("code")
|
125
|
+
evt.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
126
|
+
evt.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
127
|
+
evt.some_msg[:links] = o["links"] if o.has_key?("links")
|
128
|
+
evt
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.from_hash(o)
|
132
|
+
evt = self.new(o)
|
133
|
+
evt.from_hash(o)
|
134
|
+
evt
|
135
|
+
end
|
136
|
+
|
137
|
+
def from_hash(o)
|
138
|
+
@account_id = o[:account_id] if o.has_key?(:account_id)
|
139
|
+
@event_type = o[:event_type] if o.has_key?(:event_type)
|
140
|
+
@data = o[:data] if o.has_key?(:data)
|
141
|
+
@limit = o[:limit] if o.has_key?(:limit)
|
142
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
143
|
+
self
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.create(params)
|
147
|
+
evt = from_hash(params)
|
148
|
+
evt.create
|
149
|
+
end
|
150
|
+
|
151
|
+
# Create the node via the REST API
|
152
|
+
def create
|
153
|
+
megam_rest.post_events(to_hash)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Load a account by email_p
|
157
|
+
def self.list(params)
|
158
|
+
asm = self.new(params)
|
159
|
+
asm.megam_rest.list_eventsstorage(params[:limit])
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.index(params)
|
163
|
+
asm = self.new(params)
|
164
|
+
asm.megam_rest.index_eventsstorage
|
165
|
+
end
|
166
|
+
|
167
|
+
def to_s
|
168
|
+
Megam::Stuff.styled_hash(to_hash)
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,137 @@
|
|
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
|
+
module Megam
|
17
|
+
class EventsStorageCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
attr_reader :iterator
|
21
|
+
def initialize
|
22
|
+
@eventsstorage = Array.new
|
23
|
+
@eventsstorage_by_name = Hash.new
|
24
|
+
@insert_after_idx = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_eventsstorage
|
28
|
+
@eventsstorage
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](index)
|
32
|
+
@eventsstorage[index]
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, arg)
|
36
|
+
is_megam_eventsstorage(arg)
|
37
|
+
@eventsstorage[index] = arg
|
38
|
+
@eventsstorage_by_name[arg.account_id] = index
|
39
|
+
end
|
40
|
+
|
41
|
+
def <<(*args)
|
42
|
+
args.flatten.each do |a|
|
43
|
+
is_megam_events(a)
|
44
|
+
@eventsstorage << a
|
45
|
+
@eventsstorage_by_name[a.account_id] = @eventsstorage.length - 1
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# 'push' is an alias method to <<
|
51
|
+
alias_method :push, :<<
|
52
|
+
|
53
|
+
def insert(eventsstorage)
|
54
|
+
is_megam_eventsstorage(eventsstorage)
|
55
|
+
if @insert_after_idx
|
56
|
+
# in the middle of executing a run, so any nodes inserted now should
|
57
|
+
# be placed after the most recent addition done by the currently executing
|
58
|
+
# node
|
59
|
+
@eventsstorage.insert(@insert_after_idx + 1, eventsstorage)
|
60
|
+
# update name -> location mappings and register new node
|
61
|
+
@eventsstorage_by_name.each_key do |key|
|
62
|
+
@eventsstorage_by_name[key] += 1 if @eventsstorage_by_name[key] > @insert_after_idx
|
63
|
+
end
|
64
|
+
@eventsstorage_by_name[eventsstorage.account_id] = @insert_after_idx + 1
|
65
|
+
@insert_after_idx += 1
|
66
|
+
else
|
67
|
+
@eventsstorage << eventsstorage
|
68
|
+
@eventsstorage_by_name[eventsstorage.account_id] = @eventsstorage.length - 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def each
|
73
|
+
@eventsstorage.each do |eventsstorage|
|
74
|
+
yield eventsstorage
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def each_index
|
79
|
+
@eventsstorage.each_index do |i|
|
80
|
+
yield i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def empty?
|
85
|
+
@eventsstorage.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def lookup(eventsstorage)
|
89
|
+
lookup_by = nil
|
90
|
+
if events.kind_of?(Megam::EventsStorage)
|
91
|
+
lookup_by = eventsstorage.account_id
|
92
|
+
elsif events.kind_of?(String)
|
93
|
+
lookup_by = eventsstorage
|
94
|
+
else
|
95
|
+
raise ArgumentError, "Must pass a Megam::EventsStorage or String to lookup"
|
96
|
+
end
|
97
|
+
res = @eventsstorage_by_name[lookup_by]
|
98
|
+
unless res
|
99
|
+
raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
|
100
|
+
end
|
101
|
+
@eventsstorage[res]
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_s
|
105
|
+
@eventsstorage.join(", ")
|
106
|
+
end
|
107
|
+
|
108
|
+
def for_json
|
109
|
+
to_a.map { |item| item.to_s }
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_json(*a)
|
113
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.json_create(o)
|
117
|
+
collection = self.new()
|
118
|
+
o["results"].each do |eventsstorage_list|
|
119
|
+
eventsstorage_array = eventsstorage_list.kind_of?(Array) ? eventsstorage_list : [ eventsstorage_list ]
|
120
|
+
eventsstorage_array.each do |eventsstorage|
|
121
|
+
collection.insert(eventsstorage)
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
collection
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def is_megam_eventsstorage(arg)
|
131
|
+
unless arg.kind_of?(Megam::EventsStorage)
|
132
|
+
raise ArgumentError, "Members must be Megam::EventsStorage's"
|
133
|
+
end
|
134
|
+
true
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,190 @@
|
|
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
|
+
|
17
|
+
module Megam
|
18
|
+
class EventsVm < Megam::RestAdapter
|
19
|
+
def initialize(o)
|
20
|
+
@account_id = nil
|
21
|
+
@assembly_id = nil
|
22
|
+
@event_type = nil
|
23
|
+
@data = []
|
24
|
+
@created_at = nil
|
25
|
+
@limit = nil
|
26
|
+
@some_msg = {}
|
27
|
+
super(o)
|
28
|
+
end
|
29
|
+
|
30
|
+
def eventsvm
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def account_id(arg=nil)
|
35
|
+
if arg != nil
|
36
|
+
@account_id = arg
|
37
|
+
else
|
38
|
+
@account_id
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def assembly_id(arg=nil)
|
43
|
+
if arg != nil
|
44
|
+
@assembly_id = arg
|
45
|
+
else
|
46
|
+
@assembly_id
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def event_type(arg=nil)
|
51
|
+
if arg != nil
|
52
|
+
@event_type = arg
|
53
|
+
else
|
54
|
+
@event_type
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def data(arg=[])
|
60
|
+
if arg != []
|
61
|
+
@data = arg
|
62
|
+
else
|
63
|
+
@data
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def limit(arg=[])
|
68
|
+
if arg != []
|
69
|
+
@limit = arg
|
70
|
+
else
|
71
|
+
@limit
|
72
|
+
end
|
73
|
+
end
|
74
|
+
def created_at(arg=nil)
|
75
|
+
if arg != nil
|
76
|
+
@created_at = arg
|
77
|
+
else
|
78
|
+
@created_at
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def error?
|
83
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def some_msg(arg=nil)
|
88
|
+
if arg != nil
|
89
|
+
@some_msg = arg
|
90
|
+
else
|
91
|
+
@some_msg
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
# Transform the ruby obj -> to a Hash
|
97
|
+
def to_hash
|
98
|
+
index_hash = Hash.new
|
99
|
+
index_hash["json_claz"] = self.class.name
|
100
|
+
index_hash["account_id"] = account_id
|
101
|
+
index_hash["assembly_id"] = assembly_id
|
102
|
+
index_hash["event_type"] = event_type
|
103
|
+
index_hash["data"] = data
|
104
|
+
index_hash["limit"] = limit
|
105
|
+
index_hash["created_at"] = created_at
|
106
|
+
index_hash["some_msg"] = some_msg
|
107
|
+
index_hash
|
108
|
+
end
|
109
|
+
|
110
|
+
# Serialize this object as a hash: called from JsonCompat.
|
111
|
+
# Verify if this called from JsonCompat during testing.
|
112
|
+
def to_json(*a)
|
113
|
+
for_json.to_json(*a)
|
114
|
+
end
|
115
|
+
|
116
|
+
def for_json
|
117
|
+
result = {
|
118
|
+
"account_id" => account_id,
|
119
|
+
"assembly_id" => assembly_id,
|
120
|
+
"event_type" => event_type,
|
121
|
+
"data" => data,
|
122
|
+
"limit" => limit,
|
123
|
+
"created_at" => created_at
|
124
|
+
}
|
125
|
+
result
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.json_create(o)
|
129
|
+
evt = new({})
|
130
|
+
evt.account_id(o["account_id"]) if o.has_key?("account_id")
|
131
|
+
evt.assembly_id(o["assembly_id"]) if o.has_key?("assembly_id")
|
132
|
+
evt.event_type(o["event_type"]) if o.has_key?("event_type") #this will be an array? can hash store array?
|
133
|
+
evt.data(o["data"]) if o.has_key?("data")
|
134
|
+
evt.limit(o["limit"]) if o.has_key?("limit")
|
135
|
+
evt.created_at(o["created_at"]) if o.has_key?("created_at")
|
136
|
+
evt.some_msg[:code] = o["code"] if o.has_key?("code")
|
137
|
+
evt.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
138
|
+
evt.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
139
|
+
evt.some_msg[:links] = o["links"] if o.has_key?("links")
|
140
|
+
evt
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.from_hash(o)
|
144
|
+
evt = self.new(o)
|
145
|
+
evt.from_hash(o)
|
146
|
+
evt
|
147
|
+
end
|
148
|
+
|
149
|
+
def from_hash(o)
|
150
|
+
@account_id = o[:account_id] if o.has_key?(:account_id)
|
151
|
+
@assembly_id = o[:assembly_id] if o.has_key?(:assembly_id)
|
152
|
+
@event_type = o[:event_type] if o.has_key?(:event_type)
|
153
|
+
@data = o[:data] if o.has_key?(:data)
|
154
|
+
@limit = o[:limit] if o.has_key?(:limit)
|
155
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
156
|
+
self
|
157
|
+
end
|
158
|
+
|
159
|
+
def self.create(params)
|
160
|
+
evt = from_hash(params)
|
161
|
+
evt.create
|
162
|
+
end
|
163
|
+
|
164
|
+
# Create the node via the REST API
|
165
|
+
def create
|
166
|
+
megam_rest.post_events(to_hash)
|
167
|
+
end
|
168
|
+
|
169
|
+
# Load a account by email_p
|
170
|
+
def self.show(o)
|
171
|
+
evt = self.new(o)
|
172
|
+
evt.megam_rest.get_eventsvm(o[:limit], to_hash)
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.list(params)
|
176
|
+
asm = self.new(params)
|
177
|
+
asm.megam_rest.list_eventsvm(params[:limit])
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.index(params)
|
181
|
+
asm = self.new(params)
|
182
|
+
asm.megam_rest.index_eventsvm
|
183
|
+
end
|
184
|
+
|
185
|
+
def to_s
|
186
|
+
Megam::Stuff.styled_hash(to_hash)
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
end
|