Class: Datacentred::Request::Roles

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

Overview

RESTful API requests for the roles endpoints.

Class Method Summary collapse

Methods inherited from Base

delete, get, post, put

Class Method Details

.add_user(role_id, user_id) ⇒ nil

Add new user to this role, giving them the associated permissions.

PUT /api/roles/ea894bed9d738d9f/users/82fa8de8f09102cc

Parameters:

  • role_id (String)

    The unique identifier for this role.

  • user_id (String)

    The unique identifier for this user.

Returns:

  • (nil)

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

Raises:



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

def add_user(role_id, user_id)
  put("roles/#{role_id}/users/#{user_id}")
end

.create(params) ⇒ Hash

Create a new role.

POST /api/roles

Parameters:

  • params (Hash)

    Role attributes.

Returns:

  • (Hash)

    New role.

Raises:



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

def create(params)
  post('roles', 'role' => params)['role']
end

.destroy(id) ⇒ nil

Permanently remove the specified role.

DELETE /api/roles/ea894bed9d738d9f

Parameters:

  • id (String)

    The unique identifier for this role.

Returns:

  • (nil)

    Confirms the role was destroyed.

Raises:



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

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

.list[Hash]

List all available roles.

GET /api/roles

Returns:

  • ([Hash])

    A collection of all roles on this account.

Raises:



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

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

.list_users(role_id) ⇒ [Hash]

List all users assigned to this role.

GET /api/roles/ea894bed9d738d9f/users

Parameters:

  • role_id (String)

    The unique identifier for this role.

Returns:

  • ([Hash])

    A collection of the role's users.

Raises:



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

def list_users(role_id)
  get("roles/#{role_id}/users")['users']
end

.remove_user(role_id, user_id) ⇒ nil

Remove user from this role, revoking the associated permissions.

DELETE /api/roles/ea894bed9d738d9f/users/82fa8de8f09102cc

Parameters:

  • role_id (String)

    The unique identifier for this role.

  • 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/roles.rb', line 100

def remove_user(role_id, user_id)
  delete("roles/#{role_id}/users/#{user_id}")
end

.show(id) ⇒ Hash

Find a role by unique ID.

GET /api/roles/ea894bed9d738d9f

Parameters:

  • id (String)

    The unique identifier for this role.

Returns:

  • (Hash)

    The role, if it exists.

Raises:



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

def show(id)
  get("roles/#{id}")['role']
end

.update(id, params) ⇒ Hash

Update a role by unique ID.

PUT /api/roles/ea894bed9d738d9f

Parameters:

  • id (String)

    The unique identifier for this role.

  • params (Hash)

    Role attributes.

Returns:

  • (Hash)

    The updated role.

Raises:



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

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