Class: YouTubeIt::OAuthClient

Inherits:
Client
  • Object
show all
Defined in:
lib/youtube_it/client.rb

Instance Method Summary collapse

Methods inherited from Client

#add_comment, #add_favorite, #add_playlist, #add_video_to_playlist, #comments, #delete_favorite, #delete_playlist, #delete_video_from_playlist, #enable_http_debugging, #favorites, #playlist, #playlists, #playlists_for, #update_playlist, #upload_token, #video_by, #video_by_user, #video_delete, #video_update, #video_upload, #videos_by

Methods included from Logging

#logger

Constructor Details

#initialize(*params) ⇒ OAuthClient

Returns a new instance of OAuthClient.



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/youtube_it/client.rb', line 259

def initialize *params
  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] || "youtube_it"
    @legacy_debug_flag             = hash_options[:debug]
  else
    puts "* warning: the method YouTubeIt::OAuthClient.new(consumer_key, consumer_secrect, dev_key) is depricated, use YouTubeIt::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 || "youtube_it"
    @legacy_debug_flag             = params.shift
  end
end

Instance Method Details

#access_tokenObject



291
292
293
# File 'lib/youtube_it/client.rb', line 291

def access_token
  @access_token = ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
end

#authorize_from_access(atoken, asecret) ⇒ Object



301
302
303
# File 'lib/youtube_it/client.rb', line 301

def authorize_from_access(atoken,asecret)
  @atoken,@asecret = atoken, asecret
end

#authorize_from_request(rtoken, rsecret, verifier) ⇒ Object



295
296
297
298
299
# File 'lib/youtube_it/client.rb', line 295

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

#consumerObject



279
280
281
282
283
284
285
# File 'lib/youtube_it/client.rb', line 279

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_userObject



305
306
307
308
# File 'lib/youtube_it/client.rb', line 305

def current_user
  body = access_token.get("http://gdata.youtube.com/feeds/api/users/default").body
  REXML::Document.new(body).elements["entry"].elements['author'].elements['name'].text
end

#request_token(callback) ⇒ Object



287
288
289
# File 'lib/youtube_it/client.rb', line 287

def request_token(callback)
  @request_token = consumer.get_request_token({:oauth_callback => callback},{:scope => "http://gdata.youtube.com"})
end