Class: Smshelper::Api::Bulksms

Inherits:
Base
  • Object
show all
Defined in:
lib/smshelper/api/bulksms.rb

Instance Attribute Summary

Attributes inherited from Base

#extra_options, #sent_message_ids, #sent_message_statuses

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Bulksms

Returns a new instance of Bulksms.



6
7
8
9
10
# 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

Instance Method Details

#get_balanceObject



29
30
31
# 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 = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
# 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) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# 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) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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