Class: Elk::SMS
Overview
Used to send SMS through 46elks SMS-gateway
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#loaded_at ⇒ Object
readonly
Returns the value of attribute loaded_at.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Class Method Summary collapse
-
.all ⇒ Object
Get outgoing and incomming messages.
-
.send(parameters) ⇒ Object
Send SMS Required parameters.
Instance Method Summary collapse
-
#initialize(parameters) ⇒ SMS
constructor
:nodoc:.
-
#reload ⇒ Object
Reloads a SMS from server.
-
#set_parameters(parameters) ⇒ Object
:nodoc:.
Methods included from Util
Constructor Details
#initialize(parameters) ⇒ SMS
:nodoc:
7 8 9 |
# File 'lib/elk/sms.rb', line 7 def initialize(parameters) #:nodoc: set_parameters(parameters) end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
4 5 6 |
# File 'lib/elk/sms.rb', line 4 def created_at @created_at end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
4 5 6 |
# File 'lib/elk/sms.rb', line 4 def direction @direction end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
4 5 6 |
# File 'lib/elk/sms.rb', line 4 def from @from end |
#loaded_at ⇒ Object (readonly)
Returns the value of attribute loaded_at.
4 5 6 |
# File 'lib/elk/sms.rb', line 4 def loaded_at @loaded_at end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
4 5 6 |
# File 'lib/elk/sms.rb', line 4 def end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
4 5 6 |
# File 'lib/elk/sms.rb', line 4 def end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/elk/sms.rb', line 4 def status @status end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
4 5 6 |
# File 'lib/elk/sms.rb', line 4 def to @to end |
Class Method Details
.all ⇒ Object
Get outgoing and incomming messages. Limited by the API to 100 latest
68 69 70 71 |
# File 'lib/elk/sms.rb', line 68 def all response = Elk.get('/SMS') instantiate_multiple(Elk.parse_json(response.body)[:data]) end |
.send(parameters) ⇒ Object
Send SMS Required parameters
-
:from - Either the one of the allocated numbers or arbitrary alphanumeric string of at most 11 characters
-
:to - Any phone number capable of receiving SMS. Multiple numbers can be given as Array or comma separated String
-
:message - Any UTF-8 text Splitting and joining multi-part SMS messages are automatically handled by the API
Optional parameters
-
:flash - if set to non-false value SMS is sent as a “Flash SMS”
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/elk/sms.rb', line 42 def send(parameters) verify_parameters(parameters, [:from, :message, :to]) parameters[:to] = Array(parameters[:to]).join(',') if parameters[:flash] parameters.delete(:flash) parameters[:flashsms] = 'yes' end # Warn if the from string will be capped by the sms gateway if parameters[:from] && parameters[:from].match(/^(\w{11,})$/) warn "SMS 'from' value #{parameters[:from]} will be capped at 11 chars" end response = Elk.post('/SMS', parameters) parsed_response = Elk.parse_json(response.body) if multiple_recipients?(parameters[:to]) instantiate_multiple(parsed_response) else self.new(parsed_response) end end |
Instance Method Details
#reload ⇒ Object
Reloads a SMS from server
23 24 25 26 27 |
# File 'lib/elk/sms.rb', line 23 def reload response = Elk.get("/SMS/#{self.message_id}") self.set_parameters(Elk.parse_json(response.body)) response.code == 200 end |
#set_parameters(parameters) ⇒ Object
:nodoc:
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/elk/sms.rb', line 11 def set_parameters(parameters) #:nodoc: @from = parameters[:from] @to = parameters[:to] = parameters[:message] = parameters[:id] @created_at = Time.parse(parameters[:created]) if parameters[:created] @loaded_at = Time.now @direction = parameters[:direction] @status = parameters[:status] end |