lib/smshelper/api/vianett.rb in smshelper-0.4.5 vs lib/smshelper/api/vianett.rb in smshelper-0.4.6
- old
+ new
@@ -1,41 +1,63 @@
module Smshelper
module Api
class Vianett < Base
- base_uri 'http://smsc.vianett.no/V3/CPA/MT'
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
def send_message(message)
uuid = (Digest::CRC32.hexdigest @uuid.generate).unpack('U*').collect {|x| sprintf '%02X', x}.join
options = {
- :destinationaddr => message.recipient,
- :message => message.text,
- :sourceaddr => message.sender,
+ :tel => message.recipient,
+ :msg => message.text,
+ :senderaddress => message.sender,
+ :senderaddresstype => '1',
+ :nrq => '1',
# :refno => '1',
:msgid => uuid}
- options = options.merge(@extra_options) unless @extra_options.nil?
- resp = (post 'MT.ashx', :extra_query => options)
- process_response_code(resp['ack']) ? (@sent_message_ids << uuid; uuid) : (raise ErrorDuringSend, "#{self.class.name} does not implement detailed errors")
+binding.pry
+ 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
def get_balance
- {:fake => :value}
+ {'EUR' => (post 'http://oldsms.vianett.com/files/balancelimit_check.asp').split('|').last}
end
+ # Vianett provides async lookup as well with callbacks
+ def hlr_lookup_synchronous(number)
+ opts = {:phonenumber => number}
+ (get 'http://smsc.vianett.no/v3/cpa/cpawebservice.asmx/SubmitHLR2', :extra_query => opts )['SubmitHLRResponse']
+ end
+ alias_method :hlr_lookup, :hlr_lookup_synchronous
+
def get_status(message_id)
raise NotImplementedError, "Sms status checks unsupported by #{self.class.name}"
end
- private
+ 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
+ private
def process_response_code(code)
- (code == 'OK') ? true : false
+ (code['ack']['__content__'] == 'OK') ? true : false
end
end
end
end