Sha256: 6d758201a7cb0b994c4df2e782c183fd45a850920dbaff236fd2c5d19ffd3cad

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

module Aninipot
  class Response
    attr_reader :response_code
    #TODO:
    # Service Exception Extension	
    # Policy Exceptions	
    # Policy Exception Extension	    
    @@error_map = {
      :sent? => 200,
      :queued? => 201,
      :not_authorized? => 100,
      :not_enough_balance? => 101,
      :featured_not_allowed? => 102,
      :invalid_option? => 103,
      :gateway_down? => 104
    }
    
    @@status_messages = {
      200 => "Successfully Sent",
      201 => "Message Queued",
      100 => "Not Authorized",
      101 => "Not Enough Balance",
      102 => "Feature Not Allowed",
      103 => "Invalid Options",
      104 => "Gateway Down"
    }
    
    def initialize(code)
      @response_code = code
    end
    
    def valid?
      [200, 201].include?(self.response_code)
    end
    
    def to_s
      #"#{self.response_code} - #{msg}"
      msg
    end
    
    def msg(code = self.response_code)
      if msg = @@status_messages[code]
        msg
      else
        raise ArgumentError, "#{code} - undefined response code"
      end
    end
    
    def method_missing(method_id)
      if code = @@error_map[method_id.to_sym]
        self.response_code == code
      else
        raise NoMethodError
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aninipot-0.0.3 lib/aninipot/response.rb
aninipot-0.0.2 lib/aninipot/response.rb
aninipot-0.0.1 lib/aninipot/response.rb