Class: Smartcall::Soap::SmsClient
- Inherits:
-
Object
- Object
- Smartcall::Soap::SmsClient
- Defined in:
- lib/smartcall/soap/sms_client.rb
Constant Summary collapse
- WSDL =
"http://www.smartcalltech.co.za/SmsWS/Service.asmx?wsdl"
- RESPONSE_HANDLER =
{ 'Success' => true , 'InvalidSourceAddress' => Proc.new { SmsClient.invalid_source_address_error } , 'InvalidToken' => Proc.new { SmsClient.invalid_token_error } , 'Failed' => false , 'InvalidNumber' => Proc.new { SmsClient.invalid_number_error } }
- @@token =
nil
Class Method Summary collapse
- .invalid_number_error ⇒ Object
- .invalid_source_address_error ⇒ Object
- .invalid_token_error ⇒ Object
- .no_authorisation_error ⇒ Object
- .not_implemented_error ⇒ Object
Instance Method Summary collapse
-
#initialize(username, password, campaign_id, reference) ⇒ SmsClient
constructor
A new instance of SmsClient.
- #send_sms(recipient, message_body) ⇒ Object
Constructor Details
#initialize(username, password, campaign_id, reference) ⇒ SmsClient
Returns a new instance of SmsClient.
36 37 38 39 40 41 42 |
# File 'lib/smartcall/soap/sms_client.rb', line 36 def initialize(username, password, campaign_id, reference) @retry = true @username, @password, @campaign_id, @reference = username, password, campaign_id, reference @client = Savon::Client.new do wsdl.document = WSDL end end |
Class Method Details
.invalid_number_error ⇒ Object
23 24 25 |
# File 'lib/smartcall/soap/sms_client.rb', line 23 def invalid_number_error raise SmartcallError.new("SmsWSErrors: InvalidNumber") end |
.invalid_source_address_error ⇒ Object
19 20 21 |
# File 'lib/smartcall/soap/sms_client.rb', line 19 def invalid_source_address_error raise SmartcallError.new("SmsWSErrors: Invalid Source Address") end |
.invalid_token_error ⇒ Object
15 16 17 |
# File 'lib/smartcall/soap/sms_client.rb', line 15 def invalid_token_error raise TokenExpiredError.new("SmsWSErrors: Invalid Token") end |
.no_authorisation_error ⇒ Object
11 12 13 |
# File 'lib/smartcall/soap/sms_client.rb', line 11 def raise SmartcallError.new("SmsWSErrors: Unable to Login") end |
.not_implemented_error ⇒ Object
27 28 29 |
# File 'lib/smartcall/soap/sms_client.rb', line 27 def not_implemented_error raise SmartcallError.new("SmsWSErrors: Not Implemented") end |
Instance Method Details
#send_sms(recipient, message_body) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/smartcall/soap/sms_client.rb', line 44 def send_sms(recipient, ) debugger retry_count = 0 begin login unless @@token response = @client.request(:send_sms, namespace) do |soap| soap.body = { :token => @@token, :recipient => recipient, :message => , :reference => @reference, :campaignid => @campaign_id } end.to_hash return process_response(RESPONSE_HANDLER[response[:send_sms_response][:send_sms_result]]) rescue TokenExpiredError => e @@token = nil retry_count += 1 retry if retry_count <= 2 raise e end end |