From 9a2e3bb3e978c5f8d13ffc28a5300ab4e6ab61a6 Mon Sep 17 00:00:00 2001 From: Halle Winkler Date: Mon, 1 May 2023 16:24:51 +0200 Subject: [PATCH 01/10] Add export_bundle and download_bundle --- lib/crowdin-api/api_resources/bundles.rb | 32 ++++++++++++++++++++++++ spec/api_resources/bundles_spec.rb | 16 ++++++++++++ spec/unit/client_spec.rb | 6 +++++ 3 files changed, 54 insertions(+) diff --git a/lib/crowdin-api/api_resources/bundles.rb b/lib/crowdin-api/api_resources/bundles.rb index 03bfab4..fd20d56 100644 --- a/lib/crowdin-api/api_resources/bundles.rb +++ b/lib/crowdin-api/api_resources/bundles.rb @@ -36,6 +36,38 @@ def add_bundle(query = {}, project_id = config.project_id) Web::SendRequest.new(request).perform end + # @param query [Hash] Request Body + # * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.post API Documentation} + # * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.post Enterprise API Documentation} + def export_bundle(query = {}, project_id = config.project_id, bundle_id) + bundle_id || raise_parameter_is_required_error(:bundle_id) + project_id || raise_project_id_is_required_error + + request = Web::Request.new( + connection, + :post, + "#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports", + { params: query } + ) + Web::SendRequest.new(request).perform + end + + # @param bundle_id [Integer] Bundle ID + # * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.download.get API Documentation} + # * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.download.get Enterprise API Documentation} + def download_bundle(project_id = config.project_id, bundle_id, export_id) + bundle_id || raise_parameter_is_required_error(:bundle_id) + export_id || raise_parameter_is_required_error(:export_id) + project_id || raise_project_id_is_required_error + + request = Web::Request.new( + connection, + :get, + "#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}/download" + ) + Web::SendRequest.new(request).perform + end + # @param bundle_id [Integer] Bundle ID # * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.get API Documentation} # * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.get Enterprise API Documentation} diff --git a/spec/api_resources/bundles_spec.rb b/spec/api_resources/bundles_spec.rb index fa43405..b76117b 100644 --- a/spec/api_resources/bundles_spec.rb +++ b/spec/api_resources/bundles_spec.rb @@ -18,6 +18,22 @@ end end + describe '#export_bundle' do + it 'when request are valid', :default do + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports") + export_bundle = @crowdin.export_bundle({ name: '', format: '', sourcePatterns: [], exportPattern: '' }, project_id, bundle_id) + expect(export_bundle).to eq(200) + end + end + + describe '#download_bundle' do + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}/download") + download_bundle = @crowdin.download_bundle(project_id, bundle_id, export_id) + expect(download_bundle).to eq(200) + end + end + describe '#get_bundle' do let(:bundle_id) { 1 } diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 2eb7dfc..c8707fd 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -88,4 +88,10 @@ expect { @crowdin.fetch_all(:add_bundle).to raise_error(Crowdin::Errors::FetchAllProcessingError) } end end + + describe 'Crowdin Client fetch_all' do + it 'should raise error if fetch_all is called for unsupported methods' do + expect { @crowdin.fetch_all(:export_bundle).to raise_error(Crowdin::Errors::FetchAllProcessingError) } + end + end end From ff836cbf76b0908b1b1317a5963225f1cb9583f3 Mon Sep 17 00:00:00 2001 From: Halle Winkler Date: Thu, 15 Jun 2023 12:06:24 +0200 Subject: [PATCH 02/10] Rubocop fixes --- lib/crowdin-api/api_resources/bundles.rb | 26 +++++++++++++++++++----- spec/api_resources/bundles_spec.rb | 18 +++++++++++++--- spec/unit/client_spec.rb | 4 ++-- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/lib/crowdin-api/api_resources/bundles.rb b/lib/crowdin-api/api_resources/bundles.rb index fd20d56..41b70b9 100644 --- a/lib/crowdin-api/api_resources/bundles.rb +++ b/lib/crowdin-api/api_resources/bundles.rb @@ -39,10 +39,10 @@ def add_bundle(query = {}, project_id = config.project_id) # @param query [Hash] Request Body # * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.post API Documentation} # * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.post Enterprise API Documentation} - def export_bundle(query = {}, project_id = config.project_id, bundle_id) + def export_bundle(bundle_id, query = {}, project_id = config.project_id) bundle_id || raise_parameter_is_required_error(:bundle_id) project_id || raise_project_id_is_required_error - + request = Web::Request.new( connection, :post, @@ -52,12 +52,28 @@ def export_bundle(query = {}, project_id = config.project_id, bundle_id) Web::SendRequest.new(request).perform end + # @param bundle_id [Integer] Bundle ID + # * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.get API Documentation} + # * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.get Enterprise API Documentation} + def check_bundle_export_status(bundle_id = nil, export_id = nil, project_id = config.project_id) + bundle_id || raise_parameter_is_required_error(:bundle_id) + export_id || raise_parameter_is_required_error(:export_id) + project_id || raise_project_id_is_required_error + + request = Web::Request.new( + connection, + :get, + "#{config.target_api_url}/projects/#{project_id}/bundles/#{bundleId}/exports/#{exportId}" + ) + Web::SendRequest.new(request).perform + end + # @param bundle_id [Integer] Bundle ID # * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.download.get API Documentation} # * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.download.get Enterprise API Documentation} - def download_bundle(project_id = config.project_id, bundle_id, export_id) + def download_bundle(bundle_id, export_id, project_id = config.project_id) bundle_id || raise_parameter_is_required_error(:bundle_id) - export_id || raise_parameter_is_required_error(:export_id) + export_id || raise_parameter_is_required_error(:export_id) project_id || raise_project_id_is_required_error request = Web::Request.new( @@ -67,7 +83,7 @@ def download_bundle(project_id = config.project_id, bundle_id, export_id) ) Web::SendRequest.new(request).perform end - + # @param bundle_id [Integer] Bundle ID # * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.get API Documentation} # * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.get Enterprise API Documentation} diff --git a/spec/api_resources/bundles_spec.rb b/spec/api_resources/bundles_spec.rb index b76117b..3be53be 100644 --- a/spec/api_resources/bundles_spec.rb +++ b/spec/api_resources/bundles_spec.rb @@ -21,11 +21,23 @@ describe '#export_bundle' do it 'when request are valid', :default do stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports") - export_bundle = @crowdin.export_bundle({ name: '', format: '', sourcePatterns: [], exportPattern: '' }, project_id, bundle_id) + export_bundle = @crowdin.export_bundle({ name: '', format: '', sourcePatterns: [], exportPattern: '' }, + project_id, bundle_id) expect(export_bundle).to eq(200) end end - + + describe '#check_bundle_export_status' do + let(:bundle_id) { 1 } + let(:export_id) { 1 } + + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundleId}/exports/#{exportId}") + @crowdin.check_bundle_export_status(project_id, bundle_id, export_id) + expect(check_bundle_export_status).to eq(200) + end + end + describe '#download_bundle' do it 'when request are valid', :default do stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}/download") @@ -33,7 +45,7 @@ expect(download_bundle).to eq(200) end end - + describe '#get_bundle' do let(:bundle_id) { 1 } diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index c8707fd..6687c4f 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -88,8 +88,8 @@ expect { @crowdin.fetch_all(:add_bundle).to raise_error(Crowdin::Errors::FetchAllProcessingError) } end end - - describe 'Crowdin Client fetch_all' do + + describe 'Crowdin Client fetch_all' do it 'should raise error if fetch_all is called for unsupported methods' do expect { @crowdin.fetch_all(:export_bundle).to raise_error(Crowdin::Errors::FetchAllProcessingError) } end From e7b8d653f8f01e5ee395cf795ad7b9abc7570691 Mon Sep 17 00:00:00 2001 From: Halle Winkler Date: Thu, 15 Jun 2023 13:00:12 +0200 Subject: [PATCH 03/10] Style, URL error fix --- lib/crowdin-api/api_resources/bundles.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/crowdin-api/api_resources/bundles.rb b/lib/crowdin-api/api_resources/bundles.rb index 41b70b9..64ad682 100644 --- a/lib/crowdin-api/api_resources/bundles.rb +++ b/lib/crowdin-api/api_resources/bundles.rb @@ -55,7 +55,7 @@ def export_bundle(bundle_id, query = {}, project_id = config.project_id) # @param bundle_id [Integer] Bundle ID # * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.get API Documentation} # * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.get Enterprise API Documentation} - def check_bundle_export_status(bundle_id = nil, export_id = nil, project_id = config.project_id) + def check_bundle_export_status(bundle_id, export_id, project_id = config.project_id) bundle_id || raise_parameter_is_required_error(:bundle_id) export_id || raise_parameter_is_required_error(:export_id) project_id || raise_project_id_is_required_error @@ -63,7 +63,7 @@ def check_bundle_export_status(bundle_id = nil, export_id = nil, project_id = co request = Web::Request.new( connection, :get, - "#{config.target_api_url}/projects/#{project_id}/bundles/#{bundleId}/exports/#{exportId}" + "#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}/" ) Web::SendRequest.new(request).perform end From 1e8055a492edcc1b6ce489cb7286c2c8ca2f2257 Mon Sep 17 00:00:00 2001 From: Halle Winkler Date: Thu, 15 Jun 2023 13:08:55 +0200 Subject: [PATCH 04/10] Test fixes --- spec/api_resources/bundles_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/api_resources/bundles_spec.rb b/spec/api_resources/bundles_spec.rb index 3be53be..0b8c32b 100644 --- a/spec/api_resources/bundles_spec.rb +++ b/spec/api_resources/bundles_spec.rb @@ -19,6 +19,8 @@ end describe '#export_bundle' do + let(:bundle_id) { 1 } + it 'when request are valid', :default do stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports") export_bundle = @crowdin.export_bundle({ name: '', format: '', sourcePatterns: [], exportPattern: '' }, @@ -32,13 +34,16 @@ let(:export_id) { 1 } it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundleId}/exports/#{exportId}") + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}") @crowdin.check_bundle_export_status(project_id, bundle_id, export_id) expect(check_bundle_export_status).to eq(200) end end describe '#download_bundle' do + let(:bundle_id) { 1 } + let(:export_id) { 1 } + it 'when request are valid', :default do stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}/download") download_bundle = @crowdin.download_bundle(project_id, bundle_id, export_id) From 936bf2482861e30e1ee98651381804b9c2a120be Mon Sep 17 00:00:00 2001 From: Halle Winkler Date: Thu, 15 Jun 2023 13:47:40 +0200 Subject: [PATCH 05/10] Test parameters fixed --- lib/crowdin-api/api_resources/bundles.rb | 2 +- spec/api_resources/bundles_spec.rb | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/crowdin-api/api_resources/bundles.rb b/lib/crowdin-api/api_resources/bundles.rb index 64ad682..cebaa3d 100644 --- a/lib/crowdin-api/api_resources/bundles.rb +++ b/lib/crowdin-api/api_resources/bundles.rb @@ -63,7 +63,7 @@ def check_bundle_export_status(bundle_id, export_id, project_id = config.project request = Web::Request.new( connection, :get, - "#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}/" + "#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}" ) Web::SendRequest.new(request).perform end diff --git a/spec/api_resources/bundles_spec.rb b/spec/api_resources/bundles_spec.rb index 0b8c32b..fbbd02d 100644 --- a/spec/api_resources/bundles_spec.rb +++ b/spec/api_resources/bundles_spec.rb @@ -20,11 +20,10 @@ describe '#export_bundle' do let(:bundle_id) { 1 } - + it 'when request are valid', :default do stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports") - export_bundle = @crowdin.export_bundle({ name: '', format: '', sourcePatterns: [], exportPattern: '' }, - project_id, bundle_id) + export_bundle = @crowdin.export_bundle(bundle_id, project_id) expect(export_bundle).to eq(200) end end @@ -35,7 +34,7 @@ it 'when request are valid', :default do stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}") - @crowdin.check_bundle_export_status(project_id, bundle_id, export_id) + @crowdin.check_bundle_export_status(bundle_id, export_id, project_id) expect(check_bundle_export_status).to eq(200) end end @@ -46,7 +45,7 @@ it 'when request are valid', :default do stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}/download") - download_bundle = @crowdin.download_bundle(project_id, bundle_id, export_id) + download_bundle = @crowdin.download_bundle(bundle_id, export_id, project_id) expect(download_bundle).to eq(200) end end From 8929a193333d0510001ba65a536ec1634a79b7fb Mon Sep 17 00:00:00 2001 From: Halle <378795+Halle@users.noreply.github.com> Date: Thu, 15 Jun 2023 13:58:56 +0200 Subject: [PATCH 06/10] Update spec/api_resources/bundles_spec.rb Co-authored-by: Andrii Bodnar --- spec/api_resources/bundles_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/api_resources/bundles_spec.rb b/spec/api_resources/bundles_spec.rb index fbbd02d..7b659e4 100644 --- a/spec/api_resources/bundles_spec.rb +++ b/spec/api_resources/bundles_spec.rb @@ -20,7 +20,6 @@ describe '#export_bundle' do let(:bundle_id) { 1 } - it 'when request are valid', :default do stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports") export_bundle = @crowdin.export_bundle(bundle_id, project_id) From 35f58048544e0218513fec4da4a953dcdb89eb0a Mon Sep 17 00:00:00 2001 From: Halle <378795+Halle@users.noreply.github.com> Date: Thu, 15 Jun 2023 14:28:44 +0200 Subject: [PATCH 07/10] Update lib/crowdin-api/api_resources/bundles.rb Co-authored-by: Andrii Bodnar --- lib/crowdin-api/api_resources/bundles.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/crowdin-api/api_resources/bundles.rb b/lib/crowdin-api/api_resources/bundles.rb index cebaa3d..4fc78de 100644 --- a/lib/crowdin-api/api_resources/bundles.rb +++ b/lib/crowdin-api/api_resources/bundles.rb @@ -36,18 +36,17 @@ def add_bundle(query = {}, project_id = config.project_id) Web::SendRequest.new(request).perform end - # @param query [Hash] Request Body + # @param bundle_id [Integer] Bundle ID # * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.post API Documentation} # * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.post Enterprise API Documentation} - def export_bundle(bundle_id, query = {}, project_id = config.project_id) + def export_bundle(bundle_id, project_id = config.project_id) bundle_id || raise_parameter_is_required_error(:bundle_id) project_id || raise_project_id_is_required_error request = Web::Request.new( connection, :post, - "#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports", - { params: query } + "#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports" ) Web::SendRequest.new(request).perform end From d7091ba9b7a9efb10e396707fd86a938eea66088 Mon Sep 17 00:00:00 2001 From: Halle <378795+Halle@users.noreply.github.com> Date: Thu, 15 Jun 2023 14:28:51 +0200 Subject: [PATCH 08/10] Update lib/crowdin-api/api_resources/bundles.rb Co-authored-by: Andrii Bodnar --- lib/crowdin-api/api_resources/bundles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/crowdin-api/api_resources/bundles.rb b/lib/crowdin-api/api_resources/bundles.rb index 4fc78de..eaf20f1 100644 --- a/lib/crowdin-api/api_resources/bundles.rb +++ b/lib/crowdin-api/api_resources/bundles.rb @@ -52,6 +52,7 @@ def export_bundle(bundle_id, project_id = config.project_id) end # @param bundle_id [Integer] Bundle ID + # @param export_id [String] Export ID # * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.get API Documentation} # * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.get Enterprise API Documentation} def check_bundle_export_status(bundle_id, export_id, project_id = config.project_id) From 4e48b28a489d7c15ff8e13d40e7d935277fdfefc Mon Sep 17 00:00:00 2001 From: Halle <378795+Halle@users.noreply.github.com> Date: Thu, 15 Jun 2023 14:28:57 +0200 Subject: [PATCH 09/10] Update lib/crowdin-api/api_resources/bundles.rb Co-authored-by: Andrii Bodnar --- lib/crowdin-api/api_resources/bundles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/crowdin-api/api_resources/bundles.rb b/lib/crowdin-api/api_resources/bundles.rb index eaf20f1..18ea9af 100644 --- a/lib/crowdin-api/api_resources/bundles.rb +++ b/lib/crowdin-api/api_resources/bundles.rb @@ -69,6 +69,7 @@ def check_bundle_export_status(bundle_id, export_id, project_id = config.project end # @param bundle_id [Integer] Bundle ID + # @param export_id [String] Export ID # * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.download.get API Documentation} # * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.download.get Enterprise API Documentation} def download_bundle(bundle_id, export_id, project_id = config.project_id) From 2709ff65732b6b5ad3af8aa130790f2b292d17e2 Mon Sep 17 00:00:00 2001 From: Halle <378795+Halle@users.noreply.github.com> Date: Thu, 15 Jun 2023 14:41:01 +0200 Subject: [PATCH 10/10] Update spec/api_resources/bundles_spec.rb Co-authored-by: Andrii Bodnar --- spec/api_resources/bundles_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api_resources/bundles_spec.rb b/spec/api_resources/bundles_spec.rb index 7b659e4..b36a2fb 100644 --- a/spec/api_resources/bundles_spec.rb +++ b/spec/api_resources/bundles_spec.rb @@ -33,7 +33,7 @@ it 'when request are valid', :default do stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}") - @crowdin.check_bundle_export_status(bundle_id, export_id, project_id) + check_bundle_export_status = @crowdin.check_bundle_export_status(bundle_id, export_id, project_id) expect(check_bundle_export_status).to eq(200) end end