Sha256: 9ea7a894edb9e87f41cbdf1b9f8dfbe5993decef26ee9f1913a9c29bebf500c9

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require 'oauth'

module Rlyeh
  module DeepOnes
    module Auth
      class OAuth < Rlyeh::DeepOnes::Auth::Base
        attr_accessor :consumer_key, :consumer_secret, :client_options
        attr_accessor :open_timeout, :read_timeout
        attr_accessor :authorize_params, :request_params
        attr_reader :access_token

        def initialize(app, consumer_key, consumer_secret, client_options = {})
          @consumer_key = consumer_key
          @consumer_secret = consumer_secret
          @client_options = client_options
          @open_timeout = nil
          @read_timeout = nil
          @authorize_params = {}
          @request_params = {}
          super app
        end

        def consumer
          consumer = ::OAuth::Consumer.new @consumer_key, @consumer_secret, @client_options
          consumer.http.open_timeout = @open_timeout if @open_timeout
          consumer.http.read_timeout = @read_timeout if @read_timeout
          consumer
        end

        def try(env)
          welcome env
          request_phase env
        end

        def request_phase(env)
          request_token = consumer.get_request_token @request_params

          talk env, 'Access this URL get the PIN and paste it here.'
          talk env, request_token.authorize_url(@authorize_params)
        end

        protected

        def sender_nick
          '$oauth'
        end

        def talk(env, text)
          target = Target.new env, @nick
          target.privmsg text, sender_nick
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rlyeh-0.1.1 lib/rlyeh/deep_ones/auth/oauth.rb