Class: SmsNotify::Api
- Inherits:
-
Object
- Object
- SmsNotify::Api
- 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
-
#license_key ⇒ Object
Returns the value of attribute license_key.
-
#soap_driver ⇒ Object
Returns the value of attribute soap_driver.
Class Method Summary collapse
-
.endpoint_host ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(license_key, wsdl_url = 'http://ws.cdyne.com/SmsWS/SMS.asmx?wsdl') ⇒ Api
constructor
Examples: api = SmsNotify::Api.new(‘my_secret_license_key’).
-
#message_responses(text_id) ⇒ Object
Implements
GetSMSResponse
[http://ws.cdyne.com/SmsWS/SMS.asmx?op=GetSMSResponse]. -
#message_status(text_id) ⇒ Object
Implements
GetSMSStatus
[http://ws.cdyne.com/SmsWS/SMS.asmx?op=GetSMSStatus]. -
#send_advanced_message(phone_number, message, options = {}) ⇒ Object
Example options = { :enable_responses => true, :deliver_at => Time.now + 60, :status_post_url => ‘foo.com’ }.
-
#send_message(phone_number, message) ⇒ Object
Implements
SendSMSBasic
[http://ws.cdyne.com/SmsWS/SMS.asmx?op=SendSMSBasic].
Constructor Details
#initialize(license_key, wsdl_url = 'http://ws.cdyne.com/SmsWS/SMS.asmx?wsdl') ⇒ Api
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_key ⇒ Object
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_driver ⇒ Object
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_host ⇒ Object
: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.("c7d8a")
121 122 123 124 125 126 127 128 |
# File 'lib/sms_notify/api.rb', line 121 def (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.("c7d8a")
103 104 105 106 107 108 109 110 |
# File 'lib/sms_notify/api.rb', line 103 def (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
= {
:enable_responses => true,
:deliver_at => Time.now + 60,
:status_post_url => 'http://foo.com'
}
@api.('1234567890', 'Affirmative!', )
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 (phone_number, , ={}) # set some default options but let passed in options override them opts = { :enable_responses => false, :deliver_at => Time.now, :status_post_url => '' }.merge() result = soap_driver.sendSMSAdvanced( :Request => { :PhoneNumber => phone_number, :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.('1234567890', 'Hello world')
46 47 48 49 50 51 52 53 |
# File 'lib/sms_notify/api.rb', line 46 def (phone_number, ) command = Command.new('SendSMSBasic', license_key) MessageStatus.new( Response.parse( command.execute({:PhoneNumber => phone_number, :Message => }) )["SmsReturn"] ) end |