Class: Exetel::API
- Inherits:
-
Object
- Object
- Exetel::API
- Defined in:
- lib/exetel/api.rb,
lib/exetel/api/error.rb,
lib/exetel/api/command.rb,
lib/exetel/api/message_status.rb,
lib/exetel/api/command_executor.rb
Overview
This module provides the core implementation of the Exetel SMS HTTP Service
Defined Under Namespace
Classes: Command, CommandExecutor, Error, MessageStatus
Instance Attribute Summary collapse
-
#auth_options ⇒ Object
Returns the value of attribute auth_options.
Instance Method Summary collapse
-
#credit_check ⇒ Object
Requests for the amount of credit remaining.
-
#initialize(auth_options = {}) ⇒ API
constructor
A new instance of API.
-
#send_message(recipient, message_text, opts = {}) ⇒ Object
Sends a message
message_text
torecipient
.
Constructor Details
#initialize(auth_options = {}) ⇒ API
Returns a new instance of API.
6 7 8 |
# File 'lib/exetel/api.rb', line 6 def initialize(={}) @auth_options = end |
Instance Attribute Details
#auth_options ⇒ Object
Returns the value of attribute auth_options.
4 5 6 |
# File 'lib/exetel/api.rb', line 4 def @auth_options end |
Instance Method Details
#credit_check ⇒ Object
Requests for the amount of credit remaining
Returns a response hash
33 34 35 36 |
# File 'lib/exetel/api.rb', line 33 def credit_check response = execute_command('sms_credit') response = parse_response(:credit_check, response) end |
#send_message(recipient, message_text, opts = {}) ⇒ Object
Sends a message message_text
to recipient
.
Additional options:
:sender - the from number/name(default="")
:msg_type - The encoding type of message(default=text)
:ref_number - An optional reference number for local tracking
Returns a new message ID if successful.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/exetel/api.rb', line 17 def (recipient, , opts={}) = { :sender => "", :messagetype => "Text" } .merge!(:sender => opts[:sender]) if opts[:sender] .merge!(:messagetype => opts[:msg_type]) if opts[:msg_type] .merge!(:referencenumber => opts[:ref_number]) if opts[:ref_number] recipient = recipient.join(",")if recipient.is_a?(Array) response = execute_command('sms', { :mobilenumber => recipient, :message => }.merge() ) response = parse_response(:sms, response) response.is_a?(Array) ? response.map { |r| r[:status] } : response[:status] end |