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
@@ -14,7 +14,7 @@
14
14
  ## limitations under the License.
15
15
  ##
16
16
  module Megam
17
- class Billedhistories < Megam::ServerAPI
17
+ class Billedhistories < Megam::RestAdapter
18
18
  def initialize(o)
19
19
  @id = nil
20
20
  @accounts_id = nil
@@ -101,19 +101,16 @@ module Megam
101
101
  @billedhistories[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 |billedhistories|
108
- index_hash[billedhistories.accounts_id] = billedhistories.to_s
109
- end
110
- index_hash
104
+ def to_s
105
+ @billedhistories.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,10 +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
-
143
135
  end
144
136
  end
@@ -15,7 +15,7 @@
15
15
  #
16
16
 
17
17
  module Megam
18
- class Components < Megam::ServerAPI
18
+ class Components < Megam::RestAdapter
19
19
  def initialize(o)
20
20
  @id = nil
21
21
  @name = nil
@@ -14,132 +14,125 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  module Megam
17
- class ComponentsCollection
18
- include Enumerable
19
-
20
- attr_reader :iterator
21
- def initialize
22
- @components = Array.new
23
- @components_by_name = Hash.new
24
- @insert_after_idx = nil
25
- end
26
-
27
- def all_components
28
- @components
29
- end
17
+ class ComponentsCollection
18
+ include Enumerable
19
+
20
+ attr_reader :iterator
21
+ def initialize
22
+ @components = Array.new
23
+ @components_by_name = Hash.new
24
+ @insert_after_idx = nil
25
+ end
30
26
 
31
- def [](index)
32
- @components[index]
33
- end
27
+ def all_components
28
+ @components
29
+ end
34
30
 
35
- def []=(index, arg)
36
- is_megam_components(arg)
37
- @components[index] = arg
38
- @components_by_name[arg.name] = index
39
- end
31
+ def [](index)
32
+ @components[index]
33
+ end
40
34
 
41
- def <<(*args)
42
- args.flatten.each do |a|
43
- is_megam_components(a)
44
- @components << a
45
- @components_by_name[a.name] = @components.length - 1
46
- end
47
- self
48
- end
35
+ def []=(index, arg)
36
+ is_megam_components(arg)
37
+ @components[index] = arg
38
+ @components_by_name[arg.name] = index
39
+ end
49
40
 
50
- # 'push' is an alias method to <<
51
- alias_method :push, :<<
52
-
53
- def insert(components)
54
- is_megam_components(components)
55
- if @insert_after_idx
56
- # in the middle of executing a run, so any nodes inserted now should
57
- # be placed after the most recent addition done by the currently executing
58
- # node
59
- @components.insert(@insert_after_idx + 1, components)
60
- # update name -> location mappings and register new node
61
- @components_by_name.each_key do |key|
62
- @components_by_name[key] += 1 if @components_by_name[key] > @insert_after_idx
41
+ def <<(*args)
42
+ args.flatten.each do |a|
43
+ is_megam_components(a)
44
+ @components << a
45
+ @components_by_name[a.name] = @components.length - 1
46
+ end
47
+ self
63
48
  end
64
- @components_by_name[components.name] = @insert_after_idx + 1
65
- @insert_after_idx += 1
66
- else
67
- @components << components
68
- @components_by_name[components.name] = @components.length - 1
69
- end
70
- end
71
49
 
72
- def each
73
- @components.each do |components|
74
- yield components
75
- end
76
- end
50
+ # 'push' is an alias method to <<
51
+ alias_method :push, :<<
52
+
53
+ def insert(components)
54
+ is_megam_components(components)
55
+ if @insert_after_idx
56
+ # in the middle of executing a run, so any nodes inserted now should
57
+ # be placed after the most recent addition done by the currently executing
58
+ # node
59
+ @components.insert(@insert_after_idx + 1, components)
60
+ # update name -> location mappings and register new node
61
+ @components_by_name.each_key do |key|
62
+ @components_by_name[key] += 1 if @components_by_name[key] > @insert_after_idx
63
+ end
64
+ @components_by_name[components.name] = @insert_after_idx + 1
65
+ @insert_after_idx += 1
66
+ else
67
+ @components << components
68
+ @components_by_name[components.name] = @components.length - 1
69
+ end
70
+ end
77
71
 
78
- def each_index
79
- @components.each_index do |i|
80
- yield i
81
- end
82
- end
72
+ def each
73
+ @components.each do |components|
74
+ yield components
75
+ end
76
+ end
83
77
 
84
- def empty?
85
- @components.empty?
86
- end
78
+ def each_index
79
+ @components.each_index do |i|
80
+ yield i
81
+ end
82
+ end
87
83
 
88
- def lookup(components)
89
- lookup_by = nil
90
- if components.kind_of?(Megam::Components)
91
- lookup_by = components.name
92
- elsif components.kind_of?(String)
93
- lookup_by = components
94
- else
95
- raise ArgumentError, "Must pass a Megam::components or String to lookup"
96
- end
97
- res = @components_by_name[lookup_by]
98
- unless res
99
- raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
100
- end
101
- @components[res]
102
- end
84
+ def empty?
85
+ @components.empty?
86
+ end
103
87
 
104
- # Transform the ruby obj -> to a Hash
105
- def to_hash
106
- index_hash = Hash.new
107
- self.each do |components|
108
- index_hash[components.name] = components.to_s
109
- end
110
- index_hash
111
- end
88
+ def lookup(components)
89
+ lookup_by = nil
90
+ if components.kind_of?(Megam::Components)
91
+ lookup_by = components.name
92
+ elsif components.kind_of?(String)
93
+ lookup_by = components
94
+ else
95
+ raise ArgumentError, "Must pass a Megam::components or String to lookup"
96
+ end
97
+ res = @components_by_name[lookup_by]
98
+ unless res
99
+ raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
100
+ end
101
+ @components[res]
102
+ end
112
103
 
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
104
+ def to_s
105
+ @components.join(", ")
106
+ end
118
107
 
119
- def self.json_create(o)
120
- collection = self.new()
121
- o["results"].each do |components_list|
122
- components_array = components_list.kind_of?(Array) ? components_list : [ components_list ]
123
- components_array.each do |components|
124
- collection.insert(components)
108
+ def for_json
109
+ to_a.map { |item| item.to_s }
110
+ end
125
111
 
112
+ def to_json(*a)
113
+ Megam::JSONCompat.to_json(for_json, *a)
126
114
  end
127
- end
128
- collection
129
- end
130
115
 
131
- private
132
116
 
133
- def is_megam_components(arg)
134
- unless arg.kind_of?(Megam::Components)
135
- raise ArgumentError, "Members must be Megam::components"
136
- end
137
- true
138
- end
117
+ def self.json_create(o)
118
+ collection = self.new()
119
+ o["results"].each do |components_list|
120
+ components_array = components_list.kind_of?(Array) ? components_list : [ components_list ]
121
+ components_array.each do |components|
122
+ collection.insert(components)
139
123
 
140
- def to_s
141
- Megam::Stuff.styled_hash(to_hash)
142
- end
124
+ end
125
+ end
126
+ collection
127
+ end
143
128
 
144
- end
129
+ private
130
+
131
+ def is_megam_components(arg)
132
+ unless arg.kind_of?(Megam::Components)
133
+ raise ArgumentError, "Members must be Megam::components"
134
+ end
135
+ true
136
+ end
137
+ end
145
138
  end
@@ -14,131 +14,124 @@
14
14
  # limitations under the License.
15
15
  #
16
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
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
26
 
27
- def all_domains
28
- @domains
29
- end
27
+ def all_domains
28
+ @domains
29
+ end
30
30
 
31
- def [](index)
32
- @domains[index]
33
- end
31
+ def [](index)
32
+ @domains[index]
33
+ end
34
34
 
35
- def []=(index, arg)
36
- is_megam_domains(arg)
37
- @domains[index] = arg
38
- @domains_by_name[arg.name] = index
39
- end
35
+ def []=(index, arg)
36
+ is_megam_domains(arg)
37
+ @domains[index] = arg
38
+ @domains_by_name[arg.name] = index
39
+ end
40
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
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
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
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
63
70
  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
71
 
72
- def each
73
- @domains.each do |domains|
74
- yield domains
75
- end
76
- end
72
+ def each
73
+ @domains.each do |domains|
74
+ yield domains
75
+ end
76
+ end
77
77
 
78
- def each_index
79
- @domains.each_index do |i|
80
- yield i
81
- end
82
- end
78
+ def each_index
79
+ @domains.each_index do |i|
80
+ yield i
81
+ end
82
+ end
83
83
 
84
- def empty?
85
- @domains.empty?
86
- end
84
+ def empty?
85
+ @domains.empty?
86
+ end
87
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
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
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
104
 
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
105
+ def to_s
106
+ @domains.join(", ")
107
+ end
118
108
 
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)
109
+ def for_json
110
+ to_a.map { |item| item.to_s }
125
111
  end
126
- end
127
- collection
128
- end
129
112
 
130
- private
113
+ def to_json(*a)
114
+ Megam::JSONCompat.to_json(for_json, *a)
115
+ end
131
116
 
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
117
+ def self.json_create(o)
118
+ collection = self.new()
119
+ o["results"].each do |domains_list|
120
+ domains_array = domains_list.kind_of?(Array) ? domains_list : [ domains_list ]
121
+ domains_array.each do |domains|
122
+ collection.insert(domains)
123
+ end
124
+ end
125
+ collection
126
+ end
138
127
 
139
- def to_s
140
- Megam::Stuff.styled_hash(to_hash)
141
- end
128
+ private
142
129
 
143
- end
130
+ def is_megam_domains(arg)
131
+ unless arg.kind_of?(Megam::Domains)
132
+ raise ArgumentError, "Members must be Megam::Domains's"
133
+ end
134
+ true
135
+ end
136
+ end
144
137
  end