Sha256: 19837bd379fb40815bfd7c5c2a8c4abd67ad4165136b7032578f9b66e8f620fd

Contents?: true

Size: 1.25 KB

Versions: 10

Compression:

Stored size: 1.25 KB

Contents

module Smshelper
  module Api
    class Smstrade < Base
      base_uri 'http://gateway.smstrade.de'

      def initialize(*args)
        config = args.shift
        add_query_options! :key => config.smstrade[:api_key]
        super
      end

      def send_message(message)

        if message.utf_8
          message.to_hex_be
          q = {:messagetype => 'unicode',  :concat => '1', :message_id => '1'}
        else
          q = {:concat => '1', :message_id => '1'}
        end

        options = {
          :to => message.recipient,
          :message => message.text,
          :from => message.sender}
        options = options.merge(@extra_options) unless @extra_options.nil?
        resp = (post '', :extra_query => options.merge(q)).split(/\n/)
        process_response_code(resp.first) ? (@sent_message_ids << resp.last; resp.last) : (raise ErrorDuringSend, @response_code.smstrade(resp.first))
      end

      def get_balance
        resp = (post 'credits')
        {'EUR' => resp.parsed_response}
      end

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

      private
      def process_response_code(code)
        (code == '100') ? true : false
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
smshelper-0.3.1 lib/smshelper/api/smstrade.rb
smshelper-0.3.0 lib/smshelper/api/smstrade.rb
smshelper-0.2.10 lib/smshelper/api/smstrade.rb
smshelper-0.2.9 lib/smshelper/api/smstrade.rb
smshelper-0.2.8 lib/smshelper/api/smstrade.rb
smshelper-0.2.7 lib/smshelper/api/smstrade.rb
smshelper-0.2.6 lib/smshelper/api/smstrade.rb
smshelper-0.2.5 lib/smshelper/api/smstrade.rb
smshelper-0.2.4 lib/smshelper/api/smstrade.rb
smshelper-0.2.3 lib/smshelper/api/smstrade.rb