megam_api 0.19 → 0.20
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/app_requests.rb +16 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/app_request.rb +164 -0
- data/lib/megam/core/app_request_collection.rb +145 -0
- data/lib/megam/core/json_compat.rb +6 -0
- data/test/test_app_requests.rb +18 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a88d33222ae6a6df77e081ea71bf5ba49fe222fc
|
4
|
+
data.tar.gz: 9e41197340f0bd0a92123ae61c74889d9d234438
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45805bf649222838c7e10a1cdad1400699381c176278a421e45d801d835cafd5de4d8d4fafd4cbc46a34d884bfac6b739ba012a20530238f1e53e6cc2fe2d3da
|
7
|
+
data.tar.gz: f7247aa053f5100e4f0c794f191b3d1ab6558052d8373ada907c1a5b6c46a944db00104e2a4c631d4b4da77ad4fafd997746b0ae23138692c660843973559694
|
data/lib/megam/api.rb
CHANGED
@@ -19,6 +19,7 @@ require "megam/api/version"
|
|
19
19
|
require "megam/api/login"
|
20
20
|
require "megam/api/accounts"
|
21
21
|
require "megam/api/requests"
|
22
|
+
require "megam/api/app_requests"
|
22
23
|
require "megam/api/predef_clouds"
|
23
24
|
require "megam/api/cloud_tool_settings"
|
24
25
|
require "megam/api/sshkeys"
|
@@ -63,6 +64,8 @@ require "megam/core/assembly"
|
|
63
64
|
require "megam/core/assembly_collection"
|
64
65
|
require "megam/core/components"
|
65
66
|
require "megam/core/components_collection"
|
67
|
+
require "megam/core/app_request"
|
68
|
+
require "megam/core/app_request_collection"
|
66
69
|
|
67
70
|
|
68
71
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Megam
|
2
|
+
class API
|
3
|
+
|
4
|
+
def post_apprequest(new_req)
|
5
|
+
@options = {:path => '/apprequests/content',
|
6
|
+
:body => Megam::JSONCompat.to_json(new_req)}.merge(@options)
|
7
|
+
|
8
|
+
request(
|
9
|
+
:expects => 201,
|
10
|
+
:method => :post,
|
11
|
+
:body => @options[:body]
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/megam/api/version.rb
CHANGED
@@ -0,0 +1,164 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2012, 2014 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 AppRequest < Megam::ServerAPI
|
18
|
+
def initialize(email=nil, api_key=nil)
|
19
|
+
@id = nil
|
20
|
+
@app_id = nil
|
21
|
+
@app_name = nil
|
22
|
+
@action = nil
|
23
|
+
@some_msg = {}
|
24
|
+
@created_at = nil
|
25
|
+
super(email, api_key)
|
26
|
+
end
|
27
|
+
|
28
|
+
def app_request
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def id(arg=nil)
|
34
|
+
if arg != nil
|
35
|
+
@id = arg
|
36
|
+
else
|
37
|
+
@id
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def app_id(arg=nil)
|
42
|
+
if arg != nil
|
43
|
+
@app_id = arg
|
44
|
+
else
|
45
|
+
@app_id
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def app_name(arg=nil)
|
50
|
+
if arg != nil
|
51
|
+
@app_name = arg
|
52
|
+
else
|
53
|
+
@app_name
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def action(arg=nil)
|
58
|
+
if arg != nil
|
59
|
+
@action = arg
|
60
|
+
else
|
61
|
+
@action
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def created_at(arg=nil)
|
67
|
+
if arg != nil
|
68
|
+
@created_at = arg
|
69
|
+
else
|
70
|
+
@created_at
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def some_msg(arg=nil)
|
75
|
+
if arg != nil
|
76
|
+
@some_msg = arg
|
77
|
+
else
|
78
|
+
@some_msg
|
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
|
+
# Transform the ruby obj -> to a Hash
|
87
|
+
def to_hash
|
88
|
+
index_hash = Hash.new
|
89
|
+
index_hash["json_claz"] = self.class.name
|
90
|
+
index_hash["id"] = id
|
91
|
+
index_hash["app_id"] = app_id
|
92
|
+
index_hash["app_name"] = app_name
|
93
|
+
index_hash["action"] = action
|
94
|
+
index_hash["created_at"] = created_at
|
95
|
+
index_hash
|
96
|
+
end
|
97
|
+
|
98
|
+
# Serialize this object as a hash: called from JsonCompat.
|
99
|
+
# Verify if this called from JsonCompat during testing.
|
100
|
+
def to_json(*a)
|
101
|
+
for_json.to_json(*a)
|
102
|
+
end
|
103
|
+
|
104
|
+
def for_json
|
105
|
+
result = {
|
106
|
+
"id" => id,
|
107
|
+
"app_id" => app_id,
|
108
|
+
"app_name" => app_name,
|
109
|
+
"action" => action,
|
110
|
+
"created_at" => created_at
|
111
|
+
}
|
112
|
+
result
|
113
|
+
end
|
114
|
+
|
115
|
+
#
|
116
|
+
def self.json_create(o)
|
117
|
+
node = new
|
118
|
+
node.id(o["id"]) if o.has_key?("id")
|
119
|
+
node.app_id(o["app_id"]) if o.has_key?("app_id")
|
120
|
+
node.app_name(o["app_name"]) if o.has_key?("app_name")
|
121
|
+
node.action(o["action"]) if o.has_key?("action")
|
122
|
+
node.created_at(o["created_at"]) if o.has_key?("created_at")
|
123
|
+
#success or error
|
124
|
+
node.some_msg[:code] = o["code"] if o.has_key?("code")
|
125
|
+
node.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
126
|
+
node.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
127
|
+
node.some_msg[:links] = o["links"] if o.has_key?("links")
|
128
|
+
node
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
|
132
|
+
node = self.new(tmp_email, tmp_api_key)
|
133
|
+
node.from_hash(o)
|
134
|
+
node
|
135
|
+
end
|
136
|
+
|
137
|
+
def from_hash(o)
|
138
|
+
@id = o[:id] if o.has_key?(:id)
|
139
|
+
@app_id = o[:app_id] if o.has_key?(:app_id)
|
140
|
+
@app_name = o[:app_name] if o.has_key?(:app_name)
|
141
|
+
@action = o[:action] if o.has_key?(:action)
|
142
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
143
|
+
self
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
def self.create(o,tmp_email=nil, tmp_api_key=nil)
|
148
|
+
acct = from_hash(o,tmp_email, tmp_api_key)
|
149
|
+
acct.create
|
150
|
+
end
|
151
|
+
|
152
|
+
# Create the node via the REST API
|
153
|
+
def create
|
154
|
+
megam_rest.post_apprequest(to_hash)
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
def to_s
|
159
|
+
Megam::Stuff.styled_hash(to_hash)
|
160
|
+
#"---> Megam::Account:[error=#{error?}]\n"+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2012, 2014 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 AppRequestCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
attr_reader :iterator
|
21
|
+
def initialize
|
22
|
+
@apprequests = Array.new
|
23
|
+
@apprequests_by_name = Hash.new
|
24
|
+
@insert_after_idx = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_requests
|
28
|
+
@apprequests
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](index)
|
32
|
+
@apprequests[index]
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, arg)
|
36
|
+
is_megam_request(arg)
|
37
|
+
@apprequests[index] = arg
|
38
|
+
@apprequests_by_name[arg.app_id] = index
|
39
|
+
end
|
40
|
+
|
41
|
+
def <<(*args)
|
42
|
+
args.flatten.each do |a|
|
43
|
+
is_megam_request(a)
|
44
|
+
@apprequests << a
|
45
|
+
@apprequests_by_name[a.app_id] = @apprequests.length - 1
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# 'push' is an alias method to <<
|
51
|
+
alias_method :push, :<<
|
52
|
+
|
53
|
+
def insert(request)
|
54
|
+
is_megam_request(request)
|
55
|
+
if @insert_after_idx
|
56
|
+
# in the middle of executing a run, so any requests inserted now should
|
57
|
+
# be placed after the most recent addition done by the currently executing
|
58
|
+
# request
|
59
|
+
@apprequests.insert(@insert_after_idx + 1, request)
|
60
|
+
# update name -> location mappings and register new request
|
61
|
+
@apprequests_by_name.each_key do |key|
|
62
|
+
@apprequests_by_name[key] += 1 if @apprequests_by_name[key] > @insert_after_idx
|
63
|
+
end
|
64
|
+
@apprequests_by_name[request.app_id] = @insert_after_idx + 1
|
65
|
+
@insert_after_idx += 1
|
66
|
+
else
|
67
|
+
@apprequests << request
|
68
|
+
@apprequests_by_name[request.app_id] = @apprequests.length - 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def each
|
73
|
+
@apprequests.each do |request|
|
74
|
+
yield request
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def each_index
|
79
|
+
@apprequests.each_index do |i|
|
80
|
+
yield i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def empty?
|
85
|
+
@apprequests.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def lookup(request)
|
89
|
+
lookup_by = nil
|
90
|
+
if request.kind_of?(Megam::AppRequest)
|
91
|
+
lookup_by = request.app_id
|
92
|
+
elsif request.kind_of?(String)
|
93
|
+
lookup_by = request
|
94
|
+
else
|
95
|
+
raise ArgumentError, "Must pass a Megam::AppRequest or String to lookup"
|
96
|
+
end
|
97
|
+
res = @apprequests_by_name[lookup_by]
|
98
|
+
unless res
|
99
|
+
raise ArgumentError, "Cannot find a request matching #{lookup_by} (did you define it first?)"
|
100
|
+
end
|
101
|
+
@apprequests[res]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Transform the ruby obj -> to a Hash
|
105
|
+
def to_hash
|
106
|
+
index_hash = Hash.new
|
107
|
+
self.each do |request|
|
108
|
+
index_hash[request.app_id] = request.to_s
|
109
|
+
end
|
110
|
+
index_hash
|
111
|
+
end
|
112
|
+
|
113
|
+
# Serialize this object as a hash: called from JsonCompat.
|
114
|
+
# Verify if this called from JsonCompat during testing.
|
115
|
+
def to_json(*a)
|
116
|
+
for_json.to_json(*a)
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def self.json_create(o)
|
121
|
+
collection = self.new()
|
122
|
+
o["results"].each do |requests_list|
|
123
|
+
requests_array = requests_list.kind_of?(Array) ? requests_list : [ requests_list ]
|
124
|
+
requests_array.each do |request|
|
125
|
+
collection.insert(request)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
collection
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def is_megam_request(arg)
|
134
|
+
unless arg.kind_of?(Megam::AppRequest)
|
135
|
+
raise ArgumentError, "Members must be Megam::AppRequest's"
|
136
|
+
end
|
137
|
+
true
|
138
|
+
end
|
139
|
+
|
140
|
+
def to_s
|
141
|
+
Megam::Stuff.styled_hash(to_hash)
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|
@@ -35,6 +35,8 @@ module Megam
|
|
35
35
|
MEGAM_REQUESTCOLLECTION = "Megam::RequestCollection".freeze
|
36
36
|
MEGAM_ORGANIZATION = "Megam::Organizations".freeze
|
37
37
|
MEGAM_DOMAIN = "Megam::Domains".freeze
|
38
|
+
MEGAM_APPREQUEST = "Megam::AppRequest".freeze
|
39
|
+
MEGAM_APPREQUESTCOLLECTION = "Megam::AppRequestCollection".freeze
|
38
40
|
|
39
41
|
MEGAM_PREDEFCLOUD = "Megam::PredefCloud".freeze
|
40
42
|
MEGAM_PREDEFCLOUDCOLLECTION = "Megam::PredefCloudCollection".freeze
|
@@ -171,6 +173,10 @@ module Megam
|
|
171
173
|
Megam::CSARCollection
|
172
174
|
when MEGAM_DOMAIN
|
173
175
|
Megam::Domains
|
176
|
+
when MEGAM_APPREQUEST
|
177
|
+
Megam::AppRequest
|
178
|
+
when MEGAM_APPREQUESTCOLLECTION
|
179
|
+
Megam::AppRequestCollection
|
174
180
|
else
|
175
181
|
raise JSON::ParserError, "Unsupported `json_class` type '#{json_class}'"
|
176
182
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
+
|
3
|
+
class TestApps < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
@@tmp_hash = {
|
6
|
+
"app_id" => "ASM1136003656177549312",
|
7
|
+
"app_name" => "HermanWard.megam.co", #APP or Bolt
|
8
|
+
"action" => "start"
|
9
|
+
}
|
10
|
+
|
11
|
+
|
12
|
+
def test_request_app_start
|
13
|
+
response = megams.post_request(@@tmp_hash)
|
14
|
+
assert_equal(201, response.status)
|
15
|
+
end
|
16
|
+
#=end
|
17
|
+
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: megam_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.20'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kishorekumar Neelamegam, Thomas Alrin, Subash Sethurajan, Rajthilak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- lib/certs/cacert.pem
|
131
131
|
- lib/megam/api.rb
|
132
132
|
- lib/megam/api/accounts.rb
|
133
|
+
- lib/megam/api/app_requests.rb
|
133
134
|
- lib/megam/api/assemblies.rb
|
134
135
|
- lib/megam/api/assembly.rb
|
135
136
|
- lib/megam/api/cloud_tool_settings.rb
|
@@ -146,6 +147,8 @@ files:
|
|
146
147
|
- lib/megam/api/sshkeys.rb
|
147
148
|
- lib/megam/api/version.rb
|
148
149
|
- lib/megam/core/account.rb
|
150
|
+
- lib/megam/core/app_request.rb
|
151
|
+
- lib/megam/core/app_request_collection.rb
|
149
152
|
- lib/megam/core/assemblies.rb
|
150
153
|
- lib/megam/core/assemblies_collection.rb
|
151
154
|
- lib/megam/core/assembly.rb
|
@@ -182,6 +185,7 @@ files:
|
|
182
185
|
- lib/megam_api.rb
|
183
186
|
- megam_api.gemspec
|
184
187
|
- test/test_accounts.rb
|
188
|
+
- test/test_app_requests.rb
|
185
189
|
- test/test_assemblies.rb
|
186
190
|
- test/test_assembly.rb
|
187
191
|
- test/test_cloudtoolsettings.rb
|