Sha256: ed0582c486d7dba71fdd7412af8dcaac52b577992a09970e66d56bdd7772cabb

Contents?: true

Size: 1.7 KB

Versions: 9

Compression:

Stored size: 1.7 KB

Contents

module Smshelper
  module Api
    class Mediaburst < Base
      base_uri 'https://api.mediaburst.co.uk/http'

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

      def send_message(message)
        #TODO: rewrite Mediaburst::API.process_response to provide
        #full response data, so that msg_id could be had in @sent_message_ids
        message.utf_8 ? (q = {:msgtype => 'ucs2'}) : (q = {:msgtype => 'text'})
        options = {
          :to => message.recipient,
          :content => message.text,
          :concat => '3',
          :from => message.sender}
        options = options.merge(@extra_options) unless @extra_options.nil?
        resp = (post 'send.aspx', :extra_query => options.merge(q)).to_s.split(' ').last.strip
        process_response_code(resp) ? resp.to_s : (raise ErrorDuringSend, "#{self.class.name} does not provide detailed response codes")
      end

      def get_balance
        {'Messages' => (post 'credit.aspx').split(' ').last}
      end

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

      def get_callback_response(args = {})
        DeliveryReport.new(
                           :message_id => args['msg_id'],
                           :timestamp => Time.now,
                           :delivered => ((args['status'] =~ /DELIVRD/) ? true : false),
                           :original_params => args
                           )
      end


      private
      def process_response_code(code)
        (code =~ /Error/) ? false : true
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
smshelper-0.4.12 lib/smshelper/api/mediaburst.rb
smshelper-0.4.11 lib/smshelper/api/mediaburst.rb
smshelper-0.4.10 lib/smshelper/api/mediaburst.rb
smshelper-0.4.9 lib/smshelper/api/mediaburst.rb
smshelper-0.4.8 lib/smshelper/api/mediaburst.rb
smshelper-0.4.7 lib/smshelper/api/mediaburst.rb
smshelper-0.4.6 lib/smshelper/api/mediaburst.rb
smshelper-0.4.5 lib/smshelper/api/mediaburst.rb
smshelper-0.4.0 lib/smshelper/api/mediaburst.rb