Class: YouTubeIt::OAuthClient

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

Instance Method Summary (collapse)

Methods inherited from Client

#activity, #add_comment, #add_favorite, #add_playlist, #add_video_to_playlist, #comments, #delete_favorite, #delete_playlist, #delete_video_from_playlist, #dislike_video, #enable_http_debugging, #favorites, #like_video, #my_contacts, #my_video, #my_videos, #playlist, #playlists, #profile, #subscribe_channel, #subscriptions, #unsubscribe_channel, #update_playlist, #upload_token, #video_by, #video_by_user, #video_delete, #video_update, #video_upload, #videos_by

Methods included from Logging

#logger

Constructor Details

- (OAuthClient) initialize(*params)

A new instance of OAuthClient



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/youtube_it/client.rb', line 302

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

- (Object) access_token



334
335
336
# File 'lib/youtube_it/client.rb', line 334

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

- (Object) authorize_from_access(atoken, asecret)



353
354
355
# File 'lib/youtube_it/client.rb', line 353

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

- (Object) authorize_from_request(rtoken, rsecret, verifier)



347
348
349
350
351
# File 'lib/youtube_it/client.rb', line 347

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

- (Object) config_token



338
339
340
341
342
343
344
345
# File 'lib/youtube_it/client.rb', line 338

def config_token
  {
    :consumer_key => @consumer_key,
    :consumer_secret => @consumer_secret,
    :token => @atoken,
    :token_secret => @asecret
   }
end

- (Object) consumer



322
323
324
325
326
327
328
# File 'lib/youtube_it/client.rb', line 322

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

- (Object) current_user



357
358
359
360
361
362
363
364
365
366
# File 'lib/youtube_it/client.rb', line 357

def current_user
  yt_session = Faraday.new(:url => "http://gdata.youtube.com") do |builder|
    builder.use Faraday::Response::YouTubeIt 
    builder.use Faraday::Request::OAuth, config_token
    builder.adapter Faraday.default_adapter          
  end
  
  body = yt_session.get("/feeds/api/users/default").body
  REXML::Document.new(body).elements["entry"].elements['author'].elements['name'].text
end

- (Object) request_token(callback)



330
331
332
# File 'lib/youtube_it/client.rb', line 330

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