lib/cellular/backends/sendega.rb in cellular-1.0.0 vs lib/cellular/backends/sendega.rb in cellular-1.1.0

- old
+ new

@@ -4,11 +4,11 @@ module Backends class Sendega GATEWAY_URL = 'https://smsc.sendega.com/Content.asmx?WSDL' - def self.deliver(options = {}) + def self.deliver(options = {}, savon_options = {}) # Send an SMS and return its initial delivery status code. # # Delivery status codes: # 0 -- Message is received and is being processed. # 1001 -- Not validated @@ -32,36 +32,46 @@ # 9007 -- Demo account empty # # See Gate API Documentation: # http://www.sendega.no/downloads/Sendega%20API%20documentation%20v2.0.pdf - client = Savon.client wsdl: GATEWAY_URL + savon_options[:wsdl] = GATEWAY_URL + client = Savon.client savon_options + result = client.call(:send, message: { username: Cellular.config.username, password: Cellular.config.password, sender: options[:sender], destination: options[:recipient], pricegroup: options[:price] || 0, # default price to 0 contentTypeID: 1, - contentHeader: "", + contentHeader: '', content: options[:message], dlrUrl: Cellular.config.delivery_url, ageLimit: 0, - extID: "", - sendDate: "", - refID: "", + extID: '', + sendDate: '', + refID: '', priority: 0, gwID: 0, pid: 0, dcs: 0 } ) - if result.success? - [ result.body[:error_number], 'Message is received and is being processed.' ] + body = result.body[:send_response][:send_result] + + if body[:success] + [ + body[:error_number].to_i, + 'Message is received and is being processed.' + ] else - [ result.body[:error_number], result.body[:error_message] ] + [ + body[:error_number].to_i, + body[:error_message] + ] end end def self.receive(data) raise NotImplementedError