megam_api 0.93 → 0.95
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/.travis.yml +2 -2
- data/lib/megam/api.rb +18 -4
- data/lib/megam/api/accounts.rb +19 -4
- data/lib/megam/api/assemblies.rb +15 -0
- data/lib/megam/api/assembly.rb +15 -1
- data/lib/megam/api/availableunits.rb +15 -0
- data/lib/megam/api/balances.rb +16 -1
- data/lib/megam/api/billedhistories.rb +15 -0
- data/lib/megam/api/billings.rb +15 -0
- data/lib/megam/api/components.rb +15 -0
- data/lib/megam/api/credithistories.rb +15 -0
- data/lib/megam/api/csars.rb +16 -1
- data/lib/megam/api/discounts.rb +15 -0
- data/lib/megam/api/domains.rb +32 -22
- data/lib/megam/api/errors.rb +15 -0
- data/lib/megam/api/invoices.rb +15 -0
- data/lib/megam/api/login.rb +15 -0
- data/lib/megam/api/marketplaces.rb +15 -0
- data/lib/megam/api/organizations.rb +31 -17
- data/lib/megam/api/promos.rb +18 -3
- data/lib/megam/api/requests.rb +15 -0
- data/lib/megam/api/sensors.rb +15 -0
- data/lib/megam/api/sshkeys.rb +15 -0
- data/lib/megam/api/subscriptions.rb +15 -0
- data/lib/megam/api/version.rb +16 -1
- data/lib/megam/core/account.rb +1 -1
- data/lib/megam/core/assemblies.rb +1 -1
- data/lib/megam/core/assemblies_collection.rb +1 -1
- data/lib/megam/core/assembly.rb +1 -1
- data/lib/megam/core/assembly_collection.rb +1 -1
- data/lib/megam/core/auth.rb +1 -1
- data/lib/megam/core/availableunits.rb +1 -1
- data/lib/megam/core/availableunits_collection.rb +1 -1
- data/lib/megam/core/balances.rb +4 -5
- data/lib/megam/core/balances_collection.rb +1 -1
- data/lib/megam/core/billedhistories.rb +4 -5
- data/lib/megam/core/billedhistories_collection.rb +1 -1
- data/lib/megam/core/billings.rb +4 -4
- data/lib/megam/core/billings_collection.rb +1 -1
- data/lib/megam/core/components.rb +1 -1
- data/lib/megam/core/components_collection.rb +1 -1
- data/lib/megam/core/config.rb +1 -1
- data/lib/megam/core/credithistories.rb +1 -1
- data/lib/megam/core/credithistories_collection.rb +1 -1
- data/lib/megam/core/csar.rb +1 -1
- data/lib/megam/core/csar_collection.rb +1 -1
- data/lib/megam/core/discounts.rb +1 -1
- data/lib/megam/core/discounts_collection.rb +1 -1
- data/lib/megam/core/domain_collection.rb +144 -0
- data/lib/megam/core/domains.rb +76 -85
- data/lib/megam/core/error.rb +1 -1
- data/lib/megam/core/invoices.rb +1 -1
- data/lib/megam/core/invoices_collection.rb +1 -1
- data/lib/megam/core/json_compat.rb +3 -0
- data/lib/megam/core/konipai.rb +1 -1
- data/lib/megam/core/marketplace.rb +1 -1
- data/lib/megam/core/marketplace_collection.rb +1 -1
- data/lib/megam/core/organizations.rb +1 -3
- data/lib/megam/core/organizations_collection.rb +1 -1
- data/lib/megam/core/promos.rb +1 -1
- data/lib/megam/core/request.rb +1 -1
- data/lib/megam/core/request_collection.rb +1 -1
- data/lib/megam/core/sensors.rb +1 -1
- data/lib/megam/core/sensors_collection.rb +1 -1
- data/lib/megam/core/server_api.rb +1 -1
- data/lib/megam/core/sshkey.rb +1 -1
- data/lib/megam/core/sshkey_collection.rb +1 -1
- data/lib/megam/core/subscriptions.rb +1 -1
- data/lib/megam/core/subscriptions_collection.rb +1 -1
- data/lib/megam/mixins/assemblies.rb +15 -0
- data/lib/megam/mixins/assembly.rb +16 -0
- data/lib/megam/mixins/common_deployable.rb +15 -0
- data/lib/megam/mixins/components.rb +15 -0
- data/lib/megam/mixins/megam_attributes.rb +15 -0
- data/lib/megam/mixins/outputs.rb +15 -0
- data/lib/megam/mixins/policies.rb +15 -0
- data/lib/megam_api.rb +15 -0
- data/megam_api.gemspec +6 -6
- data/test/test_accounts.rb +46 -9
- data/test/test_assemblies.rb +7 -7
- data/test/test_assembly.rb +4 -4
- data/test/test_availableunits.rb +3 -4
- data/test/test_balances.rb +9 -10
- data/test/test_billedhistories.rb +4 -4
- data/test/test_billings.rb +1 -2
- data/test/test_components.rb +4 -4
- data/test/test_credithistories.rb +3 -4
- data/test/test_csars.rb +2 -1
- data/test/test_discounts.rb +4 -5
- data/test/test_domains.rb +8 -7
- data/test/test_invoices.rb +2 -2
- data/test/test_marketplaces.rb +4 -4
- data/test/test_organizations.rb +3 -3
- data/test/test_requests.rb +1 -1
- data/test/test_sshkeys.rb +15 -14
- metadata +41 -12
data/lib/megam/core/config.rb
CHANGED
data/lib/megam/core/csar.rb
CHANGED
data/lib/megam/core/discounts.rb
CHANGED
|
@@ -0,0 +1,144 @@
|
|
|
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 DomainsCollection
|
|
18
|
+
include Enumerable
|
|
19
|
+
|
|
20
|
+
attr_reader :iterator
|
|
21
|
+
def initialize
|
|
22
|
+
@domains = Array.new
|
|
23
|
+
@domains_by_name = Hash.new
|
|
24
|
+
@insert_after_idx = nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def all_domains
|
|
28
|
+
@domains
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def [](index)
|
|
32
|
+
@domains[index]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def []=(index, arg)
|
|
36
|
+
is_megam_domains(arg)
|
|
37
|
+
@domains[index] = arg
|
|
38
|
+
@domains_by_name[arg.name] = index
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def <<(*args)
|
|
42
|
+
args.flatten.each do |a|
|
|
43
|
+
is_megam_domains(a)
|
|
44
|
+
@domains << a
|
|
45
|
+
@domains_by_name[a.name] =@domains.length - 1
|
|
46
|
+
end
|
|
47
|
+
self
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# 'push' is an alias method to <<
|
|
51
|
+
alias_method :push, :<<
|
|
52
|
+
|
|
53
|
+
def insert(domains)
|
|
54
|
+
is_megam_domains(domains)
|
|
55
|
+
if @insert_after_idx
|
|
56
|
+
# in the middle of executing a run, so any domain inserted now should
|
|
57
|
+
# be placed after the most recent addition done by the currently executing
|
|
58
|
+
# domain
|
|
59
|
+
@domains.insert(@insert_after_idx + 1, domains)
|
|
60
|
+
# update name -> location mappings and register new sshkeys
|
|
61
|
+
@domains_by_name.each_key do |key|
|
|
62
|
+
@domains_by_name[key] += 1 if@domains_by_name[key] > @insert_after_idx
|
|
63
|
+
end
|
|
64
|
+
@domains_by_name[domains.name] = @insert_after_idx + 1
|
|
65
|
+
@insert_after_idx += 1
|
|
66
|
+
else
|
|
67
|
+
@domains << domains
|
|
68
|
+
@domains_by_name[domains.name] =@domains.length - 1
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def each
|
|
73
|
+
@domains.each do |domains|
|
|
74
|
+
yield domains
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def each_index
|
|
79
|
+
@domains.each_index do |i|
|
|
80
|
+
yield i
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def empty?
|
|
85
|
+
@domains.empty?
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def lookup(domains)
|
|
89
|
+
lookup_by = nil
|
|
90
|
+
if domains.kind_of?(Megam::Domains)
|
|
91
|
+
lookup_by = domains.name
|
|
92
|
+
elsif domains.kind_of?(String)
|
|
93
|
+
lookup_by = domains
|
|
94
|
+
else
|
|
95
|
+
raise ArgumentError, "Must pass a Megam::Domains or String to lookup"
|
|
96
|
+
end
|
|
97
|
+
res =@domains_by_name[lookup_by]
|
|
98
|
+
unless res
|
|
99
|
+
raise ArgumentError, "Cannot find a domain matching #{lookup_by} (did you define it first?)"
|
|
100
|
+
end
|
|
101
|
+
@domains[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 |domains|
|
|
108
|
+
index_hash[domains.name] = domains.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
|
+
def self.json_create(o)
|
|
120
|
+
collection = self.new()
|
|
121
|
+
o["results"].each do |domains_list|
|
|
122
|
+
domains_array = domains_list.kind_of?(Array) ? domains_list : [ domains_list ]
|
|
123
|
+
domains_array.each do |domains|
|
|
124
|
+
collection.insert(domains)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
collection
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
private
|
|
131
|
+
|
|
132
|
+
def is_megam_domains(arg)
|
|
133
|
+
unless arg.kind_of?(Megam::Domains)
|
|
134
|
+
raise ArgumentError, "Members must be Megam::Domains's"
|
|
135
|
+
end
|
|
136
|
+
true
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def to_s
|
|
140
|
+
Megam::Stuff.styled_hash(to_hash)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
end
|
|
144
|
+
end
|
data/lib/megam/core/domains.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright:: Copyright (c)
|
|
1
|
+
# Copyright:: Copyright (c) 2013-2016 Megam Systems, Inc.
|
|
2
2
|
# License:: Apache License, Version 2.0
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -13,52 +13,43 @@
|
|
|
13
13
|
# See the License for the specific language governing permissions and
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
#
|
|
16
|
-
|
|
17
16
|
module Megam
|
|
18
17
|
class Domains < Megam::ServerAPI
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def domain
|
|
28
|
-
self
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def id(arg=nil)
|
|
32
|
-
if arg != nil
|
|
33
|
-
@id = arg
|
|
34
|
-
else
|
|
35
|
-
@id
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def name(arg=nil)
|
|
42
|
-
if arg != nil
|
|
43
|
-
@name = arg
|
|
44
|
-
else
|
|
45
|
-
@name
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
18
|
+
def initialize(o)
|
|
19
|
+
@id = nil
|
|
20
|
+
@name = nil
|
|
21
|
+
@created_at = nil
|
|
22
|
+
super(o)
|
|
23
|
+
end
|
|
49
24
|
|
|
25
|
+
def domain
|
|
26
|
+
self
|
|
27
|
+
end
|
|
50
28
|
|
|
51
|
-
def
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
end
|
|
29
|
+
def id(arg=nil)
|
|
30
|
+
if arg != nil
|
|
31
|
+
@id = arg
|
|
32
|
+
else
|
|
33
|
+
@id
|
|
34
|
+
end
|
|
35
|
+
end
|
|
58
36
|
|
|
37
|
+
def name(arg=nil)
|
|
38
|
+
if arg != nil
|
|
39
|
+
@name = arg
|
|
40
|
+
else
|
|
41
|
+
@name
|
|
42
|
+
end
|
|
43
|
+
end
|
|
59
44
|
|
|
45
|
+
def created_at(arg=nil)
|
|
46
|
+
if arg != nil
|
|
47
|
+
@created_at = arg
|
|
48
|
+
else
|
|
49
|
+
@created_at
|
|
50
|
+
end
|
|
51
|
+
end
|
|
60
52
|
|
|
61
|
-
# Transform the ruby obj -> to a Hash
|
|
62
53
|
def to_hash
|
|
63
54
|
index_hash = Hash.new
|
|
64
55
|
index_hash["json_claz"] = self.class.name
|
|
@@ -68,62 +59,62 @@ end
|
|
|
68
59
|
index_hash
|
|
69
60
|
end
|
|
70
61
|
|
|
71
|
-
def to_json(*a)
|
|
72
|
-
|
|
73
|
-
end
|
|
62
|
+
def to_json(*a)
|
|
63
|
+
for_json.to_json(*a)
|
|
64
|
+
end
|
|
74
65
|
|
|
75
|
-
def for_json
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
end
|
|
66
|
+
def for_json
|
|
67
|
+
result = {
|
|
68
|
+
"id" => id,
|
|
69
|
+
"name" => name,
|
|
70
|
+
"created_at" => created_at
|
|
71
|
+
}
|
|
72
|
+
result
|
|
73
|
+
end
|
|
83
74
|
|
|
84
|
-
# Create a Megam::Domains from JSON (used by the backgroud job workers)
|
|
85
|
-
def self.json_create(o)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
end
|
|
75
|
+
# Create a Megam::Domains from JSON (used by the backgroud job workers)
|
|
76
|
+
def self.json_create(o)
|
|
77
|
+
dmn = new
|
|
78
|
+
dmn.id(o["id"]) if o.has_key?("id")
|
|
79
|
+
dmn.name(o["name"]) if o.has_key?("name")
|
|
80
|
+
dmn.created_at(o["created_at"]) if o.has_key?("created_at")
|
|
81
|
+
dmn
|
|
82
|
+
end
|
|
92
83
|
|
|
93
|
-
def self.from_hash(o)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
end
|
|
84
|
+
def self.from_hash(o)
|
|
85
|
+
org = self.new(o)
|
|
86
|
+
org.from_hash(o)
|
|
87
|
+
org
|
|
88
|
+
end
|
|
98
89
|
|
|
99
|
-
def from_hash(o)
|
|
100
|
-
@id = o[:id] if o.has_key?(:id)
|
|
101
|
-
@name = o[:name] if o.has_key?(:name)
|
|
102
|
-
@created_at = o[:created_at] if o.has_key?(:created_at)
|
|
103
|
-
self
|
|
104
|
-
end
|
|
105
90
|
|
|
106
|
-
def
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
91
|
+
def from_hash(o)
|
|
92
|
+
@id = o[:id] if o.has_key?(:id)
|
|
93
|
+
@name = o[:name] if o.has_key?(:name)
|
|
94
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
|
95
|
+
self
|
|
96
|
+
end
|
|
110
97
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
end
|
|
98
|
+
def self.create(o)
|
|
99
|
+
dom = from_hash(o)
|
|
100
|
+
dom.create
|
|
101
|
+
end
|
|
116
102
|
|
|
103
|
+
def self.list(o)
|
|
104
|
+
dom = from_hash(o)
|
|
105
|
+
dom.megam_rest.get_domains
|
|
106
|
+
end
|
|
117
107
|
|
|
118
|
-
def create
|
|
108
|
+
def create
|
|
119
109
|
megam_rest.post_domains(to_hash)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def to_s
|
|
123
|
-
Megam::Stuff.styled_hash(to_hash)
|
|
124
110
|
end
|
|
125
111
|
|
|
112
|
+
def show
|
|
113
|
+
megam_rest.get_domains(to_hash)
|
|
114
|
+
end
|
|
126
115
|
|
|
116
|
+
def to_s
|
|
117
|
+
Megam::Stuff.styled_hash(to_hash)
|
|
118
|
+
end
|
|
127
119
|
end
|
|
128
|
-
|
|
129
120
|
end
|
data/lib/megam/core/error.rb
CHANGED
data/lib/megam/core/invoices.rb
CHANGED
|
@@ -44,6 +44,7 @@ module Megam
|
|
|
44
44
|
MEGAM_CSAR = 'Megam::CSAR'.freeze
|
|
45
45
|
MEGAM_CSARCOLLECTION = 'Megam::CSARCollection'.freeze
|
|
46
46
|
MEGAM_DOMAIN = 'Megam::Domains'.freeze
|
|
47
|
+
MEGAM_DOMAINCOLLECTION = 'Megam::DomainsCollection'.freeze
|
|
47
48
|
MEGAM_DISCOUNTS = 'Megam::Discounts'.freeze
|
|
48
49
|
MEGAM_DISCOUNTSCOLLECTION = 'Megam::DiscountsCollection'.freeze
|
|
49
50
|
MEGAM_ERROR = 'Megam::Error'.freeze
|
|
@@ -178,6 +179,8 @@ module Megam
|
|
|
178
179
|
Megam::CSARCollection
|
|
179
180
|
when MEGAM_DOMAIN
|
|
180
181
|
Megam::Domains
|
|
182
|
+
when MEGAM_DOMAINCOLLECTION
|
|
183
|
+
Megam::DomainsCollection
|
|
181
184
|
when MEGAM_SENSORS
|
|
182
185
|
Megam::Sensors
|
|
183
186
|
when MEGAM_SENSORSCOLLECTION
|
data/lib/megam/core/konipai.rb
CHANGED