Class: ReqresRspec::Uploader::GoogleDrive

Inherits:
Object
  • Object
show all
Defined in:
lib/reqres_rspec/uploaders/google_drive.rb

Overview

You can find more detailed information here github.com/gimite/google-drive-ruby

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGoogleDrive

Returns a new instance of GoogleDrive.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/reqres_rspec/uploaders/google_drive.rb', line 8

def initialize
  @path     = ReqresRspec.configuration.output_path
  @logger   = ReqresRspec.logger

  client = Google::APIClient.new
  auth = client.authorization
  auth.client_id = ENV['GOOGLE_CLIENT_ID']
  auth.client_secret = ENV['GOOGLE_CLIENT_SECRET']
  auth.scope = [
      'https://www.googleapis.com/auth/drive',
      'https://spreadsheets.google.com/feeds/'
  ]
  auth.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob'
  puts("\n\n1. Open this page:\n%s\n\n" % auth.authorization_uri)
  puts('2. Enter the authorization code shown in the page: ')
  auth.code = $stdin.gets.chomp
  auth.fetch_access_token!
  access_token = auth.access_token
  @session = GoogleDrive::GoogleDrive.(access_token)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



29
30
31
# File 'lib/reqres_rspec/uploaders/google_drive.rb', line 29

def logger
  @logger
end

#pathObject (readonly)

Returns the value of attribute path.



29
30
31
# File 'lib/reqres_rspec/uploaders/google_drive.rb', line 29

def path
  @path
end

Class Method Details

.uploadObject



31
32
33
34
# File 'lib/reqres_rspec/uploaders/google_drive.rb', line 31

def self.upload
  uploader = self.new
  uploader.process
end

Instance Method Details

#processObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/reqres_rspec/uploaders/google_drive.rb', line 36

def process
  Dir["#{path}/**/*"].each { |file|
    next if File.directory?(file)
    local_path = file.gsub("#{@path}/", '')

    start = Time.now
    @session.upload_from_file(file, local_path, convert: false)
    done = Time.now

    puts "\n[#{local_path}] Uploaded in #{done.to_i - start.to_i}s"
  }
end