From 1785745e0d7db1e09fc6f653653de4e6b353ef6c Mon Sep 17 00:00:00 2001 From: saranour700 Date: Tue, 3 Mar 2026 16:02:09 +0200 Subject: [PATCH 01/10] Add support for AI Translate Strings method --- .vscode/launch.json | 21 +++++++++++++++++++++ lib/crowdin-api.rb | 2 +- lib/crowdin-api/api_resources/ai.rb | 20 ++++++++++++++++++++ spec/api_resources/ai_spec.rb | 15 +++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json create mode 100644 lib/crowdin-api/api_resources/ai.rb create mode 100644 spec/api_resources/ai_spec.rb diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..869b60e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "rdbg", + "name": "Debug current file with rdbg", + "request": "launch", + "script": "${file}", + "args": [], + "askParameters": true + }, + { + "type": "rdbg", + "name": "Attach with rdbg", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/lib/crowdin-api.rb b/lib/crowdin-api.rb index 4b3ddcc..d18f35f 100644 --- a/lib/crowdin-api.rb +++ b/lib/crowdin-api.rb @@ -6,7 +6,7 @@ module Crowdin StringTranslations StringComments Screenshots Glossaries TranslationMemory MachineTranslationEngines Reports Tasks Users Teams Vendors Webhooks Dictionaries Distributions Labels TranslationStatus Bundles Notifications - Applications StringCorrections].freeze + Applications StringCorrections AI].freeze # Error Raisers modules ERROR_RAISERS_MODULES = %i[ApiErrorsRaiser ClientErrorsRaiser].freeze diff --git a/lib/crowdin-api/api_resources/ai.rb b/lib/crowdin-api/api_resources/ai.rb new file mode 100644 index 0000000..03888c5 --- /dev/null +++ b/lib/crowdin-api/api_resources/ai.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Crowdin + module ApiResources + module AI + # https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.translate.strings.post + def ai_translate_strings(user_id = nil, query = {}) + user_id || raise_parameter_is_required_error(:user_id) + + request = Web::Request.new( + connection, + :post, + "#{config.target_api_url}/users/#{user_id}/ai/translations/translate-strings", + { params: query } + ) + Web::SendRequest.new(request).perform + end + end + end +end diff --git a/spec/api_resources/ai_spec.rb b/spec/api_resources/ai_spec.rb new file mode 100644 index 0000000..65d1f76 --- /dev/null +++ b/spec/api_resources/ai_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +describe Crowdin::ApiResources::AI do + describe 'Default endpoints' do + describe '#ai_translate_strings' do + let(:user_id) { 1 } + + it 'when request are valid', :default do + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/users/#{user_id}/ai/translations/translate-strings") + ai_translate_strings = @crowdin.ai_translate_strings(user_id) + expect(ai_translate_strings).to eq(200) + end + end + end +end From 9faed5cec903433d1cf07d2cd78046032fda565c Mon Sep 17 00:00:00 2001 From: saranour700 Date: Wed, 4 Mar 2026 00:16:27 +0200 Subject: [PATCH 02/10] fix: address review comments --- .vscode/launch.json | 21 --------------------- lib/crowdin-api/api_resources/ai.rb | 1 + spec/api_resources/ai_spec.rb | 4 ++-- 3 files changed, 3 insertions(+), 23 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 869b60e..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "rdbg", - "name": "Debug current file with rdbg", - "request": "launch", - "script": "${file}", - "args": [], - "askParameters": true - }, - { - "type": "rdbg", - "name": "Attach with rdbg", - "request": "attach" - } - ] -} \ No newline at end of file diff --git a/lib/crowdin-api/api_resources/ai.rb b/lib/crowdin-api/api_resources/ai.rb index 03888c5..922f897 100644 --- a/lib/crowdin-api/api_resources/ai.rb +++ b/lib/crowdin-api/api_resources/ai.rb @@ -6,6 +6,7 @@ module AI # https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.translate.strings.post def ai_translate_strings(user_id = nil, query = {}) user_id || raise_parameter_is_required_error(:user_id) + enterprise_mode? || raise_only_for_enterprise_mode_error request = Web::Request.new( connection, diff --git a/spec/api_resources/ai_spec.rb b/spec/api_resources/ai_spec.rb index 65d1f76..bafdba4 100644 --- a/spec/api_resources/ai_spec.rb +++ b/spec/api_resources/ai_spec.rb @@ -5,8 +5,8 @@ describe '#ai_translate_strings' do let(:user_id) { 1 } - it 'when request are valid', :default do - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/users/#{user_id}/ai/translations/translate-strings") + it 'when request are valid', :enterprise do + stub_request(:post, "https://domain.api.crowdin.com/#{target_api_url}/users/#{user_id}/ai/translations/translate-strings") ai_translate_strings = @crowdin.ai_translate_strings(user_id) expect(ai_translate_strings).to eq(200) end From f1fe3f64dff1439762800a21b7b5424a25c2ab83 Mon Sep 17 00:00:00 2001 From: saranour700 Date: Thu, 5 Mar 2026 15:20:13 +0200 Subject: [PATCH 03/10] fix: add enterprise mode check to ai_translate_strings --- lib/crowdin-api/api_resources/ai.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/crowdin-api/api_resources/ai.rb b/lib/crowdin-api/api_resources/ai.rb index 922f897..1da1f41 100644 --- a/lib/crowdin-api/api_resources/ai.rb +++ b/lib/crowdin-api/api_resources/ai.rb @@ -2,11 +2,14 @@ module Crowdin module ApiResources - module AI - # https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.translate.strings.post + module Ai + # AI Translate Strings + # @param user_id [Integer] User ID + # @param query [Hash] Request Body + # @see https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.translate.strings.post def ai_translate_strings(user_id = nil, query = {}) - user_id || raise_parameter_is_required_error(:user_id) enterprise_mode? || raise_only_for_enterprise_mode_error + user_id || raise_parameter_is_required_error(:user_id) request = Web::Request.new( connection, From bfb7fcb0ddc1deae0a283bb00104a063b72c6aae Mon Sep 17 00:00:00 2001 From: saranour700 Date: Thu, 5 Mar 2026 15:29:23 +0200 Subject: [PATCH 04/10] fix: update ai_spec to use enterprise mode and improve tests --- spec/api_resources/ai_spec.rb | 15 ---------- spec/crowdin-api/api_resources/ai_spec.rb | 35 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 15 deletions(-) delete mode 100644 spec/api_resources/ai_spec.rb create mode 100644 spec/crowdin-api/api_resources/ai_spec.rb diff --git a/spec/api_resources/ai_spec.rb b/spec/api_resources/ai_spec.rb deleted file mode 100644 index bafdba4..0000000 --- a/spec/api_resources/ai_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -describe Crowdin::ApiResources::AI do - describe 'Default endpoints' do - describe '#ai_translate_strings' do - let(:user_id) { 1 } - - it 'when request are valid', :enterprise do - stub_request(:post, "https://domain.api.crowdin.com/#{target_api_url}/users/#{user_id}/ai/translations/translate-strings") - ai_translate_strings = @crowdin.ai_translate_strings(user_id) - expect(ai_translate_strings).to eq(200) - end - end - end -end diff --git a/spec/crowdin-api/api_resources/ai_spec.rb b/spec/crowdin-api/api_resources/ai_spec.rb new file mode 100644 index 0000000..e4da4cd --- /dev/null +++ b/spec/crowdin-api/api_resources/ai_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Crowdin::ApiResources::Ai do + describe '#ai_translate_strings' do + let(:user_id) { 1 } + + it 'when request are valid', :enterprise do + stub_request(:post, "https://domain.api.crowdin.com/api/v2/users/#{user_id}/ai/translations/translate-strings") + .to_return( + status: 200, + body: { + data: { + translations: ['Hallo Welt'] + } + }.to_json + ) + + result = @crowdin.ai_translate_strings(user_id, { strings: ['Hello'], targetLanguageId: 'de' }) + expect(result['data']['translations']).to eq(['Hallo Welt']) + end + + it 'should raise error when user_id is missing' do + expect { @crowdin.ai_translate_strings(nil, { strings: ['Hello'] }) } + .to raise_error(Crowdin::Errors::ParameterIsRequiredError) + end + + it 'should raise error when not in enterprise mode' do + allow(@crowdin).to receive(:enterprise_mode?).and_return(false) + expect { @crowdin.ai_translate_strings(user_id, { strings: ['Hello'] }) } + .to raise_error(Crowdin::Errors::OnlyForEnterpriseModeError) + end + end +end \ No newline at end of file From cbc2f7cabae7061c538d6a88f9b6b48a5b73baf9 Mon Sep 17 00:00:00 2001 From: saranour700 Date: Thu, 5 Mar 2026 15:39:09 +0200 Subject: [PATCH 05/10] fix: address review comments --- .gitignore | 2 ++ lib/crowdin-api.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3203173..c490dba 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ # Ignore tests coverage folder coverage +.vscode/ +*.tgz diff --git a/lib/crowdin-api.rb b/lib/crowdin-api.rb index d18f35f..7893257 100644 --- a/lib/crowdin-api.rb +++ b/lib/crowdin-api.rb @@ -6,7 +6,7 @@ module Crowdin StringTranslations StringComments Screenshots Glossaries TranslationMemory MachineTranslationEngines Reports Tasks Users Teams Vendors Webhooks Dictionaries Distributions Labels TranslationStatus Bundles Notifications - Applications StringCorrections AI].freeze + Applications StringCorrections Ai].freeze # Error Raisers modules ERROR_RAISERS_MODULES = %i[ApiErrorsRaiser ClientErrorsRaiser].freeze From e80e4c2c0a9e4f7b5b3c2b240f9641d9b45624fb Mon Sep 17 00:00:00 2001 From: saranour700 Date: Thu, 5 Mar 2026 16:23:29 +0200 Subject: [PATCH 06/10] fix: correct error classes in ai_spec tests --- spec/crowdin-api/api_resources/ai_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/crowdin-api/api_resources/ai_spec.rb b/spec/crowdin-api/api_resources/ai_spec.rb index e4da4cd..436ca79 100644 --- a/spec/crowdin-api/api_resources/ai_spec.rb +++ b/spec/crowdin-api/api_resources/ai_spec.rb @@ -21,9 +21,9 @@ expect(result['data']['translations']).to eq(['Hallo Welt']) end - it 'should raise error when user_id is missing' do + it 'should raise error when user_id is missing', :enterprise do expect { @crowdin.ai_translate_strings(nil, { strings: ['Hello'] }) } - .to raise_error(Crowdin::Errors::ParameterIsRequiredError) + .to raise_error(ArgumentError) end it 'should raise error when not in enterprise mode' do @@ -32,4 +32,4 @@ .to raise_error(Crowdin::Errors::OnlyForEnterpriseModeError) end end -end \ No newline at end of file +end From ee495d32038927e8cc569a146c4005cdc466b446 Mon Sep 17 00:00:00 2001 From: saranour700 Date: Sat, 7 Mar 2026 10:54:10 +0200 Subject: [PATCH 07/10] fix: use organization_domain variable in ai_spec.rb stub URL --- spec/crowdin-api/api_resources/ai_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/crowdin-api/api_resources/ai_spec.rb b/spec/crowdin-api/api_resources/ai_spec.rb index 436ca79..0be556d 100644 --- a/spec/crowdin-api/api_resources/ai_spec.rb +++ b/spec/crowdin-api/api_resources/ai_spec.rb @@ -7,7 +7,7 @@ let(:user_id) { 1 } it 'when request are valid', :enterprise do - stub_request(:post, "https://domain.api.crowdin.com/api/v2/users/#{user_id}/ai/translations/translate-strings") + stub_request(:post, "https://#{organization_domain}.api.crowdin.com/api/v2/users/#{user_id}/ai/translations/translate-strings") .to_return( status: 200, body: { From fb6950b5d9c31a9ad2d18f78662c977578020e7f Mon Sep 17 00:00:00 2001 From: saranour700 Date: Sat, 7 Mar 2026 11:01:11 +0200 Subject: [PATCH 08/10] fix: move ai_spec.rb to correct directory (spec/api_resources) --- spec/{crowdin-api => }/api_resources/ai_spec.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/{crowdin-api => }/api_resources/ai_spec.rb (100%) diff --git a/spec/crowdin-api/api_resources/ai_spec.rb b/spec/api_resources/ai_spec.rb similarity index 100% rename from spec/crowdin-api/api_resources/ai_spec.rb rename to spec/api_resources/ai_spec.rb From d0040befb7b8be2ef19617ee0f933cd5d20d138d Mon Sep 17 00:00:00 2001 From: saranour700 Date: Sat, 7 Mar 2026 11:23:23 +0200 Subject: [PATCH 09/10] fix: support ai_translate_strings in both Crowdin and Enterprise modes --- lib/crowdin-api/api_resources/ai.rb | 9 +++++---- spec/api_resources/ai_spec.rb | 31 ++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/lib/crowdin-api/api_resources/ai.rb b/lib/crowdin-api/api_resources/ai.rb index 1da1f41..32e8c5a 100644 --- a/lib/crowdin-api/api_resources/ai.rb +++ b/lib/crowdin-api/api_resources/ai.rb @@ -6,19 +6,20 @@ module Ai # AI Translate Strings # @param user_id [Integer] User ID # @param query [Hash] Request Body - # @see https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.translate.strings.post + # @see https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.translate.strings.post def ai_translate_strings(user_id = nil, query = {}) - enterprise_mode? || raise_only_for_enterprise_mode_error user_id || raise_parameter_is_required_error(:user_id) + path = enterprise_mode? ? "/ai/translations/translate-strings" : "/users/#{user_id}/ai/translations/translate-strings" + request = Web::Request.new( connection, :post, - "#{config.target_api_url}/users/#{user_id}/ai/translations/translate-strings", + "#{config.target_api_url}#{path}", { params: query } ) Web::SendRequest.new(request).perform end end end -end +end \ No newline at end of file diff --git a/spec/api_resources/ai_spec.rb b/spec/api_resources/ai_spec.rb index 0be556d..2d14798 100644 --- a/spec/api_resources/ai_spec.rb +++ b/spec/api_resources/ai_spec.rb @@ -6,8 +6,10 @@ describe '#ai_translate_strings' do let(:user_id) { 1 } - it 'when request are valid', :enterprise do - stub_request(:post, "https://#{organization_domain}.api.crowdin.com/api/v2/users/#{user_id}/ai/translations/translate-strings") + it 'when request are valid in Crowdin mode' do + @crowdin = Crowdin::Client.new + + stub_request(:post, "https://api.crowdin.com/api/v2/users/#{user_id}/ai/translations/translate-strings") .to_return( status: 200, body: { @@ -21,15 +23,26 @@ expect(result['data']['translations']).to eq(['Hallo Welt']) end - it 'should raise error when user_id is missing', :enterprise do - expect { @crowdin.ai_translate_strings(nil, { strings: ['Hello'] }) } - .to raise_error(ArgumentError) + it 'when request are valid in Enterprise mode' do + @crowdin = Crowdin::Client.new { |cfg| cfg.organization_domain = 'domain' } + + stub_request(:post, "https://domain.api.crowdin.com/api/v2/ai/translations/translate-strings") + .to_return( + status: 200, + body: { + data: { + translations: ['Hallo Welt'] + } + }.to_json + ) + + result = @crowdin.ai_translate_strings(user_id, { strings: ['Hello'], targetLanguageId: 'de' }) + expect(result['data']['translations']).to eq(['Hallo Welt']) end - it 'should raise error when not in enterprise mode' do - allow(@crowdin).to receive(:enterprise_mode?).and_return(false) - expect { @crowdin.ai_translate_strings(user_id, { strings: ['Hello'] }) } - .to raise_error(Crowdin::Errors::OnlyForEnterpriseModeError) + it 'should raise error when user_id is missing' do + expect { @crowdin.ai_translate_strings(nil, { strings: ['Hello'] }) } + .to raise_error(ArgumentError) end end end From a524ab16587c84419bb21dd2c8053f511153381a Mon Sep 17 00:00:00 2001 From: saranour700 Date: Sat, 7 Mar 2026 11:58:07 +0200 Subject: [PATCH 10/10] fix: move ai_spec to correct directory --- "\033[200~spec/api_resources/ai_spec.rb~" | 48 +++++++++++++++++++ .../api_resources/ai_spec.rb | 0 2 files changed, 48 insertions(+) create mode 100644 "\033[200~spec/api_resources/ai_spec.rb~" rename spec/{ => crowdin-api}/api_resources/ai_spec.rb (100%) diff --git "a/\033[200~spec/api_resources/ai_spec.rb~" "b/\033[200~spec/api_resources/ai_spec.rb~" new file mode 100644 index 0000000..758bf1d --- /dev/null +++ "b/\033[200~spec/api_resources/ai_spec.rb~" @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Crowdin::ApiResources::Ai do + describe '#ai_translate_strings' do + let(:user_id) { 1 } + + context 'in Crowdin mode (non-enterprise)' do + it 'when request are valid' do + stub_request(:post, "https://api.crowdin.com/api/v2/users/#{user_id}/ai/translations/translate-strings") + .to_return( + status: 200, + body: { + data: { + translations: ['Hallo Welt'] + } + }.to_json + ) + + result = @crowdin.ai_translate_strings(user_id, { strings: ['Hello'], targetLanguageId: 'de' }) + expect(result['data']['translations']).to eq(['Hallo Welt']) + end + end + + context 'in Enterprise mode', :enterprise do + it 'when request are valid' do + stub_request(:post, "https://#{organization_domain}.api.crowdin.com/api/v2/ai/translations/translate-strings") + .to_return( + status: 200, + body: { + data: { + translations: ['Hallo Welt'] + } + }.to_json + ) + + result = @crowdin.ai_translate_strings(user_id, { strings: ['Hello'], targetLanguageId: 'de' }) + expect(result['data']['translations']).to eq(['Hallo Welt']) + end + end + + it 'should raise error when user_id is missing' do + expect { @crowdin.ai_translate_strings(nil, { strings: ['Hello'] }) } + .to raise_error(ArgumentError) + end + end +end \ No newline at end of file diff --git a/spec/api_resources/ai_spec.rb b/spec/crowdin-api/api_resources/ai_spec.rb similarity index 100% rename from spec/api_resources/ai_spec.rb rename to spec/crowdin-api/api_resources/ai_spec.rb