class Smshelper::Api::Esendex

Constants

ACCOUNT_SERVICE_WSDL
INBOX_SERVICE_WSDL
SEND_SERVICE_WSDL

Attributes

inbox[R]

Public Class Methods

new(*args) click to toggle source
Calls superclass method Smshelper::Api::Base::new
# 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

Public Instance Methods

get_balance() click to toggle source
# 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 = {}) click to toggle source

This expects a sinatra style params.merge(:request_body => request.body.read.to_s)

# 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() click to toggle source
# 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) click to toggle source
# File lib/smshelper/api/esendex.rb, line 53
def get_status(*message_id)
  message_id.flatten!

  client = connect 'message'
  message_id.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) click to toggle source
# File lib/smshelper/api/esendex.rb, line 27
def send_message(message)
  client = connect 'message'
  message.utf_8 ? (message_kind = 'Unicode') : (message_kind = 'Text')
  body = {
    "com:recipient" => message.recipient,
    "com:body" => message.text,
    "com:type" => message_kind,
    "com:originator" => message.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

Private Instance Methods

api(service) click to toggle source
# File lib/smshelper/api/esendex.rb, line 98
def api(service)
  client = Savon::Client.new(service)
  #http://jira.codehaus.org/browse/JRUBY-5529 - jruby-openssl in --1.9 jruby mode
  client.http.auth.ssl.verify_mode=(:none)
  client
end
connect(service) click to toggle source
# File lib/smshelper/api/esendex.rb, line 87
def connect(service)
  case service
  when 'message'
    api SEND_SERVICE_WSDL
  when 'account'
    api ACCOUNT_SERVICE_WSDL
  when 'inbox'
    api INBOX_SERVICE_WSDL
  end
end