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,41 +0,0 @@
1
- #
2
- # Copyright:: Copyright (c) 2013-2016 Megam Systems.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require 'mixlib/config'
18
-
19
- module Megam
20
- class Config
21
-
22
- extend Mixlib::Config
23
-
24
- def self.inspect
25
- configuration.inspect
26
- end
27
-
28
- email nil
29
- password nil
30
- api_key nil
31
-
32
- # Set these to enable SSL authentication / mutual-authentication
33
- # with the server
34
- ssl_client_cert nil
35
- ssl_client_key nil
36
- ssl_verify_mode :verify_none
37
- ssl_ca_path nil
38
- ssl_ca_file nil
39
-
40
- end
41
- end
@@ -1,191 +0,0 @@
1
- # Copyright:: Copyright (c) 2013-2016 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 Credithistories < Megam::ServerAPI
18
-
19
- def initialize(email=nil, api_key=nil, host=nil)
20
- @id = nil
21
- @accounts_id = nil
22
- @bill_type = nil
23
- @credit_amount = nil
24
- @currency_type = nil
25
- @created_at = nil
26
- @some_msg = {}
27
- super(email, api_key, host)
28
- end
29
-
30
- def credithistories
31
- self
32
- end
33
-
34
-
35
- def id(arg=nil)
36
- if arg != nil
37
- @id = arg
38
- else
39
- @id
40
- end
41
- end
42
-
43
- def accounts_id(arg=nil)
44
- if arg != nil
45
- @accounts_id= arg
46
- else
47
- @accounts_id
48
- end
49
- end
50
-
51
- def bill_type(arg=nil)
52
- if arg != nil
53
- @bill_type = arg
54
- else
55
- @bill_type
56
- end
57
- end
58
-
59
- def credit_amount(arg=nil)
60
- if arg != nil
61
- @credit_amount = arg
62
- else
63
- @credit_amount
64
- end
65
- end
66
-
67
- def currency_type(arg=nil)
68
- if arg != nil
69
- @currency_type = arg
70
- else
71
- @currency_type
72
- end
73
- end
74
-
75
- def created_at(arg=nil)
76
- if arg != nil
77
- @created_at = arg
78
- else
79
- @created_at
80
- end
81
- end
82
-
83
- def some_msg(arg=nil)
84
- if arg != nil
85
- @some_msg = arg
86
- else
87
- @some_msg
88
- end
89
- end
90
-
91
- def error?
92
- crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
93
- end
94
-
95
- # Transform the ruby obj -> to a Hash
96
- def to_hash
97
- index_hash = Hash.new
98
- index_hash["json_claz"] = self.class.name
99
- index_hash["id"] = id
100
- index_hash["accounts_id"] = accounts_id
101
- index_hash["bill_type"] = bill_type
102
- index_hash["credit_amount"] = credit_amount
103
- index_hash["currency_type"] = currency_type
104
- index_hash["created_at"] = created_at
105
- index_hash["some_msg"] = some_msg
106
- index_hash
107
- end
108
-
109
- # Serialize this object as a hash: called from JsonCompat.
110
- # Verify if this called from JsonCompat during testing.
111
- def to_json(*a)
112
- for_json.to_json(*a)
113
- end
114
-
115
- def for_json
116
- result = {
117
- "id" => id,
118
- "accounts_id" => accounts_id,
119
- "bill_type" => bill_type,
120
- "credit_amount" => credit_amount,
121
- "currency_type" => currency_type,
122
- "created_at" => created_at
123
- }
124
- result
125
- end
126
-
127
- #
128
- def self.json_create(o)
129
- cts = new
130
- cts.id(o["id"]) if o.has_key?("id")
131
- cts.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
132
- cts.bill_type(o["bill_type"]) if o.has_key?("bill_type")
133
- cts.credit_amount(o["credit_amount"]) if o.has_key?("credit_amount")
134
- cts.currency_type(o["currency_type"]) if o.has_key?("currency_type")
135
-
136
- cts.created_at(o["created_at"]) if o.has_key?("created_at")
137
- #success or error
138
- cts.some_msg[:code] = o["code"] if o.has_key?("code")
139
- cts.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
140
- cts.some_msg[:msg]= o["msg"] if o.has_key?("msg")
141
- cts.some_msg[:links] = o["links"] if o.has_key?("links")
142
- cts
143
- end
144
-
145
- def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
146
- cts = self.new(tmp_email,tmp_api_key, tmp_host)
147
- cts.from_hash(o)
148
- cts
149
- end
150
-
151
- def from_hash(o)
152
- @id = o[:id] if o.has_key?(:id)
153
- @accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
154
- @bill_type = o[:bill_type] if o.has_key?(:bill_type)
155
- @credit_amount = o[:credit_amount] if o.has_key?(:credit_amount)
156
- @currency_type = o[:currency_type] if o.has_key?(:currency_type)
157
- @created_at = o[:created_at] if o.has_key?(:created_at)
158
- self
159
- end
160
-
161
- def self.create(params)
162
- acct = from_hash(params,params["email"], params["api_key"], params["host"])
163
- acct.create
164
- end
165
-
166
- # Create the credit histories via the REST API
167
- def create
168
- megam_rest.post_credithistories(to_hash)
169
- end
170
-
171
- # Load all credithistories -
172
- # returns a credithistoriesCollection
173
- # don't return self. check if the Megam::ccredithistoriesCollection is returned.
174
- def self.list(params)
175
- cts = self.new(params["email"], params["api_key"], params["host"])
176
- cts.megam_rest.get_credithistories
177
- end
178
-
179
- # Show a particular credithistories by name,
180
- # Megam::credithistories
181
- def self.show(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
182
- pre = self.new(tmp_email, tmp_api_key, tmp_host)
183
- pre.megam_rest.get_credithistories(p_name)
184
- end
185
-
186
- def to_s
187
- Megam::Stuff.styled_hash(to_hash)
188
- end
189
-
190
- end
191
- end
@@ -1,144 +0,0 @@
1
- # Copyright:: Copyright (c) 2013-2016 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 CredithistoriesCollection
18
- include Enumerable
19
-
20
- attr_reader :iterator
21
- def initialize
22
- @credithistories = Array.new
23
- @credithistories_by_name = Hash.new
24
- @insert_after_idx = nil
25
- end
26
-
27
- def all_credithistories
28
- @credithistories
29
- end
30
-
31
- def [](index)
32
- @credithistories[index]
33
- end
34
-
35
- def []=(index, arg)
36
- is_megam_credithistories(arg)
37
- @credithistories[index] = arg
38
- @credithistories_by_name[arg.repo_name] = index
39
- end
40
-
41
- def <<(*args)
42
- args.flatten.each do |a|
43
- is_megam_credithistories(a)
44
- @credithistories << a
45
- @credithistories_by_name[a.repo_name] =@credithistories.length - 1
46
- end
47
- self
48
- end
49
-
50
- # 'push' is an alias method to <<
51
- alias_method :push, :<<
52
-
53
- def insert(credithistories)
54
- is_megam_credithistories(credithistories)
55
- if @insert_after_idx
56
- # in the middle of executing a run, so any credithistories inserted now should
57
- # be placed after the most recent addition done by the currently executing
58
- # credithistories
59
- @credithistories.insert(@insert_after_idx + 1, credithistories)
60
- # update name -> location mappings and register new credithistories
61
- @credithistories_by_name.each_key do |key|
62
- @credithistories_by_name[key] += 1 if@credithistories_by_name[key] > @insert_after_idx
63
- end
64
- @credithistories_by_name[credithistories.repo_name] = @insert_after_idx + 1
65
- @insert_after_idx += 1
66
- else
67
- @credithistories << credithistories
68
- @credithistories_by_name[credithistories.repo_name] =@credithistories.length - 1
69
- end
70
- end
71
-
72
- def each
73
- @credithistories.each do |credithistories|
74
- yield credithistories
75
- end
76
- end
77
-
78
- def each_index
79
- @credithistories.each_index do |i|
80
- yield i
81
- end
82
- end
83
-
84
- def empty?
85
- @credithistories.empty?
86
- end
87
-
88
- def lookup(credithistories)
89
- lookup_by = nil
90
- if credithistories.kind_of?(Megam::Credithistories)
91
- lookup_by = credithistories.repo_name
92
- elsif credithistories.kind_of?(String)
93
- lookup_by = credithistories
94
- else
95
- raise ArgumentError, "Must pass a Megam::credithistories or String to lookup"
96
- end
97
- res =@credithistories_by_name[lookup_by]
98
- unless res
99
- raise ArgumentError, "Cannot find a credithistories matching #{lookup_by} (did you define it first?)"
100
- end
101
- @credithistories[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 |credithistories|
108
- index_hash[credithistories.repo_name] = credithistories.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 |credithistories_list|
122
- credithistories_array = credithistories_list.kind_of?(Array) ? credithistories_list : [ credithistories_list ]
123
- credithistories_array.each do |credithistories|
124
- collection.insert(credithistories)
125
- end
126
- end
127
- collection
128
- end
129
-
130
- private
131
-
132
- def is_megam_credithistories(arg)
133
- unless arg.kind_of?(Megam::Credithistories)
134
- raise ArgumentError, "Members must be Megam::Credithistories"
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,179 +0,0 @@
1
- # Copyright:: Copyright (c) 2013-2016 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
-
17
- module Megam
18
- class CSAR < Megam::ServerAPI
19
- def initialize(email=nil, api_key=nil, host=nil)
20
- @id = nil
21
- @desc = nil
22
- @link = {}
23
- @some_msg = {}
24
- @created_at = nil
25
- super(email, api_key, host)
26
- end
27
-
28
- def csar
29
- self
30
- end
31
-
32
- def id(arg=nil)
33
- if arg != nil
34
- @id = arg
35
- else
36
- @id
37
- end
38
- end
39
-
40
- def desc(arg=nil)
41
- if arg != nil
42
- @desc = arg
43
- else
44
- @desc
45
- end
46
- end
47
-
48
- def yamldata(arg=nil)
49
- if arg != nil
50
- @yamldata = arg
51
- else
52
- @yamldata
53
- end
54
- end
55
-
56
- def link(arg=nil)
57
- if arg != nil
58
- @link = arg
59
- else
60
- @link
61
- end
62
- end
63
-
64
-
65
- def created_at(arg=nil)
66
- if arg != nil
67
- @created_at = arg
68
- else
69
- @created_at
70
- end
71
- end
72
-
73
- def some_msg(arg=nil)
74
- if arg != nil
75
- @some_msg = arg
76
- else
77
- @some_msg
78
- end
79
- end
80
-
81
- def error?
82
- crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
83
- end
84
-
85
- # Transform the ruby obj -> to a Hash
86
- def to_hash
87
- index_hash = Hash.new
88
- index_hash["json_claz"] = self.class.name
89
- index_hash["id"] = id
90
- index_hash["desc"] = desc
91
- index_hash["link"] = link
92
- index_hash["some_msg"] = some_msg
93
- index_hash["created_at"] = created_at
94
- index_hash
95
- end
96
-
97
- # Serialize this object as a hash: called from JsonCompat.
98
- # Verify if this called from JsonCompat during testing.
99
- def to_json(*a)
100
- for_json.to_json(*a)
101
- end
102
-
103
- def for_json
104
- result = {
105
- "id" => id,
106
- "desc" => desc,
107
- "link" => link,
108
- "created_at" => created_at
109
- }
110
- result
111
- end
112
-
113
- def self.json_create(o)
114
- csarjslf = new
115
- csarjslf.id(o["id"]) if o.has_key?("id")
116
- csarjslf.desc(o["desc"]) if o.has_key?("desc")
117
- csarjslf.link(o["link"]) if o.has_key?("link")
118
- csarjslf.created_at(o["created_at"]) if o.has_key?("created_at")
119
-
120
- #success or error
121
- csarjslf.some_msg[:code] = o["code"] if o.has_key?("code")
122
- csarjslf.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
123
- csarjslf.some_msg[:msg]= o["msg"] if o.has_key?("msg")
124
- csarjslf.some_msg[:links] = o["links"] if o.has_key?("links")
125
-
126
- csarjslf
127
- end
128
-
129
- def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
130
- csarhslf = self.new(tmp_email, tmp_api_key, tmp_host)
131
- csarhslf.from_hash(o)
132
- csarhslf
133
- end
134
-
135
- def from_hash(o)
136
- @id = o["id"] if o.has_key?("id")
137
- @desc = o["desc"] if o.has_key?("desc")
138
- @link = o["link"] if o.has_key?("link")
139
- @yamldata = o["yamldata"] if o.has_key?("yamldata")
140
- @created_at = o["created_at"] if o.has_key?("created_at")
141
- self
142
- end
143
-
144
- #This won't work, as the body just needs the yaml string.
145
- def self.create(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
146
- csarslf = from_hash(o, tmp_email, tmp_api_key, tmp_host)
147
- csarslf.create
148
- end
149
-
150
- # Create the csar yaml
151
- #This won't work, as the body just needs the yaml string.
152
- def create
153
- megam_rest.post_csar(@yamldata)
154
- end
155
-
156
- # Load the yaml back from the link
157
- def self.show(tmp_email=nil, tmp_api_key=nil, tmp_host=nil, csarlink_name)
158
- csarslf = self.new(tmp_email, tmp_api_key, tmp_host)
159
- csarslf.megam_rest.get_csar(csarlink_name)
160
- end
161
-
162
- #list all csars (links)
163
- def self.list(tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
164
- csarslf = self.new(tmp_email, tmp_api_key, tmp_host)
165
- csarslf.megam_rest.get_csars
166
- end
167
-
168
- #push csar (links)
169
- def self.push(tmp_email=nil, tmp_api_key=nil, tmp_host=nil, csar_id)
170
- csarslf = self.new(tmp_email, tmp_api_key, tmp_host)
171
- csarslf.megam_rest.push_csar(csar_id)
172
- end
173
-
174
- def to_s
175
- Megam::Stuff.styled_hash(to_hash)
176
- end
177
-
178
- end
179
- end