Class: Exetel::API

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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={})
  @auth_options = auth_options
end

Instance Attribute Details

#auth_optionsObject

Returns the value of attribute auth_options.



4
5
6
# File 'lib/exetel/api.rb', line 4

def auth_options
  @auth_options
end

Instance Method Details

#credit_checkObject

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 send_message(recipient, message_text, opts={})
  valid_options = { :sender => "", :messagetype => "Text" }
  valid_options.merge!(:sender => opts[:sender]) if opts[:sender]
  valid_options.merge!(:messagetype => opts[:msg_type]) if opts[:msg_type]
  valid_options.merge!(:referencenumber => opts[:ref_number]) if opts[:ref_number]
  recipient = recipient.join(",")if recipient.is_a?(Array)
  response = execute_command('sms',
                             { :mobilenumber => recipient, :message => message_text}.merge(valid_options)
                            )
  response = parse_response(:sms, response)
  response.is_a?(Array) ? response.map { |r| r[:status] } : response[:status]
end