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

Added SessionApi.

parent e8c27ffa
...@@ -14,6 +14,7 @@ public class GitLabApi { ...@@ -14,6 +14,7 @@ public class GitLabApi {
private MergeRequestApi mergeRequestApi; private MergeRequestApi mergeRequestApi;
private ProjectApi projectApi; private ProjectApi projectApi;
private RepositoryApi repositoryApi; private RepositoryApi repositoryApi;
private SessionApi sessoinApi;
private UserApi userApi; private UserApi userApi;
...@@ -31,6 +32,7 @@ public class GitLabApi { ...@@ -31,6 +32,7 @@ public class GitLabApi {
mergeRequestApi = new MergeRequestApi(this); mergeRequestApi = new MergeRequestApi(this);
projectApi = new ProjectApi(this); projectApi = new ProjectApi(this);
repositoryApi = new RepositoryApi(this); repositoryApi = new RepositoryApi(this);
sessoinApi = new SessionApi(this);
userApi = new UserApi(this); userApi = new UserApi(this);
} }
...@@ -98,6 +100,17 @@ public class GitLabApi { ...@@ -98,6 +100,17 @@ public class GitLabApi {
*/ */
public RepositoryApi getRepositoryApi () { public RepositoryApi getRepositoryApi () {
return (repositoryApi); return (repositoryApi);
}
/**
* Gets the SessionApi instance owned by this GitLabApi instance. The SessionApi is used
* to perform a login to the GitLab API.
*
* @return the SessionApi instance owned by this GitLabApi instance
*/
public SessionApi getSessionApi () {
return (sessoinApi);
} }
...@@ -105,7 +118,7 @@ public class GitLabApi { ...@@ -105,7 +118,7 @@ public class GitLabApi {
* 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 ProjectApi 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);
......
package com.messners.gitlab.api;
import com.messners.gitlab.api.models.Session;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.representation.Form;
/**
* This class implements the client side API for the GitLab login call.
*
* @author Greg Messner <greg@messners.com>
*
*/
public class SessionApi extends AbstractApi {
public SessionApi (GitLabApi gitLabApi) {
super(gitLabApi);
}
/**
* Login to get private token.
*
* POST /session
*
* @param username
* @param email
* @param password
* @return
* @throws GitLabApiException
*/
public Session login (String username, String email, String password) throws GitLabApiException {
if ((username == null || username.trim().length() == 0)
&& (email == null || email.trim().length() == 0)) {
throw new IllegalArgumentException("both username and email cannot be empty or null");
}
Form formData = new Form();
addFormParam(formData, "email", email, false);
addFormParam(formData, "password", password, true);
addFormParam(formData, "login", username, false);
ClientResponse response = post(ClientResponse.Status.OK, formData, "session");
return (response.getEntity(Session.class));
}
}
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