Class: Smshelper::Api::Vianett

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

Instance Attribute Summary

Attributes inherited from Base

#extra_options, #sent_message_ids, #sent_message_statuses

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Vianett

Returns a new instance of Vianett.



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

def initialize(*args)
  config = args.shift
  add_query_options! :username => config.vianett[:uname], :password => config.vianett[:passwd]
  add_request_options! :skip_endpoint => true
  super
end

Instance Method Details

#get_balanceObject



28
29
30
# File 'lib/smshelper/api/vianett.rb', line 28

def get_balance
  {'EUR' => (post 'http://oldsms.vianett.com/files/balancelimit_check.asp').split('|').last}
end

#get_callback_response(args = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/smshelper/api/vianett.rb', line 43

def get_callback_response(args = {})
  if args['requesttype'] == 'notificationstatus'
    DeliveryReport.new(
                       :message_id => args['refno'],
                       :timestamp => Time.parse(args['now']),
                       :delivered => ((args['Status'] == 'DELIVRD') ? true : false),
                       :original_params => args
                       )
  else
    UnknownReply.new(args)
  end
end

#get_status(message_id) ⇒ Object



39
40
41
# File 'lib/smshelper/api/vianett.rb', line 39

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

#hlr_lookup_synchronous(number) ⇒ Object Also known as: hlr_lookup

Vianett provides async lookup as well with callbacks



33
34
35
36
# File 'lib/smshelper/api/vianett.rb', line 33

def hlr_lookup_synchronous(number)
  opts = {:phonenumber => number}
  (get 'http://smsc.vianett.no/v3/cpa/cpawebservice.asmx/SubmitHLR2', :extra_query => opts )['SubmitHLRResponse']
end

#send_message(message) ⇒ Object



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

def send_message(message)
  uuid = (Digest::CRC32.hexdigest @uuid.generate).unpack('U*').collect {|x| sprintf '%02X', x}.join

  options = {
    :tel => message.recipient,
    :msg => message.text,
    :senderaddress => message.sender,
    :senderaddresstype => '1',
    :nrq => '1',
    # :refno => '1',
    :msgid => uuid}
  options.merge!(@extra_options) unless @extra_options.nil?
  resp = (post 'http://smsc.vianett.no/V3/CPA/MT/MT.ashx', :extra_query => options)
  process_response_code(resp) ? (@sent_message_ids << uuid; uuid) : (raise ErrorDuringSend, "#{self.class.name} does not implement detailed error reporting - #{resp}")
end