Class: SmsNotify::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/sms_notify/api.rb,
lib/sms_notify/api/command.rb

Overview

Provides the methods that implement each of the operations of the CDYNE SmsNotify! API.

API Spec PDF - www.cdyne.com/downloads/SPECS_SMS-Notify.pdf

API Operations - ws.cdyne.com/SmsWS/SMS.asmx

API WSDL - ws.cdyne.com/SmsWS/SMS.asmx?WSDL

Defined Under Namespace

Classes: Command

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(license_key, wsdl_url = 'http://ws.cdyne.com/SmsWS/SMS.asmx?wsdl') ⇒ Api

Examples:

api = SmsNotify::Api.new('my_secret_license_key')


31
32
33
34
# File 'lib/sms_notify/api.rb', line 31

def initialize(license_key, wsdl_url='http://ws.cdyne.com/SmsWS/SMS.asmx?wsdl')
  @license_key = license_key
			@soap_driver = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver
end

Instance Attribute Details

#license_keyObject

Returns the value of attribute license_key.



15
16
17
# File 'lib/sms_notify/api.rb', line 15

def license_key
  @license_key
end

#soap_driverObject

Returns the value of attribute soap_driver.



15
16
17
# File 'lib/sms_notify/api.rb', line 15

def soap_driver
  @soap_driver
end

Class Method Details

.endpoint_hostObject

:nodoc:



17
18
19
# File 'lib/sms_notify/api.rb', line 17

def self.endpoint_host #:nodoc:
  'ws.cdyne.com/SmsWs/SMS.asmx'
end

Instance Method Details

#message_responses(text_id) ⇒ Object

Implements GetSMSResponse[http://ws.cdyne.com/SmsWS/SMS.asmx?op=GetSMSResponse].

Required Attributes

  • text_id

Returns an array of #MessageStatus objects.

Example:

@api.message_responses("c7d8a")


121
122
123
124
125
126
127
128
# File 'lib/sms_notify/api.rb', line 121

def message_responses(text_id)
  command = Command.new('GetSMSResponse', license_key)
  responses = Response.parse( 
    command.execute({:TextID => text_id}) 
  )["ArrayOfSmsResponse"]["SmsResponse"] || []

			responses.is_a?(Array) ? responses.collect { |r| MessageResponse.new(r) } : MessageResponse.new(responses)
end

#message_status(text_id) ⇒ Object

Implements GetSMSStatus[http://ws.cdyne.com/SmsWS/SMS.asmx?op=GetSMSStatus].

Required Attributes

  • text_id

Returns an #MessageStatus object.

Example:

@api.message_status("c7d8a")


103
104
105
106
107
108
109
110
# File 'lib/sms_notify/api.rb', line 103

def message_status(text_id)
  command = Command.new('GetSMSStatus', license_key)
  MessageStatus.new(
    Response.parse(
      command.execute({:TextID => text_id})
    )["SmsReturn"]
  )
end

#send_advanced_message(phone_number, message, options = {}) ⇒ Object

Example

options = { 
  :enable_responses => true, 
  :deliver_at       => Time.now + 60, 
  :status_post_url  => 'http://foo.com' 
}

@api.send_advanced_message('1234567890', 'Affirmative!', options)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/sms_notify/api.rb', line 74

def send_advanced_message(phone_number, message, options={})
    # set some default options but let passed in options override them
	opts = {
		:enable_responses => false, 
		:deliver_at       => Time.now,
		:status_post_url  => ''
	}.merge(options) 

	result = soap_driver.sendSMSAdvanced( :Request => {
		:PhoneNumber			=> phone_number,
		:Message					=> message,
		:Licensekey				=> license_key,
		:ScheduledTime		=> opts[:deliver_at].utc.xmlschema(2),
		:Response					=> opts[:enable_responses] ? 1 : 0,
		:ResponsePostURL	=> opts[:status_post_url]
		}
	)
    MessageStatus.new(Response.parse(result))
end

#send_message(phone_number, message) ⇒ Object

Implements SendSMSBasic[http://ws.cdyne.com/SmsWS/SMS.asmx?op=SendSMSBasic].

Required Attributes

  • phone_number

  • message

Returns an #MessageStatus object.

Example:

api.send_message('1234567890', 'Hello world')


46
47
48
49
50
51
52
53
# File 'lib/sms_notify/api.rb', line 46

def send_message(phone_number, message)
  command = Command.new('SendSMSBasic', license_key)
  MessageStatus.new(
    Response.parse(
      command.execute({:PhoneNumber => phone_number, :Message => message})
    )["SmsReturn"]
  )
end