Sha256: 90fde96f5bd6823d907f6fa4971e742ee4a2aeeba97380120a9fc17732471543

Contents?: true

Size: 943 Bytes

Versions: 7

Compression:

Stored size: 943 Bytes

Contents

module T2Airtime
  class Reply
    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' ? Integer(value) : value
      end; hash
    end

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

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

    def status
      @response[:status]
    end

    def error_code
      data[:error_code]
    end

    def error_message
      data[:error_txt]
    end

    def url
      (@response[:url]).to_s
    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

7 entries across 7 versions & 1 rubygems

Version Path
t2_airtime-0.6.0 lib/t2_airtime/reply.rb
t2_airtime-0.5.2 lib/t2_airtime/reply.rb
t2_airtime-0.5.1 lib/t2_airtime/reply.rb
t2_airtime-0.5.0 lib/t2_airtime/reply.rb
t2_airtime-0.4.1 lib/t2_airtime/reply.rb
t2_airtime-0.4.0 lib/t2_airtime/reply.rb
t2_airtime-0.3.1 lib/t2_airtime/reply.rb