Class: T2Airtime::Reply
- Inherits:
-
Object
- Object
- T2Airtime::Reply
- Defined in:
- lib/t2_airtime/reply.rb
Instance Method Summary collapse
- #auth_key ⇒ Object
- #data ⇒ Object
- #error_code ⇒ Object
- #error_message ⇒ Object
- #headers ⇒ Object
- #information ⇒ Object
-
#initialize(reply) ⇒ Reply
constructor
A new instance of Reply.
- #message ⇒ Object
- #raw ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
- #url ⇒ Object
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_key ⇒ Object
45 46 47 |
# File 'lib/t2_airtime/reply.rb', line 45 def auth_key data[:authentication_key] end |
#data ⇒ Object
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_code ⇒ Object
29 30 31 |
# File 'lib/t2_airtime/reply.rb', line 29 def error_code data[:error_code] end |
#error_message ⇒ Object
33 34 35 |
# File 'lib/t2_airtime/reply.rb', line 33 def data[:error_txt] end |
#headers ⇒ Object
49 50 51 |
# File 'lib/t2_airtime/reply.rb', line 49 def headers @response[:response_headers] end |
#information ⇒ Object
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 |
#message ⇒ Object
41 42 43 |
# File 'lib/t2_airtime/reply.rb', line 41 def information[:info_txt] end |
#raw ⇒ Object
53 54 55 |
# File 'lib/t2_airtime/reply.rb', line 53 def raw @response[:body] end |
#status ⇒ Object
25 26 27 |
# File 'lib/t2_airtime/reply.rb', line 25 def status @response[:status] end |
#success? ⇒ Boolean
21 22 23 |
# File 'lib/t2_airtime/reply.rb', line 21 def success? status == 200 && error_code == 0 end |
#url ⇒ Object
37 38 39 |
# File 'lib/t2_airtime/reply.rb', line 37 def url (@response[:url]).to_s end |