Sha256: afdeb39a11d53d8f683a9c2922272921480401ff9b3e5495d299f5e29eef8aaf

Contents?: true

Size: 851 Bytes

Versions: 1

Compression:

Stored size: 851 Bytes

Contents

module T
  module Authorizable

    DEFAULT_HOST = 'api.twitter.com'
    DEFAULT_PROTOCOL = 'https'

  private

    def base_url
      "#{protocol}://#{host}"
    end

    def consumer
      require 'oauth'
      OAuth::Consumer.new(
        options['consumer-key'],
        options['consumer-secret'],
        :site => base_url
      )
    end

    def generate_authorize_url(request_token)
      request = consumer.create_signed_request(:get, consumer.authorize_path, request_token, pin_auth_parameters)
      params = request['Authorization'].sub(/^OAuth\s+/, '').split(/,\s+/).map do |param|
        key, value = param.split('=')
        value =~ /"(.*?)"/
        "#{key}=#{CGI::escape($1)}"
      end.join('&')
      "#{base_url}#{request.path}?#{params}"
    end

    def pin_auth_parameters
      {:oauth_callback => 'oob'}
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
t-0.9.8 lib/t/authorizable.rb