Skip to content

Commit

Permalink
feat: Strings Exporter Settings API (#99)
Browse files Browse the repository at this point in the history
* feat: Strings Exporter Settings API
* config: rubocop ignore metrics block length on tests
  • Loading branch information
IgorFroehner authored Oct 28, 2024
1 parent 65db494 commit dbcdbd8
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ AllCops:

Gemspec/DevelopmentDependencies:
Enabled: false

Metrics/BlockLength:
Exclude:
- 'spec/**/*'
83 changes: 83 additions & 0 deletions lib/crowdin-api/api_resources/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,89 @@ def edit_project(project_id = nil, query = {})
Web::SendRequest.new(request).perform
end

# @param project_id [Integer] Project ID
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.getMany API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.strings-exporter-settings.getMany Enterprise API Documentation}
def list_project_strings_exporter_settings(project_id = nil)
project_id || raise_parameter_is_required_error(:project_id)

request = Web::Request.new(
connection,
:get,
"#{config.target_api_url}/projects/#{project_id}/strings-exporter-settings"
)
Web::SendRequest.new(request).perform
end

# @param project_id [Integer] Project ID
# @param query [Hash] Request Body
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.post API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.strings-exporter-settings.post Enterprise API Documentation}
def add_project_strings_exporter_settings(project_id = nil, query = {})
project_id || raise_parameter_is_required_error(:project_id)

request = Web::Request.new(
connection,
:post,
"#{config.target_api_url}/projects/#{project_id}/strings-exporter-settings",
{ params: query }
)
Web::SendRequest.new(request).perform
end

# @param project_id [Integer] Project ID
# @param system_strings_exporter_settings_id [Integer] Request Body
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.get API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.strings-exporter-settings.get Enterprise API Documentation}
def get_project_strings_exporter_settings(project_id = nil, system_strings_exporter_settings_id = nil)
project_id || raise_parameter_is_required_error(:project_id)
system_strings_exporter_settings_id || raise_parameter_is_required_error(:system_strings_exporter_settings_id)

path = "projects/#{project_id}/strings-exporter-settings/#{system_strings_exporter_settings_id}"
request = Web::Request.new(
connection,
:get,
"#{config.target_api_url}/#{path}"
)
Web::SendRequest.new(request).perform
end

# @param project_id [Integer] Project ID
# @param system_strings_exporter_settings_id [Integer] Request Body
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.delete API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.strings-exporter-settings.delete Enterprise API Documentation}
def delete_project_strings_exporter_settings(project_id = nil, system_strings_exporter_settings_id = nil)
project_id || raise_parameter_is_required_error(:project_id)
system_strings_exporter_settings_id || raise_parameter_is_required_error(:system_strings_exporter_settings_id)

path = "projects/#{project_id}/strings-exporter-settings/#{system_strings_exporter_settings_id}"
request = Web::Request.new(
connection,
:delete,
"#{config.target_api_url}/#{path}"
)
Web::SendRequest.new(request).perform
end

# @param project_id [Integer] Project ID
# @param system_strings_exporter_settings_id [Integer] Request Body
# @param query [Hash] Request Body
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.patch API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.strings-exporter-settings.patch Enterprise API Documentation}
def edit_project_strings_exporter_settings(project_id = nil, system_strings_exporter_settings_id = nil, query = {})
project_id || raise_parameter_is_required_error(:project_id)
system_strings_exporter_settings_id || raise_parameter_is_required_error(:system_strings_exporter_settings_id)

path = "projects/#{project_id}/strings-exporter-settings/#{system_strings_exporter_settings_id}"
request = Web::Request.new(
connection,
:patch,
"#{config.target_api_url}/#{path}",
params: query
)
Web::SendRequest.new(request).perform
end

# -- For Enterprise mode only --

# @param query [Hash] Request Body
Expand Down
111 changes: 111 additions & 0 deletions spec/api_resources/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,117 @@
expect { @crowdin.edit_project }.to raise_error(ArgumentError)
end
end

describe '#list_project_strings_exporter_settings' do
let(:project_id) { 1 }

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

it 'when the request is invalid', :default do
stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/strings-exporter-settings")
expect { @crowdin.list_project_strings_exporter_settings }.to raise_error(ArgumentError)
end
end

describe '#add_project_strings_exporter_settings' do
let(:project_id) { 1 }
let(:body) do
{
format: 'json',
settings: {
convertPlaceholders: true,
convertLineBreaks: true
}
}
end

it 'when request are valid', :default do
stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/strings-exporter-settings")
.with(body: body.to_json)
add_project_strings_exporter_settings = @crowdin.add_project_strings_exporter_settings(project_id, body)
expect(add_project_strings_exporter_settings).to eq(200)
end

it 'when the request is invalid', :default do
stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/strings-exporter-settings")
expect { @crowdin.add_project_strings_exporter_settings }.to raise_error(ArgumentError)
end
end

describe '#get_project_strings_exporter_settings' do
let(:project_id) { 1 }
let(:system_strings_exporter_settings_id) { 1 }
let(:path) { "projects/#{project_id}/strings-exporter-settings/#{system_strings_exporter_settings_id}" }

it 'when request are valid', :default do
stub_request(:get, "https://api.crowdin.com/#{target_api_url}/#{path}")
get_project_strings_exporter_settings = @crowdin.get_project_strings_exporter_settings(
project_id,
system_strings_exporter_settings_id
)
expect(get_project_strings_exporter_settings).to eq(200)
end

it 'when the request is invalid', :default do
stub_request(:get, "https://api.crowdin.com/#{target_api_url}/#{path}")
expect { @crowdin.get_project_strings_exporter_settings }.to raise_error(ArgumentError)
end
end

describe '#delete_project_strings_exporter_settings' do
let(:project_id) { 1 }
let(:system_strings_exporter_settings_id) { 1 }
let(:path) { "projects/#{project_id}/strings-exporter-settings/#{system_strings_exporter_settings_id}" }

it 'when request are valid', :default do
stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/#{path}")
delete_project_strings_exporter_settings = @crowdin.delete_project_strings_exporter_settings(
project_id,
system_strings_exporter_settings_id
)
expect(delete_project_strings_exporter_settings).to eq(200)
end

it 'when the request is invalid', :default do
stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/#{path}")
expect { @crowdin.delete_project_strings_exporter_settings }.to raise_error(ArgumentError)
end
end

describe '#edit_project_strings_exporter_settings' do
let(:project_id) { 1 }
let(:system_strings_exporter_settings_id) { 1 }
let(:body) do
{
format: 'json',
settings: {
convertPlaceholders: true,
convertLineBreaks: true
}
}
end
let(:path) { "projects/#{project_id}/strings-exporter-settings/#{system_strings_exporter_settings_id}" }

it 'when request are valid', :default do
stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/#{path}")
.with(body: body.to_json)
edit_project_strings_exporter_settings = @crowdin.edit_project_strings_exporter_settings(
project_id,
system_strings_exporter_settings_id,
body
)
expect(edit_project_strings_exporter_settings).to eq(200)
end

it 'when the request is invalid', :default do
stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/#{path}")
expect { @crowdin.edit_project_strings_exporter_settings }.to raise_error(ArgumentError)
end
end
end

describe 'Enterprise endpoints' do
Expand Down

0 comments on commit dbcdbd8

Please sign in to comment.