Skip to content

Commit 2460a88

Browse files
authored
feat: Support new 'Remove String Approvals' API endpoint (#95)
* refactor: delete_string_translations to use the SendRequest * feat: support new 'Remove String Approvals' API endpoint
1 parent a7246ff commit 2460a88

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

lib/crowdin-api/api_resources/string_translations.rb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ def remove_approval(approval_id = nil, project_id = config.project_id)
5151
Web::SendRequest.new(request).perform
5252
end
5353

54+
def remove_string_approvals(query = {}, project_id = config.project_id)
55+
project_id || raise_project_id_is_required_error
56+
57+
request = Web::Request.new(
58+
connection,
59+
:delete,
60+
"#{config.target_api_url}/projects/#{project_id}/approvals",
61+
{ params: query }
62+
)
63+
Web::SendRequest.new(request).perform
64+
end
65+
5466
def list_language_translations(language_id = nil, query = {}, project_id = config.project_id)
5567
language_id || raise_parameter_is_required_error(:language_id)
5668
project_id || raise_project_id_is_required_error
@@ -91,17 +103,13 @@ def add_translation(query = {}, project_id = config.project_id)
91103
def delete_string_translations(query = {}, project_id = config.project_id)
92104
project_id || raise_project_id_is_required_error
93105

94-
response = ::RestClient::Request.execute(
95-
{
96-
method: :delete,
97-
url: config.base_url + config.target_api_url + "/projects/#{project_id}/translations",
98-
payload: query.to_json
99-
}.merge(@options)
106+
request = Web::Request.new(
107+
connection,
108+
:delete,
109+
"#{config.target_api_url}/projects/#{project_id}/translations",
110+
{ params: query }
100111
)
101-
102-
response.body.empty? ? response.code : JSON.parse(response.body)
103-
rescue StandardError => e
104-
e.message
112+
Web::SendRequest.new(request).perform
105113
end
106114

107115
def get_translation(translation_id = nil, query = {}, project_id = config.project_id)

lib/crowdin-api/core/request.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def delete?
2626
end
2727

2828
def delete
29-
connection.delete
29+
connection.delete(prepare_payload(payload[:params]))
3030
end
3131

3232
def process_with_body
@@ -60,7 +60,7 @@ def build_payload(payload)
6060
def prepare_payload(params)
6161
return params if params.is_a?(File)
6262

63-
get? ? { params: fetch_cleared_params(params) } : fetch_cleared_params(params).to_json
63+
get? || delete? ? { params: fetch_cleared_params(params) } : fetch_cleared_params(params).to_json
6464
end
6565

6666
def fetch_cleared_params(params)

spec/api_resources/string_translations_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
end
3939
end
4040

41+
describe '#remove_string_approvals' do
42+
it 'when request are valid', :default do
43+
stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/approvals")
44+
remove_string_approvals = @crowdin.remove_string_approvals({}, project_id)
45+
expect(remove_string_approvals).to eq(200)
46+
end
47+
end
48+
4149
describe '#list_language_translations' do
4250
let(:language_id) { 1 }
4351

0 commit comments

Comments
 (0)