Class: T2Airtime::Reply

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

Instance Method Summary collapse

Constructor Details

#initialize(reply) ⇒ Reply

Returns a new instance of Reply



4
# File 'lib/t2_airtime/reply.rb', line 4

def initialize(reply) @response = Hash(reply) end

Instance Method Details

#auth_keyObject



32
# File 'lib/t2_airtime/reply.rb', line 32

def auth_key() data[:authentication_key] end

#dataObject



6
7
8
9
10
11
12
# File 'lib/t2_airtime/reply.rb', line 6

def data
  hash = {}
  @response[:body].lines.each do |line|
    key, value = line.strip.split "="
    hash[key.to_sym] = (key == "error_code") ? Integer(value) : value
  end; hash
end

#error_codeObject



24
# File 'lib/t2_airtime/reply.rb', line 24

def error_code() data[:error_code] end

#error_messageObject



26
# File 'lib/t2_airtime/reply.rb', line 26

def error_message() data[:error_txt] end

#headersObject



34
# File 'lib/t2_airtime/reply.rb', line 34

def headers() @response[:response_headers] end

#informationObject



14
15
16
17
18
# File 'lib/t2_airtime/reply.rb', line 14

def information
  data.reject do |key, value|
    [:authentication_key, :error_code, :error_txt].include?(key)
  end
end

#messageObject



30
# File 'lib/t2_airtime/reply.rb', line 30

def message() information[:info_txt] end

#rawObject



36
# File 'lib/t2_airtime/reply.rb', line 36

def raw() @response[:body] end

#statusObject



22
# File 'lib/t2_airtime/reply.rb', line 22

def status() @response[:status] end

#success?Boolean

Returns:

  • (Boolean)


20
# File 'lib/t2_airtime/reply.rb', line 20

def success?() status == 200 && error_code == 0 end

#urlObject



28
# File 'lib/t2_airtime/reply.rb', line 28

def url() "#{@response[:url]}" end