class Tubeclip::OAuth2Client

Public Class Methods

new(options) click to toggle source
# File lib/tubeclip/client.rb, line 484
def initialize(options)
  @client_id = options[:client_id]
  @client_secret = options[:client_secret]
  @client_access_token = options[:client_access_token]
  @client_refresh_token = options[:client_refresh_token]
  @client_token_expires_at = options[:client_token_expires_at]
  @dev_key = options[:dev_key]
  @legacy_debug_flag = options[:debug]
end

Public Instance Methods

access_token() click to toggle source
# File lib/tubeclip/client.rb, line 503
def access_token
  @access_token ||= ::OAuth2::AccessToken.new(oauth_client, @client_access_token, :refresh_token => @client_refresh_token, :expires_at => @client_token_expires_at)
end
current_user() click to toggle source
# File lib/tubeclip/client.rb, line 522
def current_user
  profile = access_token.get("http://gdata.youtube.com/feeds/api/users/default")
  response_code = profile.status

  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
oauth_client() click to toggle source
# File lib/tubeclip/client.rb, line 494
def oauth_client
  options = {:site => "https://accounts.google.com",
    :authorize_url => '/o/oauth2/auth',
    :token_url => '/o/oauth2/token'
   }
  options.merge(:connection_opts => @connection_opts) if @connection_opts
  @oauth_client ||= ::OAuth2::Client.new(@client_id, @client_secret, options)
end
refresh_access_token!() click to toggle source
# File lib/tubeclip/client.rb, line 507
def refresh_access_token!
  new_access_token = access_token.refresh!
  require 'thread' unless Thread.respond_to?(:exclusive)
  Thread.exclusive do
    @access_token = new_access_token
    @client = nil
  end
  @access_token
end
session_token_info() click to toggle source
# File lib/tubeclip/client.rb, line 517
def session_token_info
  response = Faraday.get("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=#{@client_access_token}")
  {:code => response.status, :body => response.body }
end

Private Instance Methods

client() click to toggle source
# File lib/tubeclip/client.rb, line 537
def client
  @client ||= Tubeclip::Upload::VideoUpload.new(:username => current_user, :access_token => access_token, :dev_key => @dev_key)
end