megam_api 0.100 → 1.5.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -69
- data/lib/megam/api.rb +15 -37
- data/lib/megam/api/errors.rb +19 -19
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/account.rb +1 -1
- data/lib/megam/core/assemblies.rb +1 -1
- data/lib/megam/core/assemblies_collection.rb +7 -15
- data/lib/megam/core/assembly.rb +1 -1
- data/lib/megam/core/assembly_collection.rb +7 -15
- data/lib/megam/core/balances.rb +1 -1
- data/lib/megam/core/balances_collection.rb +8 -16
- data/lib/megam/core/billedhistories.rb +1 -1
- data/lib/megam/core/billedhistories_collection.rb +7 -15
- data/lib/megam/core/components.rb +1 -1
- data/lib/megam/core/components_collection.rb +103 -110
- data/lib/megam/core/domain_collection.rb +102 -109
- data/lib/megam/core/domains.rb +1 -1
- data/lib/megam/core/error.rb +1 -15
- data/lib/megam/core/json_compat.rb +170 -208
- data/lib/megam/core/marketplace.rb +1 -1
- data/lib/megam/core/marketplace_collection.rb +7 -16
- data/lib/megam/core/organizations.rb +1 -1
- data/lib/megam/core/organizations_collection.rb +8 -40
- data/lib/megam/core/promos.rb +1 -1
- data/lib/megam/core/request.rb +1 -1
- data/lib/megam/core/request_collection.rb +7 -16
- data/lib/megam/core/rest_adapter.rb +54 -0
- data/lib/megam/core/sensors.rb +1 -1
- data/lib/megam/core/sensors_collection.rb +7 -14
- data/lib/megam/core/sshkey.rb +1 -1
- data/lib/megam/core/sshkey_collection.rb +103 -110
- data/lib/megam/core/stuff.rb +2 -34
- data/lib/megam/core/text.rb +1 -0
- data/lib/megam/core/text_formatter.rb +2 -1
- data/megam_api.gemspec +2 -2
- metadata +10 -56
- data/lib/megam/api/availableunits.rb +0 -50
- data/lib/megam/api/billings.rb +0 -50
- data/lib/megam/api/credithistories.rb +0 -50
- data/lib/megam/api/csars.rb +0 -75
- data/lib/megam/api/discounts.rb +0 -50
- data/lib/megam/api/invoices.rb +0 -50
- data/lib/megam/api/login.rb +0 -29
- data/lib/megam/api/subscriptions.rb +0 -50
- data/lib/megam/core/auth.rb +0 -91
- data/lib/megam/core/availableunits.rb +0 -182
- data/lib/megam/core/availableunits_collection.rb +0 -144
- data/lib/megam/core/billings.rb +0 -242
- data/lib/megam/core/billings_collection.rb +0 -144
- data/lib/megam/core/config.rb +0 -41
- data/lib/megam/core/credithistories.rb +0 -191
- data/lib/megam/core/credithistories_collection.rb +0 -144
- data/lib/megam/core/csar.rb +0 -179
- data/lib/megam/core/csar_collection.rb +0 -148
- data/lib/megam/core/discounts.rb +0 -204
- data/lib/megam/core/discounts_collection.rb +0 -164
- data/lib/megam/core/invoices.rb +0 -231
- data/lib/megam/core/invoices_collection.rb +0 -144
- data/lib/megam/core/server_api.rb +0 -52
- data/lib/megam/core/subscriptions.rb +0 -191
- data/lib/megam/core/subscriptions_collection.rb +0 -144
- data/test/test_availableunits.rb +0 -28
- data/test/test_billings.rb +0 -33
- data/test/test_cat_requests.rb +0 -20
- data/test/test_credithistories.rb +0 -29
- data/test/test_csars.rb +0 -22
- data/test/test_discounts.rb +0 -31
- data/test/test_invoices.rb +0 -31
- data/test/test_login.rb +0 -10
- data/test/test_marketplaceaddons.rb +0 -46
- data/test/test_predefclouds.rb +0 -80
- data/test/test_subscriptions.rb +0 -29
data/lib/megam/core/invoices.rb
DELETED
@@ -1,231 +0,0 @@
|
|
1
|
-
##
|
2
|
-
## Copyright 2013-2016 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 Invoices < Megam::ServerAPI
|
18
|
-
def initialize(email=nil, api_key=nil, host=nil)
|
19
|
-
@id = nil
|
20
|
-
@accounts_id = nil
|
21
|
-
@from_date = nil
|
22
|
-
@to_date = nil
|
23
|
-
@month = nil
|
24
|
-
@bill_type = nil
|
25
|
-
@billing_amount = nil
|
26
|
-
@currency_type = nil
|
27
|
-
@created_at = nil
|
28
|
-
@some_msg = {}
|
29
|
-
super(email, api_key, host)
|
30
|
-
end
|
31
|
-
|
32
|
-
def invoices
|
33
|
-
self
|
34
|
-
end
|
35
|
-
|
36
|
-
def id(arg=nil)
|
37
|
-
if arg != nil
|
38
|
-
@id = arg
|
39
|
-
else
|
40
|
-
@id
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def accounts_id(arg=nil)
|
45
|
-
if arg != nil
|
46
|
-
@accounts_id= arg
|
47
|
-
else
|
48
|
-
@accounts_id
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def from_date(arg=nil)
|
53
|
-
if arg != nil
|
54
|
-
@from_date = arg
|
55
|
-
else
|
56
|
-
@from_date
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def to_date(arg=nil)
|
61
|
-
if arg != nil
|
62
|
-
@to_date = arg
|
63
|
-
else
|
64
|
-
@to_date
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def month(arg=nil)
|
69
|
-
if arg != nil
|
70
|
-
@month =arg
|
71
|
-
else
|
72
|
-
@month
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def bill_type(arg=nil)
|
77
|
-
if arg != nil
|
78
|
-
@bill_type = arg
|
79
|
-
else
|
80
|
-
@bill_type
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def billing_amount(arg=nil)
|
85
|
-
if arg != nil
|
86
|
-
@billing_amount= arg
|
87
|
-
else
|
88
|
-
@billing_amount
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def currency_type(arg=nil)
|
93
|
-
if arg != nil
|
94
|
-
@currency_type = arg
|
95
|
-
else
|
96
|
-
@currency_type
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def created_at(arg=nil)
|
101
|
-
if arg != nil
|
102
|
-
@created_at = arg
|
103
|
-
else
|
104
|
-
@created_at
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def some_msg(arg=nil)
|
109
|
-
if arg != nil
|
110
|
-
@some_msg = arg
|
111
|
-
else
|
112
|
-
@some_msg
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def error?
|
117
|
-
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
118
|
-
end
|
119
|
-
|
120
|
-
# Transform the ruby obj -> to a Hash
|
121
|
-
def to_hash
|
122
|
-
index_hash = Hash.new
|
123
|
-
index_hash["json_claz"] = self.class.name
|
124
|
-
index_hash["id"] = id
|
125
|
-
index_hash["accounts_id"] = accounts_id
|
126
|
-
index_hash["from_date"] = from_date
|
127
|
-
index_hash["to_date"] = to_date
|
128
|
-
index_hash["month"] = month
|
129
|
-
index_hash["bill_type"] = bill_type
|
130
|
-
index_hash["billing_amount"] = billing_amount
|
131
|
-
index_hash["currency_type"] = currency_type
|
132
|
-
index_hash["created_at"] = created_at
|
133
|
-
index_hash
|
134
|
-
end
|
135
|
-
|
136
|
-
# Serialize this object as a hash: called from JsonCompat.
|
137
|
-
# Verify if this called from JsonCompat during testing.
|
138
|
-
def to_json(*a)
|
139
|
-
for_json.to_json(*a)
|
140
|
-
end
|
141
|
-
|
142
|
-
def for_json
|
143
|
-
result = {
|
144
|
-
"id" => id,
|
145
|
-
"accounts_id" => accounts_id,
|
146
|
-
"from_date" => from_date,
|
147
|
-
"to_date" => to_date,
|
148
|
-
"month" => month,
|
149
|
-
"bill_type" => bill_type,
|
150
|
-
"billing_amount" => billing_amount,
|
151
|
-
"currency_type" => currency_type,
|
152
|
-
"created_at" => created_at
|
153
|
-
}
|
154
|
-
result
|
155
|
-
end
|
156
|
-
|
157
|
-
#
|
158
|
-
def self.json_create(o)
|
159
|
-
bal = new
|
160
|
-
bal.id(o["id"]) if o.has_key?("id")
|
161
|
-
bal.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
|
162
|
-
bal.from_date(o["from_date"]) if o.has_key?("from_date")
|
163
|
-
bal.to_date(o["to_date"]) if o.has_key?("to_date")
|
164
|
-
bal.month(o["month"]) if o.has_key?("month")
|
165
|
-
bal.bill_type(o["bill_type"]) if o.has_key?("bill_type")
|
166
|
-
bal.billing_amount(o["billing_amount"]) if o.has_key?("billing_amount")
|
167
|
-
bal.currency_type(o["currency_type"]) if o.has_key?("currency_type")
|
168
|
-
bal.created_at(o["created_at"]) if o.has_key?("created_at")
|
169
|
-
#success or error
|
170
|
-
bal.some_msg[:code] = o["code"] if o.has_key?("code")
|
171
|
-
bal.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
172
|
-
bal.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
173
|
-
bal.some_msg[:links] = o["links"] if o.has_key?("links")
|
174
|
-
bal
|
175
|
-
end
|
176
|
-
|
177
|
-
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
178
|
-
bal = self.new(tmp_email, tmp_api_key, tmp_host)
|
179
|
-
bal.from_hash(o)
|
180
|
-
bal
|
181
|
-
end
|
182
|
-
|
183
|
-
def from_hash(o)
|
184
|
-
@id = o[:id] if o.has_key?(:id)
|
185
|
-
@accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
|
186
|
-
@from_date = o[:from_date] if o.has_key?(:from_date)
|
187
|
-
@to_date = o[:to_date] if o.has_key?(:to_date)
|
188
|
-
@month = o[:month] if o.has_key?(:month)
|
189
|
-
@bill_type = o[:bill_type] if o.has_key?(:bill_type)
|
190
|
-
@billing_amount = o[:billing_amount] if o.has_key?(:billing_amount)
|
191
|
-
@currency_type = o[:currency_type] if o.has_key?(:currency_type)
|
192
|
-
@created_at = o[:created_at] if o.has_key?(:created_at)
|
193
|
-
self
|
194
|
-
end
|
195
|
-
|
196
|
-
def self.create(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
197
|
-
acct = from_hash(o,tmp_email, tmp_api_key, tmp_host)
|
198
|
-
acct.create
|
199
|
-
end
|
200
|
-
|
201
|
-
# Create the invoices via the REST API
|
202
|
-
def create
|
203
|
-
megam_rest.post_invoices(to_hash)
|
204
|
-
end
|
205
|
-
|
206
|
-
# Load all billing histories -
|
207
|
-
# returns a BillingHistoriesCollection
|
208
|
-
# don't return self. check if the Megam::BillingHistoriesCollection is returned.
|
209
|
-
def self.list(params)
|
210
|
-
invoices = self.new(params["email"], params["api_key"], params["host"])
|
211
|
-
invoices.megam_rest.get_invoices
|
212
|
-
end
|
213
|
-
|
214
|
-
# Show a particular billing history by name,
|
215
|
-
# Megam::BillingHistory
|
216
|
-
def self.show(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
217
|
-
pre = self.new(tmp_email,tmp_api_key, tmp_host)
|
218
|
-
pre.megam_rest.get_invoice(p_name)
|
219
|
-
end
|
220
|
-
|
221
|
-
def self.delete(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
222
|
-
pre = self.new(tmp_email,tmp_api_key, tmp_host)
|
223
|
-
pre.megam_rest.delete_invoice(p_name)
|
224
|
-
end
|
225
|
-
|
226
|
-
def to_s
|
227
|
-
Megam::Stuff.styled_hash(to_hash)
|
228
|
-
end
|
229
|
-
|
230
|
-
end
|
231
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
##
|
2
|
-
## Copyright 2013-2016 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 InvoicesCollection
|
18
|
-
include Enumerable
|
19
|
-
|
20
|
-
attr_reader :iterator
|
21
|
-
def initialize
|
22
|
-
@invoices = Array.new
|
23
|
-
@invoices_by_name = Hash.new
|
24
|
-
@insert_after_idx = nil
|
25
|
-
end
|
26
|
-
|
27
|
-
def all_invoices
|
28
|
-
@invoices
|
29
|
-
end
|
30
|
-
|
31
|
-
def [](index)
|
32
|
-
@invoices[index]
|
33
|
-
end
|
34
|
-
|
35
|
-
def []=(index, arg)
|
36
|
-
is_megam_invoices(arg)
|
37
|
-
@invoices[index] = arg
|
38
|
-
@invoices_by_name[arg.accounts_id] = index
|
39
|
-
end
|
40
|
-
|
41
|
-
def <<(*args)
|
42
|
-
args.flatten.each do |a|
|
43
|
-
is_megam_invoices(a)
|
44
|
-
@invoices << a
|
45
|
-
@invoices_by_name[a.accounts_id] =@invoices.length - 1
|
46
|
-
end
|
47
|
-
self
|
48
|
-
end
|
49
|
-
|
50
|
-
# 'push' is an alias method to <<
|
51
|
-
alias_method :push, :<<
|
52
|
-
|
53
|
-
def insert(invoices)
|
54
|
-
is_megam_invoices(invoices)
|
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
|
-
# invoices
|
59
|
-
@invoices.insert(@insert_after_idx + 1, invoices)
|
60
|
-
# update name -> location mappings and register new invoices
|
61
|
-
@invoices_by_name.each_key do |key|
|
62
|
-
@invoices_by_name[key] += 1 if@invoices_by_name[key] > @insert_after_idx
|
63
|
-
end
|
64
|
-
@invoices_by_name[invoices.accounts_id] = @insert_after_idx + 1
|
65
|
-
@insert_after_idx += 1
|
66
|
-
else
|
67
|
-
@invoices << invoices
|
68
|
-
@invoices_by_name[invoices.accounts_id] =@invoices.length - 1
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def each
|
73
|
-
@invoices.each do |invoices|
|
74
|
-
yield invoices
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def each_index
|
79
|
-
@invoices.each_index do |i|
|
80
|
-
yield i
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def empty?
|
85
|
-
@invoices.empty?
|
86
|
-
end
|
87
|
-
|
88
|
-
def lookup(invoices)
|
89
|
-
lookup_by = nil
|
90
|
-
if invoices.kind_of?(Megam::invoices)
|
91
|
-
lookup_by = invoices.accounts_id
|
92
|
-
elsif invoices.kind_of?(String)
|
93
|
-
lookup_by = invoices
|
94
|
-
else
|
95
|
-
raise ArgumentError, "Must pass a Megam::invoices or String to lookup"
|
96
|
-
end
|
97
|
-
res =@invoices_by_name[lookup_by]
|
98
|
-
unless res
|
99
|
-
raise ArgumentError, "Cannot find a invoices matching #{lookup_by} (did you define it first?)"
|
100
|
-
end
|
101
|
-
@invoices[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 |invoices|
|
108
|
-
index_hash[invoices.accounts_id] = invoices.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 |invoices_list|
|
122
|
-
invoices_array = invoices_list.kind_of?(Array) ? invoices_list : [ invoices_list ]
|
123
|
-
invoices_array.each do |invoices|
|
124
|
-
collection.insert(invoices)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
collection
|
128
|
-
end
|
129
|
-
|
130
|
-
private
|
131
|
-
|
132
|
-
def is_megam_invoices(arg)
|
133
|
-
unless arg.kind_of?(Megam::Invoices)
|
134
|
-
raise ArgumentError, "Members must be Megam::invoices'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,52 +0,0 @@
|
|
1
|
-
# Copyright:: Copyright (c) 2013-2016 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
|
-
|
17
|
-
module Megam
|
18
|
-
# Basic HTTP client, with support for adding features via middleware
|
19
|
-
class ServerAPI
|
20
|
-
|
21
|
-
|
22
|
-
attr_reader :email
|
23
|
-
attr_reader :api_key
|
24
|
-
attr_reader :host
|
25
|
-
attr_reader :password
|
26
|
-
attr_reader :org_id
|
27
|
-
|
28
|
-
# Create a Megam REST object. The supplied email and api_key is used as the base for
|
29
|
-
# all subsequent requests. For example, when initialized with an email, api_key url
|
30
|
-
# https://api.megam.io, a call to +get+ with 'accounts' will make an
|
31
|
-
# HTTP GET request to https://api.megam.io/accounts using the email, api_key
|
32
|
-
def initialize(o)
|
33
|
-
@email = o[:email]
|
34
|
-
@api_key = o[:api_key] || nil
|
35
|
-
@host = o[:host]
|
36
|
-
@password = o[:password] || nil
|
37
|
-
@org_id = o[:org_id]
|
38
|
-
end
|
39
|
-
|
40
|
-
# Build a megam api client
|
41
|
-
#
|
42
|
-
# === Parameters
|
43
|
-
# api:: The Megam::API client
|
44
|
-
def megam_rest
|
45
|
-
options = { :email => email || Megam::Config[:email], :api_key => api_key || Megam::Config[:api_key], :org_id => org_id || Megam::Config[:org_id], :password => password || Megam::Config[:password], :host => host || Megam::Config[:host]}
|
46
|
-
Megam::API.new(options)
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
@@ -1,191 +0,0 @@
|
|
1
|
-
# Copyright:: Copyright (c) 2013-2016 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 Subscriptions < Megam::ServerAPI
|
18
|
-
|
19
|
-
def initialize(email=nil, api_key=nil, host=nil)
|
20
|
-
@id = nil
|
21
|
-
@accounts_id = nil
|
22
|
-
@assembly_id = nil
|
23
|
-
@start_date = nil
|
24
|
-
@end_date = nil
|
25
|
-
@created_at = nil
|
26
|
-
@some_msg = {}
|
27
|
-
super(email, api_key, host)
|
28
|
-
end
|
29
|
-
|
30
|
-
def subscriptions
|
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 assembly_id(arg=nil)
|
52
|
-
if arg != nil
|
53
|
-
@assembly_id = arg
|
54
|
-
else
|
55
|
-
@assembly_id
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def start_date(arg=nil)
|
60
|
-
if arg != nil
|
61
|
-
@start_date = arg
|
62
|
-
else
|
63
|
-
@start_date
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def end_date(arg=nil)
|
68
|
-
if arg != nil
|
69
|
-
@end_date = arg
|
70
|
-
else
|
71
|
-
@end_date
|
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["assembly_id"] = assembly_id
|
102
|
-
index_hash["start_date"] = start_date
|
103
|
-
index_hash["end_date"] = end_date
|
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
|
-
"assembly_id" => assembly_id,
|
120
|
-
"start_date" => start_date,
|
121
|
-
"end_date" => end_date,
|
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.assembly_id(o["assembly_id"]) if o.has_key?("assembly_id")
|
133
|
-
cts.start_date(o["start_date"]) if o.has_key?("start_date")
|
134
|
-
cts.end_date(o["end_date"]) if o.has_key?("end_date")
|
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, tmp_host=nil)
|
146
|
-
cts = self.new(tmp_email,tmp_api_key,tmp_host)
|
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
|
-
@assembly_id = o[:assembly_id] if o.has_key?(:assembly_id)
|
155
|
-
@start_date = o[:start_date] if o.has_key?(:start_date)
|
156
|
-
@end_date = o[:end_date] if o.has_key?(:end_date)
|
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, tmp_host=nil)
|
162
|
-
acct = from_hash(o,tmp_email, tmp_api_key, tmp_host)
|
163
|
-
acct.create
|
164
|
-
end
|
165
|
-
|
166
|
-
# Create the subscriptions via the REST API
|
167
|
-
def create
|
168
|
-
megam_rest.post_subscriptions(to_hash)
|
169
|
-
end
|
170
|
-
|
171
|
-
# Load all subscriptions -
|
172
|
-
# returns a subscriptionsCollection
|
173
|
-
# don't return self. check if the Megam::subscriptionsCollection is returned.
|
174
|
-
def self.list(tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
175
|
-
cts = self.new(tmp_email, tmp_api_key, tmp_host)
|
176
|
-
cts.megam_rest.get_subscriptions
|
177
|
-
end
|
178
|
-
|
179
|
-
# Show a particular subscriptions by name,
|
180
|
-
# Megam::subscriptions
|
181
|
-
def self.show(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
182
|
-
pre = self.new(tmp_email, tmp_api_key, tmp_host)
|
183
|
-
pre.megam_rest.get_subscriptions(p_name)
|
184
|
-
end
|
185
|
-
|
186
|
-
def to_s
|
187
|
-
Megam::Stuff.styled_hash(to_hash)
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
191
|
-
end
|