Skip to content

Commit 17b1075

Browse files
authored
feat: Add support for String Corrections API endpoints (#110)
1 parent 7bb18db commit 17b1075

3 files changed

Lines changed: 170 additions & 1 deletion

File tree

lib/crowdin-api.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Crowdin
66
StringTranslations StringComments Screenshots Glossaries TranslationMemory
77
MachineTranslationEngines Reports Tasks Users Teams Vendors Webhooks
88
Dictionaries Distributions Labels TranslationStatus Bundles Notifications
9-
Applications].freeze
9+
Applications StringCorrections].freeze
1010

1111
# Error Raisers modules
1212
ERROR_RAISERS_MODULES = %i[ApiErrorsRaiser ClientErrorsRaiser].freeze
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# frozen_string_literal: true
2+
3+
module Crowdin
4+
module ApiResources
5+
module StringCorrections
6+
# * {https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.getMany Enterprise API Documentation}
7+
def list_corrections(query = {}, project_id = config.project_id)
8+
project_id || raise_project_id_is_required_error
9+
10+
request = Web::Request.new(
11+
connection,
12+
:get,
13+
"#{config.target_api_url}/projects/#{project_id}/corrections",
14+
{ params: query }
15+
)
16+
Web::SendRequest.new(request).perform
17+
end
18+
19+
# * {https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.post Enterprise API Documentation}
20+
def add_correction(body = {}, project_id = config.project_id)
21+
project_id || raise_project_id_is_required_error
22+
23+
request = Web::Request.new(
24+
connection,
25+
:post,
26+
"#{config.target_api_url}/projects/#{project_id}/corrections",
27+
{ params: body }
28+
)
29+
Web::SendRequest.new(request).perform
30+
end
31+
32+
# * {https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.get Enterprise API Documentation}
33+
def get_correction(correction_id = nil, query = {}, project_id = config.project_id)
34+
correction_id || raise_parameter_is_required_error(:correction_id)
35+
project_id || raise_project_id_is_required_error
36+
37+
request = Web::Request.new(
38+
connection,
39+
:get,
40+
"#{config.target_api_url}/projects/#{project_id}/corrections/#{correction_id}",
41+
{ params: query }
42+
)
43+
Web::SendRequest.new(request).perform
44+
end
45+
46+
# * {https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.deleteMany Enterprise API Documentation}
47+
def delete_corrections(query = {}, project_id = config.project_id)
48+
project_id || raise_project_id_is_required_error
49+
50+
request = Web::Request.new(
51+
connection,
52+
:delete,
53+
"#{config.target_api_url}/projects/#{project_id}/corrections",
54+
{ params: query }
55+
)
56+
Web::SendRequest.new(request).perform
57+
end
58+
59+
# * {https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.delete Enterprise API Documentation}
60+
def delete_correction(correction_id = nil, project_id = config.project_id)
61+
correction_id || raise_parameter_is_required_error(:correction_id)
62+
project_id || raise_project_id_is_required_error
63+
64+
request = Web::Request.new(
65+
connection,
66+
:delete,
67+
"#{config.target_api_url}/projects/#{project_id}/corrections/#{correction_id}"
68+
)
69+
Web::SendRequest.new(request).perform
70+
end
71+
72+
# * {https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.put Enterprise API Documentation}
73+
def restore_correction(correction_id = nil, project_id = config.project_id)
74+
correction_id || raise_parameter_is_required_error(:correction_id)
75+
project_id || raise_project_id_is_required_error
76+
77+
request = Web::Request.new(
78+
connection,
79+
:put,
80+
"#{config.target_api_url}/projects/#{project_id}/corrections/#{correction_id}"
81+
)
82+
Web::SendRequest.new(request).perform
83+
end
84+
end
85+
end
86+
end
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# frozen_string_literal: true
2+
3+
describe Crowdin::ApiResources::StringCorrections do
4+
describe 'Default endpoints' do
5+
let(:correction_id) { 35 }
6+
let(:string_id) { 2 }
7+
8+
describe '#list_corrections' do
9+
it 'when request is valid', :default do
10+
stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections")
11+
.with(query: { stringId: string_id })
12+
list_corrections = @crowdin.list_corrections({ stringId: string_id }, project_id)
13+
expect(list_corrections).to eq(200)
14+
end
15+
16+
it 'when request is valid', :default do
17+
query = { stringId: string_id, limit: 50, offset: 10, orderBy: 'createdAt desc', denormalizePlaceholders: 1 }
18+
stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections")
19+
.with(query: query)
20+
list_corrections = @crowdin.list_corrections(query, project_id)
21+
expect(list_corrections).to eq(200)
22+
end
23+
end
24+
25+
describe '#add_correction' do
26+
it 'when request is valid', :default do
27+
body = { stringId: 35_434, text: 'This string has been corrected', pluralCategoryName: 'few' }
28+
stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections")
29+
.with(body: body)
30+
add_correction = @crowdin.add_correction(body, project_id)
31+
expect(add_correction).to eq(200)
32+
end
33+
34+
it 'when request is valid', :default do
35+
body = { stringId: 35_434, text: 'This string has been corrected' }
36+
stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections")
37+
.with(body: body)
38+
add_correction = @crowdin.add_correction(body, project_id)
39+
expect(add_correction).to eq(200)
40+
end
41+
end
42+
43+
describe '#get_correction' do
44+
it 'when request is valid', :default do
45+
stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections/#{correction_id}")
46+
get_correction = @crowdin.get_correction(correction_id, {}, project_id)
47+
expect(get_correction).to eq(200)
48+
end
49+
50+
it 'when request is valid', :default do
51+
stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections/#{correction_id}")
52+
.with(query: { denormalizePlaceholders: 1 })
53+
get_correction = @crowdin.get_correction(correction_id, { denormalizePlaceholders: 1 }, project_id)
54+
expect(get_correction).to eq(200)
55+
end
56+
end
57+
58+
describe '#delete_corrections' do
59+
it 'when request is valid', :default do
60+
stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections")
61+
.with(query: { stringId: string_id })
62+
delete_corrections = @crowdin.delete_corrections({ stringId: string_id }, project_id)
63+
expect(delete_corrections).to eq(200)
64+
end
65+
end
66+
67+
describe '#delete_correction' do
68+
it 'when request is valid', :default do
69+
stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections/#{correction_id}")
70+
delete_correction = @crowdin.delete_correction(correction_id, project_id)
71+
expect(delete_correction).to eq(200)
72+
end
73+
end
74+
75+
describe '#restore_correction' do
76+
it 'when request is valid', :default do
77+
stub_request(:put, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections/#{correction_id}")
78+
restore_correction = @crowdin.restore_correction(correction_id, project_id)
79+
expect(restore_correction).to eq(200)
80+
end
81+
end
82+
end
83+
end

0 commit comments

Comments
 (0)