Class: T2Airtime::Operator

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

Class Method Summary collapse

Class Method Details

.serialize(data, qty = nil) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/t2_airtime/serializer.rb', line 85

def self.serialize(data, qty=nil)
     names = data[:operator].split(",") 
     ids = data[:operatorid].split(",")
     ids.take(qty.nil? ? ids.count : qty).each_with_index.map{|id, n| {
       country: data[:country], 
       country_aid: Integer(data[:countryid]),
       alpha3: T2Airtime::Country.alpha3(data[:country]),
       name: names[n], 
       logo_url: T2Airtime::Util.operator_logo_url(id),
       aid: Integer(id)
     }}
end

.take(country_qty = 1, qty = 5) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/t2_airtime/serializer.rb', line 75

def self.take(country_qty=1, qty=5)
    countries = T2Airtime::Country.take(country_qty).shuffle
    unless countries.empty?
      countries.flat_map{|country| (
        reply = T2Airtime::API.api.operator_list(country[:aid])
        reply.success? ? serialize(reply.data, qty) : []
      )}        
    end
end