Class: Smsapi::SMS
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#error_code ⇒ Object
Returns the value of attribute error_code.
-
#id ⇒ Object
Returns the value of attribute id.
-
#message ⇒ Object
Returns the value of attribute message.
-
#points ⇒ Object
Returns the value of attribute points.
-
#status ⇒ Object
Returns the value of attribute status.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #deliver ⇒ Object
- #deliver_at(date) ⇒ Object
- #error? ⇒ Boolean
- #error_message ⇒ Object
-
#initialize(to, message, server, options = {}) ⇒ SMS
constructor
A new instance of SMS.
- #read_response(response) ⇒ Object
- #sent? ⇒ Boolean
- #success? ⇒ Boolean
Methods included from Defaults
Constructor Details
#initialize(to, message, server, options = {}) ⇒ SMS
Returns a new instance of SMS.
6 7 8 9 10 11 |
# File 'lib/smsapi/sms.rb', line 6 def initialize(to, , server, = {}) @options = .merge @to = to @message = @server = server end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
5 6 7 |
# File 'lib/smsapi/sms.rb', line 5 def date @date end |
#error_code ⇒ Object
Returns the value of attribute error_code.
5 6 7 |
# File 'lib/smsapi/sms.rb', line 5 def error_code @error_code end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/smsapi/sms.rb', line 5 def id @id end |
#message ⇒ Object
Returns the value of attribute message.
5 6 7 |
# File 'lib/smsapi/sms.rb', line 5 def @message end |
#points ⇒ Object
Returns the value of attribute points.
5 6 7 |
# File 'lib/smsapi/sms.rb', line 5 def points @points end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/smsapi/sms.rb', line 5 def status @status end |
#to ⇒ Object
Returns the value of attribute to.
5 6 7 |
# File 'lib/smsapi/sms.rb', line 5 def to @to end |
Instance Method Details
#deliver ⇒ Object
13 14 15 16 |
# File 'lib/smsapi/sms.rb', line 13 def deliver read_response @server.sms(server_params).first self end |
#deliver_at(date) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/smsapi/sms.rb', line 18 def deliver_at(date) @date = date params = server_params.merge(date: date.to_time.to_i) read_response @server.sms(params).first self end |
#error? ⇒ Boolean
30 31 32 |
# File 'lib/smsapi/sms.rb', line 30 def error? self.status == 'ERROR' end |
#error_message ⇒ Object
38 39 40 |
# File 'lib/smsapi/sms.rb', line 38 def Smsapi::ERROR_MESSAGES[error_code] end |
#read_response(response) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/smsapi/sms.rb', line 42 def read_response(response) response = response.split(':') self.status = response[0] if status == 'ERROR' self.error_code = response[1] else self.id = response[1] self.points = response[2] end end |
#sent? ⇒ Boolean
26 27 28 |
# File 'lib/smsapi/sms.rb', line 26 def sent? not self.status.nil? end |
#success? ⇒ Boolean
34 35 36 |
# File 'lib/smsapi/sms.rb', line 34 def success? self.status == 'SUCCESS' end |