megam_api 0.100 → 1.5.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -69
  3. data/lib/megam/api.rb +15 -37
  4. data/lib/megam/api/errors.rb +19 -19
  5. data/lib/megam/api/version.rb +1 -1
  6. data/lib/megam/core/account.rb +1 -1
  7. data/lib/megam/core/assemblies.rb +1 -1
  8. data/lib/megam/core/assemblies_collection.rb +7 -15
  9. data/lib/megam/core/assembly.rb +1 -1
  10. data/lib/megam/core/assembly_collection.rb +7 -15
  11. data/lib/megam/core/balances.rb +1 -1
  12. data/lib/megam/core/balances_collection.rb +8 -16
  13. data/lib/megam/core/billedhistories.rb +1 -1
  14. data/lib/megam/core/billedhistories_collection.rb +7 -15
  15. data/lib/megam/core/components.rb +1 -1
  16. data/lib/megam/core/components_collection.rb +103 -110
  17. data/lib/megam/core/domain_collection.rb +102 -109
  18. data/lib/megam/core/domains.rb +1 -1
  19. data/lib/megam/core/error.rb +1 -15
  20. data/lib/megam/core/json_compat.rb +170 -208
  21. data/lib/megam/core/marketplace.rb +1 -1
  22. data/lib/megam/core/marketplace_collection.rb +7 -16
  23. data/lib/megam/core/organizations.rb +1 -1
  24. data/lib/megam/core/organizations_collection.rb +8 -40
  25. data/lib/megam/core/promos.rb +1 -1
  26. data/lib/megam/core/request.rb +1 -1
  27. data/lib/megam/core/request_collection.rb +7 -16
  28. data/lib/megam/core/rest_adapter.rb +54 -0
  29. data/lib/megam/core/sensors.rb +1 -1
  30. data/lib/megam/core/sensors_collection.rb +7 -14
  31. data/lib/megam/core/sshkey.rb +1 -1
  32. data/lib/megam/core/sshkey_collection.rb +103 -110
  33. data/lib/megam/core/stuff.rb +2 -34
  34. data/lib/megam/core/text.rb +1 -0
  35. data/lib/megam/core/text_formatter.rb +2 -1
  36. data/megam_api.gemspec +2 -2
  37. metadata +10 -56
  38. data/lib/megam/api/availableunits.rb +0 -50
  39. data/lib/megam/api/billings.rb +0 -50
  40. data/lib/megam/api/credithistories.rb +0 -50
  41. data/lib/megam/api/csars.rb +0 -75
  42. data/lib/megam/api/discounts.rb +0 -50
  43. data/lib/megam/api/invoices.rb +0 -50
  44. data/lib/megam/api/login.rb +0 -29
  45. data/lib/megam/api/subscriptions.rb +0 -50
  46. data/lib/megam/core/auth.rb +0 -91
  47. data/lib/megam/core/availableunits.rb +0 -182
  48. data/lib/megam/core/availableunits_collection.rb +0 -144
  49. data/lib/megam/core/billings.rb +0 -242
  50. data/lib/megam/core/billings_collection.rb +0 -144
  51. data/lib/megam/core/config.rb +0 -41
  52. data/lib/megam/core/credithistories.rb +0 -191
  53. data/lib/megam/core/credithistories_collection.rb +0 -144
  54. data/lib/megam/core/csar.rb +0 -179
  55. data/lib/megam/core/csar_collection.rb +0 -148
  56. data/lib/megam/core/discounts.rb +0 -204
  57. data/lib/megam/core/discounts_collection.rb +0 -164
  58. data/lib/megam/core/invoices.rb +0 -231
  59. data/lib/megam/core/invoices_collection.rb +0 -144
  60. data/lib/megam/core/server_api.rb +0 -52
  61. data/lib/megam/core/subscriptions.rb +0 -191
  62. data/lib/megam/core/subscriptions_collection.rb +0 -144
  63. data/test/test_availableunits.rb +0 -28
  64. data/test/test_billings.rb +0 -33
  65. data/test/test_cat_requests.rb +0 -20
  66. data/test/test_credithistories.rb +0 -29
  67. data/test/test_csars.rb +0 -22
  68. data/test/test_discounts.rb +0 -31
  69. data/test/test_invoices.rb +0 -31
  70. data/test/test_login.rb +0 -10
  71. data/test/test_marketplaceaddons.rb +0 -46
  72. data/test/test_predefclouds.rb +0 -80
  73. data/test/test_subscriptions.rb +0 -29
@@ -1,144 +0,0 @@
1
- ##
2
- ## Copyright 2013-2016 Megam Systems
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 AvailableunitsCollection
18
- include Enumerable
19
-
20
- attr_reader :iterator
21
- def initialize
22
- @availableunits = Array.new
23
- @availableunits_by_name = Hash.new
24
- @insert_after_idx = nil
25
- end
26
-
27
- def all_availableunits
28
- @availableunits
29
- end
30
-
31
- def [](index)
32
- @availableunits[index]
33
- end
34
-
35
- def []=(index, arg)
36
- is_megam_availableunits(arg)
37
- @availableunits[index] = arg
38
- @availableunits_by_name[arg.name] = index
39
- end
40
-
41
- def <<(*args)
42
- args.flatten.each do |a|
43
- is_megam_availableunits(a)
44
- @availableunits << a
45
- @availableunits_by_name[a.name] =@availableunits.length - 1
46
- end
47
- self
48
- end
49
-
50
- # 'push' is an alias method to <<
51
- alias_method :push, :<<
52
-
53
- def insert(availableunits)
54
- is_megam_availableunits(availableunits)
55
- if @insert_after_idx
56
- # in the middle of executing a run, so any predefs inserted now should
57
- # be placed after the most recent addition done by the currently executing
58
- # availableunits
59
- @availableunits.insert(@insert_after_idx + 1, availableunits)
60
- # update name -> location mappings and register new availableunits
61
- @availableunits_by_name.each_key do |key|
62
- @availableunits_by_name[key] += 1 if@availableunits_by_name[key] > @insert_after_idx
63
- end
64
- @availableunits_by_name[availableunits.name] = @insert_after_idx + 1
65
- @insert_after_idx += 1
66
- else
67
- @availableunits << availableunits
68
- @availableunits_by_name[availableunits.name] =@availableunits.length - 1
69
- end
70
- end
71
-
72
- def each
73
- @availableunits.each do |availableunits|
74
- yield availableunits
75
- end
76
- end
77
-
78
- def each_index
79
- @availableunits.each_index do |i|
80
- yield i
81
- end
82
- end
83
-
84
- def empty?
85
- @availableunits.empty?
86
- end
87
-
88
- def lookup(availableunits)
89
- lookup_by = nil
90
- if availableunits.kind_of?(Megam::Availableunits)
91
- lookup_by = availableunits.name
92
- elsif availableunits.kind_of?(String)
93
- lookup_by = availableunits
94
- else
95
- raise ArgumentError, "Must pass a Megam::Availableunits or String to lookup"
96
- end
97
- res =@availableunits_by_name[lookup_by]
98
- unless res
99
- raise ArgumentError, "Cannot find a availableunits matching #{lookup_by} (did you define it first?)"
100
- end
101
- @availableunits[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 |availableunits|
108
- index_hash[availableunits.name] = availableunits.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 |availableunits_list|
122
- availableunits_array = availableunits_list.kind_of?(Array) ? availableunits_list : [ availableunits_list ]
123
- availableunits_array.each do |availableunits|
124
- collection.insert(availableunits)
125
- end
126
- end
127
- collection
128
- end
129
-
130
- private
131
-
132
- def is_megam_availableunits(arg)
133
- unless arg.kind_of?(Megam::Availableunits)
134
- raise ArgumentError, "Members must be Megam::availableunits'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
@@ -1,242 +0,0 @@
1
- ##
2
- ## Copyright 2013-2016 Megam Systems
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 Billings < Megam::ServerAPI
18
-
19
- def initialize(email=nil, api_key=nil, host=nil)
20
- @id = nil
21
- @accounts_id = nil
22
- @line1 = nil
23
- @line2 = nil
24
- @country_code = nil
25
- @postal_code=nil
26
- @state=nil
27
- @phone = nil
28
- @bill_type = nil
29
- @created_at = nil
30
- @some_msg = {}
31
- super(email, api_key, host)
32
- end
33
-
34
- def billings
35
- self
36
- end
37
-
38
-
39
- def id(arg=nil)
40
- if arg != nil
41
- @id = arg
42
- else
43
- @id
44
- end
45
- end
46
-
47
- def accounts_id(arg=nil)
48
- if arg != nil
49
- @accounts_id= arg
50
- else
51
- @accounts_id
52
- end
53
- end
54
-
55
- def line1(arg=nil)
56
- if arg != nil
57
- @line1 = arg
58
- else
59
- @line1
60
- end
61
- end
62
-
63
- def line2(arg=nil)
64
- if arg != nil
65
- @line2 = arg
66
- else
67
- @line2
68
- end
69
- end
70
-
71
- def country_code(arg=nil)
72
- if arg != nil
73
- @country_code = arg
74
- else
75
- @country_code
76
- end
77
- end
78
-
79
- def postal_code(arg=nil)
80
- if arg != nil
81
- @postal_code= arg
82
- else
83
- @postal_code
84
- end
85
- end
86
-
87
- def state(arg=nil)
88
- if arg != nil
89
- @state= arg
90
- else
91
- @state
92
- end
93
- end
94
-
95
- def phone(arg=nil)
96
- if arg != nil
97
- @phone= arg
98
- else
99
- @phone
100
- end
101
- end
102
-
103
- def bill_type(arg=nil)
104
- if arg != nil
105
- @bill_type = arg
106
- else
107
- @bill_type
108
- end
109
- end
110
-
111
- def created_at(arg=nil)
112
- if arg != nil
113
- @created_at = arg
114
- else
115
- @created_at
116
- end
117
- end
118
-
119
- def some_msg(arg=nil)
120
- if arg != nil
121
- @some_msg = arg
122
- else
123
- @some_msg
124
- end
125
- end
126
-
127
- def error?
128
- crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
129
- end
130
-
131
- # Transform the ruby obj -> to a Hash
132
- def to_hash
133
- index_hash = Hash.new
134
- index_hash["json_claz"] = self.class.name
135
- index_hash["id"] = id
136
- index_hash["accounts_id"] = accounts_id
137
- index_hash["line1"] = line1
138
- index_hash["line2"] = line2
139
- index_hash["country_code"] = country_code
140
- index_hash["postal_code"] = postal_code
141
- index_hash["state"] = state
142
- index_hash["phone"] = phone
143
- index_hash["bill_type"] = bill_type
144
- index_hash["created_at"] = created_at
145
- index_hash["some_msg"] = some_msg
146
- index_hash
147
- end
148
-
149
- # Serialize this object as a hash: called from JsonCompat.
150
- # Verify if this called from JsonCompat during testing.
151
- def to_json(*a)
152
- for_json.to_json(*a)
153
- end
154
-
155
- def for_json
156
- result = {
157
- "id" => id,
158
- "accounts_id" => accounts_id,
159
- "line1" => line1,
160
- "line2" => line2,
161
- "country_code" => country_code,
162
- "postal_code" => postal_code,
163
- "state" => state,
164
- "phone" => phone,
165
- "bill_type" => bill_type,
166
- "created_at" => created_at
167
- }
168
- result
169
- end
170
-
171
- #
172
- def self.json_create(o)
173
- cts = new
174
- cts.id(o["id"]) if o.has_key?("id")
175
- cts.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
176
- cts.line1(o["line1"]) if o.has_key?("line1")
177
- cts.line2(o["line2"]) if o.has_key?("line2")
178
- cts.country_code(o["country_code"]) if o.has_key?("country_code")
179
- cts.postal_code(o["postal_code"]) if o.has_key?("postal_code")
180
- cts.state(o["state"]) if o.has_key?("state")
181
- cts.phone(o["phone"]) if o.has_key?("phone")
182
- cts.bill_type(o["bill_type"]) if o.has_key?("bill_type")
183
-
184
- cts.created_at(o["created_at"]) if o.has_key?("created_at")
185
- #success or error
186
- cts.some_msg[:code] = o["code"] if o.has_key?("code")
187
- cts.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
188
- cts.some_msg[:msg]= o["msg"] if o.has_key?("msg")
189
- cts.some_msg[:links] = o["links"] if o.has_key?("links")
190
- cts
191
- end
192
-
193
- def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
194
- cts = self.new(tmp_email,tmp_api_key,tmp_host)
195
- cts.from_hash(o)
196
- cts
197
- end
198
-
199
- def from_hash(o)
200
- @id = o[:id] if o.has_key?(:id)
201
- @accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
202
- @line1 = o[:line1] if o.has_key?(:line1)
203
- @line2 = o[:line2] if o.has_key?(:line2)
204
- @country_code = o[:country_code] if o.has_key?(:country_code)
205
- @postal_code = o[:postal_code] if o.has_key?(:postal_code)
206
- @state = o[:state] if o.has_key?(:state)
207
- @bill_type = o[:bill_type] if o.has_key?(:bill_type)
208
- @created_at = o[:created_at] if o.has_key?(:created_at)
209
- self
210
- end
211
-
212
- def self.create(o,tmp_email=nil, tmp_api_key=nil,tmp_host=nil)
213
- acct = from_hash(o,tmp_email, tmp_api_key, tmp_host)
214
- acct.create
215
- end
216
-
217
- # Create the billings via the REST API
218
- def create
219
- megam_rest.post_billings(to_hash)
220
- end
221
-
222
- # Load all billings -
223
- # returns a billingsCollection
224
- # don't return self. check if the Megam::billingsCollection is returned.
225
- def self.list(tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
226
- cts = self.new(tmp_email, tmp_api_key, tmp_host)
227
- cts.megam_rest.get_billings
228
- end
229
-
230
- # Show a particular billings by name,
231
- # Megam::billings
232
- def self.show(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
233
- pre = self.new(tmp_email, tmp_api_key, tmp_host)
234
- pre.megam_rest.get_billing(p_name)
235
- end
236
-
237
- def to_s
238
- Megam::Stuff.styled_hash(to_hash)
239
- end
240
-
241
- end
242
- end
@@ -1,144 +0,0 @@
1
- ##
2
- ## Copyright 2013-2016 Megam Systems
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 BillingsCollection
18
- include Enumerable
19
-
20
- attr_reader :iterator
21
- def initialize
22
- @billings = Array.new
23
- @billings_by_name = Hash.new
24
- @insert_after_idx = nil
25
- end
26
-
27
- def all_billings
28
- @billings
29
- end
30
-
31
- def [](index)
32
- @billings[index]
33
- end
34
-
35
- def []=(index, arg)
36
- is_megam_billings(arg)
37
- @billings[index] = arg
38
- @billings_by_name[arg.repo_name] = index
39
- end
40
-
41
- def <<(*args)
42
- args.flatten.each do |a|
43
- is_megam_billings(a)
44
- @billings << a
45
- @billings_by_name[a.repo_name] =@billings.length - 1
46
- end
47
- self
48
- end
49
-
50
- # 'push' is an alias method to <<
51
- alias_method :push, :<<
52
-
53
- def insert(billings)
54
- is_megam_billings(billings)
55
- if @insert_after_idx
56
- # in the middle of executing a run, so any billings inserted now should
57
- # be placed after the most recent addition done by the currently executing
58
- # billings
59
- @billings.insert(@insert_after_idx + 1, billings)
60
- # update name -> location mappings and register new billings
61
- @billings_by_name.each_key do |key|
62
- @billings_by_name[key] += 1 if@billings_by_name[key] > @insert_after_idx
63
- end
64
- @billings_by_name[billings.repo_name] = @insert_after_idx + 1
65
- @insert_after_idx += 1
66
- else
67
- @billings << billings
68
- @billings_by_name[billings.repo_name] =@billings.length - 1
69
- end
70
- end
71
-
72
- def each
73
- @billings.each do |billings|
74
- yield billings
75
- end
76
- end
77
-
78
- def each_index
79
- @billings.each_index do |i|
80
- yield i
81
- end
82
- end
83
-
84
- def empty?
85
- @billings.empty?
86
- end
87
-
88
- def lookup(billings)
89
- lookup_by = nil
90
- if billings.kind_of?(Megam::Billings)
91
- lookup_by = billings.repo_name
92
- elsif billings.kind_of?(String)
93
- lookup_by = billings
94
- else
95
- raise ArgumentError, "Must pass a Megam::billings or String to lookup"
96
- end
97
- res =@billings_by_name[lookup_by]
98
- unless res
99
- raise ArgumentError, "Cannot find a billings matching #{lookup_by} (did you define it first?)"
100
- end
101
- @billings[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 |billings|
108
- index_hash[billings.repo_name] = billings.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 |billings_list|
122
- billings_array = billings_list.kind_of?(Array) ? billings_list : [ billings_list ]
123
- billings_array.each do |billings|
124
- collection.insert(billings)
125
- end
126
- end
127
- collection
128
- end
129
-
130
- private
131
-
132
- def is_megam_billings(arg)
133
- unless arg.kind_of?(Megam::Billings)
134
- raise ArgumentError, "Members must be Megam::Billings"
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