megam_api 0.92 → 0.93
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 +13 -6
- data/lib/megam/api/marketplaces.rb +0 -1
- data/lib/megam/api/organizations.rb +15 -21
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/account.rb +13 -7
- data/lib/megam/core/assemblies.rb +22 -15
- data/lib/megam/core/assembly.rb +11 -10
- data/lib/megam/core/availableunits.rb +2 -1
- data/lib/megam/core/balances.rb +1 -0
- data/lib/megam/core/billedhistories.rb +1 -0
- data/lib/megam/core/components.rb +8 -8
- data/lib/megam/core/config.rb +1 -0
- data/lib/megam/core/marketplace.rb +37 -24
- data/lib/megam/core/marketplace_collection.rb +9 -10
- data/lib/megam/core/organizations.rb +18 -20
- data/lib/megam/core/server_api.rb +9 -6
- data/lib/megam/core/sshkey.rb +37 -22
- data/test/test_accounts.rb +10 -36
- data/test/test_assemblies.rb +71 -75
- data/test/test_assembly.rb +6 -25
- data/test/test_components.rb +6 -6
- data/test/test_helper.rb +9 -10
- data/test/test_marketplaces.rb +6 -4
- data/test/test_organizations.rb +7 -13
- data/test/test_sshkeys.rb +38 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8a15e5000dc77156d71acc72cfd7e6938bdd22a
|
4
|
+
data.tar.gz: fb4fcafb4e1bd33e7a0813524d1b6c80fb4fed2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58ef61fcfeeef6795df7fbb9f94ba8cf884d24b6e78e03e3b0ec3663d552bb572698a2218bba9441a178109921ea42bd5a6621ead97126a562aa55cdd658204a
|
7
|
+
data.tar.gz: 267663ea7f418aa31a6cad29e0d1155ea941b0f223283c0145dbf7652d624dbd3ab31d03123e1b1d2cf9f75fc9052cd2d30baeffac2ce6b8a1d06e0cc8031da3
|
data/lib/megam/api.rb
CHANGED
@@ -98,6 +98,7 @@ module Megam
|
|
98
98
|
X_Megam_DATE = 'X-Megam-DATE'.freeze
|
99
99
|
X_Megam_HMAC = 'X-Megam-HMAC'.freeze
|
100
100
|
X_Megam_OTTAI = 'X-Megam-OTTAI'.freeze
|
101
|
+
X_Megam_ORG = 'X-Megam-ORG'.freeze
|
101
102
|
|
102
103
|
HEADERS = {
|
103
104
|
'Accept' => 'application/json',
|
@@ -131,7 +132,9 @@ module Megam
|
|
131
132
|
@options = OPTIONS.merge(options)
|
132
133
|
@api_key = @options.delete(:api_key) || ENV['MEGAM_API_KEY']
|
133
134
|
@email = @options.delete(:email)
|
134
|
-
|
135
|
+
@password = @options.delete(:password)
|
136
|
+
@org_id = @options.delete(:org_id)
|
137
|
+
fail Megam::API::Errors::AuthKeysMissing if (@email.nil? && @api_key.nil?) || (@email.nil? && @password.nil?)
|
135
138
|
end
|
136
139
|
|
137
140
|
def request(params, &block)
|
@@ -184,7 +187,7 @@ module Megam
|
|
184
187
|
Megam::Log.debug("#{response.body}")
|
185
188
|
|
186
189
|
begin
|
187
|
-
unless response.headers[X_Megam_OTTAI]
|
190
|
+
unless response.headers[X_Megam_OTTAI]
|
188
191
|
response.body = Megam::JSONCompat.from_json(response.body.chomp)
|
189
192
|
Megam::Log.debug('RESPONSE: Ruby Object')
|
190
193
|
else
|
@@ -214,8 +217,8 @@ module Megam
|
|
214
217
|
@options[:path] = API_VERSION2 + @options[:path]
|
215
218
|
encoded_api_header = encode_header(@options)
|
216
219
|
@options[:headers] = HEADERS.merge(X_Megam_HMAC => encoded_api_header[:hmac],
|
217
|
-
X_Megam_DATE => encoded_api_header[:date]).merge(@options[:headers])
|
218
|
-
|
220
|
+
X_Megam_DATE => encoded_api_header[:date], X_Megam_ORG => "#{@org_id}").merge(@options[:headers])
|
221
|
+
@options[:headers] = @options[:headers].merge('X-Megam-PUTTUSAVI' => "true") unless (@password == "" || @password.nil?)
|
219
222
|
Megam::Log.debug('HTTP Request Data:')
|
220
223
|
Megam::Log.debug("> HTTP #{@options[:scheme]}://#{@options[:host]}")
|
221
224
|
@options.each do |key, value|
|
@@ -248,8 +251,12 @@ module Megam
|
|
248
251
|
data = "#{current_date}" + "\n" + "#{cmd_parms[:path]}" + "\n" + "#{body_base64}"
|
249
252
|
|
250
253
|
digest = OpenSSL::Digest.new('sha1')
|
251
|
-
movingFactor = data.rstrip!
|
252
|
-
|
254
|
+
movingFactor = data.rstrip!
|
255
|
+
if !(@password.nil?)
|
256
|
+
hash = OpenSSL::HMAC.hexdigest(digest, Base64.strict_decode64(@password), movingFactor)
|
257
|
+
else
|
258
|
+
hash = OpenSSL::HMAC.hexdigest(digest, @api_key, movingFactor)
|
259
|
+
end
|
253
260
|
final_hmac = @email + ':' + hash
|
254
261
|
header_params = { hmac: final_hmac, date: current_date }
|
255
262
|
end
|
@@ -1,57 +1,51 @@
|
|
1
1
|
module Megam
|
2
2
|
class API
|
3
|
+
def get_organizations
|
3
4
|
|
4
|
-
|
5
|
+
@options = {:path => '/organizations',:body => ''}.merge(@options)
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
request(
|
7
|
+
request(
|
9
8
|
:expects => 200,
|
10
9
|
:method => :get,
|
11
10
|
:body => @options[:body]
|
12
11
|
|
13
12
|
)
|
14
|
-
|
13
|
+
end
|
15
14
|
|
16
|
-
def get_organization(id)
|
15
|
+
def get_organization(id)
|
17
16
|
|
18
|
-
|
17
|
+
@options = {:path => "/organizations/#{id}",
|
19
18
|
:body => ''}.merge(@options)
|
20
19
|
|
21
|
-
|
20
|
+
request(
|
22
21
|
:expects => 200,
|
23
22
|
:method => :get,
|
24
23
|
:body => @options[:body]
|
25
24
|
)
|
26
|
-
end
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
def post_organization(new_organization)
|
27
|
+
def post_organization(new_organization)
|
30
28
|
|
31
29
|
@options = {:path => '/organizations/content',
|
32
30
|
:body => Megam::JSONCompat.to_json(new_organization)}.merge(@options)
|
33
31
|
|
34
|
-
|
35
|
-
request(
|
32
|
+
request(
|
36
33
|
:expects => 201,
|
37
34
|
:method => :post,
|
38
35
|
:body => @options[:body]
|
39
36
|
)
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
end
|
43
38
|
|
44
39
|
def update_organization(new_organization)
|
45
40
|
|
46
|
-
|
41
|
+
@options = {:path => '/organizations/update',
|
47
42
|
:body => Megam::JSONCompat.to_json(new_organization)}.merge(@options)
|
48
43
|
|
49
|
-
|
50
|
-
request(
|
44
|
+
request(
|
51
45
|
:expects => 201,
|
52
46
|
:method => :post,
|
53
47
|
:body => @options[:body]
|
54
48
|
)
|
55
|
-
|
56
|
-
|
49
|
+
end
|
50
|
+
end
|
57
51
|
end
|
data/lib/megam/api/version.rb
CHANGED
data/lib/megam/core/account.rb
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
#
|
16
16
|
module Megam
|
17
17
|
class Account < Megam::ServerAPI
|
18
|
-
def initialize(
|
18
|
+
def initialize(o)
|
19
19
|
@id = nil
|
20
20
|
@email = nil
|
21
21
|
@api_key = nil
|
@@ -28,7 +28,7 @@ module Megam
|
|
28
28
|
@password_reset_sent_at = nil
|
29
29
|
@created_at = nil
|
30
30
|
@some_msg = {}
|
31
|
-
super(email, api_key, host)
|
31
|
+
super({:email => o[:email], :api_key => o[:api_key], :host => o[:host], :password => o[:password], :org_id => o[:org_id]})
|
32
32
|
end
|
33
33
|
|
34
34
|
#used by resque workers and any other background job
|
@@ -181,7 +181,7 @@ module Megam
|
|
181
181
|
|
182
182
|
# Create a Megam::Account from JSON (used by the backgroud job workers)
|
183
183
|
def self.json_create(o)
|
184
|
-
acct = new
|
184
|
+
acct = new({})
|
185
185
|
acct.id(o["id"]) if o.has_key?("id")
|
186
186
|
acct.email(o["email"]) if o.has_key?("email")
|
187
187
|
acct.api_key(o["api_key"]) if o.has_key?("api_key")
|
@@ -201,7 +201,7 @@ module Megam
|
|
201
201
|
end
|
202
202
|
|
203
203
|
def self.from_hash(o)
|
204
|
-
acct = self.new(o[:email], o[:api_key], o[:host])
|
204
|
+
acct = self.new({:email => o[:email], :api_key => o[:api_key], :host => o[:host], :password => o[:password], :org_id => o[:org_id]})
|
205
205
|
acct.from_hash(o)
|
206
206
|
acct
|
207
207
|
end
|
@@ -231,13 +231,19 @@ module Megam
|
|
231
231
|
megam_rest.post_accounts(to_hash)
|
232
232
|
end
|
233
233
|
|
234
|
-
|
234
|
+
=begin
|
235
235
|
# Load a account by email_p
|
236
|
-
def self.show(email,api_key,host=nil)
|
237
|
-
acct = self.new(email, api_key, host)
|
236
|
+
def self.show(email,api_key,host=nil,password=nil)
|
237
|
+
acct = self.new(email, api_key, host, password)
|
238
238
|
acct.megam_rest.get_accounts(email)
|
239
239
|
end
|
240
|
+
=end
|
240
241
|
|
242
|
+
# Load a account by email_p
|
243
|
+
def self.show(o)
|
244
|
+
acct = self.new({:email => o[:email], :api_key => o[:api_key], :host => o[:host], :password => o[:password], :org_id => o[:org_id]})
|
245
|
+
acct.megam_rest.get_accounts(o[:email])
|
246
|
+
end
|
241
247
|
|
242
248
|
def self.update(o)
|
243
249
|
acct = from_hash(o)
|
@@ -16,22 +16,22 @@
|
|
16
16
|
|
17
17
|
module Megam
|
18
18
|
class Assemblies < Megam::ServerAPI
|
19
|
-
def initialize(
|
19
|
+
def initialize(o)
|
20
20
|
@id = nil
|
21
21
|
@accounts_id = nil
|
22
22
|
@org_id = nil
|
23
23
|
@name = nil
|
24
|
+
@password = nil
|
24
25
|
@assemblies = []
|
25
26
|
@inputs = []
|
26
27
|
@created_at = nil
|
27
|
-
super(
|
28
|
+
super(o)
|
28
29
|
end
|
29
30
|
|
30
31
|
def assemblies
|
31
32
|
self
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
35
|
def id(arg=nil)
|
36
36
|
if arg != nil
|
37
37
|
@id = arg
|
@@ -47,7 +47,7 @@ module Megam
|
|
47
47
|
@accounts_id
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def org_id(arg=nil)
|
52
52
|
if arg != nil
|
53
53
|
@org_id = arg
|
@@ -56,6 +56,14 @@ module Megam
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
def password(arg=nil)
|
60
|
+
if arg != nil
|
61
|
+
@password = arg
|
62
|
+
else
|
63
|
+
@password
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
59
67
|
def name(arg=nil)
|
60
68
|
if arg != nil
|
61
69
|
@name = arg
|
@@ -72,7 +80,6 @@ module Megam
|
|
72
80
|
end
|
73
81
|
end
|
74
82
|
|
75
|
-
|
76
83
|
def inputs(arg=[])
|
77
84
|
if arg != []
|
78
85
|
@inputs = arg
|
@@ -127,7 +134,7 @@ module Megam
|
|
127
134
|
end
|
128
135
|
|
129
136
|
def self.json_create(o)
|
130
|
-
asm = new
|
137
|
+
asm = new({})
|
131
138
|
asm.id(o["id"]) if o.has_key?("id")
|
132
139
|
asm.name(o["name"]) if o.has_key?("name")
|
133
140
|
asm.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
|
@@ -138,8 +145,8 @@ module Megam
|
|
138
145
|
asm
|
139
146
|
end
|
140
147
|
|
141
|
-
def self.from_hash(o
|
142
|
-
asm = self.new(
|
148
|
+
def self.from_hash(o)
|
149
|
+
asm = self.new(o)
|
143
150
|
asm.from_hash(o)
|
144
151
|
asm
|
145
152
|
end
|
@@ -148,15 +155,15 @@ module Megam
|
|
148
155
|
@id = o["id"] if o.has_key?("id")
|
149
156
|
@name = o["name"] if o.has_key?("name")
|
150
157
|
@accounts_id = o["accounts_id"] if o.has_key?("accounts_id")
|
151
|
-
@org_id
|
158
|
+
@org_id = o["org_id"] if o.has_key?("org_id")
|
152
159
|
@assemblies = o["assemblies"] if o.has_key?("assemblies")
|
153
|
-
@inputs
|
160
|
+
@inputs = o["inputs"] if o.has_key?("inputs")
|
154
161
|
@created_at = o["created_at"] if o.has_key?("created_at")
|
155
162
|
self
|
156
163
|
end
|
157
164
|
|
158
165
|
def self.create(params)
|
159
|
-
asm = from_hash(params
|
166
|
+
asm = from_hash(params)
|
160
167
|
asm.create
|
161
168
|
end
|
162
169
|
|
@@ -166,13 +173,13 @@ module Megam
|
|
166
173
|
end
|
167
174
|
|
168
175
|
# Load a account by email_p
|
169
|
-
def self.show(
|
170
|
-
asm = self.new(
|
171
|
-
asm.megam_rest.get_one_assemblies(
|
176
|
+
def self.show(o)
|
177
|
+
asm = self.new(o)
|
178
|
+
asm.megam_rest.get_one_assemblies(o[:assemblies_id])
|
172
179
|
end
|
173
180
|
|
174
181
|
def self.list(params)
|
175
|
-
asm = self.new(params
|
182
|
+
asm = self.new(params)
|
176
183
|
asm.megam_rest.get_assemblies
|
177
184
|
end
|
178
185
|
|
data/lib/megam/core/assembly.rb
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
module Megam
|
18
18
|
class Assembly < Megam::ServerAPI
|
19
|
-
def initialize(
|
19
|
+
def initialize(o)
|
20
20
|
@id = nil
|
21
21
|
@asms_id = nil
|
22
22
|
@name = nil
|
@@ -28,7 +28,7 @@ module Megam
|
|
28
28
|
@status = nil
|
29
29
|
@created_at = nil
|
30
30
|
|
31
|
-
super(
|
31
|
+
super(o)
|
32
32
|
end
|
33
33
|
|
34
34
|
def assembly
|
@@ -124,7 +124,7 @@ module Megam
|
|
124
124
|
index_hash = {}
|
125
125
|
index_hash['json_claz'] = self.class.name
|
126
126
|
index_hash['id'] = id
|
127
|
-
|
127
|
+
index_hash["asms_id"] = asms_id
|
128
128
|
index_hash['name'] = name
|
129
129
|
index_hash['components'] = components
|
130
130
|
index_hash['tosca_type'] = tosca_type
|
@@ -159,7 +159,7 @@ module Megam
|
|
159
159
|
end
|
160
160
|
|
161
161
|
def self.json_create(o)
|
162
|
-
asm = new
|
162
|
+
asm = new({})
|
163
163
|
asm.id(o['id']) if o.key?('id')
|
164
164
|
asm.asms_id(o["asms_id"]) if o.has_key?("asms_id")
|
165
165
|
asm.name(o['name']) if o.key?('name')
|
@@ -173,15 +173,15 @@ module Megam
|
|
173
173
|
asm
|
174
174
|
end
|
175
175
|
|
176
|
-
def self.from_hash(o
|
177
|
-
asm = new(
|
176
|
+
def self.from_hash(o)
|
177
|
+
asm = new(o)
|
178
178
|
asm.from_hash(o)
|
179
179
|
asm
|
180
180
|
end
|
181
181
|
|
182
182
|
def from_hash(o)
|
183
183
|
@id = o['id'] if o.key?('id')
|
184
|
-
|
184
|
+
@asms_id = o["asms_id"] if o.has_key?("asms_id")
|
185
185
|
@name = o['name'] if o.key?('name')
|
186
186
|
@components = o['components'] if o.key?('components')
|
187
187
|
@tosca_type = o['tosca_type'] if o.key?('tosca_type')
|
@@ -194,17 +194,17 @@ module Megam
|
|
194
194
|
end
|
195
195
|
|
196
196
|
def self.show(params)
|
197
|
-
asm = new(params
|
197
|
+
asm = new(params)
|
198
198
|
asm.megam_rest.get_one_assembly(params['id'])
|
199
199
|
end
|
200
200
|
|
201
201
|
def self.update(params)
|
202
|
-
asm = from_hash(params
|
202
|
+
asm = from_hash(params)
|
203
203
|
asm.update
|
204
204
|
end
|
205
205
|
|
206
206
|
def self.upgrade(params)
|
207
|
-
asm = from_hash(params
|
207
|
+
asm = from_hash(params)
|
208
208
|
asm.megam_rest.upgrade_assembly(params['id'])
|
209
209
|
end
|
210
210
|
|
@@ -218,3 +218,4 @@ module Megam
|
|
218
218
|
end
|
219
219
|
end
|
220
220
|
end
|
221
|
+
|
@@ -113,7 +113,7 @@ module Megam
|
|
113
113
|
|
114
114
|
#
|
115
115
|
def self.json_create(o)
|
116
|
-
aunit = new
|
116
|
+
aunit = new({})
|
117
117
|
aunit.id(o["id"]) if o.has_key?("id")
|
118
118
|
aunit.name(o["name"]) if o.has_key?("name")
|
119
119
|
aunit.duration(o["duration"]) if o.has_key?("duration")
|
@@ -179,3 +179,4 @@ module Megam
|
|
179
179
|
|
180
180
|
end
|
181
181
|
end
|
182
|
+
|
data/lib/megam/core/balances.rb
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
module Megam
|
18
18
|
class Components < Megam::ServerAPI
|
19
|
-
def initialize(
|
19
|
+
def initialize(o)
|
20
20
|
@id = nil
|
21
21
|
@name = nil
|
22
22
|
@tosca_type = nil
|
@@ -37,7 +37,7 @@ module Megam
|
|
37
37
|
@url = nil
|
38
38
|
@created_at = nil
|
39
39
|
|
40
|
-
super(
|
40
|
+
super(o)
|
41
41
|
end
|
42
42
|
|
43
43
|
def components
|
@@ -244,7 +244,7 @@ module Megam
|
|
244
244
|
end
|
245
245
|
|
246
246
|
def self.json_create(o)
|
247
|
-
asm = new
|
247
|
+
asm = new({})
|
248
248
|
asm.id(o['id']) if o.key?('id')
|
249
249
|
asm.name(o['name']) if o.key?('name')
|
250
250
|
asm.tosca_type(o['tosca_type']) if o.key?('tosca_type')
|
@@ -269,8 +269,8 @@ module Megam
|
|
269
269
|
asm
|
270
270
|
end
|
271
271
|
|
272
|
-
def self.from_hash(o
|
273
|
-
asm = new(
|
272
|
+
def self.from_hash(o)
|
273
|
+
asm = new(o)
|
274
274
|
asm.from_hash(o)
|
275
275
|
asm
|
276
276
|
end
|
@@ -292,18 +292,18 @@ module Megam
|
|
292
292
|
end
|
293
293
|
|
294
294
|
def self.create(params)
|
295
|
-
asm = from_hash(params
|
295
|
+
asm = from_hash(params)
|
296
296
|
asm.create
|
297
297
|
end
|
298
298
|
|
299
299
|
# Load a account by email_p
|
300
300
|
def self.show(params)
|
301
|
-
asm = new(params
|
301
|
+
asm = new(params)
|
302
302
|
asm.megam_rest.get_components(params['id'])
|
303
303
|
end
|
304
304
|
|
305
305
|
def self.update(params)
|
306
|
-
asm = from_hash(params
|
306
|
+
asm = from_hash(params)
|
307
307
|
asm.update
|
308
308
|
end
|
309
309
|
|