Class: MessageBird::HTTP::ResponseCode

Inherits:
Object
  • Object
show all
Defined in:
lib/messagebird/http/response_code.rb

Defined Under Namespace

Classes: ResponseCodeNotFound

Constant Summary collapse

RESPONSE_CODES =
{
  "01" => ResponseCode.new(:success,                          "Request processed successfully"),
  "69" => ResponseCode.new(:message_cannot_schedule_on_date,  "Message cannot be scheduled on this date"),
  "70" => ResponseCode.new(:timestamp_incorrect,              "Timestamp notation invalid"),
  "71" => ResponseCode.new(:timestamp_in_past,                "Timestamp is in the past"),
  "72" => ResponseCode.new(:message_too_long,                 "Message is too long"),
  "89" => ResponseCode.new(:sender_invalid,                   "Sender invalid"),
  "93" => ResponseCode.new(:receivers_invalid,                "One or several receivers invalid"),
  "95" => ResponseCode.new(:message_not_selected,             "No message selected"),
  "96" => ResponseCode.new(:credits_insufficient,             "Insufficient credits"),
  "97" => ResponseCode.new(:login_invalid,                    "Invalid username and/or password"),
  "98" => ResponseCode.new(:ip_address_not_authorized,        "IP address is not authorized for this account"),
  "99" => ResponseCode.new(:connection_failed,                "Cannot connect to server")
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol, description) ⇒ ResponseCode

Returns a new instance of ResponseCode.



4
5
6
7
# File 'lib/messagebird/http/response_code.rb', line 4

def initialize(symbol, description)
  @symbol      = symbol
  @description = description
end

Class Method Details

.decode(string) ⇒ Object



25
26
27
# File 'lib/messagebird/http/response_code.rb', line 25

def self.decode(string)
  RESPONSE_CODES[string] || raise(ResponseCodeNotFound.new(string))
end

Instance Method Details

#==(other) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/messagebird/http/response_code.rb', line 17

def ==(other)
  if other.is_a? Symbol
    self.to_sym == other
  else
    self.to_s == other
  end
end

#to_sObject



13
14
15
# File 'lib/messagebird/http/response_code.rb', line 13

def to_s
  @description
end

#to_symObject



9
10
11
# File 'lib/messagebird/http/response_code.rb', line 9

def to_sym
  @symbol
end