megam_api 0.36 → 0.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/lib/megam/api.rb +22 -3
- data/lib/megam/api/accounts.rb +15 -1
- data/lib/megam/api/availableunits.rb +35 -0
- data/lib/megam/api/balances.rb +46 -0
- data/lib/megam/api/billinghistories.rb +35 -0
- data/lib/megam/api/billings.rb +35 -0
- data/lib/megam/api/components.rb +2 -2
- data/lib/megam/api/credithistories.rb +35 -0
- data/lib/megam/api/discounts.rb +35 -0
- data/lib/megam/api/profile.rb +42 -0
- data/lib/megam/api/subscriptions.rb +35 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/account.rb +85 -8
- data/lib/megam/core/assembly.rb +5 -9
- data/lib/megam/core/availableunits.rb +181 -0
- data/lib/megam/core/availableunits_collection.rb +144 -0
- data/lib/megam/core/balances.rb +201 -0
- data/lib/megam/core/balances_collection.rb +144 -0
- data/lib/megam/core/billinghistories.rb +206 -0
- data/lib/megam/core/billinghistories_collection.rb +144 -0
- data/lib/megam/core/billings.rb +242 -0
- data/lib/megam/core/billings_collection.rb +144 -0
- data/lib/megam/core/credithistories.rb +191 -0
- data/lib/megam/core/credithistories_collection.rb +144 -0
- data/lib/megam/core/discounts.rb +191 -0
- data/lib/megam/core/discounts_collection.rb +144 -0
- data/lib/megam/core/json_compat.rb +57 -15
- data/lib/megam/core/subscriptions.rb +191 -0
- data/lib/megam/core/subscriptions_collection.rb +144 -0
- data/megam_api.gemspec +2 -2
- data/test/test_accounts.rb +19 -0
- data/test/test_availableunits.rb +29 -0
- data/test/test_balances.rb +39 -0
- data/test/test_billinghistories.rb +31 -0
- data/test/test_billings.rb +34 -0
- data/test/test_credithistories.rb +30 -0
- data/test/test_discounts.rb +30 -0
- data/test/test_helper.rb +2 -2
- data/test/test_subscriptions.rb +30 -0
- metadata +61 -7
@@ -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 CredithistoriesCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
attr_reader :iterator
|
21
|
+
def initialize
|
22
|
+
@credithistories = Array.new
|
23
|
+
@credithistories_by_name = Hash.new
|
24
|
+
@insert_after_idx = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_credithistories
|
28
|
+
@credithistories
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](index)
|
32
|
+
@credithistories[index]
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, arg)
|
36
|
+
is_megam_credithistories(arg)
|
37
|
+
@credithistories[index] = arg
|
38
|
+
@credithistories_by_name[arg.repo_name] = index
|
39
|
+
end
|
40
|
+
|
41
|
+
def <<(*args)
|
42
|
+
args.flatten.each do |a|
|
43
|
+
is_megam_credithistories(a)
|
44
|
+
@credithistories << a
|
45
|
+
@credithistories_by_name[a.repo_name] =@credithistories.length - 1
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# 'push' is an alias method to <<
|
51
|
+
alias_method :push, :<<
|
52
|
+
|
53
|
+
def insert(credithistories)
|
54
|
+
is_megam_credithistories(credithistories)
|
55
|
+
if @insert_after_idx
|
56
|
+
# in the middle of executing a run, so any credithistories inserted now should
|
57
|
+
# be placed after the most recent addition done by the currently executing
|
58
|
+
# credithistories
|
59
|
+
@credithistories.insert(@insert_after_idx + 1, credithistories)
|
60
|
+
# update name -> location mappings and register new credithistories
|
61
|
+
@credithistories_by_name.each_key do |key|
|
62
|
+
@credithistories_by_name[key] += 1 if@credithistories_by_name[key] > @insert_after_idx
|
63
|
+
end
|
64
|
+
@credithistories_by_name[credithistories.repo_name] = @insert_after_idx + 1
|
65
|
+
@insert_after_idx += 1
|
66
|
+
else
|
67
|
+
@credithistories << credithistories
|
68
|
+
@credithistories_by_name[credithistories.repo_name] =@credithistories.length - 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def each
|
73
|
+
@credithistories.each do |credithistories|
|
74
|
+
yield credithistories
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def each_index
|
79
|
+
@credithistories.each_index do |i|
|
80
|
+
yield i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def empty?
|
85
|
+
@credithistories.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def lookup(credithistories)
|
89
|
+
lookup_by = nil
|
90
|
+
if credithistories.kind_of?(Megam::Credithistories)
|
91
|
+
lookup_by = credithistories.repo_name
|
92
|
+
elsif credithistories.kind_of?(String)
|
93
|
+
lookup_by = credithistories
|
94
|
+
else
|
95
|
+
raise ArgumentError, "Must pass a Megam::credithistories or String to lookup"
|
96
|
+
end
|
97
|
+
res =@credithistories_by_name[lookup_by]
|
98
|
+
unless res
|
99
|
+
raise ArgumentError, "Cannot find a credithistories matching #{lookup_by} (did you define it first?)"
|
100
|
+
end
|
101
|
+
@credithistories[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 |credithistories|
|
108
|
+
index_hash[credithistories.repo_name] = credithistories.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 |credithistories_list|
|
122
|
+
credithistories_array = credithistories_list.kind_of?(Array) ? credithistories_list : [ credithistories_list ]
|
123
|
+
credithistories_array.each do |credithistories|
|
124
|
+
collection.insert(credithistories)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
collection
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def is_megam_credithistories(arg)
|
133
|
+
unless arg.kind_of?(Megam::Credithistories)
|
134
|
+
raise ArgumentError, "Members must be Megam::Credithistories"
|
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
|
@@ -0,0 +1,191 @@
|
|
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 Discounts < Megam::ServerAPI
|
18
|
+
|
19
|
+
def initialize(email=nil, api_key=nil)
|
20
|
+
@id = nil
|
21
|
+
@accounts_id = nil
|
22
|
+
@bill_type = nil
|
23
|
+
@code = nil
|
24
|
+
@status = nil
|
25
|
+
@created_at = nil
|
26
|
+
@some_msg = {}
|
27
|
+
super(email, api_key)
|
28
|
+
end
|
29
|
+
|
30
|
+
def cloud_tool_setting
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def id(arg=nil)
|
36
|
+
if arg != nil
|
37
|
+
@id = arg
|
38
|
+
else
|
39
|
+
@id
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def accounts_id(arg=nil)
|
44
|
+
if arg != nil
|
45
|
+
@accounts_id= arg
|
46
|
+
else
|
47
|
+
@accounts_id
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def bill_type(arg=nil)
|
52
|
+
if arg != nil
|
53
|
+
@bill_type = arg
|
54
|
+
else
|
55
|
+
@bill_type
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def code(arg=nil)
|
60
|
+
if arg != nil
|
61
|
+
@code = arg
|
62
|
+
else
|
63
|
+
@code
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def status(arg=nil)
|
68
|
+
if arg != nil
|
69
|
+
@status = arg
|
70
|
+
else
|
71
|
+
@status
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def created_at(arg=nil)
|
76
|
+
if arg != nil
|
77
|
+
@created_at = arg
|
78
|
+
else
|
79
|
+
@created_at
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def some_msg(arg=nil)
|
84
|
+
if arg != nil
|
85
|
+
@some_msg = arg
|
86
|
+
else
|
87
|
+
@some_msg
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def error?
|
92
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
93
|
+
end
|
94
|
+
|
95
|
+
# Transform the ruby obj -> to a Hash
|
96
|
+
def to_hash
|
97
|
+
index_hash = Hash.new
|
98
|
+
index_hash["json_claz"] = self.class.name
|
99
|
+
index_hash["id"] = id
|
100
|
+
index_hash["accounts_id"] = accounts_id
|
101
|
+
index_hash["bill_type"] = bill_type
|
102
|
+
index_hash["code"] = code
|
103
|
+
index_hash["status"] = status
|
104
|
+
index_hash["created_at"] = created_at
|
105
|
+
index_hash["some_msg"] = some_msg
|
106
|
+
index_hash
|
107
|
+
end
|
108
|
+
|
109
|
+
# Serialize this object as a hash: called from JsonCompat.
|
110
|
+
# Verify if this called from JsonCompat during testing.
|
111
|
+
def to_json(*a)
|
112
|
+
for_json.to_json(*a)
|
113
|
+
end
|
114
|
+
|
115
|
+
def for_json
|
116
|
+
result = {
|
117
|
+
"id" => id,
|
118
|
+
"accounts_id" => accounts_id,
|
119
|
+
"bill_type" => bill_type,
|
120
|
+
"code" => code,
|
121
|
+
"status" => status,
|
122
|
+
"created_at" => created_at
|
123
|
+
}
|
124
|
+
result
|
125
|
+
end
|
126
|
+
|
127
|
+
#
|
128
|
+
def self.json_create(o)
|
129
|
+
cts = new
|
130
|
+
cts.id(o["id"]) if o.has_key?("id")
|
131
|
+
cts.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
|
132
|
+
cts.bill_type(o["bill_type"]) if o.has_key?("bill_type")
|
133
|
+
cts.code(o["code"]) if o.has_key?("code")
|
134
|
+
cts.status(o["status"]) if o.has_key?("status")
|
135
|
+
|
136
|
+
cts.created_at(o["created_at"]) if o.has_key?("created_at")
|
137
|
+
#success or error
|
138
|
+
cts.some_msg[:code] = o["code"] if o.has_key?("code")
|
139
|
+
cts.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
140
|
+
cts.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
141
|
+
cts.some_msg[:links] = o["links"] if o.has_key?("links")
|
142
|
+
cts
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
|
146
|
+
cts = self.new(tmp_email,tmp_api_key)
|
147
|
+
cts.from_hash(o)
|
148
|
+
cts
|
149
|
+
end
|
150
|
+
|
151
|
+
def from_hash(o)
|
152
|
+
@id = o[:id] if o.has_key?(:id)
|
153
|
+
@accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
|
154
|
+
@bill_type = o[:bill_type] if o.has_key?(:bill_type)
|
155
|
+
@code = o[:code] if o.has_key?(:code)
|
156
|
+
@status = o[:status] if o.has_key?(:status)
|
157
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
158
|
+
self
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.create(o,tmp_email=nil, tmp_api_key=nil)
|
162
|
+
acct = from_hash(o,tmp_email, tmp_api_key)
|
163
|
+
acct.create
|
164
|
+
end
|
165
|
+
|
166
|
+
# Create the discounts via the REST API
|
167
|
+
def create
|
168
|
+
megam_rest.post_discounts(to_hash)
|
169
|
+
end
|
170
|
+
|
171
|
+
# Load all discounts -
|
172
|
+
# returns a discountsCollection
|
173
|
+
# don't return self. check if the Megam::discountsCollection is returned.
|
174
|
+
def self.list(tmp_email=nil, tmp_api_key=nil)
|
175
|
+
cts = self.new(tmp_email, tmp_api_key)
|
176
|
+
cts.megam_rest.get_discounts
|
177
|
+
end
|
178
|
+
|
179
|
+
# Show a particular discounts by name,
|
180
|
+
# Megam::discounts
|
181
|
+
def self.show(p_name,tmp_email=nil, tmp_api_key=nil)
|
182
|
+
pre = self.new(tmp_email, tmp_api_key)
|
183
|
+
pre.megam_rest.get_discounts(p_name)
|
184
|
+
end
|
185
|
+
|
186
|
+
def to_s
|
187
|
+
Megam::Stuff.styled_hash(to_hash)
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
@@ -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 DiscountsCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
attr_reader :iterator
|
21
|
+
def initialize
|
22
|
+
@discounts = Array.new
|
23
|
+
@discounts_by_name = Hash.new
|
24
|
+
@insert_after_idx = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_discounts
|
28
|
+
@discounts
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](index)
|
32
|
+
@discounts[index]
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, arg)
|
36
|
+
is_megam_discounts(arg)
|
37
|
+
@discounts[index] = arg
|
38
|
+
@discounts_by_name[arg.repo_name] = index
|
39
|
+
end
|
40
|
+
|
41
|
+
def <<(*args)
|
42
|
+
args.flatten.each do |a|
|
43
|
+
is_megam_discounts(a)
|
44
|
+
@discounts << a
|
45
|
+
@discounts_by_name[a.repo_name] =@discounts.length - 1
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# 'push' is an alias method to <<
|
51
|
+
alias_method :push, :<<
|
52
|
+
|
53
|
+
def insert(discounts)
|
54
|
+
is_megam_discounts(discounts)
|
55
|
+
if @insert_after_idx
|
56
|
+
# in the middle of executing a run, so any discounts inserted now should
|
57
|
+
# be placed after the most recent addition done by the currently executing
|
58
|
+
# discounts
|
59
|
+
@discounts.insert(@insert_after_idx + 1, discounts)
|
60
|
+
# update name -> location mappings and register new discounts
|
61
|
+
@discounts_by_name.each_key do |key|
|
62
|
+
@discounts_by_name[key] += 1 if@discounts_by_name[key] > @insert_after_idx
|
63
|
+
end
|
64
|
+
@discounts_by_name[discounts.repo_name] = @insert_after_idx + 1
|
65
|
+
@insert_after_idx += 1
|
66
|
+
else
|
67
|
+
@discounts << discounts
|
68
|
+
@discounts_by_name[discounts.repo_name] =@discounts.length - 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def each
|
73
|
+
@discounts.each do |discounts|
|
74
|
+
yield discounts
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def each_index
|
79
|
+
@discounts.each_index do |i|
|
80
|
+
yield i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def empty?
|
85
|
+
@discounts.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def lookup(discounts)
|
89
|
+
lookup_by = nil
|
90
|
+
if discounts.kind_of?(Megam::Discounts)
|
91
|
+
lookup_by = discounts.repo_name
|
92
|
+
elsif discounts.kind_of?(String)
|
93
|
+
lookup_by = discounts
|
94
|
+
else
|
95
|
+
raise ArgumentError, "Must pass a Megam::discounts or String to lookup"
|
96
|
+
end
|
97
|
+
res =@discounts_by_name[lookup_by]
|
98
|
+
unless res
|
99
|
+
raise ArgumentError, "Cannot find a discounts matching #{lookup_by} (did you define it first?)"
|
100
|
+
end
|
101
|
+
@discounts[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 |discounts|
|
108
|
+
index_hash[discounts.repo_name] = discounts.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 |discounts_list|
|
122
|
+
discounts_array = discounts_list.kind_of?(Array) ? discounts_list : [ discounts_list ]
|
123
|
+
discounts_array.each do |discounts|
|
124
|
+
collection.insert(discounts)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
collection
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def is_megam_discounts(arg)
|
133
|
+
unless arg.kind_of?(Megam::Discounts)
|
134
|
+
raise ArgumentError, "Members must be Megam::discounts"
|
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
|