Project

General

Profile

Download (1.14 KB) Statistics
| Branch: | Tag: | Revision:

runcible / lib / runcible / resources / role.rb @ 27b106f4

1
module Runcible
2
  module Resources
3
    # @see https://docs.pulpproject.org/dev-guide/integration/rest-api/role/index.html
4
    class Role < Runcible::Base
5
      # Generates the API path for Roles
6
      #
7
      # @param  [String]  id  the ID of the role
8
      # @return [String]      the role path, may contain the ID if passed
9
      def self.path(id = nil)
10
        id.nil? ? 'roles/' : "roles/#{id}/"
11
      end
12

    
13
      # Adds a user to a role
14
      #
15
      # @param  [String]                id    the ID of the role
16
      # @param  [String]                login the login of the user being added
17
      # @return [RestClient::Response]
18
      def add(id, login)
19
        required = required_params(binding.send(:local_variables), binding, ['id'])
20
        call(:post, "#{path(id)}users/", :payload => { :required => required })
21
      end
22

    
23
      # Removes a user from a role
24
      #
25
      # @param  [String]                id    the ID of the role
26
      # @param  [String]                login the login of the user being removed
27
      # @return [RestClient::Response]
28
      def remove(id, login)
29
        call(:delete, "#{path(id)}users/#{login}/")
30
      end
31
    end
32
  end
33
end