Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion lib/crowdin-api/api_resources/labels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,37 @@ def unassign_label_from_strings(label_id = nil, query = {}, project_id = config.
response = ::RestClient::Request.execute(
{
method: :delete,
url: config.base_url + config.target_api_url + "/projects/#{project_id}/labels/#{label_id}",
url: config.base_url + config.target_api_url + "/projects/#{project_id}/labels/#{label_id}/strings",
payload: query.to_json
}.merge(@options)
)

response.body.empty? ? response.code : JSON.parse(response.body)
rescue StandardError => e
e.message
end

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

request = Web::Request.new(
connection,
:post,
"#{config.target_api_url}/projects/#{project_id}/labels/#{label_id}/screenshots",
{ params: query }
)
Web::SendRequest.new(request).perform
end

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

response = ::RestClient::Request.execute(
{
method: :delete,
url: config.base_url + config.target_api_url + "/projects/#{project_id}/labels/#{label_id}/screenshots",
payload: query.to_json
}.merge(@options)
)
Expand Down
48 changes: 40 additions & 8 deletions spec/api_resources/labels_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
describe Crowdin::ApiResources::Labels do
describe 'Default endpoints' do
describe '#list_labels' do
it 'when request are valid', :default do
it 'returns 200 when request is valid', :default do
stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels")
list_labels = @crowdin.list_labels({}, project_id)
expect(list_labels).to eq(200)
end
end

describe '#add_label' do
it 'when request are valid', :default do
it 'returns 200 when request is valid', :default do
stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels")
add_label = @crowdin.add_label({}, project_id)
expect(add_label).to eq(200)
Expand All @@ -21,7 +21,7 @@
describe '#get_label' do
let(:label_id) { 1 }

it 'when request are valid', :default do
it 'returns 200 when request is valid', :default do
stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}")
get_label = @crowdin.get_label(label_id, project_id)
expect(get_label).to eq(200)
Expand All @@ -31,7 +31,7 @@
describe '#delete_label' do
let(:label_id) { 1 }

it 'when request are valid', :default do
it 'returns 200 when request is valid', :default do
stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}")
delete_label = @crowdin.delete_label(label_id, project_id)
expect(delete_label).to eq(200)
Expand All @@ -41,7 +41,7 @@
describe '#edit_label' do
let(:label_id) { 1 }

it 'when request are valid', :default do
it 'returns 200 when request is valid', :default do
stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}")
edit_label = @crowdin.edit_label(label_id, {}, project_id)
expect(edit_label).to eq(200)
Expand All @@ -51,7 +51,7 @@
describe '#assign_label_to_strings' do
let(:label_id) { 1 }

it 'when request are valid', :default do
it 'returns 200 when request is valid', :default do
stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}/strings")
assign_label_to_strings = @crowdin.assign_label_to_strings(label_id, {}, project_id)
expect(assign_label_to_strings).to eq(200)
Expand All @@ -61,11 +61,43 @@
describe '#unassign_label_from_strings' do
let(:label_id) { 1 }

it 'when request are valid', :default do
stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}")
it 'returns 200 when request is valid', :default do
stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}/strings")
unassign_label_from_strings = @crowdin.unassign_label_from_strings(label_id, {}, project_id)
expect(unassign_label_from_strings).to eq(200)
end

it 'returns error message when request was processed with an error' do
allow(RestClient::Request).to receive(:execute).and_raise('Error')
unassign_label_from_strings = @crowdin.unassign_label_from_strings(label_id, {}, project_id)
expect(unassign_label_from_strings).to eq('Error')
end
end

describe '#assign_label_to_screenshots' do
let(:label_id) { 1 }

it 'returns 200 when request is valid', :default do
stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}/screenshots")
assign_label_to_screenshots = @crowdin.assign_label_to_screenshots(label_id, {}, project_id)
expect(assign_label_to_screenshots).to eq(200)
end
end

describe '#unassign_label_from_screenshots' do
let(:label_id) { 1 }

it 'returns 200 when request is valid', :default do
stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}/screenshots")
unassign_label_from_screenshots = @crowdin.unassign_label_from_screenshots(label_id, {}, project_id)
expect(unassign_label_from_screenshots).to eq(200)
end

it 'returns error message when request was processed with an error' do
allow(RestClient::Request).to receive(:execute).and_raise('Error')
unassign_label_from_screenshots = @crowdin.unassign_label_from_screenshots(label_id, {}, project_id)
expect(unassign_label_from_screenshots).to eq('Error')
end
end
end
end