lib/t2_airtime/reply.rb in t2_airtime-0.1.2 vs lib/t2_airtime/reply.rb in t2_airtime-0.1.3
- old
+ new
@@ -1,58 +1,39 @@
module T2Airtime
class Reply
- def initialize(reply)
- @response = reply.to_hash
- end
+ def initialize(reply) @response = Hash(reply) end
def data
hash = {}
@response[:body].lines.each do |line|
key, value = line.strip.split "="
- hash[key.to_sym] = (key == "error_code") ? value.to_i : value
+ hash[key.to_sym] = (key == "error_code") ? Integer(value) : value
end; hash
end
- def status
- @response[:status]
+ def information
+ data.reject do |key, value|
+ [:authentication_key, :error_code, :error_txt].include?(key)
+ end
end
- def error_code
- data[:error_code]
- end
+ def success?() status == 200 && error_code == 0 end
- def error_message
- data[:error_txt]
- end
+ def status() @response[:status] end
- def success?
- status == 200 && error_code == 0
- end
+ def error_code() data[:error_code] end
- def url
- @response[:url].to_s
- end
+ def error_message() data[:error_txt] end
- def information
- data.reject do |key, value|
- [:authentication_key, :error_code, :error_txt].include?(key)
- end
- end
+ def url() "#{@response[:url]}" end
- def message
- information[:info_txt]
- end
+ def message() information[:info_txt] end
- def auth_key
- data[:authentication_key]
- end
+ def auth_key() data[:authentication_key] end
- def headers
- @response[:response_headers]
- end
+ def headers() @response[:response_headers] end
- def raw
- @response[:body]
- end
+ def raw() @response[:body] end
+
end
end