class Smshelper::Api::Vianett
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Smshelper::Api::Base::new
# 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
Public Instance Methods
get_balance()
click to toggle source
# 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 = {})
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
Vianett
provides async lookup as well with callbacks
# 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
Also aliased as: hlr_lookup
send_message(message)
click to toggle source
# 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
Private Instance Methods
process_response_code(code)
click to toggle source
# File lib/smshelper/api/vianett.rb, line 57 def process_response_code(code) (code['ack']['__content__'] == 'OK') ? true : false end