Skip to content

Commit 797ea6b

Browse files
authored
Add docs for login() and sudo().
1 parent 5b878d7 commit 797ea6b

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

Diff for: README.md

+24-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To utilize the GitLab API for Java in your project, simply add the following dep
1111
```java
1212
dependencies {
1313
...
14-
compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.6.5'
14+
compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.6.6'
1515
}
1616
```
1717

@@ -20,7 +20,7 @@ dependencies {
2020
<dependency>
2121
<groupId>org.gitlab4j</groupId>
2222
<artifactId>gitlab4j-api</artifactId>
23-
<version>4.6.5</version>
23+
<version>4.6.6</version>
2424
</dependency>
2525
```
2626

@@ -37,17 +37,37 @@ GitLabApi gitLabApi = new GitLabApi("http://your.gitlab.server.com", "YOUR_PRIVA
3737
List<Project> projects = gitLabApi.getProjectApi().getProjects();
3838
```
3939

40+
You can also login to your GitLab server with username, and password:
41+
```java
42+
// Log in to the GitLab server using a username and password
43+
GitLabApi gitLabApi = GitLabApi.login("http://your.gitlab.server.com", "your-username", "your-password");
44+
```
45+
46+
As of GitLab4J-API 4.6.6, all API requests support performing the API call as if you were another user, provided you are authenticated as an administrator:
47+
```java
48+
// Create a GitLabApi instance to communicate with your GitLab server (must be an administrator)
49+
GitLabApi gitLabApi = new GitLabApi("http://your.gitlab.server.com", "YOUR_PRIVATE_TOKEN");
50+
51+
// sudo as as a different user, in this case the user named "johndoe", all future calls will be done as "johndoe"
52+
gitLabApi.sudo("johndoe")
53+
54+
// To turn off sudo mode
55+
gitLabApi.unsudo();
56+
```
57+
4058
---
4159

42-
As of GitLab4J-API 4.2.0 support has been added for GitLab API V4. If your application requires GitLab API V3 you can still use GitLab4J-API by creating your GitLabApi instance as follows:
60+
As of GitLab4J-API 4.2.0 support has been added for GitLab API V4. If your application requires GitLab API V3,
61+
you can still use GitLab4J-API by creating your GitLabApi instance as follows:
4362
```java
4463
// Create a GitLabApi instance to communicate with your GitLab server using GitLab API V3
4564
GitLabApi gitLabApi = new GitLabApi(ApiVersion.V3, "http://your.gitlab.server.com", "YOUR_PRIVATE_TOKEN");
4665
```
4766

4867
---
4968

50-
GitLab4J-API provides an easy to use paging mechanism to page through lists of results from the GitLab API. Here are a couple of examples on how to use the Pager:
69+
GitLab4J-API provides an easy to use paging mechanism to page through lists of results from the GitLab API.
70+
Here are a couple of examples on how to use the Pager:
5171
```java
5272
// Get a Pager instance that will page through the projects with 10 projects per page
5373
Pager<Project> projectPager = gitlabApi.getProjectsApi().getProjects(10);

0 commit comments

Comments
 (0)