megam_api 1.5.beta5 → 1.5.rc1
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 +3 -0
- data/lib/megam/api/events.rb +40 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/events.rb +198 -0
- data/lib/megam/core/events_collection.rb +137 -0
- data/lib/megam/core/json_compat.rb +6 -0
- data/test/test_events.rb +17 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78d3a668a4fe9d3b16509c09fd3ac164c4620324
|
4
|
+
data.tar.gz: 9931e90bb3fa8f464b322aa6b7d082fcfef0cf40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 616edf71421ad13b6bac985f934ef6028417e3c3d185bf9bec4d405159041e28667fcd9eb79481b2540b24462da2a31e69ec293a75203b4d081fac2b4971a409
|
7
|
+
data.tar.gz: 0405010efc7936d5bda918dcb0c40a504a2c2b2c447d2823472a3775e16e94e1b85c62cf20e221d5903bf0ad3ffd8e026700876fd1373f5d4ad463ba8337aee7
|
data/lib/megam/api.rb
CHANGED
@@ -37,6 +37,7 @@ require 'megam/api/promos'
|
|
37
37
|
require 'megam/api/requests'
|
38
38
|
require 'megam/api/sensors'
|
39
39
|
require 'megam/api/sshkeys'
|
40
|
+
require 'megam/api/events'
|
40
41
|
require 'megam/api/version'
|
41
42
|
|
42
43
|
require 'megam/mixins/assemblies'
|
@@ -58,6 +59,8 @@ require 'megam/core/request'
|
|
58
59
|
require 'megam/core/request_collection'
|
59
60
|
require 'megam/core/sshkey'
|
60
61
|
require 'megam/core/sshkey_collection'
|
62
|
+
require 'megam/core/events'
|
63
|
+
require 'megam/core/events_collection'
|
61
64
|
require 'megam/core/marketplace'
|
62
65
|
require 'megam/core/marketplace_collection'
|
63
66
|
require 'megam/core/organizations'
|
@@ -0,0 +1,40 @@
|
|
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 API
|
18
|
+
# GET /nodes
|
19
|
+
def list_events(limit)
|
20
|
+
@options = {:path => "/events/#{limit}",:body => ""}.merge(@options)
|
21
|
+
|
22
|
+
request(
|
23
|
+
:expects => 200,
|
24
|
+
:method => :get,
|
25
|
+
:body => @options[:body]
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_events(asm_id)
|
30
|
+
@options = {:path => "/events/show/#{asm_id}",:body => ""}.merge(@options)
|
31
|
+
|
32
|
+
request(
|
33
|
+
:expects => 200,
|
34
|
+
:method => :get,
|
35
|
+
:body => @options[:body]
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/megam/api/version.rb
CHANGED
@@ -0,0 +1,198 @@
|
|
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 Events < Megam::RestAdapter
|
19
|
+
def initialize(o)
|
20
|
+
@account_id = nil
|
21
|
+
@assembly_id = nil
|
22
|
+
@event_type = nil
|
23
|
+
@data = []
|
24
|
+
@read_status= nil
|
25
|
+
@created_at = nil
|
26
|
+
@limit = nil
|
27
|
+
@some_msg = {}
|
28
|
+
super(o)
|
29
|
+
end
|
30
|
+
|
31
|
+
def events
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def account_id(arg=nil)
|
36
|
+
if arg != nil
|
37
|
+
@account_id = arg
|
38
|
+
else
|
39
|
+
@account_id
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def assembly_id(arg=nil)
|
44
|
+
if arg != nil
|
45
|
+
@assembly_id = arg
|
46
|
+
else
|
47
|
+
@assembly_id
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def read_status(arg=nil)
|
52
|
+
if arg != nil
|
53
|
+
@read_status = arg
|
54
|
+
else
|
55
|
+
@read_status
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def event_type(arg=nil)
|
60
|
+
if arg != nil
|
61
|
+
@event_type = arg
|
62
|
+
else
|
63
|
+
@event_type
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def data(arg=[])
|
69
|
+
if arg != []
|
70
|
+
@data = arg
|
71
|
+
else
|
72
|
+
@data
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def limit(arg=[])
|
77
|
+
if arg != []
|
78
|
+
@limit = arg
|
79
|
+
else
|
80
|
+
@limit
|
81
|
+
end
|
82
|
+
end
|
83
|
+
def created_at(arg=nil)
|
84
|
+
if arg != nil
|
85
|
+
@created_at = arg
|
86
|
+
else
|
87
|
+
@created_at
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def error?
|
92
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
def some_msg(arg=nil)
|
97
|
+
if arg != nil
|
98
|
+
@some_msg = arg
|
99
|
+
else
|
100
|
+
@some_msg
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
# Transform the ruby obj -> to a Hash
|
106
|
+
def to_hash
|
107
|
+
index_hash = Hash.new
|
108
|
+
index_hash["json_claz"] = self.class.name
|
109
|
+
index_hash["account_id"] = account_id
|
110
|
+
index_hash["assembly_id"] = assembly_id
|
111
|
+
index_hash["event_type"] = event_type
|
112
|
+
index_hash["data"] = data
|
113
|
+
index_hash["read_status"] = read_status
|
114
|
+
index_hash["limit"] = limit
|
115
|
+
index_hash["created_at"] = created_at
|
116
|
+
index_hash["some_msg"] = some_msg
|
117
|
+
index_hash
|
118
|
+
end
|
119
|
+
|
120
|
+
# Serialize this object as a hash: called from JsonCompat.
|
121
|
+
# Verify if this called from JsonCompat during testing.
|
122
|
+
def to_json(*a)
|
123
|
+
for_json.to_json(*a)
|
124
|
+
end
|
125
|
+
|
126
|
+
def for_json
|
127
|
+
result = {
|
128
|
+
"account_id" => account_id,
|
129
|
+
"assembly_id" => assembly_id,
|
130
|
+
"event_type" => event_type,
|
131
|
+
"data" => data,
|
132
|
+
"read_status" => read_status,
|
133
|
+
"limit" => limit,
|
134
|
+
"created_at" => created_at
|
135
|
+
}
|
136
|
+
result
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.json_create(o)
|
140
|
+
evt = new({})
|
141
|
+
evt.account_id(o["account_id"]) if o.has_key?("account_id")
|
142
|
+
evt.assembly_id(o["assembly_id"]) if o.has_key?("assembly_id")
|
143
|
+
evt.event_type(o["event_type"]) if o.has_key?("event_type") #this will be an array? can hash store array?
|
144
|
+
evt.data(o["data"]) if o.has_key?("data")
|
145
|
+
evt.read_status(o["read_status"]) if o.has_key?("read_status")
|
146
|
+
evt.read_status(o["limit"]) if o.has_key?("limit")
|
147
|
+
evt.created_at(o["created_at"]) if o.has_key?("created_at")
|
148
|
+
evt.some_msg[:code] = o["code"] if o.has_key?("code")
|
149
|
+
evt.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
150
|
+
evt.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
151
|
+
evt.some_msg[:links] = o["links"] if o.has_key?("links")
|
152
|
+
evt
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.from_hash(o)
|
156
|
+
evt = self.new(o)
|
157
|
+
evt.from_hash(o)
|
158
|
+
evt
|
159
|
+
end
|
160
|
+
|
161
|
+
def from_hash(o)
|
162
|
+
@account_id = o[:account_id] if o.has_key?(:account_id)
|
163
|
+
@assembly_id = o[:assembly_id] if o.has_key?(:assembly_id)
|
164
|
+
@event_type = o[:event_type] if o.has_key?(:event_type)
|
165
|
+
@data = o[:data] if o.has_key?(:data)
|
166
|
+
@read_status = o[:read_status] if o.has_key?(:read_status)
|
167
|
+
@limit = o[:limit] if o.has_key?(:limit)
|
168
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
169
|
+
self
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.create(params)
|
173
|
+
evt = from_hash(params)
|
174
|
+
evt.create
|
175
|
+
end
|
176
|
+
|
177
|
+
# Create the node via the REST API
|
178
|
+
def create
|
179
|
+
megam_rest.post_events(to_hash)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Load a account by email_p
|
183
|
+
def self.show(o)
|
184
|
+
evt = self.new(o)
|
185
|
+
evt.megam_rest.get_events(o[:assembly_id])
|
186
|
+
end
|
187
|
+
|
188
|
+
def self.list(params)
|
189
|
+
asm = self.new(params)
|
190
|
+
asm.megam_rest.list_events(params[:limit])
|
191
|
+
end
|
192
|
+
|
193
|
+
def to_s
|
194
|
+
Megam::Stuff.styled_hash(to_hash)
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
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 EventsCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
attr_reader :iterator
|
21
|
+
def initialize
|
22
|
+
@events = Array.new
|
23
|
+
@events_by_name = Hash.new
|
24
|
+
@insert_after_idx = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_events
|
28
|
+
@events
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](index)
|
32
|
+
@events[index]
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, arg)
|
36
|
+
is_megam_events(arg)
|
37
|
+
@events[index] = arg
|
38
|
+
@events_by_name[arg.account_id] = index
|
39
|
+
end
|
40
|
+
|
41
|
+
def <<(*args)
|
42
|
+
args.flatten.each do |a|
|
43
|
+
is_megam_events(a)
|
44
|
+
@events << a
|
45
|
+
@events_by_name[a.account_id] = @events.length - 1
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# 'push' is an alias method to <<
|
51
|
+
alias_method :push, :<<
|
52
|
+
|
53
|
+
def insert(events)
|
54
|
+
is_megam_events(events)
|
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
|
+
@events.insert(@insert_after_idx + 1, events)
|
60
|
+
# update name -> location mappings and register new node
|
61
|
+
@events_by_name.each_key do |key|
|
62
|
+
@events_by_name[key] += 1 if @events_by_name[key] > @insert_after_idx
|
63
|
+
end
|
64
|
+
@events_by_name[events.account_id] = @insert_after_idx + 1
|
65
|
+
@insert_after_idx += 1
|
66
|
+
else
|
67
|
+
@events << events
|
68
|
+
@events_by_name[events.account_id] = @events.length - 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def each
|
73
|
+
@events.each do |events|
|
74
|
+
yield events
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def each_index
|
79
|
+
@events.each_index do |i|
|
80
|
+
yield i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def empty?
|
85
|
+
@events.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def lookup(events)
|
89
|
+
lookup_by = nil
|
90
|
+
if events.kind_of?(Megam::Events)
|
91
|
+
lookup_by = events.account_id
|
92
|
+
elsif events.kind_of?(String)
|
93
|
+
lookup_by = events
|
94
|
+
else
|
95
|
+
raise ArgumentError, "Must pass a Megam::Events or String to lookup"
|
96
|
+
end
|
97
|
+
res = @events_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
|
+
@events[res]
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_s
|
105
|
+
@events.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 |events_list|
|
119
|
+
events_array = events_list.kind_of?(Array) ? events_list : [ events_list ]
|
120
|
+
events_array.each do |events|
|
121
|
+
collection.insert(events)
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
collection
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def is_megam_events(arg)
|
131
|
+
unless arg.kind_of?(Megam::Events)
|
132
|
+
raise ArgumentError, "Members must be Megam::Events's"
|
133
|
+
end
|
134
|
+
true
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -48,6 +48,8 @@ module Megam
|
|
48
48
|
MEGAM_SENSORSCOLLECTION = 'Megam::SensorsCollection'.freeze
|
49
49
|
MEGAM_SSHKEY = 'Megam::SshKey'.freeze
|
50
50
|
MEGAM_SSHKEYCOLLECTION = 'Megam::SshKeyCollection'.freeze
|
51
|
+
MEGAM_EVENTS = 'Megam::Events'.freeze
|
52
|
+
MEGAM_EVENTSCOLLECTION = 'Megam::EventsCollection'.freeze
|
51
53
|
MEGAM_PROMOS = 'Megam::Promos'.freeze
|
52
54
|
|
53
55
|
class <<self
|
@@ -155,6 +157,10 @@ module Megam
|
|
155
157
|
Megam::SshKey
|
156
158
|
when MEGAM_SSHKEYCOLLECTION
|
157
159
|
Megam::SshKeyCollection
|
160
|
+
when MEGAM_EVENTS
|
161
|
+
Megam::Events
|
162
|
+
when MEGAM_EVENTSCOLLECTION
|
163
|
+
Megam::EventsCollection
|
158
164
|
when MEGAM_MARKETPLACE
|
159
165
|
Megam::MarketPlace
|
160
166
|
when MEGAM_MARKETPLACECOLLECTION
|
data/test/test_events.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
+
|
3
|
+
class TestApps < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
=begin
|
6
|
+
def test_get_events
|
7
|
+
response = megams.get_events("ASM9038606864211614815")
|
8
|
+
assert_equal(200, response.status)
|
9
|
+
end
|
10
|
+
=end
|
11
|
+
#=begin
|
12
|
+
def test_list_events
|
13
|
+
response = megams.list_events("10")
|
14
|
+
assert_equal(200, response.status)
|
15
|
+
end
|
16
|
+
#=end
|
17
|
+
end
|
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.5.
|
4
|
+
version: 1.5.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajthilak, Kishorekumar Neelamegam, Thomas Alrin, Yeshwanth Kumar, Subash Sethurajan,
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-06-
|
12
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: excon
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/megam/api/components.rb
|
142
142
|
- lib/megam/api/domains.rb
|
143
143
|
- lib/megam/api/errors.rb
|
144
|
+
- lib/megam/api/events.rb
|
144
145
|
- lib/megam/api/marketplaces.rb
|
145
146
|
- lib/megam/api/organizations.rb
|
146
147
|
- lib/megam/api/promos.rb
|
@@ -162,6 +163,8 @@ files:
|
|
162
163
|
- lib/megam/core/domain_collection.rb
|
163
164
|
- lib/megam/core/domains.rb
|
164
165
|
- lib/megam/core/error.rb
|
166
|
+
- lib/megam/core/events.rb
|
167
|
+
- lib/megam/core/events_collection.rb
|
165
168
|
- lib/megam/core/json_compat.rb
|
166
169
|
- lib/megam/core/konipai.rb
|
167
170
|
- lib/megam/core/log.rb
|
@@ -200,6 +203,7 @@ files:
|
|
200
203
|
- test/test_billedhistories.rb
|
201
204
|
- test/test_components.rb
|
202
205
|
- test/test_domains.rb
|
206
|
+
- test/test_events.rb
|
203
207
|
- test/test_helper.rb
|
204
208
|
- test/test_marketplaces.rb
|
205
209
|
- test/test_organizations.rb
|
@@ -242,6 +246,7 @@ test_files:
|
|
242
246
|
- test/test_billedhistories.rb
|
243
247
|
- test/test_components.rb
|
244
248
|
- test/test_domains.rb
|
249
|
+
- test/test_events.rb
|
245
250
|
- test/test_helper.rb
|
246
251
|
- test/test_marketplaces.rb
|
247
252
|
- test/test_organizations.rb
|