Sha256: 033ea8565bc7cde51a8f70a7777c5325e505b5ec8a70397df89f7ce03e756b90

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 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 process_response_code(code)
        code['success']
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
smshelper-0.3.1 lib/smshelper/api/mycoolsms.rb
smshelper-0.3.0 lib/smshelper/api/mycoolsms.rb