class Tubeclip::OAuthClient

Public Class Methods

new(*params) click to toggle source
# File lib/tubeclip/client.rb, line 405
def initialize *params
  puts "* OAuth 1.0 Client will be deprecated. Use OAuth2 Client."
  if params.first.is_a?(Hash)
    hash_options = params.first
    @consumer_key = hash_options[:consumer_key]
    @consumer_secret = hash_options[:consumer_secret]
    @user = hash_options[:username]
    @dev_key = hash_options[:dev_key]
    @client_id = hash_options[:client_id] || "tubeclip"
    @legacy_debug_flag = hash_options[:debug]
  else
    puts "* warning: the method Tubeclip::OAuthClient.new(consumer_key, consumer_secrect, dev_key) is depricated, use Tubeclip::OAuthClient.new(:consumer_key => 'consumer key', :consumer_secret => 'consumer secret', :dev_key => 'dev_key')"
    @consumer_key = params.shift
    @consumer_secret = params.shift
    @dev_key = params.shift
    @user = params.shift
    @client_id = params.shift || "tubeclip"
    @legacy_debug_flag = params.shift
  end
end

Public Instance Methods

access_token() click to toggle source
# File lib/tubeclip/client.rb, line 438
def access_token
  @access_token = ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
end
authorize_from_access(atoken, asecret) click to toggle source
# File lib/tubeclip/client.rb, line 457
def authorize_from_access(atoken, asecret)
  @atoken, @asecret = atoken, asecret
end
authorize_from_request(rtoken, rsecret, verifier) click to toggle source
# File lib/tubeclip/client.rb, line 451
def authorize_from_request(rtoken, rsecret, verifier)
  request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret)
  access_token = request_token.get_access_token({:oauth_verifier => verifier})
  @atoken, @asecret = access_token.token, access_token.secret
end
config_token() click to toggle source
# File lib/tubeclip/client.rb, line 442
def config_token
  {
      :consumer_key => @consumer_key,
      :consumer_secret => @consumer_secret,
      :token => @atoken,
      :token_secret => @asecret
  }
end
consumer() click to toggle source
# File lib/tubeclip/client.rb, line 426
def consumer
  @consumer ||= ::OAuth::Consumer.new(@consumer_key, @consumer_secret, {
      :site => "https://www.google.com",
      :request_token_path => "/accounts/OAuthGetRequestToken",
      :authorize_path => "/accounts/OAuthAuthorizeToken",
      :access_token_path => "/accounts/OAuthGetAccessToken"})
end
current_user() click to toggle source
# File lib/tubeclip/client.rb, line 461
def current_user
  profile = access_token.get("http://gdata.youtube.com/feeds/api/users/default")
  response_code = profile.code.to_i

  if (response_code / 10).to_i == 20 # success
    Nokogiri::XML(profile.body).at("//yt:username").text
  elsif response_code == 403 || response_code == 401 # auth failure
    raise AuthenticationError.new(profile.inspect, response_code)
  else
    raise UploadError.new(profile.inspect, response_code)
  end
end
request_token(callback) click to toggle source
# File lib/tubeclip/client.rb, line 434
def request_token(callback)
  @request_token = consumer.get_request_token({:oauth_callback => callback}, {:scope => "http://gdata.youtube.com"})
end

Private Instance Methods

client() click to toggle source
# File lib/tubeclip/client.rb, line 476
def client
  # IMPORTANT: make sure authorize_from_access is called before client is fetched
  @client ||= Tubeclip::Upload::VideoUpload.new(:username => current_user, :dev_key => @dev_key, :access_token => access_token, :config_token => config_token)
end