Class: Smshelper::Api::Traitel

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

Instance Attribute Summary

Attributes inherited from Base

#extra_options, #sent_message_ids, #sent_message_statuses

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Traitel

headers ‘Accept’ => ‘text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8’, ‘Accept-Language’ => ‘en-us,en;q=0.5’, ‘Accept-Encoding’ => ‘gzip, deflate’, ‘DNT’ => ‘1’, ‘Connection’ => ‘keep-alive’



6
7
8
9
10
# File 'lib/smshelper/api/traitel.rb', line 6

def initialize(*args)
  config = args.shift
  add_query_options! :user => config.traitel[:uname], :pass => config.traitel[:passwd] # "\"#{config.traitel[:passwd]}\""
  super
end

Instance Method Details

#get_balanceObject



31
32
33
# File 'lib/smshelper/api/traitel.rb', line 31

def get_balance
  {'AUD' => (get 'selfserve.pl', :extra_query => {:mode => :balance}).split(' ').last.strip}
end

#get_callback_response(args = {}) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/smshelper/api/traitel.rb', line 39

def get_callback_response(args = {})
    DeliveryReport.new(
                       :message_id => args['tt_id'],
                       :timestamp => Time.now,
                       :delivered => ((args['code'] == '0') ? true : false),
                       :original_params => args
                       )
end

#get_status(message_id) ⇒ Object



35
36
37
# File 'lib/smshelper/api/traitel.rb', line 35

def get_status(message_id)
  raise NotImplementedError, "Sms status checks unsupported by #{self.class.name}"
end

#send_message(message) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/smshelper/api/traitel.rb', line 12

def send_message(message)
  if message.utf_8
    message.to_hex_be
    q = {:unicode => 'true'}
  else
    q = {}
  end
  options = {
    :to => message.recipient,
    :message => message.text,
    :replyto => message.sender,
    :output => :verbose,
    :concatenate => true
  }
  options.merge!(@extra_options) unless @extra_options.nil?
  resp = (get 'smsgateway.pl', :extra_query => options.merge(q))
  process_response_code(resp) ?  (@sent_message_ids << resp.split(',')[2]; resp.split(',')[2]) : (raise ErrorDuringSend "Could not deliver")
end