Class: CmSms::Webhook::Response
- Inherits:
-
Object
- Object
- CmSms::Webhook::Response
- Defined in:
- lib/cm_sms/webhook/response.rb
Constant Summary collapse
- ATTRIBUTE_NAMES =
%w(sent received to reference statuscode errorcode errordescription)
Instance Method Summary collapse
- #accepted? ⇒ Boolean
- #delivered? ⇒ Boolean
- #error? ⇒ Boolean
- #errorcode? ⇒ Boolean
- #failed? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Response
constructor
A new instance of Response.
- #received? ⇒ Boolean
- #received_at ⇒ Object
- #rejected? ⇒ Boolean
- #sent? ⇒ Boolean
- #sent_at ⇒ Object
- #statuscode? ⇒ Boolean
- #to_yaml ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Response
9 10 11 12 13 |
# File 'lib/cm_sms/webhook/response.rb', line 9 def initialize(attributes = {}) @attributes = attributes attributes.each { |attr, value| instance_variable_set("@#{attr}", value) } if attributes end |
Instance Method Details
#accepted? ⇒ Boolean
39 40 41 |
# File 'lib/cm_sms/webhook/response.rb', line 39 def accepted? statuscode? && statuscode.to_s == '0' end |
#delivered? ⇒ Boolean
47 48 49 |
# File 'lib/cm_sms/webhook/response.rb', line 47 def delivered? statuscode? && statuscode.to_s == '2' end |
#error? ⇒ Boolean
55 56 57 |
# File 'lib/cm_sms/webhook/response.rb', line 55 def error? errorcode? || rejected? || failed? end |
#errorcode? ⇒ Boolean
27 28 29 |
# File 'lib/cm_sms/webhook/response.rb', line 27 def errorcode? !errorcode.to_s.strip.empty? end |
#failed? ⇒ Boolean
51 52 53 |
# File 'lib/cm_sms/webhook/response.rb', line 51 def failed? statuscode? && statuscode.to_s == '3' end |
#received? ⇒ Boolean
19 20 21 |
# File 'lib/cm_sms/webhook/response.rb', line 19 def received? !received.to_s.strip.empty? end |
#received_at ⇒ Object
35 36 37 |
# File 'lib/cm_sms/webhook/response.rb', line 35 def received_at Time.parse(received) if received? end |
#rejected? ⇒ Boolean
43 44 45 |
# File 'lib/cm_sms/webhook/response.rb', line 43 def rejected? statuscode? && statuscode.to_s == '1' end |
#sent? ⇒ Boolean
15 16 17 |
# File 'lib/cm_sms/webhook/response.rb', line 15 def sent? !sent.to_s.strip.empty? end |
#sent_at ⇒ Object
31 32 33 |
# File 'lib/cm_sms/webhook/response.rb', line 31 def sent_at Time.parse(sent) if sent? end |
#statuscode? ⇒ Boolean
23 24 25 |
# File 'lib/cm_sms/webhook/response.rb', line 23 def statuscode? !statuscode.to_s.strip.empty? end |
#to_yaml ⇒ Object
59 60 61 |
# File 'lib/cm_sms/webhook/response.rb', line 59 def to_yaml (@attributes || {}).to_yaml end |