Class: T2Airtime::Account
- Inherits:
-
Object
- Object
- T2Airtime::Account
- Defined in:
- lib/t2_airtime/serializer.rb
Class Method Summary collapse
Class Method Details
.currency ⇒ Object
75 76 77 78 79 80 |
# File 'lib/t2_airtime/serializer.rb', line 75 def self.currency account = serialize(get.data) Rails.cache.fetch('accounts/currency', expires_in: 24.hours) do # cache the result for 1 day account[:attributes][:currency] end end |
.get ⇒ Object
69 70 71 72 73 |
# File 'lib/t2_airtime/serializer.rb', line 69 def self.get Rails.cache.fetch('accounts', expires_in: 1.hour) do T2Airtime::API.api.account_info end end |
.info ⇒ Object
82 83 84 |
# File 'lib/t2_airtime/serializer.rb', line 82 def self.info get.success? ? serialize(get.data, get.headers[:date]) : [] end |
.serialize(data, ts = Time.zone.now.to_s) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/t2_airtime/serializer.rb', line 86 def self.serialize(data, ts = Time.zone.now.to_s) { type: 'accounts', id: T2Airtime::API.api.user, attributes: { type: data[:type], name: data[:name], currency: data[:currency], balance: Float(data[:balance]), wallet: Float(data[:wallet]), fetchedAt: T2Airtime::Util.format_time(ts) } } end |