diff --git a/lib/crowdin-api/api_resources/bundles.rb b/lib/crowdin-api/api_resources/bundles.rb index 03bfab4..18ea9af 100644 --- a/lib/crowdin-api/api_resources/bundles.rb +++ b/lib/crowdin-api/api_resources/bundles.rb @@ -36,6 +36,55 @@ def add_bundle(query = {}, project_id = config.project_id) Web::SendRequest.new(request).perform end + # @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, 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" + ) + Web::SendRequest.new(request).perform + 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) + 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}" + ) + Web::SendRequest.new(request).perform + 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) + 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..b36a2fb 100644 --- a/spec/api_resources/bundles_spec.rb +++ b/spec/api_resources/bundles_spec.rb @@ -18,6 +18,37 @@ end 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(bundle_id, project_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/#{bundle_id}/exports/#{export_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 + + 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(bundle_id, export_id, project_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..6687c4f 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