Class: Fastbill::Automatic::UsageData
- Inherits:
-
Base
- Object
- Base
- Fastbill::Automatic::UsageData
show all
- Defined in:
- lib/fastbill-automatic/usage_data.rb
Constant Summary
collapse
- ATTRIBUTES =
[
:subscription_id,
:customer_id,
:article_number,
:unit_price,
:description,
:currency_code,
:status,
:usage_date,
:created,
:quantity,
:usagedata_id
]
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
clear_request_infos, #initialize, request_infos, request_infos=, #set_attributes
included
included
Class Method Details
.deleteusagedata(delete_params) ⇒ Object
153
154
155
|
# File 'lib/fastbill-automatic/usage_data.rb', line 153
def deleteusagedata(delete_params)
response = Fastbill::Automatic.request("subscription.deleteusagedata", delete_params)
end
|
.find_by_usage_date(subscription_id, time) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/fastbill-automatic/usage_data.rb', line 85
def self.find_by_usage_date(subscription_id, time)
time = time.strftime("%Y-%m-%d %H:%M:%S")
result = getusagedata(subscription_id: subscription_id, start: time, end: time)
result_items = result['RESPONSE']['ITEMS']
last_item_attributes = result_items ? result_items.last : nil
if last_item_attributes
if last_item_attributes['CURRENCY_CODE'] == []
last_item_attributes['CURRENCY_CODE'] = ''
end
init_attributes = Hash[*last_item_attributes.map{|k,v| [k.downcase.to_sym, v]}.flatten]
self.new(init_attributes)
end
end
|
.get_remote_attributes(get_params) ⇒ Object
77
78
79
80
81
82
|
# File 'lib/fastbill-automatic/usage_data.rb', line 77
def self.get_remote_attributes(get_params)
response = UsageData.getusagedata(get_params)
binding.pry
item_attributes = response['RESPONSE']['ITEMS'].last
item_attributes
end
|
.getusagedata(get_params) ⇒ Object
149
150
151
|
# File 'lib/fastbill-automatic/usage_data.rb', line 149
def getusagedata(get_params)
response = Fastbill::Automatic.request("subscription.getusagedata", get_params)
end
|
.prepare_attributes(attributes) ⇒ Object
141
142
143
|
# File 'lib/fastbill-automatic/usage_data.rb', line 141
def prepare_attributes(attributes)
Hash[*attributes.map{|k,v| [k.downcase.to_sym, v.to_s]}.flatten]
end
|
.setusagedata(set_params) ⇒ Object
145
146
147
|
# File 'lib/fastbill-automatic/usage_data.rb', line 145
def setusagedata(set_params)
response = Fastbill::Automatic.request("subscription.setusagedata", set_params)
end
|
.where(get_params) ⇒ Object
157
158
159
160
161
162
163
164
165
|
# File 'lib/fastbill-automatic/usage_data.rb', line 157
def where(get_params)
response = UsageData.getusagedata(get_params)
result = []
items = response['RESPONSE']['ITEMS']||[]
items.each do|item|
result << UsageData.new(prepare_attributes(item))
end
result
end
|
Instance Method Details
#==(other) ⇒ Object
105
106
107
|
# File 'lib/fastbill-automatic/usage_data.rb', line 105
def ==(other)
other.attributes == self.attributes
end
|
#attributes ⇒ Object
21
22
23
|
# File 'lib/fastbill-automatic/usage_data.rb', line 21
def attributes
Hash[*ATTRIBUTES.map{|a| [a, instance_variable_get("@#{a}")]}.flatten]
end
|
#create ⇒ Object
49
50
51
52
|
# File 'lib/fastbill-automatic/usage_data.rb', line 49
def create
save
self
end
|
#created ⇒ Object
33
34
35
|
# File 'lib/fastbill-automatic/usage_data.rb', line 33
def created
Time.parse(@created)
end
|
#currency_code ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/fastbill-automatic/usage_data.rb', line 41
def currency_code
if @currency_code.is_a?(Array)
@currency_code.join('')
else
@currency_code.to_s
end
end
|
#quantity ⇒ Object
37
38
39
|
# File 'lib/fastbill-automatic/usage_data.rb', line 37
def quantity
@quantity.to_i
end
|
#unit_price ⇒ Object
25
26
27
|
# File 'lib/fastbill-automatic/usage_data.rb', line 25
def unit_price
@unit_price.to_f
end
|
#update_attributes(attributes) ⇒ Object
58
59
60
61
62
|
# File 'lib/fastbill-automatic/usage_data.rb', line 58
def update_attributes(attributes)
initialize(UsageData.prepare_attributes(attributes.merge(attributes)))
save
self
end
|
#usage_date ⇒ Object
29
30
31
|
# File 'lib/fastbill-automatic/usage_data.rb', line 29
def usage_date
Time.parse(@usage_date)
end
|