Sha256: 8af2e4f8b943effcc9283237d9307ea73d4640b4cc166eeda2c7e7875f9122bd

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module Twitter
  class OAuth
    extend Forwardable
    def_delegators :access_token, :get, :post
    
    attr_reader :ctoken, :csecret, :consumer_options
    
    # Options
    #   :sign_in => true to just sign in with twitter instead of doing oauth authorization
    #               (http://apiwiki.twitter.com/Sign-in-with-Twitter)
    def initialize(ctoken, csecret, options={})
      @ctoken, @csecret, @consumer_options = ctoken, csecret, {}
      
      if options[:sign_in]
        @consumer_options[:authorize_path] =  '/oauth/authenticate'
      end
    end
    
    def consumer
      @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => 'http://twitter.com'}.merge(consumer_options))
    end
    
    def request_token(callback_url=nil)
      @request_token ||= consumer.get_request_token(:oauth_callback => callback_url)
    end
    
    def authorize_from_request(rtoken, rsecret)
      request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret)
      access_token = request_token.get_access_token
      @atoken, @asecret = access_token.token, access_token.secret
    end
    
    def access_token
      @access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
    end
    
    def authorize_from_access(atoken, asecret)
      @atoken, @asecret = atoken, asecret
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ddollar-twitter-0.7.0 lib/twitter/oauth.rb