Class: DeepL::Utils::TranslationMemoryOperations Private
- Inherits:
-
Object
- Object
- DeepL::Utils::TranslationMemoryOperations
- Defined in:
- lib/deepl/utils/translation_memory_operations.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The requests, polling and ID handling behind the translation memory methods of DeepL::Client.
Constant Summary collapse
- JOB_POLLING_INTERVAL_SECONDS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Time to wait between two status queries of an import or export job.
5
Instance Method Summary collapse
- #create_export(translation_memory, options = {}) ⇒ Object private
- #create_import(file_name, content_length, content_type: nil, display_name: nil, extra_body_parameters: nil) ⇒ Object private
- #destroy(translation_memory, options = {}) ⇒ Object private
- #download_export(job, output_path) ⇒ Object private
- #export_to_filepath(translation_memory, output_path, timeout_s: nil) ⇒ Object private
- #find(translation_memory, options = {}) ⇒ Object private
- #find_job(job, options = {}) ⇒ Object private
- #import_from_filepath(input_file_path, display_name: nil, timeout_s: nil, content_type: nil, extra_body_parameters: nil) ⇒ Object private
-
#initialize(api) ⇒ TranslationMemoryOperations
constructor
private
A new instance of TranslationMemoryOperations.
- #list(options = {}) ⇒ Object private
- #segments(translation_memory, options = {}) ⇒ Object private
- #upload_file(translation_memory_import, file_content, content_type: Requests::TranslationMemory::UploadFile::DEFAULT_CONTENT_TYPE) ⇒ Object private
-
#wait_until_job_done(job, timeout_s: nil, &on_status) ⇒ Object
private
Yields each status it receives, if a block is given.
Constructor Details
#initialize(api) ⇒ TranslationMemoryOperations
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TranslationMemoryOperations.
15 16 17 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 15 def initialize(api) @api = api end |
Instance Method Details
#create_export(translation_memory, options = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 60 61 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 57 def create_export(translation_memory, = {}) DeepL::Requests::TranslationMemory::CreateExport.new( @api, extract_translation_memory_id(translation_memory), ).request end |
#create_import(file_name, content_length, content_type: nil, display_name: nil, extra_body_parameters: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 44 45 46 47 48 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 41 def create_import(file_name, content_length, content_type: nil, display_name: nil, extra_body_parameters: nil) = { content_type: content_type, display_name: display_name, extra_body_parameters: extra_body_parameters }.compact DeepL::Requests::TranslationMemory::CreateImport.new( @api, file_name, content_length, ).request end |
#destroy(translation_memory, options = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 39 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 35 def destroy(translation_memory, = {}) DeepL::Requests::TranslationMemory::Destroy.new( @api, extract_translation_memory_id(translation_memory), ).request end |
#download_export(job, output_path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 85 86 87 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 82 def download_export(job, output_path) download_url = extract_download_url(job) Utils::OutputPath.check!(output_path) DeepL::Requests::TranslationMemory::DownloadExport.new(@api, download_url, output_path).request end |
#export_to_filepath(translation_memory, output_path, timeout_s: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 103 def export_to_filepath(translation_memory, output_path, timeout_s: nil) with_job_error('export') do |progress| check_output_path(output_path) created = create_export(translation_memory) progress[:job_id] = created.job_id job = wait_until_job_done(created.job_id, timeout_s: timeout_s) { progress[:job] = _1 } download_export(job, output_path) job end end |
#find(translation_memory, options = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 26 27 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 23 def find(translation_memory, = {}) DeepL::Requests::TranslationMemory::Find.new( @api, extract_translation_memory_id(translation_memory), ).request end |
#find_job(job, options = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 63 def find_job(job, = {}) DeepL::Requests::TranslationMemory::FindJob.new(@api, extract_job_id(job), ).request end |
#import_from_filepath(input_file_path, display_name: nil, timeout_s: nil, content_type: nil, extra_body_parameters: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 89 def import_from_filepath(input_file_path, display_name: nil, timeout_s: nil, content_type: nil, extra_body_parameters: nil) check_input_file(input_file_path) with_job_error('import') do |progress| file_content = read_input_file(input_file_path) raise ArgumentError, "File #{input_file_path} is empty" if file_content.empty? created = create_import(File.basename(input_file_path), file_content.bytesize, content_type: content_type, display_name: display_name, extra_body_parameters: extra_body_parameters) upload_and_wait(created, file_content, content_type, timeout_s, progress) end end |
#list(options = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 19 def list( = {}) DeepL::Requests::TranslationMemory::List.new(@api, ).request end |
#segments(translation_memory, options = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 32 33 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 29 def segments(translation_memory, = {}) DeepL::Requests::TranslationMemory::Segments.new( @api, extract_translation_memory_id(translation_memory), ).request end |
#upload_file(translation_memory_import, file_content, content_type: Requests::TranslationMemory::UploadFile::DEFAULT_CONTENT_TYPE) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 53 54 55 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 50 def upload_file(translation_memory_import, file_content, content_type: Requests::TranslationMemory::UploadFile::DEFAULT_CONTENT_TYPE) DeepL::Requests::TranslationMemory::UploadFile.new( @api, extract_upload_url(translation_memory_import), file_content, content_type ).request end |
#wait_until_job_done(job, timeout_s: nil, &on_status) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Yields each status it receives, if a block is given.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/deepl/utils/translation_memory_operations.rb', line 68 def wait_until_job_done(job, timeout_s: nil, &on_status) deadline = timeout_s.nil? ? nil : monotonic_time + timeout_s job_status = find_job(job).tap { |status| on_status&.call(status) } until job_status.finished? interval = polling_interval_until(deadline, timeout_s) log_job_polling(interval) sleep(interval) job_status = find_job(job).tap { |status| on_status&.call(status) } end raise_job_error(job_status) if job_status.error? job_status end |