Sha256: d453281696317bc60b01403db29fc437b13fd1fd9201e1d898683fd9a5b6ec85
Contents?: true
Size: 1.38 KB
Versions: 2
Compression:
Stored size: 1.38 KB
Contents
require 'googleauth' require 'googleauth/stores/file_token_store' require 'fileutils' require 'google/apis/youtube_v3' YOUTUBE_TIMEOUT_SEC = 12000 GOOGLE_CREDENTIAL_STORE = ENV['GOOGLE_CREDENTIAL_STORE'] or abort "GOOGLE_CREDENTIAL_STORE needed" GOOGLE_CLIENT_ID = ENV['GOOGLE_CLIENT_ID'] or abort "GOOGLE_CLIENT_ID needed" GOOGLE_CLIENT_SECRET = ENV['GOOGLE_CLIENT_SECRET'] or abort "GOOGLE_CLIENT_SECRET needed" def google_youtube(cb_uri, user_id, &blk) Google::Apis::YoutubeV3::YouTubeService.new.tap do |youtube| FileUtils.mkdir_p File.dirname GOOGLE_CREDENTIAL_STORE authorizer = Google::Auth::UserAuthorizer.new( Google::Auth::ClientId.new(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET), Google::Apis::YoutubeV3::AUTH_YOUTUBE, Google::Auth::Stores::FileTokenStore.new(file: GOOGLE_CREDENTIAL_STORE) ) youtube.client_options.send_timeout_sec = youtube.client_options.open_timeout_sec = youtube.client_options.read_timeout_sec = YOUTUBE_TIMEOUT_SEC youtube.authorization = if (credentials = authorizer.get_credentials(user_id)) credentials else fail "Internal: Needs auth'n procedure block" unless block_given? code = yield(authorizer.get_authorization_url base_url: cb_uri) authorizer.get_and_store_credentials_from_code( user_id: user_id, code: code, base_url: cb_uri) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ffmprb-0.12.2 | exp/youtubby/google_youtube.rb |
ffmprb-0.12.1 | exp/youtubby/google_youtube.rb |