Class: T2Airtime::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/t2_airtime/serializer.rb

Class Method Summary collapse

Class Method Details

.currencyObject



9
10
11
12
13
# File 'lib/t2_airtime/serializer.rb', line 9

def self.currency
  Rails.cache.fetch('accounts/currency', expires_in: 24.hours) do        
    serialize(get.data)["attributes"]["currency"]
  end      
end

.getObject



3
4
5
6
7
# File 'lib/t2_airtime/serializer.rb', line 3

def self.get
  Rails.cache.fetch('accounts', expires_in: 1.hour) do
    T2Airtime::API.api.
  end
end

.infoObject



15
16
17
# File 'lib/t2_airtime/serializer.rb', line 15

def self.info
  get.success? ? serialize(get.data, get.headers[:date]) : []
end

.serialize(data, ts = Time.zone.now.to_s) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/t2_airtime/serializer.rb', line 19

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