Class: DocumentExporter::Gdoc::Base
- Inherits:
-
Base
- Object
- Base
- DocumentExporter::Gdoc::Base
show all
- Defined in:
- lib/document_exporter/gdoc/base.rb
Constant Summary
collapse
- GOOGLE_API_CLIENT_UPLOAD_RETRIES =
ENV.fetch('GOOGLE_API_CLIENT_UPLOAD_RETRIES', 5).to_i
- GOOGLE_API_CLIENT_UPLOAD_TIMEOUT =
ENV.fetch('GOOGLE_API_CLIENT_UPLOAD_TIMEOUT', 60).to_i
- GOOGLE_API_UPLOAD_OPTIONS =
{
options: {
open_timeout_sec: GOOGLE_API_CLIENT_UPLOAD_TIMEOUT,
read_timeout_sec: GOOGLE_API_CLIENT_UPLOAD_TIMEOUT,
retries: GOOGLE_API_CLIENT_UPLOAD_RETRIES,
send_timeout_sec: GOOGLE_API_CLIENT_UPLOAD_TIMEOUT
}
}.freeze
- VERSION_RE =
/_v\d+$/i.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#included_materials, #initialize, #ordered_materials, pdf_key
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
21
22
23
|
# File 'lib/document_exporter/gdoc/base.rb', line 21
def document
@document
end
|
#options ⇒ Object
Returns the value of attribute options.
21
22
23
|
# File 'lib/document_exporter/gdoc/base.rb', line 21
def options
@options
end
|
Class Method Details
.gdoc_key(type) ⇒ Object
24
25
26
|
# File 'lib/document_exporter/gdoc/base.rb', line 24
def gdoc_key(type)
"gdoc_#{type}"
end
|
.url_for(file_id) ⇒ Object
28
29
30
|
# File 'lib/document_exporter/gdoc/base.rb', line 28
def url_for(file_id)
"https://drive.google.com/open?id=#{file_id}"
end
|
Instance Method Details
#create_gdoc_folders(folder) ⇒ Object
#export ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/document_exporter/gdoc/base.rb', line 41
def export
file_id = @options[:file_id] || drive_service.file_id
parent_folder = file_id.blank? ? @options[:folder_id] || drive_service.parent : nil
file_name = "#{@options[:prefix]}#{document.base_filename}"
file_params = { name: file_name, mime_type: 'application/vnd.google-apps.document' }
file_params[:parents] = [parent_folder] if parent_folder.present?
metadata = Google::Apis::DriveV3::File.new(file_params)
params = {
content_type: 'text/html',
upload_source: StringIO.new(content)
}.merge(GOOGLE_API_UPLOAD_OPTIONS)
@id = if file_id.blank?
drive_service.service.create_file(metadata, params)
else
drive_service.service.update_file(file_id, metadata, params)
end.id
post_processing
self
end
|
#export_to(folder_id, file_id: nil) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/document_exporter/gdoc/base.rb', line 70
def export_to(folder_id, file_id: nil)
metadata = Google::Apis::DriveV3::File.new(
name: document.base_filename(with_version: false),
mime_type: 'application/vnd.google-apps.document',
parents: [folder_id]
)
params = {
content_type: 'text/html',
upload_source: StringIO.new(content)
}.merge(GOOGLE_API_UPLOAD_OPTIONS)
@id = if file_id.present?
drive_service.service.update_file(file_id, metadata, params)
else
drive_service.service.create_file(metadata, params)
end.id
post_processing
self
end
|
#url ⇒ Object
93
94
95
|
# File 'lib/document_exporter/gdoc/base.rb', line 93
def url
self.class.url_for @id
end
|