Class: Locraft::GoogleDriveWrapper
- Inherits:
-
Object
- Object
- Locraft::GoogleDriveWrapper
- Includes:
- FileUtils
- Defined in:
- lib/locraft/google_drive_wrapper.rb
Constant Summary collapse
- EXPORTED_CSV_FILE =
'google_doc_sheet.csv'- SESSION_TOKEN_FILE =
'.locraft_gdrive_token'
Instance Method Summary collapse
- #authenticate ⇒ Object
- #doc_named(name) ⇒ Object
-
#export_worksheet ⇒ Object
return worksheet.
-
#export_worksheet_csv ⇒ Object
return worksheet as string in csv format.
-
#export_worksheet_file ⇒ Object
return exported worksheet file path.
-
#initialize(config) ⇒ GoogleDriveWrapper
constructor
A new instance of GoogleDriveWrapper.
Constructor Details
#initialize(config) ⇒ GoogleDriveWrapper
Returns a new instance of GoogleDriveWrapper.
12 13 14 |
# File 'lib/locraft/google_drive_wrapper.rb', line 12 def initialize(config) @config = config end |
Instance Method Details
#authenticate ⇒ Object
16 17 18 19 |
# File 'lib/locraft/google_drive_wrapper.rb', line 16 def authenticate token_file = File.join(@config.from_folder, SESSION_TOKEN_FILE) @session = GoogleDrive.saved_session(token_file) end |
#doc_named(name) ⇒ Object
21 22 23 24 |
# File 'lib/locraft/google_drive_wrapper.rb', line 21 def doc_named(name) authenticate unless @session @session.spreadsheet_by_title(name) end |
#export_worksheet ⇒ Object
return worksheet
27 28 29 30 31 32 33 34 35 |
# File 'lib/locraft/google_drive_wrapper.rb', line 27 def export_worksheet worksheets = doc_named(@config.gdoc_file)&.worksheets if worksheets.count > @config.gdoc_sheet worksheets[@config.gdoc_sheet] else warn 'gdrive_wrapper worksheet export error: You have no access to google_doc or sheet number in config out of bounds!' end end |
#export_worksheet_csv ⇒ Object
return worksheet as string in csv format
46 47 48 49 |
# File 'lib/locraft/google_drive_wrapper.rb', line 46 def export_worksheet_csv worksheet = export_worksheet worksheet.export_as_string end |
#export_worksheet_file ⇒ Object
return exported worksheet file path
38 39 40 41 42 43 |
# File 'lib/locraft/google_drive_wrapper.rb', line 38 def export_worksheet_file sheet = export_worksheet file = File.join(@config.relative_strings_destination, EXPORTED_CSV_FILE) File.delete(file) if File.exist?(file) sheet.export_as_file(file) end |