Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bundle API #48

Merged
merged 11 commits into from
Jun 15, 2023
49 changes: 49 additions & 0 deletions lib/crowdin-api/api_resources/bundles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
andrii-bodnar marked this conversation as resolved.
Show resolved Hide resolved
# @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
andrii-bodnar marked this conversation as resolved.
Show resolved Hide resolved
# @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}
Expand Down
31 changes: 31 additions & 0 deletions spec/api_resources/bundles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
6 changes: 6 additions & 0 deletions spec/unit/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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