diff --git a/lib/crowdin-api/api_resources/glossaries.rb b/lib/crowdin-api/api_resources/glossaries.rb index 61f36fc..163954b 100644 --- a/lib/crowdin-api/api_resources/glossaries.rb +++ b/lib/crowdin-api/api_resources/glossaries.rb @@ -243,6 +243,22 @@ def delete_concept(glossary_id = nil, concept_id = nil) ) Web::SendRequest.new(request).perform end + + def search_glossaries_concordance(project_id = nil, query = {}) + project_id || raise_project_id_is_required_error + + %i[source_language_id target_language_id expression].each do |param| + query[param] || raise_parameter_is_required_error(param) + end + + request = Web::Request.new( + connection, + :post, + "#{config.target_api_url}/projects/#{project_id}/glossaries/concordance", + { params: query } + ) + Web::SendRequest.new(request).perform + end end end end diff --git a/lib/crowdin-api/api_resources/string_translations.rb b/lib/crowdin-api/api_resources/string_translations.rb index a02638b..b0c3070 100644 --- a/lib/crowdin-api/api_resources/string_translations.rb +++ b/lib/crowdin-api/api_resources/string_translations.rb @@ -188,6 +188,22 @@ def cancel_vote(vote_id = nil, project_id = config.project_id) ) Web::SendRequest.new(request).perform end + + def add_translation_alignment(project_id = nil, query = {}) + project_id || raise_project_id_is_required_error + + %i[source_language_id target_language_id text].each do |param| + query[param] || raise_parameter_is_required_error(param) + end + + request = Web::Request.new( + connection, + :post, + "#{config.target_api_url}/projects/#{project_id}/translations/alignment", + { params: query } + ) + Web::SendRequest.new(request).perform + end end end end diff --git a/lib/crowdin-api/api_resources/translation_memory.rb b/lib/crowdin-api/api_resources/translation_memory.rb index 4284b5a..831f887 100644 --- a/lib/crowdin-api/api_resources/translation_memory.rb +++ b/lib/crowdin-api/api_resources/translation_memory.rb @@ -126,6 +126,22 @@ def check_tm_import_status(tm_id = nil, import_id = nil) ) Web::SendRequest.new(request).perform end + + def search_tms_concordance(project_id = nil, query = {}) + project_id || raise_project_id_is_required_error + + %i[source_language_id target_language_id expression auto_substitution min_relevant].each do |param| + query[param] || raise_parameter_is_required_error(param) + end + + request = Web::Request.new( + connection, + :post, + "#{config.target_api_url}/projects/#{project_id}/tms/concordance", + { params: query } + ) + Web::SendRequest.new(request).perform + end end end end diff --git a/spec/api_resources/glossaries_spec.rb b/spec/api_resources/glossaries_spec.rb index ae8e5b8..c137c13 100644 --- a/spec/api_resources/glossaries_spec.rb +++ b/spec/api_resources/glossaries_spec.rb @@ -1,210 +1,231 @@ # frozen_string_literal: true -describe Crowdin::ApiResources::Glossaries do - describe 'Default endpoints' do - describe '#list_glossaries' do - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries") - list_glossaries = @crowdin.list_glossaries - expect(list_glossaries).to eq(200) - end +describe Crowdin::ApiResources::Glossaries, 'Default endpoints' do + describe '#list_glossaries' do + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries") + list_glossaries = @crowdin.list_glossaries + expect(list_glossaries).to eq(200) end + end - describe '#add_glossary' do - it 'when request are valid', :default do - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries") - add_glossary = @crowdin.add_glossary - expect(add_glossary).to eq(200) - end + describe '#add_glossary' do + it 'when request are valid', :default do + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries") + add_glossary = @crowdin.add_glossary + expect(add_glossary).to eq(200) end + end - describe '#get_glossary' do - let(:glossary_id) { 1 } + describe '#get_glossary' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}") - get_glossary = @crowdin.get_glossary(glossary_id) - expect(get_glossary).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}") + get_glossary = @crowdin.get_glossary(glossary_id) + expect(get_glossary).to eq(200) end + end - describe '#delete_glossary' do - let(:glossary_id) { 1 } + describe '#delete_glossary' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}") - delete_glossary = @crowdin.delete_glossary(glossary_id) - expect(delete_glossary).to eq(200) - end + it 'when request are valid', :default do + stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}") + delete_glossary = @crowdin.delete_glossary(glossary_id) + expect(delete_glossary).to eq(200) end + end - describe '#edit_glossary' do - let(:glossary_id) { 1 } + describe '#edit_glossary' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}") - edit_glossary = @crowdin.edit_glossary(glossary_id) - expect(edit_glossary).to eq(200) - end + it 'when request are valid', :default do + stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}") + edit_glossary = @crowdin.edit_glossary(glossary_id) + expect(edit_glossary).to eq(200) end + end - describe '#export_glossary' do - let(:glossary_id) { 1 } + describe '#export_glossary' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports") - export_glossary = @crowdin.export_glossary({}, glossary_id) - expect(export_glossary).to eq(200) - end + it 'when request are valid', :default do + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports") + export_glossary = @crowdin.export_glossary({}, glossary_id) + expect(export_glossary).to eq(200) end + end - describe '#check_glossary_export_status' do - let(:glossary_id) { 1 } - let(:export_id) { 1 } + describe '#check_glossary_export_status' do + let(:glossary_id) { 1 } + let(:export_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}") - check_glossary_export_status = @crowdin.check_glossary_export_status(glossary_id, export_id) - expect(check_glossary_export_status).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}") + check_glossary_export_status = @crowdin.check_glossary_export_status(glossary_id, export_id) + expect(check_glossary_export_status).to eq(200) end + end - describe '#download_glossary' do - let(:glossary_id) { 1 } - let(:export_id) { 1 } + describe '#download_glossary' do + let(:glossary_id) { 1 } + let(:export_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}/download") - download_glossary = @crowdin.download_glossary(glossary_id, export_id) - expect(download_glossary).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}/download") + download_glossary = @crowdin.download_glossary(glossary_id, export_id) + expect(download_glossary).to eq(200) end + end - describe '#import_glossary' do - let(:glossary_id) { 1 } + describe '#import_glossary' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports") - import_glossary = @crowdin.import_glossary(glossary_id) - expect(import_glossary).to eq(200) - end + it 'when request are valid', :default do + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports") + import_glossary = @crowdin.import_glossary(glossary_id) + expect(import_glossary).to eq(200) end + end - describe '#check_glossary_import_status' do - let(:glossary_id) { 1 } - let(:import_id) { 1 } + describe '#check_glossary_import_status' do + let(:glossary_id) { 1 } + let(:import_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports/#{import_id}") - check_glossary_import_status = @crowdin.check_glossary_import_status(glossary_id, import_id) - expect(check_glossary_import_status).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports/#{import_id}") + check_glossary_import_status = @crowdin.check_glossary_import_status(glossary_id, import_id) + expect(check_glossary_import_status).to eq(200) end + end - describe '#list_terms' do - let(:glossary_id) { 1 } + describe '#clear_glossary' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms") - list_terms = @crowdin.list_terms(glossary_id) - expect(list_terms).to eq(200) - end + it 'when request are valid', :default do + stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms") + clear_glossary = @crowdin.clear_glossary(glossary_id) + expect(clear_glossary).to eq(200) end + end - describe '#add_term' do - let(:glossary_id) { 1 } + describe '#search_glossaries_concordance' do + let(:project_id) { 1 } - it 'when request are valid', :default do - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms") - add_term = @crowdin.add_term(glossary_id) - expect(add_term).to eq(200) - end + it 'returns 200 when request is valid', :default do + query = { source_language_id: 'en', target_language_id: 'ar', expression: 'Hello world!' } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/glossaries/concordance") + search_glossaries_concordance = @crowdin.search_glossaries_concordance(project_id, query) + expect(search_glossaries_concordance).to eq(200) end - describe '#clear_glossary' do - let(:glossary_id) { 1 } + it 'raises ArgumentError when request is missing required query parameter', :default do + query = { source_language_id: 'en', target_language_id: 'ar' } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/glossaries/concordance") + expect do + @crowdin.search_glossaries_concordance(project_id, query) + end.to raise_error(ArgumentError, ':expression is required') + end + end +end - it 'when request are valid', :default do - stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms") - clear_glossary = @crowdin.clear_glossary(glossary_id) - expect(clear_glossary).to eq(200) - end +describe Crowdin::ApiResources::Glossaries, 'Concept endpoints' do + describe '#list_concepts' do + let(:glossary_id) { 1 } + + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts") + concepts = @crowdin.list_concepts(glossary_id) + expect(concepts).to eq(200) end + end - describe '#get_term' do - let(:glossary_id) { 1 } - let(:term_id) { 1 } + describe '#get_concept' do + let(:glossary_id) { 1 } + let(:concept_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}") - get_term = @crowdin.get_term(glossary_id, term_id) - expect(get_term).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}") + concept = @crowdin.get_concept(glossary_id, concept_id) + expect(concept).to eq(200) end + end - describe '#delete_term' do - let(:glossary_id) { 1 } - let(:term_id) { 1 } + describe '#update_concept' do + let(:glossary_id) { 1 } + let(:concept_id) { 1 } - it 'when request are valid', :default do - stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}") - delete_term = @crowdin.delete_term(glossary_id, term_id) - expect(delete_term).to eq(200) - end + it 'when request are valid', :default do + stub_request(:put, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}") + concept = @crowdin.update_concept(glossary_id, concept_id) + expect(concept).to eq(200) end + end - describe '#edit_term' do - let(:glossary_id) { 1 } - let(:term_id) { 1 } + describe '#update_concept' do + let(:glossary_id) { 1 } + let(:concept_id) { 1 } - it 'when request are valid', :default do - stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}") - edit_term = @crowdin.edit_term(glossary_id, term_id) - expect(edit_term).to eq(200) - end + it 'when request are valid', :default do + stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}") + concept = @crowdin.delete_concept(glossary_id, concept_id) + expect(concept).to eq(200) end + end +end - describe '#list_concepts' do - let(:glossary_id) { 1 } +describe Crowdin::ApiResources::Glossaries, 'Term endpoints' do + describe '#list_terms' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts") - concepts = @crowdin.list_concepts(glossary_id) - expect(concepts).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms") + list_terms = @crowdin.list_terms(glossary_id) + expect(list_terms).to eq(200) end + end - describe '#get_concept' do - let(:glossary_id) { 1 } - let(:concept_id) { 1 } + describe '#add_term' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}") - concept = @crowdin.get_concept(glossary_id, concept_id) - expect(concept).to eq(200) - end + it 'when request are valid', :default do + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms") + add_term = @crowdin.add_term(glossary_id) + expect(add_term).to eq(200) end + end + + describe '#get_term' do + let(:glossary_id) { 1 } + let(:term_id) { 1 } + + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}") + get_term = @crowdin.get_term(glossary_id, term_id) + expect(get_term).to eq(200) + end + end - describe '#update_concept' do - let(:glossary_id) { 1 } - let(:concept_id) { 1 } + describe '#delete_term' do + let(:glossary_id) { 1 } + let(:term_id) { 1 } - it 'when request are valid', :default do - stub_request(:put, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}") - concept = @crowdin.update_concept(glossary_id, concept_id) - expect(concept).to eq(200) - end + it 'when request are valid', :default do + stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}") + delete_term = @crowdin.delete_term(glossary_id, term_id) + expect(delete_term).to eq(200) end + end - describe '#update_concept' do - let(:glossary_id) { 1 } - let(:concept_id) { 1 } + describe '#edit_term' do + let(:glossary_id) { 1 } + let(:term_id) { 1 } - it 'when request are valid', :default do - stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}") - concept = @crowdin.delete_concept(glossary_id, concept_id) - expect(concept).to eq(200) - end + it 'when request are valid', :default do + stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}") + edit_term = @crowdin.edit_term(glossary_id, term_id) + expect(edit_term).to eq(200) end end end diff --git a/spec/api_resources/string_translations_spec.rb b/spec/api_resources/string_translations_spec.rb index 88fe864..8022c84 100644 --- a/spec/api_resources/string_translations_spec.rb +++ b/spec/api_resources/string_translations_spec.rb @@ -137,5 +137,24 @@ expect(cancel_vote).to eq(200) end end + + describe '#add_translation_alignment' do + let(:project_id) { 1 } + + it 'returns 200 when request is valid', :default do + query = { source_language_id: 'en', target_language_id: 'ar', text: 'Hello world!' } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/alignment") + add_translation_alignment = @crowdin.add_translation_alignment(project_id, query) + expect(add_translation_alignment).to eq(200) + end + + it 'raises ArgumentError when request is missing required query parameter', :default do + query = { source_language_id: 'en', target_language_id: 'ar' } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/alignment") + expect do + @crowdin.add_translation_alignment(project_id, query) + end.to raise_error(ArgumentError, ':text is required') + end + end end end diff --git a/spec/api_resources/translation_memory_spec.rb b/spec/api_resources/translation_memory_spec.rb index c86821c..878cb79 100644 --- a/spec/api_resources/translation_memory_spec.rb +++ b/spec/api_resources/translation_memory_spec.rb @@ -110,5 +110,26 @@ expect(check_tm_import_status).to eq(200) end end + + describe '#search_tms_concordance' do + let(:project_id) { 1 } + + it 'returns 200 when request is valid', :default do + query = { source_language_id: 'en', target_language_id: 'ar', expression: 'Hello world!', + auto_substitution: true, min_relevant: 60 } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/tms/concordance") + search_tms_concordance = @crowdin.search_tms_concordance(project_id, query) + expect(search_tms_concordance).to eq(200) + end + + it 'raises ArgumentError when request is missing required query parameter', :default do + query = { source_language_id: 'en', target_language_id: 'ar', expression: 'Hello world!', + auto_substitution: true } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/tms/concordance") + expect do + @crowdin.search_tms_concordance(project_id, query) + end.to raise_error(ArgumentError, ':min_relevant is required') + end + end end end