diff --git a/.rubocop.yml b/.rubocop.yml index 2f65577..a96d5a3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,3 +6,7 @@ AllCops: Gemspec/DevelopmentDependencies: Enabled: false + +Metrics/BlockLength: + Exclude: + - 'spec/**/*' diff --git a/lib/crowdin-api/api_resources/projects.rb b/lib/crowdin-api/api_resources/projects.rb index ebdf0c4..8c40283 100644 --- a/lib/crowdin-api/api_resources/projects.rb +++ b/lib/crowdin-api/api_resources/projects.rb @@ -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 diff --git a/spec/api_resources/projects_spec.rb b/spec/api_resources/projects_spec.rb index 3727d16..e5b670d 100644 --- a/spec/api_resources/projects_spec.rb +++ b/spec/api_resources/projects_spec.rb @@ -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