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
@@ -15,7 +15,7 @@
15
15
  #
16
16
 
17
17
  module Megam
18
- class Organizations < Megam::ServerAPI
18
+ class Organizations < Megam::RestAdapter
19
19
  def initialize(o)
20
20
  @id = nil
21
21
  @name = nil
@@ -101,45 +101,18 @@ module Megam
101
101
  @organizations[res]
102
102
  end
103
103
 
104
- # Transform the ruby obj -> to a Hash
105
- def to_hash
106
- index_hash = Hash.new
107
- self.each do |organizations|
108
- index_hash[organizations.name] = organizations.to_s
109
- end
110
- index_hash
104
+ def to_s
105
+ @organizations.join(", ")
106
+ end
107
+
108
+ def for_json
109
+ to_a.map { |item| item.to_s }
111
110
  end
112
111
 
113
- # Serialize this object as a hash: called from JsonCompat.
114
- # Verify if this called from JsonCompat during testing.
115
112
  def to_json(*a)
116
- for_json.to_json(*a)
113
+ Megam::JSONCompat.to_json(for_json, *a)
117
114
  end
118
115
 
119
- =begin
120
- {
121
- "json_claz":"Megam::PredefCloudCollection",
122
- "results":[{
123
- "id":"NOD362554470640386048",
124
- "name":"ec2_rails",
125
- "account_id":"ACT362544229488001024",
126
- "json_claz":"Megam::PredefCloud",
127
- "spec":{
128
- "type_name":"sensor-type",
129
- "groups":"sens-group",
130
- "image":"sens-image",
131
- "flavor":"sens-flvr"
132
- },
133
- "access":{
134
- "ssh_key":"sens-ssh",
135
- "identity_file":"sens-identity-file",
136
- "ssh_user":"sens-sshuser"
137
- },
138
- "ideal":"",
139
- "performance":""
140
- }]
141
- }
142
- =end
143
116
  def self.json_create(o)
144
117
  collection = self.new()
145
118
  o["results"].each do |organizations_list|
@@ -159,10 +132,5 @@ module Megam
159
132
  end
160
133
  true
161
134
  end
162
-
163
- def to_s
164
- Megam::Stuff.styled_hash(to_hash)
165
- end
166
-
167
135
  end
168
- end
136
+ end
@@ -14,7 +14,7 @@
14
14
  ## limitations under the License.
15
15
  ##
16
16
  module Megam
17
- class Promos < Megam::ServerAPI
17
+ class Promos < Megam::RestAdapter
18
18
  def initialize(email=nil, api_key=nil, host=nil)
19
19
  @id = nil
20
20
  @code = nil
@@ -14,7 +14,7 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  module Megam
17
- class Request < Megam::ServerAPI
17
+ class Request < Megam::RestAdapter
18
18
  def initialize(params)
19
19
  @id = nil
20
20
  @cat_id = nil
@@ -101,21 +101,17 @@ module Megam
101
101
  @requests[res]
102
102
  end
103
103
 
104
- # Transform the ruby obj -> to a Hash
105
- def to_hash
106
- index_hash = Hash.new
107
- self.each do |request|
108
- index_hash[request.node_name] = request.to_s
109
- end
110
- index_hash
104
+ def to_s
105
+ @requests.join(", ")
111
106
  end
112
107
 
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)
108
+ def for_json
109
+ to_a.map { |item| item.to_s }
117
110
  end
118
111
 
112
+ def to_json(*a)
113
+ Megam::JSONCompat.to_json(for_json, *a)
114
+ end
119
115
 
120
116
  def self.json_create(o)
121
117
  collection = self.new()
@@ -136,10 +132,5 @@ module Megam
136
132
  end
137
133
  true
138
134
  end
139
-
140
- def to_s
141
- Megam::Stuff.styled_hash(to_hash)
142
- end
143
-
144
135
  end
145
136
  end
@@ -0,0 +1,54 @@
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 RestAdapter
18
+ attr_reader :email
19
+ attr_reader :api_key
20
+ attr_reader :host
21
+ attr_reader :password
22
+ attr_reader :org_id
23
+ attr_reader :headers
24
+
25
+
26
+ ## clean up this module later.
27
+ def initialize(o)
28
+ @email = o[:email]
29
+ @api_key = o[:api_key] || nil
30
+ @host = o[:host]
31
+ @password = o[:password] || nil
32
+ @org_id = o[:org_id]
33
+ @headers = o[:headers]
34
+ end
35
+
36
+ # Build a megam api client
37
+ #
38
+ # === Parameters
39
+ # api:: The Megam::API client
40
+ def megam_rest
41
+ options = {
42
+ :email => email,
43
+ :api_key => api_key,
44
+ :org_id => org_id,
45
+ :password => password,
46
+ :host => host
47
+ }
48
+ if headers
49
+ options[:headers] = headers
50
+ end
51
+ Megam::API.new(options)
52
+ end
53
+ end
54
+ end
@@ -15,7 +15,7 @@
15
15
  #
16
16
 
17
17
  module Megam
18
- class Sensors < Megam::ServerAPI
18
+ class Sensors < Megam::RestAdapter
19
19
  def initialize(email = nil, api_key = nil, host = nil)
20
20
  @id = nil
21
21
  @sensor_type = nil
@@ -101,19 +101,16 @@ module Megam
101
101
  @sensors[res]
102
102
  end
103
103
 
104
- # Transform the ruby obj -> to a Hash
105
- def to_hash
106
- index_hash = {}
107
- each do |sensors|
108
- index_hash[sensors.id] = sensors.to_s
109
- end
110
- index_hash
104
+ def to_s
105
+ @sensors.join(", ")
106
+ end
107
+
108
+ def for_json
109
+ to_a.map { |item| item.to_s }
111
110
  end
112
111
 
113
- # Serialize this object as a hash: called from JsonCompat.
114
- # Verify if this called from JsonCompat during testing.
115
112
  def to_json(*a)
116
- for_json.to_json(*a)
113
+ Megam::JSONCompat.to_json(for_json, *a)
117
114
  end
118
115
 
119
116
  def self.json_create(o)
@@ -135,9 +132,5 @@ module Megam
135
132
  end
136
133
  true
137
134
  end
138
-
139
- def to_s
140
- Megam::Stuff.styled_hash(to_hash)
141
- end
142
135
  end
143
136
  end
@@ -14,7 +14,7 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  module Megam
17
- class SshKey < Megam::ServerAPI
17
+ class SshKey < Megam::RestAdapter
18
18
  def initialize(o)
19
19
  @id = nil
20
20
  @name = nil
@@ -14,131 +14,124 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  module Megam
17
- class SshKeyCollection
18
- include Enumerable
19
-
20
- attr_reader :iterator
21
- def initialize
22
- @sshkeys = Array.new
23
- @sshkeys_by_name = Hash.new
24
- @insert_after_idx = nil
25
- end
17
+ class SshKeyCollection
18
+ include Enumerable
26
19
 
27
- def all_sshkeys
28
- @sshkeys
29
- end
20
+ attr_reader :iterator
30
21
 
31
- def [](index)
32
- @sshkeys[index]
33
- end
22
+ def initialize
23
+ @sshkeys = Array.new
24
+ @sshkeys_by_name = Hash.new
25
+ @insert_after_idx = nil
26
+ end
34
27
 
35
- def []=(index, arg)
36
- is_megam_sshkeys(arg)
37
- @sshkeys[index] = arg
38
- @sshkeys_by_name[arg.name] = index
39
- end
28
+ def all_sshkeys
29
+ @sshkeys
30
+ end
40
31
 
41
- def <<(*args)
42
- args.flatten.each do |a|
43
- is_megam_sshkeys(a)
44
- @sshkeys << a
45
- @sshkeys_by_name[a.name] =@sshkeys.length - 1
46
- end
47
- self
48
- end
32
+ def [](index)
33
+ @sshkeys[index]
34
+ end
49
35
 
50
- # 'push' is an alias method to <<
51
- alias_method :push, :<<
52
-
53
- def insert(sshkeys)
54
- is_megam_sshkeys(sshkeys)
55
- if @insert_after_idx
56
- # in the middle of executing a run, so any sshkeys inserted now should
57
- # be placed after the most recent addition done by the currently executing
58
- # sshkey
59
- @sshkeys.insert(@insert_after_idx + 1, sshkeys)
60
- # update name -> location mappings and register new sshkeys
61
- @sshkeys_by_name.each_key do |key|
62
- @sshkeys_by_name[key] += 1 if@sshkeys_by_name[key] > @insert_after_idx
36
+ def []=(index, arg)
37
+ is_megam_sshkeys(arg)
38
+ @sshkeys[index] = arg
39
+ @sshkeys_by_name[arg.name] = index
63
40
  end
64
- @sshkeys_by_name[sshkeys.name] = @insert_after_idx + 1
65
- @insert_after_idx += 1
66
- else
67
- @sshkeys << sshkeys
68
- @sshkeys_by_name[sshkeys.name] =@sshkeys.length - 1
69
- end
70
- end
71
41
 
72
- def each
73
- @sshkeys.each do |sshkeys|
74
- yield sshkeys
75
- end
76
- end
42
+ def <<(*args)
43
+ args.flatten.each do |a|
44
+ is_megam_sshkeys(a)
45
+ @sshkeys << a
46
+ @sshkeys_by_name[a.name] =@sshkeys.length - 1
47
+ end
48
+ self
49
+ end
77
50
 
78
- def each_index
79
- @sshkeys.each_index do |i|
80
- yield i
81
- end
82
- end
51
+ # 'push' is an alias method to <<
52
+ alias_method :push, :<<
53
+
54
+ def insert(sshkeys)
55
+ is_megam_sshkeys(sshkeys)
56
+ if @insert_after_idx
57
+ # in the middle of executing a run, so any sshkeys inserted now should
58
+ # be placed after the most recent addition done by the currently executing
59
+ # sshkey
60
+ @sshkeys.insert(@insert_after_idx + 1, sshkeys)
61
+ # update name -> location mappings and register new sshkeys
62
+ @sshkeys_by_name.each_key do |key|
63
+ @sshkeys_by_name[key] += 1 if@sshkeys_by_name[key] > @insert_after_idx
64
+ end
65
+ @sshkeys_by_name[sshkeys.name] = @insert_after_idx + 1
66
+ @insert_after_idx += 1
67
+ else
68
+ @sshkeys << sshkeys
69
+ @sshkeys_by_name[sshkeys.name] =@sshkeys.length - 1
70
+ end
71
+ end
83
72
 
84
- def empty?
85
- @sshkeys.empty?
86
- end
73
+ def each
74
+ @sshkeys.each do |sshkeys|
75
+ yield sshkeys
76
+ end
77
+ end
87
78
 
88
- def lookup(sshkeys)
89
- lookup_by = nil
90
- if sshkeys.kind_of?(Megam::SshKey)
91
- lookup_by = sshkeys.name
92
- elsif sshkeys.kind_of?(String)
93
- lookup_by = sshkeys
94
- else
95
- raise ArgumentError, "Must pass a Megam::sshkeys or String to lookup"
96
- end
97
- res =@sshkeys_by_name[lookup_by]
98
- unless res
99
- raise ArgumentError, "Cannot find a sshkeys matching #{lookup_by} (did you define it first?)"
100
- end
101
- @sshkeys[res]
102
- end
79
+ def each_index
80
+ @sshkeys.each_index do |i|
81
+ yield i
82
+ end
83
+ end
103
84
 
104
- # Transform the ruby obj -> to a Hash
105
- def to_hash
106
- index_hash = Hash.new
107
- self.each do |sshkeys|
108
- index_hash[sshkeys.name] = sshkeys.to_s
109
- end
110
- index_hash
111
- end
85
+ def empty?
86
+ @sshkeys.empty?
87
+ end
112
88
 
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
89
+ def lookup(sshkeys)
90
+ lookup_by = nil
91
+ if sshkeys.kind_of?(Megam::SshKey)
92
+ lookup_by = sshkeys.name
93
+ elsif sshkeys.kind_of?(String)
94
+ lookup_by = sshkeys
95
+ else
96
+ raise ArgumentError, "Must pass a Megam::sshkeys or String to lookup"
97
+ end
98
+ res =@sshkeys_by_name[lookup_by]
99
+ unless res
100
+ raise ArgumentError, "Cannot find a sshkeys matching #{lookup_by} (did you define it first?)"
101
+ end
102
+ @sshkeys[res]
103
+ end
118
104
 
119
- def self.json_create(o)
120
- collection = self.new()
121
- o["results"].each do |sshkeys_list|
122
- sshkeys_array = sshkeys_list.kind_of?(Array) ? sshkeys_list : [ sshkeys_list ]
123
- sshkeys_array.each do |sshkeys|
124
- collection.insert(sshkeys)
105
+ def to_s
106
+ @sshkeys.join(", ")
125
107
  end
126
- end
127
- collection
128
- end
129
108
 
130
- private
109
+ def for_json
110
+ to_a.map { |item| item.to_s }
111
+ end
131
112
 
132
- def is_megam_sshkeys(arg)
133
- unless arg.kind_of?(Megam::SshKey)
134
- raise ArgumentError, "Members must be Megam::SshKeys's"
135
- end
136
- true
137
- end
113
+ def to_json(*a)
114
+ Megam::JSONCompat.to_json(for_json, *a)
115
+ end
138
116
 
139
- def to_s
140
- Megam::Stuff.styled_hash(to_hash)
141
- end
117
+ def self.json_create(o)
118
+ collection = self.new()
119
+ o["results"].each do |sshkeys_list|
120
+ sshkeys_array = sshkeys_list.kind_of?(Array) ? sshkeys_list : [ sshkeys_list ]
121
+ sshkeys_array.each do |sshkeys|
122
+ collection.insert(sshkeys)
123
+ end
124
+ end
125
+ collection
126
+ end
142
127
 
143
- end
144
- end
128
+ private
129
+
130
+ def is_megam_sshkeys(arg)
131
+ unless arg.kind_of?(Megam::SshKey)
132
+ raise ArgumentError, "Members must be Megam::SshKeys's"
133
+ end
134
+ true
135
+ end
136
+ end
137
+ end