megam_api 0.72 → 0.73
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 +4 -4
- data/lib/megam/api/{billinghistories.rb → billedhistories.rb} +7 -7
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/api.rb +3 -3
- data/lib/megam/core/{billinghistories.rb → billedhistories.rb} +6 -6
- data/lib/megam/core/billedhistories_collection.rb +144 -0
- data/lib/megam/core/json_compat.rb +6 -6
- data/megam_api.gemspec +3 -3
- data/test/{test_billinghistories.rb → test_billedhistories.rb} +7 -8
- data/test/test_helper.rb +5 -5
- metadata +12 -12
- data/lib/megam/core/billinghistories_collection.rb +0 -144
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67d28ae2a87930c4b944ae4b778696e72ce0ac7c
|
4
|
+
data.tar.gz: fa247596489d7a31251b48b8335c1fafffd95498
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4922f672dcafdb0993c93ef84e96a392dcea443eec3403d5dd4cbc72198ff78c808db5352234c238fb8ce7085d4d2bb773dc362783fb4f0697c9e4f568fe694e
|
7
|
+
data.tar.gz: 3895bfc122d83b32c1ee3ec9dbaa2948786527a8c0ff6f767313bbf9a9a2125848be2d46a7a83daabe78a5eec7562d48f85e51fc4fedf104bbbd7349de378fc7
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Megam
|
2
2
|
class API
|
3
|
-
def
|
4
|
-
@options = {:path => '/
|
3
|
+
def get_billedhistories
|
4
|
+
@options = {:path => '/billedhistories',:body => ""}.merge(@options)
|
5
5
|
|
6
6
|
request(
|
7
7
|
:expects => 200,
|
@@ -10,8 +10,8 @@ module Megam
|
|
10
10
|
)
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
@options = {:path => "/
|
13
|
+
def get_billedhistory(id)
|
14
|
+
@options = {:path => "/billedhistories/#{id}",:body => ""}.merge(@options)
|
15
15
|
|
16
16
|
request(
|
17
17
|
:expects => 200,
|
@@ -20,9 +20,9 @@ module Megam
|
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
@options = {:path => '/
|
25
|
-
:body => Megam::JSONCompat.to_json(
|
23
|
+
def post_billedhistories(new_billedhistory)
|
24
|
+
@options = {:path => '/billedhistories/content',
|
25
|
+
:body => Megam::JSONCompat.to_json(new_billedhistory)}.merge(@options)
|
26
26
|
|
27
27
|
request(
|
28
28
|
:expects => 201,
|
data/lib/megam/api/version.rb
CHANGED
data/lib/megam/api.rb
CHANGED
@@ -27,7 +27,7 @@ require 'megam/api/components'
|
|
27
27
|
require 'megam/api/event'
|
28
28
|
require 'megam/api/availableunits'
|
29
29
|
require 'megam/api/balances'
|
30
|
-
require 'megam/api/
|
30
|
+
require 'megam/api/billedhistories'
|
31
31
|
require 'megam/api/billings'
|
32
32
|
require 'megam/api/credithistories'
|
33
33
|
require 'megam/api/discounts'
|
@@ -71,8 +71,8 @@ require 'megam/core/availableunits_collection'
|
|
71
71
|
require 'megam/core/availableunits'
|
72
72
|
require 'megam/core/balances_collection'
|
73
73
|
require 'megam/core/balances'
|
74
|
-
require 'megam/core/
|
75
|
-
require 'megam/core/
|
74
|
+
require 'megam/core/billedhistories_collection'
|
75
|
+
require 'megam/core/billedhistories'
|
76
76
|
require 'megam/core/billings_collection'
|
77
77
|
require 'megam/core/billings'
|
78
78
|
require 'megam/core/credithistories_collection'
|
@@ -14,7 +14,7 @@
|
|
14
14
|
## limitations under the License.
|
15
15
|
##
|
16
16
|
module Megam
|
17
|
-
class
|
17
|
+
class Billedhistories < Megam::ServerAPI
|
18
18
|
def initialize(email=nil, api_key=nil, host=nil)
|
19
19
|
@id = nil
|
20
20
|
@accounts_id = nil
|
@@ -27,7 +27,7 @@ module Megam
|
|
27
27
|
super(email, api_key, host)
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def billedhistories
|
31
31
|
self
|
32
32
|
end
|
33
33
|
|
@@ -174,7 +174,7 @@ module Megam
|
|
174
174
|
|
175
175
|
# Create the billing histories via the REST API
|
176
176
|
def create
|
177
|
-
megam_rest.
|
177
|
+
megam_rest.post_billedhistories(to_hash)
|
178
178
|
end
|
179
179
|
|
180
180
|
# Load all billing histories -
|
@@ -182,19 +182,19 @@ module Megam
|
|
182
182
|
# don't return self. check if the Megam::BillingHistoriesCollection is returned.
|
183
183
|
def self.list(params)
|
184
184
|
billhistory = self.new(params["email"], params["api_key"], params["host"])
|
185
|
-
billhistory.megam_rest.
|
185
|
+
billhistory.megam_rest.get_billedhistories
|
186
186
|
end
|
187
187
|
|
188
188
|
# Show a particular billing history by name,
|
189
189
|
# Megam::BillingHistory
|
190
190
|
def self.show(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
191
191
|
pre = self.new(tmp_email,tmp_api_key, tmp_host)
|
192
|
-
pre.megam_rest.
|
192
|
+
pre.megam_rest.get_billedhistory(p_name)
|
193
193
|
end
|
194
194
|
|
195
195
|
def self.delete(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
196
196
|
pre = self.new(tmp_email,tmp_api_key, tmp_host)
|
197
|
-
pre.megam_rest.
|
197
|
+
pre.megam_rest.delete_billedhistory(p_name)
|
198
198
|
end
|
199
199
|
|
200
200
|
def to_s
|
@@ -0,0 +1,144 @@
|
|
1
|
+
##
|
2
|
+
## Copyright [2013-2015] [Megam Systems]
|
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 BilledhistoriesCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
attr_reader :iterator
|
21
|
+
def initialize
|
22
|
+
@billedhistories = Array.new
|
23
|
+
@billedhistories_by_name = Hash.new
|
24
|
+
@insert_after_idx = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_billedhistories
|
28
|
+
@billedhistories
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](index)
|
32
|
+
@billedhistories[index]
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, arg)
|
36
|
+
is_megam_billedhistories(arg)
|
37
|
+
@billedhistories[index] = arg
|
38
|
+
@billedhistories_by_name[arg.accounts_id] = index
|
39
|
+
end
|
40
|
+
|
41
|
+
def <<(*args)
|
42
|
+
args.flatten.each do |a|
|
43
|
+
is_megam_billedhistories(a)
|
44
|
+
@billedhistories << a
|
45
|
+
@billedhistories_by_name[a.accounts_id] =@billedhistories.length - 1
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# 'push' is an alias method to <<
|
51
|
+
alias_method :push, :<<
|
52
|
+
|
53
|
+
def insert(billedhistories)
|
54
|
+
is_megam_billedhistories(billedhistories)
|
55
|
+
if @insert_after_idx
|
56
|
+
# in the middle of executing a run, so any predefs inserted now should
|
57
|
+
# be placed after the most recent addition done by the currently executing
|
58
|
+
# billedhistories
|
59
|
+
@billedhistories.insert(@insert_after_idx + 1, billedhistories)
|
60
|
+
# update name -> location mappings and register new billedhistories
|
61
|
+
@billedhistories_by_name.each_key do |key|
|
62
|
+
@billedhistories_by_name[key] += 1 if@billedhistories_by_name[key] > @insert_after_idx
|
63
|
+
end
|
64
|
+
@billedhistories_by_name[billedhistories.accounts_id] = @insert_after_idx + 1
|
65
|
+
@insert_after_idx += 1
|
66
|
+
else
|
67
|
+
@billedhistories << billedhistories
|
68
|
+
@billedhistories_by_name[billedhistories.accounts_id] =@billedhistories.length - 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def each
|
73
|
+
@billedhistories.each do |billedhistories|
|
74
|
+
yield billedhistories
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def each_index
|
79
|
+
@billedhistories.each_index do |i|
|
80
|
+
yield i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def empty?
|
85
|
+
@billedhistories.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def lookup(billedhistories)
|
89
|
+
lookup_by = nil
|
90
|
+
if Billedhistories.kind_of?(Megam::Billedhistories)
|
91
|
+
lookup_by = billedhistories.accounts_id
|
92
|
+
elsif billedhistories.kind_of?(String)
|
93
|
+
lookup_by = billedhistories
|
94
|
+
else
|
95
|
+
raise ArgumentError, "Must pass a Megam::billedhistories or String to lookup"
|
96
|
+
end
|
97
|
+
res =@billedhistories_by_name[lookup_by]
|
98
|
+
unless res
|
99
|
+
raise ArgumentError, "Cannot find a billedhistories matching #{lookup_by} (did you define it first?)"
|
100
|
+
end
|
101
|
+
@billedhistories[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 |billedhistories|
|
108
|
+
index_hash[billedhistories.accounts_id] = billedhistories.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 |billedhistories_list|
|
122
|
+
billedhistories_array = billedhistories_list.kind_of?(Array) ? billedhistories_list : [ billedhistories_list ]
|
123
|
+
billedhistories_array.each do |billedhistories|
|
124
|
+
collection.insert(billedhistories)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
collection
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def is_megam_billedhistories(arg)
|
133
|
+
unless arg.kind_of?(Megam::Billedhistories)
|
134
|
+
raise ArgumentError, "Members must be Megam::billedhistories'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
|
@@ -32,8 +32,8 @@ module Megam
|
|
32
32
|
MEGAM_AVAILABLEUNITSCOLLECTION = "Megam::AvailableunitsCollection".freeze
|
33
33
|
MEGAM_BALANCES = "Megam::Balances".freeze
|
34
34
|
MEGAM_BALANCESCOLLECTION = "Megam::BalancesCollection".freeze
|
35
|
-
|
36
|
-
|
35
|
+
MEGAM_BILLEDHISTORIES = "Megam::Billedhistories".freeze
|
36
|
+
MEGAM_BILLEDHISTORIESCOLLECTION = "Megam::BilledhistoriesCollection".freeze
|
37
37
|
MEGAM_BILLINGS = "Megam::Billings".freeze
|
38
38
|
MEGAM_BILLINGSCOLLECTION = "Megam::BillingsCollection".freeze
|
39
39
|
MEGAM_CLOUDTOOLSETTING = "Megam::CloudToolSetting".freeze
|
@@ -194,10 +194,10 @@ module Megam
|
|
194
194
|
Megam::Balances
|
195
195
|
when MEGAM_BALANCESCOLLECTION
|
196
196
|
Megam::BalancesCollection
|
197
|
-
when
|
198
|
-
Megam::
|
199
|
-
when
|
200
|
-
Megam::
|
197
|
+
when MEGAM_BILLEDHISTORIES
|
198
|
+
Megam::Billedhistories
|
199
|
+
when MEGAM_BILLEDHISTORIESCOLLECTION
|
200
|
+
Megam::BilledhistoriesCollection
|
201
201
|
when MEGAM_BILLINGS
|
202
202
|
Megam::Billings
|
203
203
|
when MEGAM_BILLINGSCOLLECTION
|
data/megam_api.gemspec
CHANGED
@@ -16,11 +16,11 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
|
-
s.add_runtime_dependency 'excon', '~> 0.45.
|
19
|
+
s.add_runtime_dependency 'excon', '~> 0.45.4'
|
20
20
|
s.add_runtime_dependency 'highline', '~> 1.7'
|
21
21
|
s.add_runtime_dependency 'yajl-ruby', '~> 1.2'
|
22
|
-
s.add_runtime_dependency 'mixlib-config', '~> 2.
|
22
|
+
s.add_runtime_dependency 'mixlib-config', '~> 2.2'
|
23
23
|
s.add_runtime_dependency 'mixlib-log', '~> 1.6'
|
24
|
-
s.add_development_dependency 'minitest', '~> 5.
|
24
|
+
s.add_development_dependency 'minitest', '~> 5.8'
|
25
25
|
s.add_development_dependency 'rake', '~> 10.4'
|
26
26
|
end
|
@@ -2,30 +2,29 @@ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
|
2
2
|
|
3
3
|
class TestApps < MiniTest::Unit::TestCase
|
4
4
|
#=begin
|
5
|
-
def
|
6
|
-
tmp_hash = { :accounts_id => "
|
5
|
+
def test_post_billedhistories
|
6
|
+
tmp_hash = { :accounts_id => "ACT1262792663065821184",
|
7
7
|
:assembly_id => "ASM89687",
|
8
8
|
:bill_type => "paypal",
|
9
9
|
:billing_amount => "45",
|
10
10
|
:currency_type => "USD"
|
11
11
|
}
|
12
12
|
|
13
|
-
response = megams.
|
13
|
+
response = megams.post_billedhistories(tmp_hash)
|
14
14
|
assert_equal(201, response.status)
|
15
15
|
end
|
16
16
|
#=end
|
17
17
|
|
18
18
|
=begin
|
19
|
-
def
|
20
|
-
response = megams.
|
19
|
+
def test_get_billedhistories
|
20
|
+
response = megams.get_billedhistories
|
21
21
|
assert_equal(200, response.status)
|
22
22
|
end
|
23
23
|
=end
|
24
24
|
=begin
|
25
|
-
def
|
26
|
-
response = megams.
|
25
|
+
def test_get_billedhistories
|
26
|
+
response = megams.get_billedhistory("iaas_default")
|
27
27
|
assert_equal(200, response.status)
|
28
28
|
end
|
29
29
|
=end
|
30
30
|
end
|
31
|
-
|
data/test/test_helper.rb
CHANGED
@@ -21,8 +21,8 @@ end
|
|
21
21
|
|
22
22
|
def megams_new(options={})
|
23
23
|
s_options = SANDBOX_HOST_OPTIONS.merge({
|
24
|
-
:email => "
|
25
|
-
:api_key => "
|
24
|
+
:email => "rr@e.com",
|
25
|
+
:api_key => "7DDsX3Nw6tFkOMHAM1Es8w=="
|
26
26
|
})
|
27
27
|
options = s_options.merge(options)
|
28
28
|
mg=Megam::API.new(options)
|
@@ -61,7 +61,7 @@ def random_email
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def domain_name
|
64
|
-
"
|
64
|
+
"megambox.com"
|
65
65
|
end
|
66
66
|
|
67
67
|
def sandbox_name
|
@@ -69,11 +69,11 @@ def sandbox_name
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def sandbox_apikey
|
72
|
-
"
|
72
|
+
"7DDsX3Nw6tFkOMHAM1Es8w==" #{}"IamAtlas{74}NobdyCanSedfefdeME#07"
|
73
73
|
end
|
74
74
|
|
75
75
|
def sandbox_email
|
76
76
|
# "darth@vader.com"
|
77
77
|
#"coolvader@iamswag.com"
|
78
|
-
"
|
78
|
+
"rr@e.com"
|
79
79
|
end
|
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: '0.
|
4
|
+
version: '0.73'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajthilak, Kishorekumar Neelamegam, Thomas Alrin, Yeshwanth Kumar, Subash Sethurajan,
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.45.
|
20
|
+
version: 0.45.4
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.45.
|
27
|
+
version: 0.45.4
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: highline
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,14 +59,14 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '2.
|
62
|
+
version: '2.2'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '2.
|
69
|
+
version: '2.2'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: mixlib-log
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,14 +87,14 @@ dependencies:
|
|
87
87
|
requirements:
|
88
88
|
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: '5.
|
90
|
+
version: '5.8'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
95
|
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: '5.
|
97
|
+
version: '5.8'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: rake
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,7 +137,7 @@ files:
|
|
137
137
|
- lib/megam/api/assembly.rb
|
138
138
|
- lib/megam/api/availableunits.rb
|
139
139
|
- lib/megam/api/balances.rb
|
140
|
-
- lib/megam/api/
|
140
|
+
- lib/megam/api/billedhistories.rb
|
141
141
|
- lib/megam/api/billings.rb
|
142
142
|
- lib/megam/api/components.rb
|
143
143
|
- lib/megam/api/credithistories.rb
|
@@ -165,8 +165,8 @@ files:
|
|
165
165
|
- lib/megam/core/availableunits_collection.rb
|
166
166
|
- lib/megam/core/balances.rb
|
167
167
|
- lib/megam/core/balances_collection.rb
|
168
|
-
- lib/megam/core/
|
169
|
-
- lib/megam/core/
|
168
|
+
- lib/megam/core/billedhistories.rb
|
169
|
+
- lib/megam/core/billedhistories_collection.rb
|
170
170
|
- lib/megam/core/billings.rb
|
171
171
|
- lib/megam/core/billings_collection.rb
|
172
172
|
- lib/megam/core/components.rb
|
@@ -209,7 +209,7 @@ files:
|
|
209
209
|
- test/test_assembly.rb
|
210
210
|
- test/test_availableunits.rb
|
211
211
|
- test/test_balances.rb
|
212
|
-
- test/
|
212
|
+
- test/test_billedhistories.rb
|
213
213
|
- test/test_billings.rb
|
214
214
|
- test/test_cat_requests.rb
|
215
215
|
- test/test_components.rb
|
@@ -259,7 +259,7 @@ test_files:
|
|
259
259
|
- test/test_assembly.rb
|
260
260
|
- test/test_availableunits.rb
|
261
261
|
- test/test_balances.rb
|
262
|
-
- test/
|
262
|
+
- test/test_billedhistories.rb
|
263
263
|
- test/test_billings.rb
|
264
264
|
- test/test_cat_requests.rb
|
265
265
|
- test/test_components.rb
|
@@ -1,144 +0,0 @@
|
|
1
|
-
##
|
2
|
-
## Copyright [2013-2015] [Megam Systems]
|
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 BillinghistoriesCollection
|
18
|
-
include Enumerable
|
19
|
-
|
20
|
-
attr_reader :iterator
|
21
|
-
def initialize
|
22
|
-
@billinghistories = Array.new
|
23
|
-
@billinghistories_by_name = Hash.new
|
24
|
-
@insert_after_idx = nil
|
25
|
-
end
|
26
|
-
|
27
|
-
def all_billinghistories
|
28
|
-
@billinghistories
|
29
|
-
end
|
30
|
-
|
31
|
-
def [](index)
|
32
|
-
@billinghistories[index]
|
33
|
-
end
|
34
|
-
|
35
|
-
def []=(index, arg)
|
36
|
-
is_megam_billinghistories(arg)
|
37
|
-
@billinghistories[index] = arg
|
38
|
-
@billinghistories_by_name[arg.accounts_id] = index
|
39
|
-
end
|
40
|
-
|
41
|
-
def <<(*args)
|
42
|
-
args.flatten.each do |a|
|
43
|
-
is_megam_billinghistories(a)
|
44
|
-
@billinghistories << a
|
45
|
-
@billinghistories_by_name[a.accounts_id] =@billinghistories.length - 1
|
46
|
-
end
|
47
|
-
self
|
48
|
-
end
|
49
|
-
|
50
|
-
# 'push' is an alias method to <<
|
51
|
-
alias_method :push, :<<
|
52
|
-
|
53
|
-
def insert(billinghistories)
|
54
|
-
is_megam_billinghistories(billinghistories)
|
55
|
-
if @insert_after_idx
|
56
|
-
# in the middle of executing a run, so any predefs inserted now should
|
57
|
-
# be placed after the most recent addition done by the currently executing
|
58
|
-
# billinghistories
|
59
|
-
@billinghistories.insert(@insert_after_idx + 1, billinghistories)
|
60
|
-
# update name -> location mappings and register new billinghistories
|
61
|
-
@billinghistories_by_name.each_key do |key|
|
62
|
-
@billinghistories_by_name[key] += 1 if@billinghistories_by_name[key] > @insert_after_idx
|
63
|
-
end
|
64
|
-
@billinghistories_by_name[billinghistories.accounts_id] = @insert_after_idx + 1
|
65
|
-
@insert_after_idx += 1
|
66
|
-
else
|
67
|
-
@billinghistories << billinghistories
|
68
|
-
@billinghistories_by_name[billinghistories.accounts_id] =@billinghistories.length - 1
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def each
|
73
|
-
@billinghistories.each do |billinghistories|
|
74
|
-
yield billinghistories
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def each_index
|
79
|
-
@billinghistories.each_index do |i|
|
80
|
-
yield i
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def empty?
|
85
|
-
@billinghistories.empty?
|
86
|
-
end
|
87
|
-
|
88
|
-
def lookup(billinghistories)
|
89
|
-
lookup_by = nil
|
90
|
-
if billinghistories.kind_of?(Megam::Billinghistories)
|
91
|
-
lookup_by = billinghistories.accounts_id
|
92
|
-
elsif billinghistories.kind_of?(String)
|
93
|
-
lookup_by = billinghistories
|
94
|
-
else
|
95
|
-
raise ArgumentError, "Must pass a Megam::billinghistories or String to lookup"
|
96
|
-
end
|
97
|
-
res =@billinghistories_by_name[lookup_by]
|
98
|
-
unless res
|
99
|
-
raise ArgumentError, "Cannot find a billinghistories matching #{lookup_by} (did you define it first?)"
|
100
|
-
end
|
101
|
-
@billinghistories[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 |billinghistories|
|
108
|
-
index_hash[billinghistories.accounts_id] = billinghistories.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 |billinghistories_list|
|
122
|
-
billinghistories_array = billinghistories_list.kind_of?(Array) ? billinghistories_list : [ billinghistories_list ]
|
123
|
-
billinghistories_array.each do |billinghistories|
|
124
|
-
collection.insert(billinghistories)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
collection
|
128
|
-
end
|
129
|
-
|
130
|
-
private
|
131
|
-
|
132
|
-
def is_megam_billinghistories(arg)
|
133
|
-
unless arg.kind_of?(Megam::Billinghistories)
|
134
|
-
raise ArgumentError, "Members must be Megam::billinghistories'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
|