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.



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

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

Instance Method Details

#auth_keyObject



45
46
47
# File 'lib/t2_airtime/reply.rb', line 45

def auth_key
  data[:authentication_key]
end

#dataObject



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

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



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

def error_code
  data[:error_code]
end

#error_messageObject



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

def error_message
  data[:error_txt]
end

#headersObject



49
50
51
# File 'lib/t2_airtime/reply.rb', line 49

def headers
  @response[:response_headers]
end

#informationObject



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

def information
  data.reject do |key, _value|
    %i[authentication_key error_code error_txt].include?(key)
  end
end

#messageObject



41
42
43
# File 'lib/t2_airtime/reply.rb', line 41

def message
  information[:info_txt]
end

#rawObject



53
54
55
# File 'lib/t2_airtime/reply.rb', line 53

def raw
  @response[:body]
end

#statusObject



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

def status
  @response[:status]
end

#success?Boolean

Returns:

  • (Boolean)


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

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

#urlObject



37
38
39
# File 'lib/t2_airtime/reply.rb', line 37

def url
  (@response[:url]).to_s
end