Sha256: afffc27d69d25dcf695d75b093ac7c042d69559d0b75c7fd0835b0ba88427811

Contents?: true

Size: 1.36 KB

Versions: 17

Compression:

Stored size: 1.36 KB

Contents

# -*- coding: utf-8 -*-
module Smshelper
  module Api
    class  Webtext < Base
      base_uri "http://www.webtext.com"
      endpoint "api"

      def initialize(*args)
        config = args.shift
        add_query_options! :api_id => config.webtext[:uname], :api_pwd => config.webtext[:passwd]
        super
      end

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

        if message.utf_8
          message.to_hex_be
          q = {:unicode => '1', :hex => message.text}
        else
          q = {:txt => message.text}
        end

        options = {:dest => message.recipient, :tag => message.sender, :msgid => uuid}
        options = options.merge(@extra_options) unless @extra_options.nil?
        resp = (post "send_text.html", :extra_query => options.merge(q))
        process_response_code(resp.to_s) ? (@sent_message_ids << uuid; uuid) : (raise ErrorDuringSend, @response_code.webtext(resp))
        # :validity => '2'
      end

      def get_balance
        {'EUR' => (post "get_balance.html").to_s.split(':').last.strip}
      end

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

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
smshelper-0.4.12 lib/smshelper/api/webtext.rb
smshelper-0.4.11 lib/smshelper/api/webtext.rb
smshelper-0.4.10 lib/smshelper/api/webtext.rb
smshelper-0.4.9 lib/smshelper/api/webtext.rb
smshelper-0.4.8 lib/smshelper/api/webtext.rb
smshelper-0.4.7 lib/smshelper/api/webtext.rb
smshelper-0.4.6 lib/smshelper/api/webtext.rb
smshelper-0.4.5 lib/smshelper/api/webtext.rb
smshelper-0.4.0 lib/smshelper/api/webtext.rb
smshelper-0.3.1 lib/smshelper/api/webtext.rb
smshelper-0.3.0 lib/smshelper/api/webtext.rb
smshelper-0.2.10 lib/smshelper/api/webtext.rb
smshelper-0.2.9 lib/smshelper/api/webtext.rb
smshelper-0.2.8 lib/smshelper/api/webtext.rb
smshelper-0.2.7 lib/smshelper/api/webtext.rb
smshelper-0.2.6 lib/smshelper/api/webtext.rb
smshelper-0.2.5 lib/smshelper/api/webtext.rb