class Smshelper::Api::Bulksms

Public Class Methods

new(*args) click to toggle source
Calls superclass method Smshelper::Api::Base::new
# File lib/smshelper/api/bulksms.rb, line 6
def initialize(*args)
  config = args.shift
  add_query_options! :username => config.bulksms[:uname], :password => config.bulksms[:passwd]
  super
end

Public Instance Methods

get_balance() click to toggle source
# File lib/smshelper/api/bulksms.rb, line 29
def get_balance
  {'Credits' => (post 'eapi/user/get_credits/1/1.1').split('|').last.chomp}
end
get_callback_response(args = {}) click to toggle source
# File lib/smshelper/api/bulksms.rb, line 44
def get_callback_response(args = {})
    DeliveryReport.new(
                       :message_id => args['batch_id'],
                       :timestamp => Time.now,
                       :delivered => ((args['status'] == '11') ? true : false),
                       :status => @response_code.bulksms(args['status']),
                       :original_params => args
                       )
end
get_status(message_id) click to toggle source
# File lib/smshelper/api/bulksms.rb, line 33
def get_status(message_id)
  options = {:batch_id => message_id}
  resp = (post 'eapi/status_reports/get_report/2/2.0', :extra_query => options)
  @sent_message_statuses[message_id] = []
  resp.split(/\n\n/).last.split(/\n/).each_with_index do |status, index|
    status = status.split('|').last
    @sent_message_statuses[message_id] << {"part #{index}" => @response_code.bulksms(status)}
  end
  {message_id => @sent_message_statuses[message_id]}
end
send_message(message) click to toggle source
# File lib/smshelper/api/bulksms.rb, line 12
def send_message(message)
  if message.utf_8
    message.to_hex_be
    q = {:dca => '16bit'}
  else
    q = {:allow_concat_text_sms => '1', :concat_text_sms_max_parts => '5'}
  end

  options = {
    :msisdn => message.recipient,
    :message => message.text,
    :sender => message.sender}
  options.merge!(@extra_options) unless @extra_options.nil?
  resp = (post 'eapi/submission/send_sms/2/2.0', :extra_query => options.merge(q)).split('|')
  process_response_code(resp.first) ? (@sent_message_ids << resp.last.strip; resp.last.strip) : (raise ErrorDuringSend, @response_code.bulksms(resp.first))
end

Private Instance Methods

process_response_code(code) click to toggle source
# File lib/smshelper/api/bulksms.rb, line 55
def process_response_code(code)
  (code == '0') ? true : false
end