Sha256: 852e610c16c32723db2a7fc89dbca1f7a2700c3eb5b091d7c3d03a82dc0a7100

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

module Smshelper
  module Api
    class Mycoolsms < Base
      base_uri 'https://www.my-cool-sms.com/'

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

      def send_message(message)
        options = {
          :number => message.recipient,
          :message => message.text,
          :senderid => message.sender,
          :function => 'sendSms'}
        options = options.merge(@extra_options) unless @extra_options.nil?
        resp = JSON.parse(post 'api-socket.php', :extra_query => options)
        process_response_code(resp) ? (@sent_message_ids << resp['smsid']; resp['smsid']) : (raise ErrorDuringSend, resp)
      end

      def get_balance
        {'EUR' => JSON.parse(post 'api-socket.php', :extra_query => {:function => 'getBalance'})['balance']}
      end

      def hlr_lookup(number)
        JSON.parse(post 'api-socket.php', :extra_query => {:function => 'doHlrLookup', :number => number})
      end

      def get_callback_response(args = {})
        data = JSON.parse args[:request_body]
        DeliveryReport.new(
                           :message_id => data['smsid'],
                           :timestamp => Time.now,
                           :delivered => ((data['status'] == 'SMS_STATUS_DELIVERED') ? true : false),
                           :original_params => args
                           )
      end

      private
      def process_response_code(code)
        code['success']
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
smshelper-0.4.5 lib/smshelper/api/mycoolsms.rb
smshelper-0.4.0 lib/smshelper/api/mycoolsms.rb