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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/lib/megam/api.rb +18 -4
  4. data/lib/megam/api/accounts.rb +19 -4
  5. data/lib/megam/api/assemblies.rb +15 -0
  6. data/lib/megam/api/assembly.rb +15 -1
  7. data/lib/megam/api/availableunits.rb +15 -0
  8. data/lib/megam/api/balances.rb +16 -1
  9. data/lib/megam/api/billedhistories.rb +15 -0
  10. data/lib/megam/api/billings.rb +15 -0
  11. data/lib/megam/api/components.rb +15 -0
  12. data/lib/megam/api/credithistories.rb +15 -0
  13. data/lib/megam/api/csars.rb +16 -1
  14. data/lib/megam/api/discounts.rb +15 -0
  15. data/lib/megam/api/domains.rb +32 -22
  16. data/lib/megam/api/errors.rb +15 -0
  17. data/lib/megam/api/invoices.rb +15 -0
  18. data/lib/megam/api/login.rb +15 -0
  19. data/lib/megam/api/marketplaces.rb +15 -0
  20. data/lib/megam/api/organizations.rb +31 -17
  21. data/lib/megam/api/promos.rb +18 -3
  22. data/lib/megam/api/requests.rb +15 -0
  23. data/lib/megam/api/sensors.rb +15 -0
  24. data/lib/megam/api/sshkeys.rb +15 -0
  25. data/lib/megam/api/subscriptions.rb +15 -0
  26. data/lib/megam/api/version.rb +16 -1
  27. data/lib/megam/core/account.rb +1 -1
  28. data/lib/megam/core/assemblies.rb +1 -1
  29. data/lib/megam/core/assemblies_collection.rb +1 -1
  30. data/lib/megam/core/assembly.rb +1 -1
  31. data/lib/megam/core/assembly_collection.rb +1 -1
  32. data/lib/megam/core/auth.rb +1 -1
  33. data/lib/megam/core/availableunits.rb +1 -1
  34. data/lib/megam/core/availableunits_collection.rb +1 -1
  35. data/lib/megam/core/balances.rb +4 -5
  36. data/lib/megam/core/balances_collection.rb +1 -1
  37. data/lib/megam/core/billedhistories.rb +4 -5
  38. data/lib/megam/core/billedhistories_collection.rb +1 -1
  39. data/lib/megam/core/billings.rb +4 -4
  40. data/lib/megam/core/billings_collection.rb +1 -1
  41. data/lib/megam/core/components.rb +1 -1
  42. data/lib/megam/core/components_collection.rb +1 -1
  43. data/lib/megam/core/config.rb +1 -1
  44. data/lib/megam/core/credithistories.rb +1 -1
  45. data/lib/megam/core/credithistories_collection.rb +1 -1
  46. data/lib/megam/core/csar.rb +1 -1
  47. data/lib/megam/core/csar_collection.rb +1 -1
  48. data/lib/megam/core/discounts.rb +1 -1
  49. data/lib/megam/core/discounts_collection.rb +1 -1
  50. data/lib/megam/core/domain_collection.rb +144 -0
  51. data/lib/megam/core/domains.rb +76 -85
  52. data/lib/megam/core/error.rb +1 -1
  53. data/lib/megam/core/invoices.rb +1 -1
  54. data/lib/megam/core/invoices_collection.rb +1 -1
  55. data/lib/megam/core/json_compat.rb +3 -0
  56. data/lib/megam/core/konipai.rb +1 -1
  57. data/lib/megam/core/marketplace.rb +1 -1
  58. data/lib/megam/core/marketplace_collection.rb +1 -1
  59. data/lib/megam/core/organizations.rb +1 -3
  60. data/lib/megam/core/organizations_collection.rb +1 -1
  61. data/lib/megam/core/promos.rb +1 -1
  62. data/lib/megam/core/request.rb +1 -1
  63. data/lib/megam/core/request_collection.rb +1 -1
  64. data/lib/megam/core/sensors.rb +1 -1
  65. data/lib/megam/core/sensors_collection.rb +1 -1
  66. data/lib/megam/core/server_api.rb +1 -1
  67. data/lib/megam/core/sshkey.rb +1 -1
  68. data/lib/megam/core/sshkey_collection.rb +1 -1
  69. data/lib/megam/core/subscriptions.rb +1 -1
  70. data/lib/megam/core/subscriptions_collection.rb +1 -1
  71. data/lib/megam/mixins/assemblies.rb +15 -0
  72. data/lib/megam/mixins/assembly.rb +16 -0
  73. data/lib/megam/mixins/common_deployable.rb +15 -0
  74. data/lib/megam/mixins/components.rb +15 -0
  75. data/lib/megam/mixins/megam_attributes.rb +15 -0
  76. data/lib/megam/mixins/outputs.rb +15 -0
  77. data/lib/megam/mixins/policies.rb +15 -0
  78. data/lib/megam_api.rb +15 -0
  79. data/megam_api.gemspec +6 -6
  80. data/test/test_accounts.rb +46 -9
  81. data/test/test_assemblies.rb +7 -7
  82. data/test/test_assembly.rb +4 -4
  83. data/test/test_availableunits.rb +3 -4
  84. data/test/test_balances.rb +9 -10
  85. data/test/test_billedhistories.rb +4 -4
  86. data/test/test_billings.rb +1 -2
  87. data/test/test_components.rb +4 -4
  88. data/test/test_credithistories.rb +3 -4
  89. data/test/test_csars.rb +2 -1
  90. data/test/test_discounts.rb +4 -5
  91. data/test/test_domains.rb +8 -7
  92. data/test/test_invoices.rb +2 -2
  93. data/test/test_marketplaces.rb +4 -4
  94. data/test/test_organizations.rb +3 -3
  95. data/test/test_requests.rb +1 -1
  96. data/test/test_sshkeys.rb +15 -14
  97. metadata +41 -12
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2012-2013 Megam Systems.
2
+ # Copyright:: Copyright (c) 2013-2016 Megam Systems.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2014 Megam Systems
1
+ # Copyright:: Copyright (c) 2013-2016 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2014 Megam Systems
1
+ # Copyright:: Copyright (c) 2013-2016 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2014 Megam Systems
1
+ # Copyright:: Copyright (c) 2013-2016 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2014 Megam Systems
1
+ # Copyright:: Copyright (c) 2013-2016 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2014 Megam Systems
1
+ # Copyright:: Copyright (c) 2013-2016 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2014 Megam Systems
1
+ # Copyright:: Copyright (c) 2013-2016 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -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
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012-2013 Megam Systems, Inc.
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
- def initialize(email=nil, api_key=nil, host=nil)
20
- @id = nil
21
- @name = nil
22
- @created_at = nil
23
- super(email, api_key, host)
24
- end
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 created_at(arg=nil)
52
- if arg != nil
53
- @created_at = arg
54
- else
55
- @created_at
56
- end
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
- for_json.to_json(*a)
73
- end
62
+ def to_json(*a)
63
+ for_json.to_json(*a)
64
+ end
74
65
 
75
- def for_json
76
- result = {
77
- "id" => id,
78
- "name" => name,
79
- "created_at" => created_at
80
- }
81
- result
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
- dmn = new
87
- dmn.id(o["id"]) if o.has_key?("id")
88
- dmn.name(o["name"]) if o.has_key?("name")
89
- dmn.created_at(o["created_at"]) if o.has_key?("created_at")
90
- dmn
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
- dmn = self.new(o[:email], o[:api_key], o[:host])
95
- dmn.from_hash(o)
96
- dmn
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 self.create(o)
107
- dmn = from_hash(o)
108
- dmn.create
109
- end
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
- # Load a Domain by email_p
112
- def self.show(email,api_key,host=nil)
113
- dmn = self.new(email, api_key, host)
114
- dmn.megam_rest.get_domains(email)
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
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012-2013 Megam Systems, Inc.
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");
@@ -1,5 +1,5 @@
1
1
  ##
2
- ## Copyright [2013-2015] [Megam Systems]
2
+ ## Copyright 2013-2016 Megam Systems
3
3
  ##
4
4
  ## Licensed under the Apache License, Version 2.0 (the "License");
5
5
  ## you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  ##
2
- ## Copyright [2013-2015] [Megam Systems]
2
+ ## Copyright 2013-2016 Megam Systems
3
3
  ##
4
4
  ## Licensed under the Apache License, Version 2.0 (the "License");
5
5
  ## you may not use this file except in compliance with the License.
@@ -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
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2014 Megam Systems
1
+ # Copyright:: Copyright (c) 2013-2016 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2014 Megam Systems
1
+ # Copyright:: Copyright (c) 2013-2016 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2014 Megam Systems
1
+ # Copyright:: Copyright (c) 2013-2016 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");