Class: Megam::Invoices
Instance Attribute Summary
Attributes inherited from ServerAPI
#api_key, #email, #host, #org_id, #password
Class Method Summary
collapse
-
.create(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
-
.delete(p_name, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
-
.from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
-
.json_create(o) ⇒ Object
-
.list(params) ⇒ Object
Load all billing histories - returns a BillingHistoriesCollection don’t return self.
-
.show(p_name, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
Show a particular billing history by name, Megam::BillingHistory.
Instance Method Summary
collapse
Methods inherited from ServerAPI
#megam_rest
Constructor Details
#initialize(email = nil, api_key = nil, host = nil) ⇒ Invoices
Returns a new instance of Invoices.
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/megam/core/invoices.rb', line 18
def initialize(email=nil, api_key=nil, host=nil)
@id = nil
@accounts_id = nil
@from_date = nil
@to_date = nil
@month = nil
@bill_type = nil
@billing_amount = nil
@currency_type = nil
@created_at = nil
@some_msg = {}
super(email, api_key, host)
end
|
Class Method Details
.create(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
196
197
198
199
|
# File 'lib/megam/core/invoices.rb', line 196
def self.create(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
acct = from_hash(o,tmp_email, tmp_api_key, tmp_host)
acct.create
end
|
.delete(p_name, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
221
222
223
224
|
# File 'lib/megam/core/invoices.rb', line 221
def self.delete(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
pre = self.new(tmp_email,tmp_api_key, tmp_host)
pre.megam_rest.delete_invoice(p_name)
end
|
.from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
177
178
179
180
181
|
# File 'lib/megam/core/invoices.rb', line 177
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
bal = self.new(tmp_email, tmp_api_key, tmp_host)
bal.from_hash(o)
bal
end
|
.json_create(o) ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/megam/core/invoices.rb', line 158
def self.json_create(o)
bal = new
bal.id(o["id"]) if o.has_key?("id")
bal.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
bal.from_date(o["from_date"]) if o.has_key?("from_date")
bal.to_date(o["to_date"]) if o.has_key?("to_date")
bal.month(o["month"]) if o.has_key?("month")
bal.bill_type(o["bill_type"]) if o.has_key?("bill_type")
bal.billing_amount(o["billing_amount"]) if o.has_key?("billing_amount")
bal.currency_type(o["currency_type"]) if o.has_key?("currency_type")
bal.created_at(o["created_at"]) if o.has_key?("created_at")
bal.some_msg[:code] = o["code"] if o.has_key?("code")
bal.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
bal.some_msg[:msg]= o["msg"] if o.has_key?("msg")
bal.some_msg[:links] = o["links"] if o.has_key?("links")
bal
end
|
.list(params) ⇒ Object
Load all billing histories - returns a BillingHistoriesCollection don’t return self. check if the Megam::BillingHistoriesCollection is returned.
209
210
211
212
|
# File 'lib/megam/core/invoices.rb', line 209
def self.list(params)
invoices = self.new(params["email"], params["api_key"], params["host"])
invoices.megam_rest.get_invoices
end
|
.show(p_name, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
Show a particular billing history by name, Megam::BillingHistory
216
217
218
219
|
# File 'lib/megam/core/invoices.rb', line 216
def self.show(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
pre = self.new(tmp_email,tmp_api_key, tmp_host)
pre.megam_rest.get_invoice(p_name)
end
|
Instance Method Details
#accounts_id(arg = nil) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/megam/core/invoices.rb', line 44
def accounts_id(arg=nil)
if arg != nil
@accounts_id= arg
else
@accounts_id
end
end
|
#bill_type(arg = nil) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/megam/core/invoices.rb', line 76
def bill_type(arg=nil)
if arg != nil
@bill_type = arg
else
@bill_type
end
end
|
#billing_amount(arg = nil) ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/megam/core/invoices.rb', line 84
def billing_amount(arg=nil)
if arg != nil
@billing_amount= arg
else
@billing_amount
end
end
|
#create ⇒ Object
Create the invoices via the REST API
202
203
204
|
# File 'lib/megam/core/invoices.rb', line 202
def create
megam_rest.post_invoices(to_hash)
end
|
#created_at(arg = nil) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/megam/core/invoices.rb', line 100
def created_at(arg=nil)
if arg != nil
@created_at = arg
else
@created_at
end
end
|
#currency_type(arg = nil) ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/megam/core/invoices.rb', line 92
def currency_type(arg=nil)
if arg != nil
@currency_type = arg
else
@currency_type
end
end
|
#error? ⇒ Boolean
116
117
118
|
# File 'lib/megam/core/invoices.rb', line 116
def error?
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end
|
#for_json ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/megam/core/invoices.rb', line 142
def for_json
result = {
"id" => id,
"accounts_id" => accounts_id,
"from_date" => from_date,
"to_date" => to_date,
"month" => month,
"bill_type" => bill_type,
"billing_amount" => billing_amount,
"currency_type" => currency_type,
"created_at" => created_at
}
result
end
|
#from_date(arg = nil) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/megam/core/invoices.rb', line 52
def from_date(arg=nil)
if arg != nil
@from_date = arg
else
@from_date
end
end
|
#from_hash(o) ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/megam/core/invoices.rb', line 183
def from_hash(o)
@id = o[:id] if o.has_key?(:id)
@accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
@from_date = o[:from_date] if o.has_key?(:from_date)
@to_date = o[:to_date] if o.has_key?(:to_date)
@month = o[:month] if o.has_key?(:month)
@bill_type = o[:bill_type] if o.has_key?(:bill_type)
@billing_amount = o[:billing_amount] if o.has_key?(:billing_amount)
@currency_type = o[:currency_type] if o.has_key?(:currency_type)
@created_at = o[:created_at] if o.has_key?(:created_at)
self
end
|
#id(arg = nil) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/megam/core/invoices.rb', line 36
def id(arg=nil)
if arg != nil
@id = arg
else
@id
end
end
|
#invoices ⇒ Object
32
33
34
|
# File 'lib/megam/core/invoices.rb', line 32
def invoices
self
end
|
#month(arg = nil) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/megam/core/invoices.rb', line 68
def month(arg=nil)
if arg != nil
@month =arg
else
@month
end
end
|
#some_msg(arg = nil) ⇒ Object
108
109
110
111
112
113
114
|
# File 'lib/megam/core/invoices.rb', line 108
def some_msg(arg=nil)
if arg != nil
@some_msg = arg
else
@some_msg
end
end
|
#to_date(arg = nil) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/megam/core/invoices.rb', line 60
def to_date(arg=nil)
if arg != nil
@to_date = arg
else
@to_date
end
end
|
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/megam/core/invoices.rb', line 121
def to_hash
index_hash = Hash.new
index_hash["json_claz"] = self.class.name
index_hash["id"] = id
index_hash["accounts_id"] = accounts_id
index_hash["from_date"] = from_date
index_hash["to_date"] = to_date
index_hash["month"] = month
index_hash["bill_type"] = bill_type
index_hash["billing_amount"] = billing_amount
index_hash["currency_type"] = currency_type
index_hash["created_at"] = created_at
index_hash
end
|
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.
138
139
140
|
# File 'lib/megam/core/invoices.rb', line 138
def to_json(*a)
for_json.to_json(*a)
end
|