Commit e0cff1d0 authored by Greg Messner's avatar Greg Messner
Browse files

Updates for the new ServicesApi.

parent 5bb6a289
...@@ -23,6 +23,7 @@ MergeRequestApi ...@@ -23,6 +23,7 @@ MergeRequestApi
ProjectApi ProjectApi
RepositoryApi RepositoryApi
RepositoryFileApi RepositoryFileApi
ServicesApi
SessionApi SessionApi
UserApi UserApi
``` ```
...@@ -63,6 +64,12 @@ RepositoryFileApi: ...@@ -63,6 +64,12 @@ RepositoryFileApi:
RepositoryFile file = gitLabApi.getRepositoryFileApi().getFile("file-path", 1234, "ref"); RepositoryFile file = gitLabApi.getRepositoryFileApi().getFile("file-path", 1234, "ref");
``` ```
ServicesApi:
```java
// Activates the gitlab-ci service.
getLabApi.getServicesApi().setGitLabCI("project-name", "auth-token", "project-ci-url");
```
SessionApi: SessionApi:
```java ```java
// Log in to the GitLab server and get the session info // Log in to the GitLab server and get the session info
......
package com.messners.gitlab.api; package com.messners.gitlab.api;
/** /**
* This class is provides a simplified interface to a GitLab API server, and divides the API up into * This class is provides a simplified interface to a GitLab API server, and divides the API up into
* a separate API class for each concern. * a separate API class for each concern.
...@@ -8,119 +7,113 @@ package com.messners.gitlab.api; ...@@ -8,119 +7,113 @@ package com.messners.gitlab.api;
* @author Greg Messner <greg@messners.com> * @author Greg Messner <greg@messners.com>
*/ */
public class GitLabApi { public class GitLabApi {
GitLabApiClient apiClient;
private CommitsApi commitsApi;
private GroupApi groupApi;
private MergeRequestApi mergeRequestApi;
private ProjectApi projectApi;
private RepositoryApi repositoryApi;
private SessionApi sessoinApi;
private UserApi userApi;
private RepositoryFileApi repositoryFileApi;
/** GitLabApiClient apiClient;
* Logs into GitLab using provided {@code username} and {@code password}, and creates a new private CommitsApi commitsApi;
* {@code GitLabApi} instance using returned private token private GroupApi groupApi;
* @param url GitLab URL private MergeRequestApi mergeRequestApi;
* @param username user name for which private token should be obtained private ProjectApi projectApi;
* @param password password for a given {@code username} private RepositoryApi repositoryApi;
* @return new {@code GitLabApi} instance configured for a user-specific token private RepositoryFileApi repositoryFileApi;
*/ private ServicesApi servicesApi;
static public GitLabApi create(String url, String username, String password) throws GitLabApiException { private SessionApi sessoinApi;
String token = new SessionApi(new GitLabApi(url, null)).login(username, null, password).getPrivateToken(); private UserApi userApi;
return new GitLabApi(url, token);
} /**
* Logs into GitLab using provided {@code username} and {@code password}, and creates a new {@code GitLabApi} instance using returned private token
*
* @param url GitLab URL
* @param username user name for which private token should be obtained
* @param password password for a given {@code username}
* @return new {@code GitLabApi} instance configured for a user-specific token
*/
static public GitLabApi create(String url, String username, String password) throws GitLabApiException {
String token = new SessionApi(new GitLabApi(url, null)).login(username, null, password).getPrivateToken();
return new GitLabApi(url, token);
}
/**
* Constructs a GitLabApi instance set up to interact with the GitLab server
* specified by hostUrl.
*
* @param hostUrl
* @param privateToken
*/
public GitLabApi(String hostUrl, String privateToken) {
apiClient = new GitLabApiClient(hostUrl, privateToken);
commitsApi = new CommitsApi(this);
groupApi = new GroupApi(this);
mergeRequestApi = new MergeRequestApi(this);
projectApi = new ProjectApi(this);
repositoryApi = new RepositoryApi(this);
servicesApi = new ServicesApi(this);
sessoinApi = new SessionApi(this);
userApi = new UserApi(this);
repositoryFileApi = new RepositoryFileApi(this);
}
/** /**
* Constructs a GitLabApi instance set up to interact with the GitLab server * Return the GitLabApiClient associated with this instance. This is used by all the sub API classes
* specified by hostUrl. * to communicate with the GitLab API.
* *
* @param hostUrl * @return the GitLabApiClient associated with this instance
* @param privateToken */
*/ GitLabApiClient getApiClient() {
public GitLabApi (String hostUrl, String privateToken) { return (apiClient);
apiClient = new GitLabApiClient(hostUrl, privateToken); }
commitsApi = new CommitsApi(this);
groupApi = new GroupApi(this);
mergeRequestApi = new MergeRequestApi(this);
projectApi = new ProjectApi(this);
repositoryApi = new RepositoryApi(this);
sessoinApi = new SessionApi(this);
userApi = new UserApi(this);
repositoryFileApi = new RepositoryFileApi(this);
}
/**
* Return the GitLabApiClient associated with this instance. This is used by all the sub API classes
* to communicate with the GitLab API.
*
* @return the GitLabApiClient associated with this instance
*/
GitLabApiClient getApiClient () {
return (apiClient);
}
/**
* Gets the CommitsApi instance owned by this GitLabApi instance. The CommitsApi is used
* to perform all commit related API calls.
*
* @return the CommitsApi instance owned by this GitLabApi instance
*/
public CommitsApi getCommitsApi () {
return (commitsApi);
}
/**
* Gets the MergeRequestApi instance owned by this GitLabApi instance. The MergeRequestApi is used
* to perform all merge request related API calls.
*
* @return the MergeRequestApi instance owned by this GitLabApi instance
*/
public MergeRequestApi getMergeRequestApi () {
return (mergeRequestApi);
}
/**
* Gets the GroupApi instance owned by this GitLabApi instance. The GroupApi is used
* to perform all group related API calls.
*
* @return the GroupApi instance owned by this GitLabApi instance
*/
public GroupApi getGroupApi () {
return (groupApi);
}
/** /**
* Gets the ProjectApi instance owned by this GitLabApi instance. The ProjectApi is used * Gets the CommitsApi instance owned by this GitLabApi instance. The CommitsApi is used
* to perform all project related API calls. * to perform all commit related API calls.
* *
* @return the ProjectApi instance owned by this GitLabApi instance * @return the CommitsApi instance owned by this GitLabApi instance
*/ */
public ProjectApi getProjectApi () { public CommitsApi getCommitsApi() {
return (projectApi); return (commitsApi);
} }
/**
* Gets the RepositoryApi instance owned by this GitLabApi instance. The RepositoryApi is used
* to perform all repository related API calls.
*
* @return the RepositoryApi instance owned by this GitLabApi instance
*/
public RepositoryApi getRepositoryApi () {
return (repositoryApi);
}
/**
* Gets the MergeRequestApi instance owned by this GitLabApi instance. The MergeRequestApi is used
* to perform all merge request related API calls.
*
* @return the MergeRequestApi instance owned by this GitLabApi instance
*/
public MergeRequestApi getMergeRequestApi() {
return (mergeRequestApi);
}
/** /**
* Gets the RepositoryFileApi instance owned by this GitLabApi instance. The RepositoryFileApi is used * Gets the GroupApi instance owned by this GitLabApi instance. The GroupApi is used
* to perform all group related API calls.
*
* @return the GroupApi instance owned by this GitLabApi instance
*/
public GroupApi getGroupApi() {
return (groupApi);
}
/**
* Gets the ProjectApi instance owned by this GitLabApi instance. The ProjectApi is used
* to perform all project related API calls.
*
* @return the ProjectApi instance owned by this GitLabApi instance
*/
public ProjectApi getProjectApi() {
return (projectApi);
}
/**
* Gets the RepositoryApi instance owned by this GitLabApi instance. The RepositoryApi is used
* to perform all repository related API calls.
*
* @return the RepositoryApi instance owned by this GitLabApi instance
*/
public RepositoryApi getRepositoryApi() {
return (repositoryApi);
}
/**
* Gets the RepositoryFileApi instance owned by this GitLabApi instance. The RepositoryFileApi is used
* to perform all repository files related API calls. * to perform all repository files related API calls.
* *
* @return the RepositoryFileApi instance owned by this GitLabApi instance * @return the RepositoryFileApi instance owned by this GitLabApi instance
...@@ -129,25 +122,33 @@ public class GitLabApi { ...@@ -129,25 +122,33 @@ public class GitLabApi {
return repositoryFileApi; return repositoryFileApi;
} }
/**
* Gets the ServicesApi instance owned by this GitLabApi instance. The ServicesApi is used
* to perform all services related API calls.
*
* @return the ServicesApi instance owned by this GitLabApi instance
*/
public ServicesApi getServicesApi() {
return (servicesApi);
}
/** /**
* Gets the SessionApi instance owned by this GitLabApi instance. The SessionApi is used * Gets the SessionApi instance owned by this GitLabApi instance. The SessionApi is used
* to perform a login to the GitLab API. * to perform a login to the GitLab API.
* *
* @return the SessionApi instance owned by this GitLabApi instance * @return the SessionApi instance owned by this GitLabApi instance
*/ */
public SessionApi getSessionApi () { public SessionApi getSessionApi() {
return (sessoinApi); return (sessoinApi);
} }
/**
/** * Gets the UserApi instance owned by this GitLabApi instance. The UserApi is used
* Gets the UserApi instance owned by this GitLabApi instance. The UserApi is used * to perform all user related API calls.
* to perform all user related API calls. *
* * @return the UserApi instance owned by this GitLabApi instance
* @return the UserApi instance owned by this GitLabApi instance */
*/ public UserApi getUserApi() {
public UserApi getUserApi () { return (userApi);
return (userApi); }
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment