Module: Code42::API::Role

Included in:
Client
Defined in:
lib/code42/api/role.rb

Instance Method Summary collapse

Instance Method Details

#assign_role(attrs = {}) ⇒ Code42::Role

Assigns a role to a user

Examples:

client.assign_role(:user_id => 2, :role_name => 'Admin')

Parameters:

  • attrs (Hash) (defaults to: {})

    A hash of attributes for assigning a user role

Returns:



11
12
13
# File 'lib/code42/api/role.rb', line 11

def assign_role(attrs = {})
  object_from_response(Code42::Role, :post, 'UserRole', attrs)
end

#create_role(name, permissions) ⇒ Object



40
41
42
# File 'lib/code42/api/role.rb', line 40

def create_role(name, permissions)
  object_from_response(Code42::Role, :post, "role", role_name: name, permissions: permissions)
end

#delete_role(id) ⇒ Object



48
49
50
# File 'lib/code42/api/role.rb', line 48

def delete_role(id)
  delete("Role/#{id}")
end

#role(id) ⇒ Object



36
37
38
# File 'lib/code42/api/role.rb', line 36

def role(id)
  object_from_response(Code42::Role, :get, "role/#{id}")
end

#roles(attrs = {}) ⇒ Object



32
33
34
# File 'lib/code42/api/role.rb', line 32

def roles(attrs = {})
  collection_from_response(Code42::RoleCollection, Code42::Role, :get, "role", attrs)
end

#unassign_role(id, role_name) ⇒ Object

Unassign a role from a user

Examples:

client.unassign_role(2, 'Admin')

Parameters:

  • id (String, Integer)

    The id of the user to return roles for

  • id (String)

    The role name to unassign

Returns:

  • true if role was unassigned



28
29
30
# File 'lib/code42/api/role.rb', line 28

def unassign_role(id, role_name)
  delete('UserRole', { :userId => id, :roleName => role_name })
end

#update_role(id, attrs = {}) ⇒ Object



44
45
46
# File 'lib/code42/api/role.rb', line 44

def update_role(id, attrs = {})
  object_from_response(Code42::Role, :put, "role/#{id}", attrs)
end

#user_roles(id = 'my') ⇒ Code42::RoleCollection

Returns a list of roles for a given user

Parameters:

  • id (String, Integer) (defaults to: 'my')

    The id of the user to return roles for

Returns:



18
19
20
# File 'lib/code42/api/role.rb', line 18

def user_roles(id = 'my')
  collection_from_response(Code42::RoleCollection, Code42::Role, :get, "userRole/#{id}")
end