megam_api 1.9.3 → 1.9.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce6adf970be932086e8e2a101362b721aaf69310
4
- data.tar.gz: 4b99c76b37256f61b10e20dad43a046bd23d2419
3
+ metadata.gz: 281139fbb01534854c57f1a5daddaeb8e497cf75
4
+ data.tar.gz: 7d03b95250f307d9ea39eacc71877a1166659fc9
5
5
  SHA512:
6
- metadata.gz: a172b38cb2ef6359b34e07f69daff3f49bcd0a4a01ce75d14b96d9bff6007917006d8de5ba1798923de27ff3073a5e68127fcf562607b55c91871e2e472edbdf
7
- data.tar.gz: 9badf0404280d648813c2de7c7b3501de86d0240b5dfbcf1c467fbedecb166bf450f3749153e132039984dc2859d85dd73f8cd541c4cdfeb210c720ec21026a2
6
+ metadata.gz: 2c75e7dcd7816723eb1bb26379d31c4f9e0a16571141d2b3ff29182e3f157cf34ba47502afd92e136b6a7a18a4e44c47f374f077a866cbc791f8fbe8fbcc76a5
7
+ data.tar.gz: c4a85e3a9a228476bf3c3d02401942824d60e8a843079172aeabb0900da6bd3fd46a5bddfc819181dd1ae3e777ae83d55bf6c9add5bcc001f7ecf892386c7ec8
@@ -31,6 +31,7 @@ require 'megam/api/eventsbilling'
31
31
  require 'megam/api/eventsstorage'
32
32
  require 'megam/api/snapshots'
33
33
  require 'megam/api/reports'
34
+ require 'megam/api/quotas'
34
35
  require 'megam/api/disks'
35
36
  require 'megam/api/subscriptions'
36
37
  require 'megam/api/addons'
@@ -88,6 +89,8 @@ require 'megam/core/snapshots'
88
89
  require 'megam/core/snapshots_collection'
89
90
  require 'megam/core/reports'
90
91
  require 'megam/core/reports_collection'
92
+ require 'megam/core/quotas'
93
+ require 'megam/core/quotas_collection'
91
94
  require 'megam/core/disks'
92
95
  require 'megam/core/disks_collection'
93
96
  require 'megam/core/balances_collection'
@@ -0,0 +1,47 @@
1
+ module Megam
2
+ class API
3
+
4
+ def get_one_quota(name)
5
+ @options = { path: "/quotas/#{name}", body: '' }.merge(@options)
6
+
7
+ request(
8
+ expects: 200,
9
+ method: :get,
10
+ body: @options[:body]
11
+ )
12
+ end
13
+
14
+ def update_quotas(new_asm)
15
+ @options = { path: '/quotas/update',
16
+ body: Megam::JSONCompat.to_json(new_asm) }.merge(@options)
17
+
18
+ request(
19
+ expects: [200, 201],
20
+ method: :post,
21
+ body: @options[:body]
22
+ )
23
+ end
24
+
25
+ def list_quotas
26
+ @options = {:path => "/quotas",:body => ""}.merge(@options)
27
+
28
+ request(
29
+ :expects => 200,
30
+ :method => :get,
31
+ :body => @options[:body]
32
+ )
33
+ end
34
+
35
+ def post_reports(new_sps)
36
+ @options = {:path => '/quotas/content',
37
+ :body => Megam::JSONCompat.to_json(new_sps)}.merge(@options)
38
+
39
+ request(
40
+ :expects => 200,
41
+ :method => :post,
42
+ :body => @options[:body]
43
+ )
44
+ end
45
+
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "1.9.3"
3
+ VERSION = "1.9.4"
4
4
  end
5
5
  end
@@ -60,6 +60,8 @@ module Megam
60
60
  MEGAM_ADDONSCOLLECTION = 'Megam::AddonsCollection'.freeze
61
61
  MEGAM_REPORTS = 'Megam::Reports'.freeze
62
62
  MEGAM_REPORTSCOLLECTION = 'Megam::ReportsCollection'.freeze
63
+ MEGAM_QUOTAS = 'Megam::Quotas'.freeze
64
+ MEGAM_QUOTASCOLLECTION = 'Megam::QuotasCollection'.freeze
63
65
  MEGAM_PROMOS = 'Megam::Promos'.freeze
64
66
 
65
67
 
@@ -242,6 +244,10 @@ module Megam
242
244
  Megam::Reports
243
245
  when MEGAM_REPORTSCOLLECTION
244
246
  Megam::ReportsCollection
247
+ when MEGAM_QUOTAS
248
+ Megam::Quotas
249
+ when MEGAM_QUOTASCOLLECTION
250
+ Megam::QuotasCollection
245
251
  when MEGAM_PROMOS
246
252
  Megam::Promos
247
253
  else
@@ -0,0 +1,201 @@
1
+ module Megam
2
+ class Quotas < Megam::RestAdapter
3
+ def initialize(o)
4
+ @id = nil
5
+ @account_id = nil
6
+ @name = nil
7
+ @cost = nil
8
+ @allowed = nil
9
+ @allocated_to = nil
10
+ @inputs = []
11
+ @created_at = nil
12
+ @updated_at = nil
13
+ super(o)
14
+ end
15
+
16
+ def quotas
17
+ self
18
+ end
19
+
20
+ def id(arg = nil)
21
+ if !arg.nil?
22
+ @id = arg
23
+ else
24
+ @id
25
+ end
26
+ end
27
+
28
+ def account_id(arg=nil)
29
+ if arg != nil
30
+ @account_id = arg
31
+ else
32
+ @account_id
33
+ end
34
+ end
35
+
36
+ def name(arg = nil)
37
+ if !arg.nil?
38
+ @name = arg
39
+ else
40
+ @name
41
+ end
42
+ end
43
+
44
+ def cost(arg = nil)
45
+ if !arg.nil?
46
+ @cost = arg
47
+ else
48
+ @cost
49
+ end
50
+ end
51
+
52
+ def allowed(arg = nil)
53
+ if !arg.nil?
54
+ @allowed = arg
55
+ else
56
+ @allowed
57
+ end
58
+ end
59
+
60
+ def allocated_to(arg = nil)
61
+ if !arg.nil?
62
+ @allocated_to = arg
63
+ else
64
+ @allocated_to
65
+ end
66
+ end
67
+
68
+ def inputs(arg = [])
69
+ if arg != []
70
+ @inputs = arg
71
+ else
72
+ @inputs
73
+ end
74
+ end
75
+
76
+ def created_at(arg = nil)
77
+ if !arg.nil?
78
+ @created_at = arg
79
+ else
80
+ @created_at
81
+ end
82
+ end
83
+
84
+ def updated_at(arg = nil)
85
+ if !arg.nil?
86
+ @updated_at = arg
87
+ else
88
+ @updated_at
89
+ end
90
+ end
91
+
92
+ def error?
93
+ crocked = true if some_msg.key?(:msg_type) && some_msg[:msg_type] == 'error'
94
+ end
95
+
96
+ # Transform the ruby obj -> to a Hash
97
+ def to_hash
98
+ index_hash = {}
99
+ index_hash['json_claz'] = self.class.name
100
+ index_hash['id'] = id
101
+ index_hash["account_id"] = account_id
102
+ index_hash['name'] = name
103
+ index_hash['cost'] = cost
104
+ index_hash['allowed'] = allowed
105
+ index_hash['allocated_to'] = allocated_to
106
+ index_hash['inputs'] = inputs
107
+ index_hash['created_at'] = created_at
108
+ index_hash['updated_at'] = updated_at
109
+ index_hash
110
+ end
111
+
112
+ # Serialize this object as a hash: called from JsonCompat.
113
+ # Verify if this called from JsonCompat during testing.
114
+ def to_json(*a)
115
+ for_json.to_json(*a)
116
+ end
117
+
118
+ def for_json
119
+ result = {
120
+ 'id' => id,
121
+ 'account_id' => account_id,
122
+ 'name' => name,
123
+ 'cost' => cost,
124
+ 'allowed' => allowed,
125
+ 'allocated_to' => allocated_to,
126
+ 'inputs' => inputs,
127
+ 'created_at' => created_at,
128
+ 'updated_at' => updated_at
129
+ }
130
+
131
+ result
132
+ end
133
+
134
+ def self.json_create(o)
135
+ quo = new({})
136
+ quo.id(o['id']) if o.key?('id')
137
+ quo.account_id(o["account_id"]) if o.has_key?("account_id")
138
+ quo.name(o['name']) if o.key?('name')
139
+ quo.cost(o['cost']) if o.key?('cost')
140
+ quo.allowed(o['allowed']) if o.key?('allowed')
141
+ quo.allocated_to(o['allocated_to']) if o.key?('allocated_to') # this will be an array? can hash store array?
142
+ quo.inputs(o['inputs']) if o.key?('inputs')
143
+ quo.created_at(o['created_at']) if o.key?('created_at')
144
+ quo.updated_at(o['updated_at']) if o.key?('updated_at')
145
+ quo
146
+ end
147
+
148
+ def self.from_hash(o)
149
+ quo = new(o)
150
+ quo.from_hash(o)
151
+ quo
152
+ end
153
+
154
+ def from_hash(o)
155
+ @id = o['id'] if o.key?('id')
156
+ @account_id = o["account_id"] if o.has_key?("account_id")
157
+ @name = o['name'] if o.key?('name')
158
+ @cost = o['cost'] if o.key?('cost')
159
+ @allowed = o['allowed'] if o.key?('allowed')
160
+ @allocated_to = o['allocated_to'] if o.key?('allocated_to')
161
+ @inputs = o['inputs'] if o.key?('inputs')
162
+ @created_at = o['created_at'] if o.key?('created_at')
163
+ @updated_at = o['updated_at'] if o.key?('updated_at')
164
+ self
165
+ end
166
+
167
+
168
+ def self.show(params)
169
+ quo = new(params)
170
+ quo.megam_rest.get_one_quota(params['id'])
171
+ end
172
+
173
+ def self.update(params)
174
+ quo = from_hash(params)
175
+ quo.update
176
+ end
177
+
178
+ def self.list(params)
179
+ quo = self.new(params)
180
+ quo.megam_rest.list_quotas
181
+ end
182
+
183
+ def self.create(params)
184
+ quo = from_hash(params)
185
+ quo.create
186
+ end
187
+
188
+ def create
189
+ megam_rest.post_quotas(to_hash)
190
+ end
191
+
192
+ # Create the node via the REST API
193
+ def update
194
+ megam_rest.update_quotas(to_hash)
195
+ end
196
+
197
+ def to_s
198
+ Megam::Stuff.styled_hash(to_hash)
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,121 @@
1
+ module Megam
2
+ class QuotasCollection
3
+ include Enumerable
4
+
5
+ attr_reader :iterator
6
+ def initialize
7
+ @quotas = Array.new
8
+ @quotas_by_name = Hash.new
9
+ @insert_after_idx = nil
10
+ end
11
+
12
+ def all_quotas
13
+ @quotas
14
+ end
15
+
16
+ def [](index)
17
+ @quotas[index]
18
+ end
19
+
20
+ def []=(index, arg)
21
+ is_megam_quotas(arg)
22
+ @quotas[index] = arg
23
+ @quotas_by_name[arg.id] = index
24
+ end
25
+
26
+ def <<(*args)
27
+ args.flatten.each do |a|
28
+ is_megam_quotas(a)
29
+ @quotas << a
30
+ @quotas_by_name[a.id] = @quotas.length - 1
31
+ end
32
+ self
33
+ end
34
+
35
+ # 'push' is an alias method to <<
36
+ alias_method :push, :<<
37
+
38
+ def insert(quotas)
39
+ is_megam_quotas(quotas)
40
+ if @insert_after_idx
41
+ # in the middle of executing a run, so any nodes inserted now should
42
+ # be placed after the most recent addition done by the currently executing
43
+ # node
44
+ @quotas.insert(@insert_after_idx + 1, quotas)
45
+ # update name -> location mappings and register new node
46
+ @quotas_by_name.each_key do |key|
47
+ @quotas_by_name[key] += 1 if @quotas_by_name[key] > @insert_after_idx
48
+ end
49
+ @quotas_by_name[quotas.id] = @insert_after_idx + 1
50
+ @insert_after_idx += 1
51
+ else
52
+ @quotas << quotas
53
+ @quotas_by_name[quotas.id] = @quotas.length - 1
54
+ end
55
+ end
56
+
57
+ def each
58
+ @quotas.each do |quotas|
59
+ yield quotas
60
+ end
61
+ end
62
+
63
+ def each_index
64
+ @quotas.each_index do |i|
65
+ yield i
66
+ end
67
+ end
68
+
69
+ def empty?
70
+ @quotas.empty?
71
+ end
72
+
73
+ def lookup(quotas)
74
+ lookup_by = nil
75
+ if quotas.kind_of?(Megam::Quotas)
76
+ lookup_by = quotas.id
77
+ elsif quotas.kind_of?(String)
78
+ lookup_by = quotas
79
+ else
80
+ raise ArgumentError, "Must pass a Megam::Quotas or String to lookup"
81
+ end
82
+ res = @quotas_by_name[lookup_by]
83
+ unless res
84
+ raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
85
+ end
86
+ @quotas[res]
87
+ end
88
+
89
+ def to_s
90
+ @quotas.join(", ")
91
+ end
92
+
93
+ def for_json
94
+ to_a.map { |item| item.to_s }
95
+ end
96
+
97
+ def to_json(*a)
98
+ Megam::JSONCompat.to_json(for_json, *a)
99
+ end
100
+
101
+ def self.json_create(o)
102
+ collection = self.new()
103
+ o["results"].each do |quotas_list|
104
+ quotas_array = quotas_list.kind_of?(Array) ? quotas_list : [ quotas_list ]
105
+ quotas_array.each do |quotas|
106
+ collection.insert(quotas)
107
+ end
108
+ end
109
+ collection
110
+ end
111
+
112
+ private
113
+
114
+ def is_megam_quotas(arg)
115
+ unless arg.kind_of?(Megam::Quotas)
116
+ raise ArgumentError, "Members must be Megam::Quotas's"
117
+ end
118
+ true
119
+ end
120
+ end
121
+ end
@@ -2,6 +2,7 @@ module Megam
2
2
  class Request < Megam::RestAdapter
3
3
  def initialize(params)
4
4
  @id = nil
5
+ @account_id = nil
5
6
  @cat_id = nil
6
7
  @name = nil
7
8
  @cattype = nil
@@ -25,6 +26,14 @@ module Megam
25
26
  end
26
27
  end
27
28
 
29
+ def account_id(arg=nil)
30
+ if arg != nil
31
+ @account_id = arg
32
+ else
33
+ @account_id
34
+ end
35
+ end
36
+
28
37
  def cat_id(arg=nil)
29
38
  if arg != nil
30
39
  @cat_id = arg
@@ -91,6 +100,7 @@ module Megam
91
100
  index_hash = Hash.new
92
101
  index_hash["json_claz"] = self.class.name
93
102
  index_hash["id"] = id
103
+ index_hash["account_id"] = account_id
94
104
  index_hash["cat_id"] = cat_id
95
105
  index_hash["name"] = name
96
106
  index_hash["cattype"] = cattype
@@ -109,6 +119,7 @@ module Megam
109
119
  def for_json
110
120
  result = {
111
121
  "id" => id,
122
+ "account_id" => account_id,
112
123
  "cat_id" => cat_id,
113
124
  "name" => name,
114
125
  "cattype" => cattype,
@@ -123,6 +134,7 @@ module Megam
123
134
  def self.json_create(o)
124
135
  node = new(o)
125
136
  node.id(o["id"]) if o.has_key?("id")
137
+ node.account_id(o["account_id"]) if o.has_key?("account_id")
126
138
  node.cat_id(o["cat_id"]) if o.has_key?("cat_id")
127
139
  node.name(o["name"]) if o.has_key?("name")
128
140
  node.cattype(o["cattype"]) if o.has_key?("cattype")
@@ -145,6 +157,7 @@ module Megam
145
157
 
146
158
  def from_hash(o)
147
159
  @id = o[:id] if o.has_key?(:id)
160
+ @account_id = o[:account_id] if o.has_key?(:account_id)
148
161
  @cat_id = o[:cat_id] if o.has_key?(:cat_id)
149
162
  @name = o[:name] if o.has_key?(:name)
150
163
  @cattype = o[:cattype] if o.has_key?(:cattype)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: megam_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.3
4
+ version: 1.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajthilak, Kishorekumar Neelamegam, Ranjitha R, Vinodhini V, Rathish VBR, Rajesh
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-09 00:00:00.000000000 Z
12
+ date: 2016-12-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon
@@ -156,6 +156,7 @@ files:
156
156
  - lib/megam/api/marketplaces.rb
157
157
  - lib/megam/api/organizations.rb
158
158
  - lib/megam/api/promos.rb
159
+ - lib/megam/api/quotas.rb
159
160
  - lib/megam/api/reports.rb
160
161
  - lib/megam/api/requests.rb
161
162
  - lib/megam/api/sensors.rb
@@ -205,6 +206,8 @@ files:
205
206
  - lib/megam/core/organizations.rb
206
207
  - lib/megam/core/organizations_collection.rb
207
208
  - lib/megam/core/promos.rb
209
+ - lib/megam/core/quotas.rb
210
+ - lib/megam/core/quotas_collection.rb
208
211
  - lib/megam/core/reports.rb
209
212
  - lib/megam/core/reports_collection.rb
210
213
  - lib/megam/core/request.rb