Sha256: bb2f7f2a53a05ecb92c310a655a9e7eb1041cea74c1cb6933957aa4360781090

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

module Smshelper
  module Api
    class Nexmo < Base
      base_uri 'http://rest.nexmo.com'
      headers 'Accept' => 'application/json'

      def initialize(*args)
        config = args.shift
        @uname, @passwd = config.nexmo[:uname], config.nexmo[:passwd]
        super
      end

      def send_message(message)
        message.utf_8 ? (q = {:type => 'unicode'}) : (q = {:type => 'text'})

        options = {
          :username => @uname,
          :password => @passwd,
          :to => message.recipient,
          :text => message.text,
          :from => message.sender}
        options = options.merge(@extra_options) unless @extra_options.nil?
        options = options.merge(q)
        resp = (post 'sms/json', :extra_query => options)
        resp
        # process_response_code(resp.first) ? (@sent_message_ids << resp.last.strip; resp.last.strip) : (raise ErrorDuringSend, @response_code.nexmo(resp.first))
      end

      def get_balance
        {'EUR' => (get "account/get-balance/#{@uname}/#{@passwd}").values.last.to_s}
      end

      def get_status(message_id)
      end

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

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
smshelper-0.2.2 lib/smshelper/api/nexmo.rb
smshelper-0.2.1 lib/smshelper/api/nexmo.rb
smshelper-0.2.0 lib/smshelper/api/nexmo.rb
smshelper-0.1.3 lib/smshelper/api/nexmo.rb