Sha256: cfafd8db78680279bd9cab2e971ddad8cdc83332b51ba3a6cde97b5ddddd277d

Contents?: true

Size: 1006 Bytes

Versions: 1

Compression:

Stored size: 1006 Bytes

Contents

module T2Airtime
  class Reply
    
    def initialize(reply)
      @response = reply.to_hash
    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
      end; hash
    end

    def status
      @response[:status]
    end

    def error_code
      data[:error_code]
    end

    def error_message
      data[:error_txt]
    end

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

    def url
      @response[:url].to_s
    end

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

    def message
      information[:info_txt]
    end

    def auth_key
      data[:authentication_key]
    end

    def headers
      @response[:response_headers]
    end

    def raw
      @response[:body]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
t2_airtime-0.1.2 lib/t2_airtime/reply.rb