Class: Elk::SMS
Overview
Used to send SMS through 46elks SMS-gateway
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#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(parameters = {}) ⇒ 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:
9 10 11 |
# File 'lib/elk/sms.rb', line 9 def initialize(parameters) #:nodoc: set_parameters(parameters) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/elk/sms.rb', line 6 def client @client end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
6 7 8 |
# File 'lib/elk/sms.rb', line 6 def created_at @created_at end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
6 7 8 |
# File 'lib/elk/sms.rb', line 6 def direction @direction end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
6 7 8 |
# File 'lib/elk/sms.rb', line 6 def from @from end |
#loaded_at ⇒ Object (readonly)
Returns the value of attribute loaded_at.
6 7 8 |
# File 'lib/elk/sms.rb', line 6 def loaded_at @loaded_at end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/elk/sms.rb', line 6 def @message end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
6 7 8 |
# File 'lib/elk/sms.rb', line 6 def @message_id end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/elk/sms.rb', line 6 def status @status end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
6 7 8 |
# File 'lib/elk/sms.rb', line 6 def to @to end |
Class Method Details
.all(parameters = {}) ⇒ Object
Get outgoing and incomming messages. Limited by the API to 100 latest
Optional parameters
-
:client - Elk::Client instance
85 86 87 88 89 90 |
# File 'lib/elk/sms.rb', line 85 def all(parameters = {}) client = parameters.fetch(:client) { Elk.client } response = client.get("/SMS") = Elk::Util.parse_json(response.body).fetch(:data).each { |m| m[:client] = client } instantiate_multiple() 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”
-
:flashsms - alias of :flash
-
:client - ‘Elk::Client` instance
-
:whendelivered - Callback URL that will receive a POST after delivery
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/elk/sms.rb', line 48 def send(parameters) verify_parameters(parameters, [:from, :message, :to]) client = parameters.fetch(:client) { Elk.client } arguments = {} arguments[:from] = parameters.fetch(:from) arguments[:to] = Array(parameters.fetch(:to)).join(",") arguments[:message] = parameters.fetch(:message) if parameters.values_at(:flash, :flashsms).any? arguments[:flashsms] = "yes" end if parameters.key?(:whendelivered) arguments[:whendelivered] = parameters.fetch(:whendelivered) end check_sender_limit(arguments[:from]) response = client.post("/SMS", arguments) parsed_response = Elk::Util.parse_json(response.body) if multiple_recipients?(arguments[:to]) parsed_response.each { |m| m[:client] = client } instantiate_multiple(parsed_response) else parsed_response[:client] = client self.new(parsed_response) end end |
Instance Method Details
#reload ⇒ Object
Reloads a SMS from server
26 27 28 29 30 |
# File 'lib/elk/sms.rb', line 26 def reload response = @client.get("/SMS/#{self.}") self.set_parameters(Elk::Util.parse_json(response.body)) response.code == 200 end |
#set_parameters(parameters) ⇒ Object
:nodoc:
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/elk/sms.rb', line 13 def set_parameters(parameters) #:nodoc: @from = parameters[:from] @to = parameters[:to] @message = parameters[:message] @message_id = parameters[:id] @created_at = Time.parse(parameters[:created]) if parameters[:created] @loaded_at = Time.now @direction = parameters[:direction] @status = parameters[:status] @client = parameters.fetch(:client) { Elk.client } end |