Class: Lcms::Engine::LessonsGdocBundler

Inherits:
Object
  • Object
show all
Defined in:
app/services/lcms/engine/lessons_gdoc_bundler.rb

Constant Summary collapse

{ full: 'gdoc_full', tm: 'gdoc_tm', sm: 'gdoc_sm' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(unit) ⇒ LessonsGdocBundler

Returns a new instance of LessonsGdocBundler.



10
11
12
# File 'app/services/lcms/engine/lessons_gdoc_bundler.rb', line 10

def initialize(unit)
  @unit = unit
end

Instance Method Details

#bundleObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/lcms/engine/lessons_gdoc_bundler.rb', line 14

def bundle
  return if unit.children.empty?

  # ensure root folder exists
  root_id = drive_service.create_folder root_folder

  unit_folder = drive_service.create_folder dirname(unit), root_id

  unit.children.includes(:documents).each do |resource|
    next unless resource.document?

    build_lesson_folder resource, unit_folder
  end

  # return (and save somewhere the unit bundle url)
  "https://drive.google.com/open?id=#{unit_folder}"
rescue Google::Apis::TransmissionError => e
  Rails.logger.error "Failed to bundle unit: #{unit.slug}, #{e.message}"
end