Class: Tubeclip::OAuthClient
Instance Method Summary
collapse
Methods inherited from Client
#activity, #add_comment, #add_favorite, #add_playlist, #add_response, #add_video_to_playlist, #add_video_to_watchlater, #all_playlists, #captions_update, #comments, #delete_comment, #delete_favorite, #delete_playlist, #delete_response, #delete_video_from_playlist, #delete_video_from_watchlater, #dislike_video, #enable_http_debugging, #favorites, #get_all_videos, #like_video, #message_delete, #my_contacts, #my_messages, #my_video, #my_videos, #new_subscription_videos, #playlist, #playlists, #profile, #profiles, #send_message, #subscribe_channel, #subscriptions, #unsubscribe_channel, #update_playlist, #update_position_video_from_playlist, #upload_token, #video_by, #video_by_user, #video_delete, #video_partial_update, #video_update, #video_upload, #videos, #videos_by, #watch_history, #watchlater
Methods included from Logging
#logger
Constructor Details
#initialize(*params) ⇒ OAuthClient
Returns a new instance of OAuthClient.
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
|
# 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
|
Instance Method Details
#access_token ⇒ Object
438
439
440
|
# File 'lib/tubeclip/client.rb', line 438
def access_token
@access_token = ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
end
|
#authorize_from_access(atoken, asecret) ⇒ Object
457
458
459
|
# File 'lib/tubeclip/client.rb', line 457
def authorize_from_access(atoken, asecret)
@atoken, @asecret = atoken, asecret
end
|
#authorize_from_request(rtoken, rsecret, verifier) ⇒ Object
451
452
453
454
455
|
# 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 ⇒ Object
442
443
444
445
446
447
448
449
|
# 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 ⇒ Object
426
427
428
429
430
431
432
|
# 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 ⇒ Object
461
462
463
464
465
466
467
468
469
470
471
472
|
# 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 Nokogiri::XML(profile.body).at("//yt:username").text
elsif response_code == 403 || response_code == 401 raise AuthenticationError.new(profile.inspect, response_code)
else
raise UploadError.new(profile.inspect, response_code)
end
end
|
#request_token(callback) ⇒ Object
434
435
436
|
# 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
|