Class: Aninipot::Response
- Inherits:
-
Object
- Object
- Aninipot::Response
- Defined in:
- lib/aninipot/response.rb
Constant Summary collapse
- @@error_map =
TODO: Service Exception Extension Policy Exceptions Policy Exception Extension
{ :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" }
Instance Attribute Summary collapse
-
#response_code ⇒ Object
readonly
Returns the value of attribute response_code.
Instance Method Summary collapse
-
#initialize(code) ⇒ Response
constructor
A new instance of Response.
- #method_missing(method_id) ⇒ Object
- #msg(code = self.response_code) ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(code) ⇒ Response
Returns a new instance of Response.
28 29 30 |
# File 'lib/aninipot/response.rb', line 28 def initialize(code) @response_code = code end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/aninipot/response.rb', line 49 def method_missing(method_id) if code = @@error_map[method_id.to_sym] self.response_code == code else raise NoMethodError end end |
Instance Attribute Details
#response_code ⇒ Object (readonly)
Returns the value of attribute response_code.
3 4 5 |
# File 'lib/aninipot/response.rb', line 3 def response_code @response_code end |
Instance Method Details
#msg(code = self.response_code) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/aninipot/response.rb', line 41 def msg(code = self.response_code) if msg = @@status_messages[code] msg else raise ArgumentError, "#{code} - undefined response code" end end |
#to_s ⇒ Object
36 37 38 39 |
# File 'lib/aninipot/response.rb', line 36 def to_s #"#{self.response_code} - #{msg}" msg end |
#valid? ⇒ Boolean
32 33 34 |
# File 'lib/aninipot/response.rb', line 32 def valid? [200, 201].include?(self.response_code) end |