Sha256: 255a996cf83f9ff24f0de853d78a1bf70ea356bfb5955410fb3b0b2d5465620f

Contents?: true

Size: 2 KB

Versions: 9

Compression:

Stored size: 2 KB

Contents

module TwitterAuth
  class Error < StandardError; end

  def self.config(environment=RAILS_ENV)
    @config ||= {}
    @config[environment] ||= YAML.load(File.open(RAILS_ROOT + '/config/twitter_auth.yml').read)[environment]
  end

  def self.base_url
    config['base_url'] || 'https://twitter.com'    
  end

  def self.api_timeout
    config['api_timeout'] || 10
  end

  def self.encryption_key
    raise TwitterAuth::Cryptify::Error, 'You must specify an encryption_key in config/twitter_auth.yml' if config['encryption_key'].blank?
    config['encryption_key'] 
  end

  def self.oauth_callback?
    config.key?('oauth_callback')
  end

  def self.oauth_callback
    config['oauth_callback']
  end

  def self.remember_for
    (config['remember_for'] || 14).to_i
  end

  # The authentication strategy employed by this
  # application. Set in +config/twitter.yml+ as
  # strategy; valid options are oauth or basic.
  def self.strategy
    strat = config['strategy']
    raise ArgumentError, 'Invalid TwitterAuth Strategy: Valid strategies are oauth and basic.' unless %w(oauth basic).include?(strat)
    strat.to_sym
  rescue Errno::ENOENT
    :oauth
  end

  def self.oauth?
    strategy == :oauth
  end

  def self.basic?
    strategy == :basic
  end
  
  # The OAuth consumer used by TwitterAuth for authentication. The consumer key and secret are set in your application's +config/twitter.yml+
  def self.consumer
    OAuth::Consumer.new(
      config['oauth_consumer_key'],          
      config['oauth_consumer_secret'],
      :site => TwitterAuth.base_url
    )
  end

  def self.net
    uri = URI.parse(TwitterAuth.base_url)
    net = Net::HTTP.new(uri.host, uri.port)
    net.use_ssl = uri.scheme == 'https'
    net.read_timeout = TwitterAuth.api_timeout
    net
  end
end

require 'twitter_auth/controller_extensions'
require 'twitter_auth/cryptify'
require 'twitter_auth/dispatcher/oauth'
require 'twitter_auth/dispatcher/basic'
require 'twitter_auth/dispatcher/shared'

class TwitterAuth::Dispatcher::Error < StandardError; end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
mbleigh-twitter-auth-0.1.10 lib/twitter_auth.rb
mbleigh-twitter-auth-0.1.11 lib/twitter_auth.rb
mbleigh-twitter-auth-0.1.12 lib/twitter_auth.rb
mbleigh-twitter-auth-0.1.13 lib/twitter_auth.rb
twitter-auth-0.1.10 lib/twitter_auth.rb
twitter-auth-0.1.11 lib/twitter_auth.rb
twitter-auth-0.1.12 lib/twitter_auth.rb
twitter-auth-0.1.13 lib/twitter_auth.rb
twitter-auth-0.1.9 lib/twitter_auth.rb