megam_api 1.5.rc7 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/megam/api.rb +6 -0
- data/lib/megam/api/addons.rb +27 -0
- data/lib/megam/api/subscriptions.rb +26 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/account.rb +210 -450
- data/lib/megam/core/addons.rb +169 -0
- data/lib/megam/core/addons_collection.rb +121 -0
- data/lib/megam/core/json_compat.rb +13 -1
- data/lib/megam/core/rest_adapter.rb +5 -3
- data/lib/megam/core/subscriptions.rb +167 -0
- data/lib/megam/core/subscriptions_collection.rb +121 -0
- data/test/test_accounts.rb +22 -50
- data/test/test_addons.rb +22 -0
- data/test/test_subscriptions.rb +22 -0
- metadata +14 -4
@@ -0,0 +1,121 @@
|
|
1
|
+
module Megam
|
2
|
+
class SubscriptionsCollection
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :iterator
|
6
|
+
def initialize
|
7
|
+
@subscriptions = Array.new
|
8
|
+
@subscriptions_by_name = Hash.new
|
9
|
+
@insert_after_idx = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def all_subscriptions
|
13
|
+
@subscriptions
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](index)
|
17
|
+
@subscriptions[index]
|
18
|
+
end
|
19
|
+
|
20
|
+
def []=(index, arg)
|
21
|
+
is_megam_subscriptions(arg)
|
22
|
+
@subscriptions[index] = arg
|
23
|
+
@subscriptions_by_name[arg.account_id] = index
|
24
|
+
end
|
25
|
+
|
26
|
+
def <<(*args)
|
27
|
+
args.flatten.each do |a|
|
28
|
+
is_megam_subscriptions(a)
|
29
|
+
@subscriptions << a
|
30
|
+
@subscriptions_by_name[a.account_id] =@subscriptions.length - 1
|
31
|
+
end
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# 'push' is an alias method to <<
|
36
|
+
alias_method :push, :<<
|
37
|
+
|
38
|
+
def insert(subscriptions)
|
39
|
+
is_megam_subscriptions(subscriptions)
|
40
|
+
if @insert_after_idx
|
41
|
+
# in the middle of executing a run, so any predefs inserted now should
|
42
|
+
# be placed after the most recent addition done by the currently executing
|
43
|
+
# subscriptions
|
44
|
+
@subscriptions.insert(@insert_after_idx + 1, subscriptions)
|
45
|
+
# update name -> location mappings and register new subscriptions
|
46
|
+
@subscriptions_by_name.each_key do |key|
|
47
|
+
@subscriptions_by_name[key] += 1 if@subscriptions_by_name[key] > @insert_after_idx
|
48
|
+
end
|
49
|
+
@subscriptions_by_name[subscriptions.account_id] = @insert_after_idx + 1
|
50
|
+
@insert_after_idx += 1
|
51
|
+
else
|
52
|
+
@subscriptions << subscriptions
|
53
|
+
@subscriptions_by_name[subscriptions.account_id] =@subscriptions.length - 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def each
|
58
|
+
@subscriptions.each do |subscriptions|
|
59
|
+
yield subscriptions
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def each_index
|
64
|
+
@subscriptions.each_index do |i|
|
65
|
+
yield i
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def empty?
|
70
|
+
@subscriptions.empty?
|
71
|
+
end
|
72
|
+
|
73
|
+
def lookup(subscriptions)
|
74
|
+
lookup_by = nil
|
75
|
+
if Subscriptions.kind_of?(Megam::Subscriptions)
|
76
|
+
lookup_by = subscriptions.account_id
|
77
|
+
elsif subscriptions.kind_of?(String)
|
78
|
+
lookup_by = subscriptions
|
79
|
+
else
|
80
|
+
raise ArgumentError, "Must pass a Megam::Subscriptions or String to lookup"
|
81
|
+
end
|
82
|
+
res =@subscriptions_by_name[lookup_by]
|
83
|
+
unless res
|
84
|
+
raise ArgumentError, "Cannot find a subscriptions matching #{lookup_by} (did you define it first?)"
|
85
|
+
end
|
86
|
+
@subscriptions[res]
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_s
|
90
|
+
@subscriptions.join(", ")
|
91
|
+
end
|
92
|
+
|
93
|
+
def for_json
|
94
|
+
to_a.map { |item| item.to_s }
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_json(*a)
|
98
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.json_create(o)
|
102
|
+
collection = self.new()
|
103
|
+
o["results"].each do |subscriptions_list|
|
104
|
+
subscriptions_array = subscriptions_list.kind_of?(Array) ? subscriptions_list : [ subscriptions_list ]
|
105
|
+
subscriptions_array.each do |subscriptions|
|
106
|
+
collection.insert(subscriptions)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
collection
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def is_megam_subscriptions(arg)
|
115
|
+
unless arg.kind_of?(Megam::Subscriptions)
|
116
|
+
raise ArgumentError, "Members must be Megam::subscriptions's"
|
117
|
+
end
|
118
|
+
true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/test/test_accounts.rb
CHANGED
@@ -14,59 +14,46 @@ def test_signin_auth
|
|
14
14
|
end
|
15
15
|
|
16
16
|
=end
|
17
|
-
|
17
|
+
=begin
|
18
18
|
def test_get_accounts_good
|
19
19
|
response =megams.get_accounts("coolvader123@iamswag.com")
|
20
20
|
response.body.to_s
|
21
21
|
assert_equal(200, response.status)
|
22
22
|
end
|
23
|
-
|
23
|
+
=end
|
24
24
|
#=begin
|
25
25
|
def test_post_accounts_good
|
26
|
+
#=begin
|
26
27
|
tmp_hash = {
|
27
28
|
"id" => "000099090909000",
|
28
|
-
"email" => "
|
29
|
+
"email" => "coolvader123reee@iamswag.com",
|
29
30
|
"api_key" => "faketest",
|
30
|
-
"name" => {
|
31
31
|
"first_name" => "Darth",
|
32
|
-
"last_name" => "Vader"
|
33
|
-
},
|
34
|
-
"phone" => {
|
32
|
+
"last_name" => "Vader",
|
35
33
|
"phone" => "1908877643",
|
36
|
-
"phone_verified" => "verified"
|
37
|
-
},
|
38
|
-
"password" => {
|
34
|
+
"phone_verified" => "verified",
|
39
35
|
"password" => "user",
|
40
36
|
"password_reset_key" => "",
|
41
|
-
"password_reset_sent_at" => ""
|
42
|
-
},
|
43
|
-
"states" => {
|
37
|
+
"password_reset_sent_at" => "",
|
44
38
|
"authority" => "admin",
|
45
39
|
"active" => "active",
|
46
40
|
"blocked" => "blocked",
|
47
|
-
"staged" => ""
|
48
|
-
},
|
49
|
-
"approval" => {
|
41
|
+
"staged" => "",
|
50
42
|
"approved" => "approved",
|
51
43
|
"approved_by_id" => "",
|
52
|
-
"approved_at" => ""
|
53
|
-
},
|
54
|
-
"suspend" => {
|
44
|
+
"approved_at" => "",
|
55
45
|
"suspended" => "suspended",
|
56
46
|
"suspended_at" => "",
|
57
|
-
"suspended_till" => ""
|
58
|
-
},
|
47
|
+
"suspended_till" => "",
|
59
48
|
"registration_ip_address" => "",
|
60
|
-
"dates" => {
|
61
49
|
"last_posted_at" => "",
|
62
50
|
"last_emailed_at" => "",
|
63
51
|
"previous_visit_at" => "",
|
64
52
|
"first_seen_at" => "",
|
65
53
|
"created_at" => "2014-10-29 13:24:06 +0000"
|
66
54
|
}
|
67
|
-
|
68
|
-
|
69
|
-
response =megams.post_accounts(tmp_hash)
|
55
|
+
#response =megams.post_accounts(tmp_hash)
|
56
|
+
response = Megam::Account.create(tmp_hash)
|
70
57
|
response.body.to_s
|
71
58
|
assert_equal(201, response.status)
|
72
59
|
end
|
@@ -76,47 +63,32 @@ end
|
|
76
63
|
def test_update_accounts_good
|
77
64
|
tmp_hash = {
|
78
65
|
"id" => "000099090909000",
|
79
|
-
"email" => "
|
66
|
+
"email" => "coolvader123reee@iamswag.com",
|
80
67
|
"api_key" => "faketest",
|
81
|
-
"name" => {
|
82
68
|
"first_name" => "Darth",
|
83
|
-
"last_name" => "Vader"
|
84
|
-
|
85
|
-
|
86
|
-
"
|
87
|
-
"phone_verified" => "verified"
|
88
|
-
},
|
89
|
-
"password" => {
|
90
|
-
"password" => "admin",
|
69
|
+
"last_name" => "Vader",
|
70
|
+
"phone" => "1908877643",
|
71
|
+
"phone_verified" => "verified",
|
72
|
+
"password" => "user",
|
91
73
|
"password_reset_key" => "",
|
92
|
-
"password_reset_sent_at" => ""
|
93
|
-
},
|
94
|
-
"states" => {
|
74
|
+
"password_reset_sent_at" => "",
|
95
75
|
"authority" => "admin",
|
96
|
-
"active" => "
|
76
|
+
"active" => "active",
|
97
77
|
"blocked" => "blocked",
|
98
|
-
"staged" => ""
|
99
|
-
},
|
100
|
-
"approval" => {
|
78
|
+
"staged" => "",
|
101
79
|
"approved" => "approved",
|
102
80
|
"approved_by_id" => "",
|
103
|
-
"approved_at" => ""
|
104
|
-
},
|
105
|
-
"suspend" => {
|
81
|
+
"approved_at" => "",
|
106
82
|
"suspended" => "suspended",
|
107
83
|
"suspended_at" => "",
|
108
|
-
"suspended_till" => ""
|
109
|
-
},
|
84
|
+
"suspended_till" => "",
|
110
85
|
"registration_ip_address" => "",
|
111
|
-
"dates" => {
|
112
86
|
"last_posted_at" => "",
|
113
87
|
"last_emailed_at" => "",
|
114
88
|
"previous_visit_at" => "",
|
115
89
|
"first_seen_at" => "",
|
116
90
|
"created_at" => "2014-10-29 13:24:06 +0000"
|
117
91
|
}
|
118
|
-
|
119
|
-
}
|
120
92
|
response = megams.update_accounts(tmp_hash)
|
121
93
|
response.body.to_s
|
122
94
|
assert_equal(201, response.status)
|
data/test/test_addons.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
+
|
3
|
+
class TestApps < MiniTest::Unit::TestCase
|
4
|
+
#=begin
|
5
|
+
def test_post_addons
|
6
|
+
tmp_hash = { :provider_id => "2334",
|
7
|
+
:account_id => "",
|
8
|
+
:provider_name => "whmcs",
|
9
|
+
:options => [],
|
10
|
+
}
|
11
|
+
|
12
|
+
response = megams.post_addons(tmp_hash)
|
13
|
+
assert_equal(201, response.status)
|
14
|
+
end
|
15
|
+
#=end
|
16
|
+
#=begin
|
17
|
+
def test_get_addon
|
18
|
+
response = megams.get_addon("whmcs")
|
19
|
+
assert_equal(200, response.status)
|
20
|
+
end
|
21
|
+
#=end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
+
|
3
|
+
class TestApps < MiniTest::Unit::TestCase
|
4
|
+
#=begin
|
5
|
+
def test_post_subscriptions
|
6
|
+
tmp_hash = { :account_id => "",
|
7
|
+
:model => "ondemand",
|
8
|
+
:license => "trial",
|
9
|
+
:trial_ends => "21/11/2016 20:30:00"
|
10
|
+
}
|
11
|
+
|
12
|
+
response = megams.post_subscriptions(tmp_hash)
|
13
|
+
assert_equal(201, response.status)
|
14
|
+
end
|
15
|
+
#=end
|
16
|
+
#=begin
|
17
|
+
def test_get_subscription
|
18
|
+
response = megams.get_subscription
|
19
|
+
assert_equal(200, response.status)
|
20
|
+
end
|
21
|
+
#=end
|
22
|
+
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajthilak, Kishorekumar Neelamegam, Ranjitha R, Rajesh Rajagopalan, Thomas Alrin,
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: excon
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- lib/certs/cacert.pem
|
137
137
|
- lib/megam/api.rb
|
138
138
|
- lib/megam/api/accounts.rb
|
139
|
+
- lib/megam/api/addons.rb
|
139
140
|
- lib/megam/api/assemblies.rb
|
140
141
|
- lib/megam/api/assembly.rb
|
141
142
|
- lib/megam/api/balances.rb
|
@@ -155,8 +156,11 @@ files:
|
|
155
156
|
- lib/megam/api/sensors.rb
|
156
157
|
- lib/megam/api/snapshots.rb
|
157
158
|
- lib/megam/api/sshkeys.rb
|
159
|
+
- lib/megam/api/subscriptions.rb
|
158
160
|
- lib/megam/api/version.rb
|
159
161
|
- lib/megam/core/account.rb
|
162
|
+
- lib/megam/core/addons.rb
|
163
|
+
- lib/megam/core/addons_collection.rb
|
160
164
|
- lib/megam/core/assemblies.rb
|
161
165
|
- lib/megam/core/assemblies_collection.rb
|
162
166
|
- lib/megam/core/assembly.rb
|
@@ -199,6 +203,8 @@ files:
|
|
199
203
|
- lib/megam/core/sshkey.rb
|
200
204
|
- lib/megam/core/sshkey_collection.rb
|
201
205
|
- lib/megam/core/stuff.rb
|
206
|
+
- lib/megam/core/subscriptions.rb
|
207
|
+
- lib/megam/core/subscriptions_collection.rb
|
202
208
|
- lib/megam/core/text.rb
|
203
209
|
- lib/megam/core/text_formatter.rb
|
204
210
|
- lib/megam/mixins/assemblies.rb
|
@@ -214,6 +220,7 @@ files:
|
|
214
220
|
- test/mixins/test_assembly.rb
|
215
221
|
- test/mixins/test_component.rb
|
216
222
|
- test/test_accounts.rb
|
223
|
+
- test/test_addons.rb
|
217
224
|
- test/test_assemblies.rb
|
218
225
|
- test/test_assembly.rb
|
219
226
|
- test/test_balances.rb
|
@@ -233,6 +240,7 @@ files:
|
|
233
240
|
- test/test_sensors.rb
|
234
241
|
- test/test_snapshots.rb
|
235
242
|
- test/test_sshkeys.rb
|
243
|
+
- test/test_subscriptions.rb
|
236
244
|
homepage: http://github.com/megamsys/megam_api
|
237
245
|
licenses:
|
238
246
|
- Apache-2.0
|
@@ -248,9 +256,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
248
256
|
version: '0'
|
249
257
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
258
|
requirements:
|
251
|
-
- - "
|
259
|
+
- - ">="
|
252
260
|
- !ruby/object:Gem::Version
|
253
|
-
version:
|
261
|
+
version: '0'
|
254
262
|
requirements: []
|
255
263
|
rubyforge_project:
|
256
264
|
rubygems_version: 2.5.1
|
@@ -262,6 +270,7 @@ test_files:
|
|
262
270
|
- test/mixins/test_assembly.rb
|
263
271
|
- test/mixins/test_component.rb
|
264
272
|
- test/test_accounts.rb
|
273
|
+
- test/test_addons.rb
|
265
274
|
- test/test_assemblies.rb
|
266
275
|
- test/test_assembly.rb
|
267
276
|
- test/test_balances.rb
|
@@ -281,3 +290,4 @@ test_files:
|
|
281
290
|
- test/test_sensors.rb
|
282
291
|
- test/test_snapshots.rb
|
283
292
|
- test/test_sshkeys.rb
|
293
|
+
- test/test_subscriptions.rb
|