Class: Datacentred::Request::Projects

Inherits:
Base
  • Object
show all
Defined in:
lib/datacentred/request/projects.rb

Overview

RESTful API requests for the projects endpoints.

Class Method Summary collapse

Methods inherited from Base

delete, get, post, put

Class Method Details

.add_user(project_id, user_id) ⇒ nil

Add a new user to this project, giving them access to it via OpenStack.

PUT /api/projects/ead738d9f894bed9/users/82fa8de8f09102cc

Parameters:

  • project_id (String)

    The unique identifier for this project.

  • user_id (String)

    The unique identifier for this user.

Returns:

  • (nil)

    Confirms the user was added (or is already present).

Raises:



87
88
89
# File 'lib/datacentred/request/projects.rb', line 87

def add_user(project_id, user_id)
  put("projects/#{project_id}/users/#{user_id}")
end

.create(params) ⇒ Hash

Create a new project.

POST /api/projects

Parameters:

  • params (Hash)

    Project attributes.

Returns:

  • (Hash)

    New project.

Raises:



14
15
16
# File 'lib/datacentred/request/projects.rb', line 14

def create(params)
  post('projects', 'project' => params)['project']
end

.destroy(id) ⇒ nil

Permanently remove the specified project.

DELETE /api/projects/ead738d9f894bed9

Parameters:

  • id (String)

    The unique identifier for this project.

Returns:

  • (nil)

    Confirms the user was destroyed.

Raises:



63
64
65
# File 'lib/datacentred/request/projects.rb', line 63

def destroy(id)
  delete("projects/#{id}")
end

.list[Hash]

List all available projects.

GET /api/projects

Returns:

  • ([Hash])

    A collection of all projects on this account.

Raises:



24
25
26
# File 'lib/datacentred/request/projects.rb', line 24

def list
  get('projects')['projects']
end

.list_users(id) ⇒ [Hash]

List all users assigned to this project.

GET /api/projects/ead738d9f894bed9/users

Parameters:

  • id (String)

    The unique identifier for this project.

Returns:

  • ([Hash])

    A collection of the project’s users.

Raises:



74
75
76
# File 'lib/datacentred/request/projects.rb', line 74

def list_users(id)
  get("projects/#{id}/users")['users']
end

.remove_user(project_id, user_id) ⇒ nil

Remove user from this project, revoking their access to it on OpenStack.

DELETE /api/projects/ead738d9f894bed9/users/82fa8de8f09102cc

Parameters:

  • project_id (String)

    The unique identifier for this project.

  • user_id (String)

    The unique identifier for this user.

Returns:

  • (nil)

    Confirms that user was removed (or is already absent).

Raises:



100
101
102
# File 'lib/datacentred/request/projects.rb', line 100

def remove_user(project_id, user_id)
  delete("projects/#{project_id}/users/#{user_id}")
end

.show(id) ⇒ Hash

Find a project by unique ID.

GET /api/projects/ead738d9f894bed9

Parameters:

  • id (String)

    The unique identifier for this project.

Returns:

  • (Hash)

    The project, if it exists.

Raises:



36
37
38
# File 'lib/datacentred/request/projects.rb', line 36

def show(id)
  get("projects/#{id}")['project']
end

.update(id, params) ⇒ Hash

Update a project by unique ID.

PUT /api/projects/ead738d9f894bed9

Parameters:

  • id (String)

    The unique identifier for this project.

  • params (Hash)

    Project attributes.

Returns:

  • (Hash)

    The updated project.

Raises:



50
51
52
# File 'lib/datacentred/request/projects.rb', line 50

def update(id, params)
  put("projects/#{id}", 'project' => params)['project']
end