Class: JenkinsApi::Client::User

Inherits:
Object
  • Object
show all
Includes:
UriHelper
Defined in:
lib/jenkins_api_client/user.rb

Overview

This class is used to communicate with Jenkins and performing some user level operations - currently limited to fetching user info, but can be extended to support updating user fields

Since:

Instance Method Summary (collapse)

Methods included from UriHelper

#form_encode, #path_encode

Constructor Details

- (User) initialize(client)

Initializes a new User object.

Parameters:

  • client (Client)

    the client object

Since:

  • 0.14.0



43
44
45
46
47
# File 'lib/jenkins_api_client/user.rb', line 43

def initialize(client)
  @client = client
  @logger = @client.logger
  @timeout = @client.timeout
end

Instance Method Details

- (Hash) get(user_id)

Get a single user

Examples:

Example JSON for user info

{
  "absoluteUrl" : "https://myjenkins.example.com/jenkins/user/fred",
  "description" : "",
  "fullName" : "Fred Flintstone",
  "id" : "fred",
  "property" : [
    {
    },
    {
    },
    {
      "address" : "fred@slaterockandgravel.com"
    },
    {
    },
    {
    },
    {
      "insensitiveSearch" : false
    }
  ]
}

Parameters:

  • user_id (String)

    User ID or Full Name

Returns:

  • (Hash)
    • id Jenkins user id

    • fullName Full name of user (or user id if not set)

    • other fields populated by Jenkins - this may vary based on version/plugins

Since:

  • 0.14.0



115
116
117
# File 'lib/jenkins_api_client/user.rb', line 115

def get(user_id)
  response = @client.api_get_request("/user/#{path_encode user_id}")
end

- (Hash) list



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/jenkins_api_client/user.rb', line 64

def list
  @logger.info "Obtaining the list of users from jenkins"
  # First we need to get the list of users.
  # This is the same as "System.list_users", but since I didn't want to
  # depend on that class I reproduced the request here.
  userlist = @client.api_get_request("/asynchPeople")
  users = {}

  userlist['users'].each { |user|
    # Jenkins seems ok to fetch by full-name, as long as perfect match
    # since the name *came* from Jenkins this seems reasonably safe
    user = get(user['user']['fullName'])
    users[user['id']] = user if user
  } unless userlist.nil?

  return users
end

- (Object) to_s

Returns a string representation of User class.

Since:

  • 0.14.0



51
52
53
# File 'lib/jenkins_api_client/user.rb', line 51

def to_s
  "#<JenkinsApi::Client::User>"
end