Class: EventMachine::Smsified::OneAPI

Inherits:
Base
  • Object
show all
Includes:
Helpers, ReportingModule, SubscriptionsModule
Defined in:
lib/em-smsified/oneapi.rb

Instance Attribute Summary

Attributes inherited from Base

#auth, #base_uri, #destination_address, #sender_address

Instance Method Summary collapse

Methods included from ReportingModule

#delivery_status, #retrieve_sms, #search_sms

Methods included from SubscriptionsModule

#create_inbound_subscription, #create_outbound_subscription, #delete_inbound_subscription, #delete_outbound_subscription, #inbound_subscriptions, #outbound_subscriptions, #update_inbound_subscription, #update_outbound_subscription

Methods inherited from Base

#delete, #get, #post

Constructor Details

#initialize(options) ⇒ OneAPI

Returns a new instance of OneAPI.

Examples:

one_api = OneAPI.new :username => 'user', :password => '123'


11
12
13
# File 'lib/em-smsified/oneapi.rb', line 11

def initialize(options)
  super(options)
end

Instance Method Details

#send_sms(options, &blk) ⇒ Object

Send an SMS to one or more addresses

Examples:

one_api.send_sms :address => '14155551212', :message => 'Hi there!', :sender_address => '13035551212'
one_api.send_sms :address => ['14155551212', '13035551212'], :message => 'Hi there!', :sender_address => '13035551212'
one_api.send_sms(:address => '14155551212', :message => 'Hi there!', :sender_address => '13035551212') do |result| ... end

Parameters:

  • to send an sms

Returns:

  • A Response Object with http and data instance methods

Raises:

  • if :sender_address is not passed as an option when not passed on object creation

  • if :address is not provided as an option

  • if :message is not provided as an option



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/em-smsified/oneapi.rb', line 32

def send_sms(options, &blk)
  raise ArgumentError, 'an options Hash is required' if !options.instance_of?(Hash)
  raise ArgumentError, ':sender_address is required' if options[:sender_address].nil? && @sender_address.nil?
  raise ArgumentError, ':address is required' if options[:address].nil?
  raise ArgumentError, ':message is required' if options[:message].nil?
  
  options[:sender_address] = options[:sender_address] || @sender_address
  query_options = options.clone
  query_options.delete(:sender_address)
  query_options = camelcase_keys(query_options)

  post("/smsmessaging/outbound/#{options[:sender_address]}/requests",
       build_query_string(query_options),
       SMSIFIED_HTTP_HEADERS, &blk)
end