API Module: Projects - mschnitzer/open-build-service-api GitHub Wiki

The Projects module allows you to create, modify, query, or delete Open Build Server source projects.

Introduction

To access this module, establish a new connection to an Open Build Service instance.

How to Use

The module itself can be accessed through an OpenBuildServiceAPI::Connection object. In this guide we assume that the object api stores an OpenBuildServiceAPI::Connection.

Instance Method: create(name, meta = nil)

Creates a new source project.

Arguments:

  • name: name of your project (String)
  • meta: the meta definition of your project - leaving it empty lets the library create a default meta which will be used to create that project (String or Nokogiri::XML)

Return Value: OpenBuildServiceAPI::Project when the creation was successful

Possible Exceptions:

  • OpenBuildServiceAPI::ProjectCreationPermissionError if the user has no permission to create this project
  • OpenBuildServiceAPI::ProjectCreationFailedError if the remote Open Build Service API didn't respond with HTTP status 200 OK
  • OpenBuildServiceAPI::ProjectAlreadyExistsError if the project name has already been taken

Example:

# depending on your permission you may only be able to create sub projects of your home project.
# If you're an Admin you will be able to create a project in any namespace.
project = api.projects.create('home:your_username:test123')

Instance Method: list()

Lists all available projects in this Open Build Service instance.

Return Value: Array (elements are an object of OpenBuildServiceAPI::Project)

Example:

api.projects.list.each do |project|
  puts project.name
end

Instance Method: exists?(name)

Checks whether a project does already exist.

Arguments:

  • name: name of the project (String)

Return Value: Boolean (true or false)

Example:

if api.projects.exists?('home:test')
  puts "I do exist"
else
  puts "This project name is still free."
end

Instance Method: find(name)

Finds a project by its name.

Arguments:

  • name: name of the project (String)

Return Value: OpenBuildServiceAPI::Project or nil

Example:

project = api.projects.find('home:test')
puts "#{project.name} has #{project.packages.size} packages."

Instance Method: find!(name)

Finds a project by its name or raises an exception if it does not exist.

Arguments:

  • name: name of the project (String)

Return Value: OpenBuildServiceAPI::Project or nil

Possible Exceptions:

  • OpenBuildServiceAPI::ProjectNotFoundError if the project does not exist

Example:

begin
  project = api.projects.find('home:test')"
  puts "#{project.name} has #{project.packages.size} packages."
rescue OpenBuildServiceAPI::ProjectNotFoundError
  puts "project does not exist"
end