Class: SmsTraffic::Sms
- Inherits:
-
Object
- Object
- SmsTraffic::Sms
- Defined in:
- lib/sms_traffic/sms.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#message ⇒ Object
Returns the value of attribute message.
-
#originator ⇒ Object
Returns the value of attribute originator.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#deliver ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(phone, message, originator: nil) ⇒ Sms
constructor
A new instance of Sms.
- #update_status ⇒ Object
Constructor Details
#initialize(phone, message, originator: nil) ⇒ Sms
Returns a new instance of Sms.
6 7 8 9 10 11 12 13 |
# File 'lib/sms_traffic/sms.rb', line 6 def initialize(phone, , originator: nil) @phone = phone @message = @originator = originator || SmsTraffic.configuration.originator @status = 'not-sent' @errors = [] validate! end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/sms_traffic/sms.rb', line 4 def errors @errors end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/sms_traffic/sms.rb', line 4 def id @id end |
#message ⇒ Object
Returns the value of attribute message.
3 4 5 |
# File 'lib/sms_traffic/sms.rb', line 3 def @message end |
#originator ⇒ Object
Returns the value of attribute originator.
3 4 5 |
# File 'lib/sms_traffic/sms.rb', line 3 def originator @originator end |
#phone ⇒ Object
Returns the value of attribute phone.
3 4 5 |
# File 'lib/sms_traffic/sms.rb', line 3 def phone @phone end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/sms_traffic/sms.rb', line 4 def status @status end |
Instance Method Details
#deliver ⇒ Object
rubocop:disable Metrics/MethodLength
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sms_traffic/sms.rb', line 15 def deliver # rubocop:disable Metrics/MethodLength # @type [Client::Response] response = Client.deliver(phone, , originator) unless response.success? @errors << response.error_description return false end # @type [Client::Response::Reply] reply = response.reply if reply.ok? @status = 'sent' @id = reply.sms_id || reply.sms_ids.values.first true else @errors << (reply.error_description || 'Sms has been not enqueued') false end end |