Class: Lcms::Engine::Google::ScriptService
- Inherits:
-
Object
- Object
- Lcms::Engine::Google::ScriptService
- Includes:
- Lcms::Engine::GoogleCredentials
- Defined in:
- app/services/lcms/engine/google/script_service.rb
Constant Summary collapse
- SCRIPT_ID =
ENV.fetch('GOOGLE_APPLICATION_SCRIPT_ID', 'PLEASE SET UP SCRIPT ID')
- SCRIPT_FUNCTION =
ENV.fetch('GOOGLE_APPLICATION_SCRIPT_FUNCTION', 'postProcessingUB')
Instance Method Summary collapse
- #execute(id) ⇒ Object
-
#initialize(document) ⇒ ScriptService
constructor
A new instance of ScriptService.
Constructor Details
#initialize(document) ⇒ ScriptService
Returns a new instance of ScriptService.
13 14 15 |
# File 'app/services/lcms/engine/google/script_service.rb', line 13 def initialize(document) @document = document end |
Instance Method Details
#execute(id) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/lcms/engine/google/script_service.rb', line 20 def execute(id) # Create an execution request object. request = ::Google::Apis::ScriptV1::ExecutionRequest.new( function: SCRIPT_FUNCTION, parameters: [id, gdoc_template_id, *Array.wrap(parameters)] ) response = service.run_script(SCRIPT_ID, request) return unless response.error # The API executed, but the script returned an error. error = response.error.details[0] msg = "Error with document: #{id}\n" msg += "Script error message: #{error['errorMessage']}\n" if error['scriptStackTraceElements'] msg += 'Script error stacktrace:' error['scriptStackTraceElements'].each do |trace| msg += "\t#{trace['function']}: #{trace['lineNumber']}" end end raise ::Google::Apis::Error, msg end |