Skip to content

Commit

Permalink
feat Add support for the new Pre-Translation API endpoint (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorFroehner authored Oct 18, 2024
1 parent 2460a88 commit 7b541e3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/crowdin-api/api_resources/translations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ def apply_pre_translation(query = {}, project_id = config.project_id)
Web::SendRequest.new(request).perform
end

def list_pre_translations(query = {}, project_id = config.project_id)
project_id || raise_project_id_is_required_error

request = Web::Request.new(
connection,
:get,
"#{config.target_api_url}/projects/#{project_id}/pre-translations",
{ params: query }
)
Web::SendRequest.new(request).perform
end

def edit_pre_translations(pre_translation_id = nil, query = {}, project_id = config.project_id)
pre_translation_id || raise_parameter_is_required_error(:pre_translation_id)
project_id || raise_project_id_is_required_error

request = Web::Request.new(
connection,
:patch,
"#{config.target_api_url}/projects/#{project_id}/pre-translations/#{pre_translation_id}",
{ params: query }
)
Web::SendRequest.new(request).perform
end

def build_project_directory_translation(directory_id = nil, query = {}, project_id = config.project_id)
directory_id || raise_parameter_is_required_error(:directory_id)
project_id || raise_project_id_is_required_error
Expand Down
18 changes: 18 additions & 0 deletions spec/api_resources/translations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@
end
end

describe '#list_pre_translations' do
it 'when request are valid', :default do
stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/pre-translations")
list_pre_translations = @crowdin.list_pre_translations({}, project_id)
expect(list_pre_translations).to eq(200)
end
end

describe '#edit_pre_translations' do
let(:pre_translation_id) { 1 }

it 'when request are valid', :default do
stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/pre-translations/#{pre_translation_id}")
edit_pre_translations = @crowdin.edit_pre_translations(pre_translation_id, {}, project_id)
expect(edit_pre_translations).to eq(200)
end
end

describe '#build_project_directory_translation' do
let(:directory_id) { 1 }

Expand Down

0 comments on commit 7b541e3

Please sign in to comment.