Module: PgDrive::Uploader
- Defined in:
- lib/pg_drive/uploader.rb
Constant Summary collapse
- Drive =
Google::Apis::DriveV2
- AUTH_SCOPE =
"https://www.googleapis.com/auth/drive".freeze
- RETRY_COUNT =
3
Class Method Summary collapse
- .authorizer ⇒ Object
- .call(pipe) ⇒ Object
- .client_id ⇒ Object
- .credentials ⇒ Object
- .google_key ⇒ Object
- .google_secret ⇒ Object
Class Method Details
.authorizer ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/pg_drive/uploader.rb', line 20 def Google::Auth::UserAuthorizer.new( Uploader.client_id, Uploader::AUTH_SCOPE, nil ) end |
.call(pipe) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/pg_drive/uploader.rb', line 8 def call(pipe) drive = Drive::DriveService.new drive. = credentials app_name = Rails.application.class.parent_name drive.insert_file( Drive::File.new(title: "#{app_name}-#{Time.now.utc.iso8601}.dmp"), upload_source: pipe, content_type: BINARY_MIME_TYPE, options: { retries: RETRY_COUNT } ) end |
.client_id ⇒ Object
28 29 30 |
# File 'lib/pg_drive/uploader.rb', line 28 def client_id Google::Auth::ClientId.new(google_key, google_secret) end |
.credentials ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pg_drive/uploader.rb', line 40 def credentials refresh_token = ENV["PG_DRIVE_CREDENTIALS"] if refresh_token.nil? || refresh_token.empty? raise InvalidEnvironment, MISSING_CRED_WARNING end Google::Auth::UserRefreshCredentials.new( client_id: google_key, client_secret: google_secret, refresh_token: refresh_token, scope: AUTH_SCOPE ) end |
.google_key ⇒ Object
32 33 34 |
# File 'lib/pg_drive/uploader.rb', line 32 def google_key ENV.fetch("PG_DRIVE_GOOGLE_KEY") end |
.google_secret ⇒ Object
36 37 38 |
# File 'lib/pg_drive/uploader.rb', line 36 def google_secret ENV.fetch("PG_DRIVE_GOOGLE_SECRET") end |