megam_api 0.75 → 0.77
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 +7 -8
- data/lib/megam/api/discounts.rb +2 -7
- data/lib/megam/api/errors.rb +4 -2
- data/lib/megam/api/sensors.rb +35 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/json_compat.rb +21 -19
- data/lib/megam/core/promos.rb +6 -8
- data/lib/megam/core/request.rb +0 -1
- data/lib/megam/core/sensors.rb +157 -0
- data/lib/megam/core/sensors_collection.rb +143 -0
- data/lib/megam/mixins/assemblies.rb +17 -0
- data/lib/megam/mixins/assemblys.rb +42 -0
- data/lib/megam/mixins/common_deployable.rb +72 -0
- data/lib/megam/mixins/components.rb +85 -0
- data/lib/megam/mixins/megam_attributes.rb +30 -0
- data/lib/megam/mixins/outputs.rb +24 -0
- data/lib/megam/mixins/policies.rb +29 -0
- data/test/mixins/test_assemblies.rb +110 -0
- data/test/mixins/test_assembly.rb +74 -0
- data/test/mixins/test_component.rb +56 -0
- data/test/test_helper.rb +5 -5
- data/test/test_invoices.rb +1 -1
- data/test/test_sensors.rb +50 -0
- metadata +20 -8
- data/lib/megam/api/event.rb +0 -23
- data/lib/megam/core/event.rb +0 -145
- data/test/test_event.rb +0 -21
- data/test/test_logs.rb +0 -15
data/lib/megam/core/event.rb
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
# Copyright:: Copyright (c) 2013, 2015 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 Event < Megam::ServerAPI
|
19
|
-
def initialize(email=nil, api_key=nil, host=nil)
|
20
|
-
@a_id = nil
|
21
|
-
@a_name = nil
|
22
|
-
@command = nil
|
23
|
-
@launch_type = nil
|
24
|
-
super(email, api_key, host)
|
25
|
-
end
|
26
|
-
|
27
|
-
def event
|
28
|
-
self
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
def a_id(arg=nil)
|
33
|
-
if arg != nil
|
34
|
-
@a_id = arg
|
35
|
-
else
|
36
|
-
@a_id
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
def a_name(arg=nil)
|
42
|
-
if arg != nil
|
43
|
-
@a_name = arg
|
44
|
-
else
|
45
|
-
@a_name
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
def command(arg=nil)
|
53
|
-
if arg != nil
|
54
|
-
@command = arg
|
55
|
-
else
|
56
|
-
@command
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def launch_type(arg=nil)
|
61
|
-
if arg != nil
|
62
|
-
@launch_type = arg
|
63
|
-
else
|
64
|
-
@launch_type
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def error?
|
69
|
-
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
70
|
-
end
|
71
|
-
|
72
|
-
# Transform the ruby obj -> to a Hash
|
73
|
-
def to_hash
|
74
|
-
index_hash = Hash.new
|
75
|
-
index_hash["json_claz"] = self.class.name
|
76
|
-
index_hash["a_id"] = a_id
|
77
|
-
index_hash["a_name"] = a_name
|
78
|
-
index_hash["command"] = command
|
79
|
-
index_hash["launch_type"] = launch_type
|
80
|
-
index_hash
|
81
|
-
end
|
82
|
-
|
83
|
-
# Serialize this object as a hash: called from JsonCompat.
|
84
|
-
# Verify if this called from JsonCompat during testing.
|
85
|
-
def to_json(*a)
|
86
|
-
for_json.to_json(*a)
|
87
|
-
end
|
88
|
-
|
89
|
-
def for_json
|
90
|
-
result = {
|
91
|
-
"a_id" => a_id,
|
92
|
-
"a_name" => a_name,
|
93
|
-
"command" => command,
|
94
|
-
"launch_type" => launch_type
|
95
|
-
}
|
96
|
-
result
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.json_create(o)
|
100
|
-
event = new
|
101
|
-
event.a_id(o["a_id"]) if o.has_key?("a_id")
|
102
|
-
event.a_name(o["a_name"]) if o.has_key?("a_name")
|
103
|
-
event.command(o["command"]) if o.has_key?("command")
|
104
|
-
event.launch_type(o["launch_type"]) if o.has_key?("launch_type") #this will be an array? can hash store array?
|
105
|
-
event
|
106
|
-
end
|
107
|
-
|
108
|
-
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
109
|
-
event = self.new(tmp_email, tmp_api_key, tmp_host)
|
110
|
-
event.from_hash(o)
|
111
|
-
event
|
112
|
-
end
|
113
|
-
|
114
|
-
def from_hash(o)
|
115
|
-
@a_id = o[:a_id] if o.has_key?(:a_id)
|
116
|
-
@a_name = o[:a_name] if o.has_key?(:a_name)
|
117
|
-
@command = o[:command] if o.has_key?(:command)
|
118
|
-
@launch_type = o[:launch_type] if o.has_key?(:launch_type)
|
119
|
-
|
120
|
-
self
|
121
|
-
end
|
122
|
-
|
123
|
-
def self.create(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
124
|
-
event = from_hash(o, tmp_email, tmp_api_key, tmp_host)
|
125
|
-
event.create
|
126
|
-
end
|
127
|
-
|
128
|
-
# Create the node via the REST API
|
129
|
-
def create
|
130
|
-
megam_rest.post_event(to_hash)
|
131
|
-
end
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
def self.list(tmp_email=nil, tmp_api_key=nil, tmp_host=nil, inflated=false)
|
136
|
-
event = self.new(tmp_email, tmp_api_key, tmp_host)
|
137
|
-
event.megam_rest.get_events
|
138
|
-
end
|
139
|
-
|
140
|
-
def to_s
|
141
|
-
Megam::Stuff.styled_hash(to_hash)
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
145
|
-
end
|
data/test/test_event.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
-
|
3
|
-
class TestApps < MiniTest::Unit::TestCase
|
4
|
-
def test_get_events
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_post_event()
|
9
|
-
tmp_hash = {
|
10
|
-
"id" => "ASM1139235178976247808",
|
11
|
-
"name" => "calcines",
|
12
|
-
|
13
|
-
"command" => "Start",
|
14
|
-
"type" => "APP",
|
15
|
-
}
|
16
|
-
|
17
|
-
response = megams.post_event(tmp_hash)
|
18
|
-
assert_equal(201, response.status)
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
data/test/test_logs.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
-
|
3
|
-
class TestLogs < MiniTest::Unit::TestCase
|
4
|
-
|
5
|
-
#Testing with the logstash key(syslog).
|
6
|
-
#This testing gives 303(See Other)
|
7
|
-
#The result will be redirected to somewhere, from where we can get the logs.
|
8
|
-
def test_get_logs
|
9
|
-
response = megams.get_logs("syslog")
|
10
|
-
|
11
|
-
assert_equal(200, response.status)
|
12
|
-
assert_match(%r{^https://localhost\.megam\.co/streams/[-a-zA-Z0-9]*\?srv=[0-9]*$}, response.body)
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|