lib/sms_notify/api.rb in cdyne-sms-notify-0.8.5 vs lib/sms_notify/api.rb in cdyne-sms-notify-0.9.6
- old
+ new
@@ -1,5 +1,8 @@
+require 'soap/wsdlDriver'
+require 'time'
+
module SmsNotify
# Provides the methods that implement each of
# the operations of the CDYNE SmsNotify! API.
#
@@ -7,25 +10,29 @@
#
# API Operations - http://ws.cdyne.com/SmsWS/SMS.asmx
#
# API WSDL - http://ws.cdyne.com/SmsWS/SMS.asmx?WSDL
class Api
- attr_accessor :license_key
+ attr_accessor :license_key, :soap_driver
def self.endpoint_host #:nodoc:
'ws.cdyne.com/SmsWs/SMS.asmx'
end
# Create a new API instance.
#
# == Required Attributes
# * license_key
#
+ # == Optional Attributes
+ # * wsdl_url
+ #
# == Examples:
# api = SmsNotify::Api.new('my_secret_license_key')
- def initialize(license_key)
+ 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
# Implements +SendSMSBasic+[http://ws.cdyne.com/SmsWS/SMS.asmx?op=SendSMSBasic].
#
# == Required Attributes
@@ -43,10 +50,38 @@
command.execute({:PhoneNumber => phone_number, :Message => message})
)[:sms_return]
)
end
+ # Implements +SendSMSAdvanced+[http://ws.cdyne.com/SmsWS/SMS.asmx?op=SendSMSAdvanced].
+ #
+ # == Required Attributes
+ # * phone_number
+ # * message
+ #
+ # == Optional Attributes
+ # * scheduled_time
+ # * response
+ # * response_post_url
+ def send_advanced_message(phone_number, message, options={})
+ opts = {
+ :response => false,
+ :scheduled_time => Time.now,
+ :response_post_url => ''
+ }.merge(options)
+
+ soap_driver.sendSMSAdvanced( :Request => {
+ :PhoneNumber => phone_number,
+ :Message => message,
+ :Licensekey => license_key,
+ :ScheduledTime => opts[:scheduled_time].utc.xmlschema(2),
+ :Response => opts[:response],
+ :ResponsePostURL => opts[:response_post_url]
+ }
+ )
+ end
+
# Implements +GetSMSStatus+[http://ws.cdyne.com/SmsWS/SMS.asmx?op=GetSMSStatus].
#
# == Required Attributes
# * text_id
#
@@ -72,12 +107,11 @@
#
# == Example:
# @api.message_response("c7d8a")
def message_responses(text_id)
command = Command.new('GetSMSResponse', license_key)
- Response.parse( command.execute({:TextID => text_id}) )["ArrayOfSmsResponse"]["SmsResponse"].collect { |r|
- MessageResponse.new( r )
- }
+ responses = Response.parse( command.execute({:TextID => text_id}) )["ArrayOfSmsResponse"]["SmsResponse"]
+ responses.is_a?(Array) ? responses.collect { |r| MessageResponse.new(r) } : MessageResponse.new(responses)
end
Dir.glob(File.join(File.dirname(__FILE__), '/api/*')).each do |lib|
require lib
end