Class: Smshelper::Api::Esendex
- Defined in:
- lib/smshelper/api/esendex.rb
Constant Summary collapse
- INBOX_SERVICE_WSDL =
'https://www.esendex.com/secure/messenger/soap/InboxService.asmx?wsdl'
- SEND_SERVICE_WSDL =
'https://www.esendex.com/secure/messenger/soap/SendService.asmx?wsdl'
- ACCOUNT_SERVICE_WSDL =
'https://www.esendex.com/secure/messenger/soap/AccountService.asmx?wsdl'
Instance Attribute Summary collapse
-
#inbox ⇒ Object
readonly
Returns the value of attribute inbox.
Attributes inherited from Base
#extra_options, #sent_message_ids, #sent_message_statuses
Instance Method Summary collapse
- #get_balance ⇒ Object
-
#get_callback_response(args = {}) ⇒ Object
This expects a sinatra style params.merge(:request_body => request.body.read.to_s).
- #get_inbox ⇒ Object
- #get_status(*message_id) ⇒ Object
-
#initialize(*args) ⇒ Esendex
constructor
A new instance of Esendex.
- #send_message(message) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Esendex
Returns a new instance of Esendex.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/smshelper/api/esendex.rb', line 10 def initialize(*args) config = args.shift @header = { "com:Username" => config.esendex[:uname], "com:Password" => config.esendex[:passwd], "com:Account" => config.esendex[:acc]} Savon.configure do |config| config.raise_errors = true config.log = false config.log_level = :debug HTTPI.log = false end @inbox = Array.new super end |
Instance Attribute Details
#inbox ⇒ Object (readonly)
Returns the value of attribute inbox.
9 10 11 |
# File 'lib/smshelper/api/esendex.rb', line 9 def inbox @inbox end |
Instance Method Details
#get_balance ⇒ Object
47 48 49 50 51 |
# File 'lib/smshelper/api/esendex.rb', line 47 def get_balance client = connect 'account' resp = client.request(:com, :get_message_limit) {|soap| soap.header["com:MessengerHeader"] = @header} {'Messages' => resp.to_hash[:get_message_limit_response][:get_message_limit_result].to_s} end |
#get_callback_response(args = {}) ⇒ Object
This expects a sinatra style params.merge(:request_body => request.body.read.to_s)
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/smshelper/api/esendex.rb', line 64 def get_callback_response(args = {}) if args['notificationType'] == 'MessageReceived' InboundMessage.new( :message_id => args['id'], :sender => args['originator'], :recipient => args['recipient'], :text => args['body'], :timestamp => Time.now, :original_params => args ) elsif args['notificationType'] == 'MessageEvent' DeliveryReport.new( :message_id => args['id'], :timestamp => Time.now, :delivered => ((args['eventType'] == 'Delivered') ? true : false), :original_params => args ) else UnknownReply.new(args) end end |
#get_inbox ⇒ Object
41 42 43 44 45 |
# File 'lib/smshelper/api/esendex.rb', line 41 def get_inbox client = connect 'inbox' resp = client.request(:com, :get_messages) {|soap| soap.header["com:MessengerHeader"] = @header} @inbox = resp[:get_messages_response][:get_messages_result][:message] end |
#get_status(*message_id) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/smshelper/api/esendex.rb', line 53 def get_status(*) .flatten! client = connect 'message' .each do |id| resp = client.request(:com, :get_message_status) {|soap| soap.header["com:MessengerHeader"] = @header; soap.body = {"com:id" => id.to_s}} @sent_message_statuses[id] = resp.to_hash[:get_message_status_response][:get_message_status_result] end end |
#send_message(message) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/smshelper/api/esendex.rb', line 27 def () client = connect 'message' .utf_8 ? ( = 'Unicode') : ( = 'Text') body = { "com:recipient" => .recipient, "com:body" => .text, "com:type" => , "com:originator" => .sender} body = body.merge(@extra_options) unless @extra_options.nil? resp = client.request(:com, :send_message_full) {|soap| soap.header["com:MessengerHeader"] = @header; soap.body = body} @sent_message_ids << resp.to_hash[:send_message_full_response][:send_message_full_result] resp.to_hash[:send_message_full_response][:send_message_full_result] end |