Class: Dbhero::GdriveExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/dbhero/gdrive_exporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GdriveExporter

Returns a new instance of GdriveExporter.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dbhero/gdrive_exporter.rb', line 7

def initialize options = {}
  @client ||= ::Google::APIClient.new
  @options = options

  @auth = @client.authorization
  @auth.client_id = Dbhero.google_api_id
  @auth.client_secret = Dbhero.google_api_secret
  @auth.scope =
    "https://www.googleapis.com/auth/drive " +
    "https://spreadsheets.google.com/feeds/"

  @auth.redirect_uri = options[:redirect_uri]
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



4
5
6
# File 'lib/dbhero/gdrive_exporter.rb', line 4

def auth
  @auth
end

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/dbhero/gdrive_exporter.rb', line 4

def client
  @client
end

#dataclipObject (readonly)

Returns the value of attribute dataclip.



4
5
6
# File 'lib/dbhero/gdrive_exporter.rb', line 4

def dataclip
  @dataclip
end

#exported_file_urlObject (readonly)

Returns the value of attribute exported_file_url.



4
5
6
# File 'lib/dbhero/gdrive_exporter.rb', line 4

def exported_file_url
  @exported_file_url
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/dbhero/gdrive_exporter.rb', line 3

def options
  @options
end

#sessionObject (readonly)

Returns the value of attribute session.



4
5
6
# File 'lib/dbhero/gdrive_exporter.rb', line 4

def session
  @session
end

#uploaded_fileObject (readonly)

Returns the value of attribute uploaded_file.



4
5
6
# File 'lib/dbhero/gdrive_exporter.rb', line 4

def uploaded_file
  @uploaded_file
end

Instance Method Details

#export_clip_by_token(token) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/dbhero/gdrive_exporter.rb', line 27

def export_clip_by_token token
  @dataclip ||= Dataclip.find_by token: token
  raise 'unable to find dataclip' unless @dataclip

  exported_file = find_or_create_spreadsheet!
  @exported_file_url = exported_file.human_url
end

#fetch_access_token!(code) ⇒ Object



21
22
23
24
25
# File 'lib/dbhero/gdrive_exporter.rb', line 21

def fetch_access_token! code
  @auth.code = code
  @auth.fetch_access_token!
  @session ||= GoogleDrive.(@auth.access_token)
end