Class: Smartcall::Soap::SmsClient

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_errorObject

Raises:



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_errorObject

Raises:



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_errorObject

Raises:



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_errorObject

Raises:



11
12
13
# File 'lib/smartcall/soap/sms_client.rb', line 11

def no_authorisation_error  
  raise SmartcallError.new("SmsWSErrors: Unable to Login")
end

.not_implemented_errorObject

Raises:



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, message_body)
  debugger
  retry_count = 0
  begin
     unless @@token
    response = @client.request(:send_sms, namespace) do |soap|
      soap.body = {
        :token => @@token,
        :recipient => recipient,
        :message => message_body,
        :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