Class: Lcms::Engine::Google::DriveService
- Inherits:
-
Lt::Google::Api::Drive
- Object
- Lt::Google::Api::Drive
- Lcms::Engine::Google::DriveService
- Includes:
- Lcms::Engine::GoogleCredentials
- Defined in:
- app/services/lcms/engine/google/drive_service.rb
Constant Summary collapse
- FOLDER_ID =
ENV.fetch('GOOGLE_APPLICATION_FOLDER_ID', 'PLEASE SET UP FOLDER ID')
Instance Attribute Summary collapse
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Class Method Summary collapse
Instance Method Summary collapse
- #copy(file_ids, folder_id = parent) ⇒ Object
- #create_folder(folder_name, parent_id = FOLDER_ID) ⇒ Object
- #file_id ⇒ Object
-
#initialize(document, options) ⇒ DriveService
constructor
A new instance of DriveService.
- #parent ⇒ Object
Constructor Details
#initialize(document, options) ⇒ DriveService
Returns a new instance of DriveService.
25 26 27 28 29 |
# File 'app/services/lcms/engine/google/drive_service.rb', line 25 def initialize(document, ) super google_credentials @document = document @options = end |
Instance Attribute Details
#service ⇒ Object (readonly)
Returns the value of attribute service.
11 12 13 |
# File 'app/services/lcms/engine/google/drive_service.rb', line 11 def service @service end |
Class Method Details
.build(document, options = {}) ⇒ Object
13 14 15 |
# File 'app/services/lcms/engine/google/drive_service.rb', line 13 def self.build(document, = {}) new document, end |
Instance Method Details
#copy(file_ids, folder_id = parent) ⇒ Object
17 18 19 |
# File 'app/services/lcms/engine/google/drive_service.rb', line 17 def copy(file_ids, folder_id = parent) super file_ids, folder_id end |
#create_folder(folder_name, parent_id = FOLDER_ID) ⇒ Object
21 22 23 |
# File 'app/services/lcms/engine/google/drive_service.rb', line 21 def create_folder(folder_name, parent_id = FOLDER_ID) super folder_name, parent_id end |
#file_id ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/lcms/engine/google/drive_service.rb', line 31 def file_id @file_id ||= begin folder = @options[:folder_id] || parent file_name = document.base_filename response = service.list_files( q: %("#{folder}" in parents and name = "#{file_name}" and mimeType = "#{MIME_FILE}" and trashed = false), fields: 'files(id)' ) files = Array.wrap(response&.files) Rails.logger.warn "Multiple files: more than 1 file with same name: #{file_name}" unless files.size == 1 files.first&.id end end |
#parent ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/services/lcms/engine/google/drive_service.rb', line 45 def parent @parent ||= begin subfolders = ([:subfolders] || []).unshift([:gdoc_folder] || document.gdoc_folder) parent_folder = FOLDER_ID subfolders.each do |folder| parent_folder = subfolder(folder, parent_folder) end parent_folder end end |