Commit 2c58b56f authored by Greg Messner's avatar Greg Messner
Browse files

Completed Javadocs.

parent d099773e
......@@ -7,6 +7,13 @@ import javax.ws.rs.core.MultivaluedMap;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.representation.Form;
/**
* This class is the base class for all the sub API classes. It provides implementations of
* delete(), get(), post() and put() that are re-used by all the sub-classes.
*
* @author Greg Messner <greg@messners.com>
*
*/
public abstract class AbstractApi {
private GitLabApi gitLabApi;
......@@ -17,8 +24,7 @@ public abstract class AbstractApi {
protected GitLabApiClient getApiClient () {
return (gitLabApi.getApiClient());
}
}
/**
......@@ -130,8 +136,7 @@ public abstract class AbstractApi {
return (response);
}
/**
* Perform an HTTP PUT call with the specified form data and path objects, returning
* a ClientResponse instance with the data returned from the endpoint.
......@@ -261,7 +266,7 @@ public abstract class AbstractApi {
* @param name
* @param value
* @param required
* @throws IllegalArgumentException
* @throws IllegalArgumentException if a required parameter is null or empty
*/
protected void addFormParam(Form formData, String name, Object value, boolean required) throws IllegalArgumentException {
......
......@@ -3,9 +3,15 @@ package com.messners.gitlab.api;
import java.util.List;
import com.messners.gitlab.api.models.Commit;
import com.messners.gitlab.api.models.Diff;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.GenericType;
/**
* This class implements the client side API for the GitLab commits calls.
*
* @author Greg Messner <greg@messners.com>
*/
public class CommitsApi extends AbstractApi {
public CommitsApi (GitLabApi gitLabApi) {
......@@ -14,14 +20,49 @@ public class CommitsApi extends AbstractApi {
/**
* GET /projects/:id/repository/commits/branch
* Get a list of repository commits in a project.
*
* @param branch
* GET /projects/:id/repository/commits
*
* @param projectId
* @return
* @throws GitLabApiException
*/
public List<Commit> getCommits (int projectId, String branch) throws GitLabApiException {
ClientResponse response = get(ClientResponse.Status.OK, null, "projects", projectId, "repository", "commits", branch);
public List<Commit> getCommits (int projectId) throws GitLabApiException {
ClientResponse response = get(ClientResponse.Status.OK, null, "projects", projectId, "repository", "commits");
return (response.getEntity(new GenericType<List<Commit>>() {}));
}
}
/**
* Get a specific commit identified by the commit hash or name of a branch or tag.
*
* GET /projects/:id/repository/commits/:sha
*
* @param projectId
* @param sha a commit hash or name of a branch or tag
* @return
* @throws GitLabApiException
*/
public Commit getCommits (int projectId, String sha) throws GitLabApiException {
ClientResponse response = get(ClientResponse.Status.OK, null, "projects", projectId, "repository", "commits", sha);
return (response.getEntity(Commit.class));
}
/**
* Get the diff of a commit in a project.
*
* GET /projects/:id/repository/commits/:sha/diff
*
* @param projectId
* @param sha a commit hash or name of a branch or tag
* @return
* @throws GitLabApiException
*/
public Diff getDiff (int projectId, String sha) throws GitLabApiException {
ClientResponse response = get(ClientResponse.Status.OK, null,
"projects", projectId, "repository", "commits", sha, "diff");
return (response.getEntity(Diff.class));
}
}
\ No newline at end of file
......@@ -2,7 +2,8 @@ package com.messners.gitlab.api;
/**
* This class specifies methods to interact with a GitLab server utilizing the standard GitLab API.
* 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.
*
* @author Greg Messner <greg@messners.com>
*/
......@@ -19,7 +20,7 @@ public class GitLabApi {
/**
* Contructs a GitLabApi instance set up to interact with the GitLab server
* Constructs a GitLabApi instance set up to interact with the GitLab server
* specified by hostUrl.
*
* @param hostUrl
......@@ -94,7 +95,7 @@ public class GitLabApi {
/**
* Gets the RepositoryApi instance owned by this GitLabApi instance. The RepositoryApi is used
* to perform all user related API calls.
* to perform all repository related API calls.
*
* @return the RepositoryApi instance owned by this GitLabApi instance
*/
......
......@@ -5,6 +5,14 @@ import javax.ws.rs.core.Response.StatusType;
import com.messners.gitlab.api.models.ErrorMessage;
import com.sun.jersey.api.client.ClientResponse;
/**
* This is the exception that will be thrown if any exception occurs while communicating
* with a GitLab API endpoint.
*
* @author Greg Messner <greg@messners.com>
*
*/
public class GitLabApiException extends Exception {
private static final long serialVersionUID = 1L;
......@@ -14,7 +22,7 @@ public class GitLabApiException extends Exception {
private String message;
/**
* Create a GitLabApiException based on the ClientResponse.
* Create a GitLabApiException instance based on the ClientResponse.
*
* @param response
*/
......@@ -35,6 +43,10 @@ public class GitLabApiException extends Exception {
}
/**
* Create a GitLabApiException instance based on the exception.
* @param e
*/
public GitLabApiException (Exception e) {
super(e);
message = e.getMessage();
......@@ -56,7 +68,7 @@ public class GitLabApiException extends Exception {
* Returns the HTTP status reason message, returns null if the
* causing error was not an HTTP related exception.
*
* @return
* @return the HTTP status reason message
*/
public final String getReason () {
return (statusInfo != null ? statusInfo.getReasonPhrase() : null);
......@@ -64,10 +76,10 @@ public class GitLabApiException extends Exception {
/**
* Returns the HTTP status code. returns 0 if the
* Returns the HTTP status code that was the cause of the exception. returns 0 if the
* causing error was not an HTTP related exception.
*
* @return
* @return the HTTP status code, returns 0 if the causing error was not an HTTP related exception
*/
public final int getHttpStatus () {
return (httpStatus);
......
......@@ -8,6 +8,11 @@ import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.representation.Form;
/**
* This class implements the client side API for the GitLab groups calls.
*
* @author Greg Messner <greg@messners.com>
*/
public class GroupApi extends AbstractApi {
GroupApi (GitLabApi gitLabApi) {
......@@ -20,7 +25,7 @@ public class GroupApi extends AbstractApi {
*
* GET /groups
*
* @return
* @return the list of groups viewable by the authenticated user
* @throws GitLabApiException
*/
public List<Group> getGroups () throws GitLabApiException {
......@@ -35,7 +40,7 @@ public class GroupApi extends AbstractApi {
* GET /groups/:id
*
* @param groupId
* @return
* @return the Group instance for the specified group ID
* @throws GitLabApiException
*/
public Group getGroup (int groupId) throws GitLabApiException {
......@@ -97,7 +102,7 @@ public class GroupApi extends AbstractApi {
*
* GET /groups/:id/members
*
* @return
* @return a list of group members viewable by the authenticated user
* @throws GitLabApiException
*/
public List<Member> getMembers (int groupId) throws GitLabApiException {
......@@ -113,7 +118,7 @@ public class GroupApi extends AbstractApi {
* @param groupId
* @param userId
* @param accessLevel
* @return
* @return a Member instance for the added user
* @throws GitLabApiException
*/
public Member addMember (Integer groupId, Integer userId, Integer accessLevel) throws GitLabApiException {
......
......@@ -6,6 +6,11 @@ import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
/**
* This class provides utility methods for parsing and formatting ISO8601 formatted dates.
*
* @author Greg Messner <greg@messners.com>
*/
public class ISO8601 {
public static final String PATTERN = "yyyy-MM-dd'T'HH:mm:ssZ";
public static final String OUTPUT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
......@@ -26,10 +31,23 @@ public class ISO8601 {
iso8601AlternateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
}
/**
* Get a ISO8601 formatted string for the current date and time.
*
* @return a ISO8601 formatted string for the current date and time
*/
public static String getTimestamp () {
return iso8601Format.format(new Date());
}
/**
* Get a ISO8601 formatted string for the provided Calendar instance.
*
* @param cal the Calendar instance to get the ISO8601 formatted string for
* @return a ISO8601 formatted string for the provided Calendar instance, or null if call is null
*/
public static String toString (Calendar cal) {
if (cal == null) {
......@@ -39,6 +57,13 @@ public class ISO8601 {
return toString(cal.getTime());
}
/**
* Get a ISO8601 formatted string for the provided Date instance.
*
* @param date the Date instance to get the ISO8601 formatted string for
* @return a ISO8601 formatted string for the provided Date instance, or null if date is null
*/
public static synchronized String toString (Date date) {
if (date == null) {
......@@ -48,6 +73,14 @@ public class ISO8601 {
return iso8601OutputFormat.format(date);
}
/**
* Parses an ISO8601 formatted string a returns a Date instance.
*
* @param dateTimeString the ISO8601 formatted string
* @return a Date instance for the ISO8601 formatted string
* @throws ParseException if the provided string is not in the proper format
*/
public static Date toDate (String dateTimeString) throws ParseException {
if (dateTimeString == null) {
......@@ -69,6 +102,14 @@ public class ISO8601 {
}
}
/**
* Parses an ISO8601 formatted string a returns a Calendar instance.
*
* @param dateTimeString the ISO8601 formatted string
* @return a Calendar instance for the ISO8601 formatted string
* @throws ParseException if the provided string is not in the proper format
*/
public static Calendar toCalendar (String dateTimeString) throws ParseException {
Date date = toDate(dateTimeString);
......
......@@ -64,18 +64,20 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol
/**
* Gets the ObjectMapper contained by this instance.
*
* @return
* @return the ObjectMapper contained by this instance
*/
public ObjectMapper getObjectMapper () {
return (objectMapper);
}
/**
* Unmarshal the JSON data on the specified Reader instance to an instance of the provided class.
*
* @param returnType
* @param reader
* @return
* @param returnType an instance of this type class will be returned
* @param reader the Reader instance that contains the JSON data
* @return an instance of the provided class containing the parsed data from the Reader
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
......@@ -87,10 +89,11 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol
}
/**
*
* @param returnType
* Unmarshal the JSON data contained by the string and populate an instance of the provided returnType class.
*
* @param returnType an instance of this type class will be returned
* @param postData
* @return
* @return an instance of the provided class containing the parsed data from the string
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
......@@ -105,7 +108,7 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol
/**
* Marshals the supplied object out as a formatted JSON string.
*
* @param object
* @param object the object to output as a JSON string
* @return
*/
public <T> String marshal (final T object) {
......@@ -131,6 +134,9 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol
}
/**
* JsonSerializer for serializing ISO8601 formatted dates.
*/
public static class JsonDateSerializer extends JsonSerializer<Date> {
@Override
......
......@@ -9,7 +9,8 @@ import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.representation.Form;
/**
*
* This class implements the client side API for the GitLab merge request calls.
*
* @author Greg Messner <greg@messners.com>
*/
public class MergeRequestApi extends AbstractApi {
......@@ -20,12 +21,12 @@ public class MergeRequestApi extends AbstractApi {
/**
* Get all merge requests for this project.
* Get all merge requests for the specified project.
*
* GET /projects/:id/merge_requests
*
* @param projectId
* @return
* @param projectId the project ID to get the merge requests for
* @return all merge requests for the specified project
* @throws GitLabApiException
*/
public List<MergeRequest> getMergeRequests (Integer projectId) throws GitLabApiException {
......@@ -95,7 +96,7 @@ public class MergeRequestApi extends AbstractApi {
* @param title
* @param description
* @param assigneeId
* @return
* @return the updated merge request
* @throws GitLabApiException
*/
public MergeRequest updateMergeRequest (Integer projectId, Integer mergeRequestId,
......@@ -129,7 +130,7 @@ public class MergeRequestApi extends AbstractApi {
* @param projectId
* @param mergeRequestId
* @param comments
* @return
* @return the added merge request comment
* @throws GitLabApiException
*/
public MergeRequestComment addMergeRequestComment (Integer projectId, Integer mergeRequestId, String comments) throws GitLabApiException {
......
......@@ -24,7 +24,7 @@ public class ProjectApi extends AbstractApi {
*
* GET /projects
*
* @return
* @return a list of projects accessible by the authenticated user
* @throws GitLabApiException
*/
public List<Project> getProjects () throws GitLabApiException {
......@@ -38,7 +38,7 @@ public class ProjectApi extends AbstractApi {
*
* GET /projects/all
*
* @return
* @return a list of all GitLab projects
* @throws GitLabApiException
*/
public List<Project> getAllProjects () throws GitLabApiException {
......@@ -52,7 +52,7 @@ public class ProjectApi extends AbstractApi {
*
* GET /projects/owned
*
* @return
* @return a list of projects owned by the authenticated user
* @throws GitLabApiException
*/
public List<Project> getOwnedProjects () throws GitLabApiException {
......@@ -67,7 +67,7 @@ public class ProjectApi extends AbstractApi {
* GET /projects/:id
*
* @param projectId
* @return
* @return the specified project
* @throws GitLabApiException
*/
public Project getProject (Integer projectId) throws GitLabApiException {
......@@ -83,7 +83,7 @@ public class ProjectApi extends AbstractApi {
*
* @param group
* @param project
* @return
* @return the specified project
* @throws GitLabApiException
*/
public Project getProject (String group, String project) throws GitLabApiException {
......@@ -105,7 +105,7 @@ public class ProjectApi extends AbstractApi {
*
* @param groupId
* @param projectName
* @return
* @return the created project
* @throws GitLabApiException
*/
public Project createProject (Integer groupId, String projectName) throws GitLabApiException {
......@@ -219,7 +219,7 @@ public class ProjectApi extends AbstractApi {
* GET /projects/:id/members
*
* @param projectId
* @return
* @return the members belonging to the specified project
* @throws GitLabApiException
*/
public List<Member> getMembers (Integer projectId) throws GitLabApiException {
......@@ -235,7 +235,7 @@ public class ProjectApi extends AbstractApi {
*
* @param projectId
* @param userId
* @return
* @return the member specified by the project ID/user ID pair
* @throws GitLabApiException
*/
public Member getMember (Integer projectId, Integer userId) throws GitLabApiException {
......@@ -254,7 +254,7 @@ public class ProjectApi extends AbstractApi {
* @param projectId
* @param userId
* @param accessLevel
* @return
* @return the added member
* @throws GitLabApiException
*/
public Member addMember (Integer projectId, Integer userId, Integer accessLevel) throws GitLabApiException {
......@@ -276,9 +276,8 @@ public class ProjectApi extends AbstractApi {
* @param userId
* @throws GitLabApiException
*/
public boolean removeMember (Integer projectId, Integer userId) throws GitLabApiException {
ClientResponse response = delete(ClientResponse.Status.OK, null, "projects", projectId, "members", userId);
return (response.getStatus() == ClientResponse.Status.OK.getStatusCode());
public void removeMember (Integer projectId, Integer userId) throws GitLabApiException {
delete(ClientResponse.Status.OK, null, "projects", projectId, "members", userId);
}
......@@ -288,7 +287,7 @@ public class ProjectApi extends AbstractApi {
* GET /projects/:id/events
*
* @param projectId
* @return
* @return the project events for the specified project
* @throws GitLabApiException
*/
public List<Event> getProjectEvents (Integer projectId) throws GitLabApiException {
......@@ -303,7 +302,7 @@ public class ProjectApi extends AbstractApi {
* GET /projects/:id/hooks
*
* @param projectId
* @return
* @return a list of project hooks for the specified project
* @throws GitLabApiException
*/
public List<ProjectHook> getHooks (Integer projectId) throws GitLabApiException {
......@@ -319,7 +318,7 @@ public class ProjectApi extends AbstractApi {
*
* @param projectId
* @param hookId
* @return
* @return the project hook for the specified project ID/hook ID pair
* @throws GitLabApiException
*/
public ProjectHook getHook (Integer projectId, Integer hookId) throws GitLabApiException {
......@@ -338,7 +337,7 @@ public class ProjectApi extends AbstractApi {
* @param doPushEvents
* @param doIssuesEvents
* @param doMergeRequestsEvents
* @return
* @return the added project hook
* @throws GitLabApiException
*/
public ProjectHook addHook (Project project, String url,
......@@ -363,7 +362,7 @@ public class ProjectApi extends AbstractApi {
* @param doPushEvents
* @param doIssuesEvents
* @param doMergeRequestsEvents
* @return
* @return the added project hook
* @throws GitLabApiException
*/
public ProjectHook addHook (Integer projectId, String url,
......@@ -418,11 +417,10 @@ public class ProjectApi extends AbstractApi {
* @param doPushEvents
* @param doIssuesEvents
* @param doMergeRequestsEvents
* @return
* @return the modified project hook
* @throws GitLabApiException
*/
public ProjectHook modifyHook (ProjectHook hook)
throws GitLabApiException {
public ProjectHook modifyHook (ProjectHook hook) throws GitLabApiException {
Form formData = new Form();
formData.add("url", hook.getUrl());
......
......@@ -28,7 +28,7 @@ public class RepositoryApi extends AbstractApi {
* GET /projects/:id/repository/branches
*
* @param projectId
* @return
* @return the list of repository branches for mthe specified project ID
* @throws GitLabApiException
*/
public List<Branch> getBranches (Integer projectId) throws GitLabApiException {
......@@ -44,7 +44,7 @@ public class RepositoryApi extends AbstractApi {
*
* @param projectId
* @param branchName
* @return
* @return the branch info for the specified project ID/branch name pair
* @throws GitLabApiException
*/
public Branch getBranch (Integer projectId, String branchName) throws GitLabApiException {
......@@ -61,7 +61,7 @@ public class RepositoryApi extends AbstractApi {
*
* @param projectId
* @param branchName
* @return
* @return the branch info for the protected branch
* @throws GitLabApiException
*/
public Branch protectBranch (Integer projectId, String branchName) throws GitLabApiException {
......@@ -78,7 +78,7 @@ public class RepositoryApi extends AbstractApi {
*
* @param projectId
* @param branchName
* @return
* @return the branch info for the unprotected branch
* @throws GitLabApiException
*/
public Branch unprotectBranch (Integer projectId, String branchName) throws GitLabApiException {
......@@ -93,7 +93,7 @@ public class RepositoryApi extends AbstractApi {
* GET /projects/:id/repository/tags
*
* @param projectId
* @return
* @return the list of tags for the specified project ID
* @throws GitLabApiException
*/
public List<Tag> getTags (Integer projectId) throws GitLabApiException {
......@@ -108,12 +108,12 @@ public class RepositoryApi extends AbstractApi {
* GET /projects/:id/repository/tree
*
* @param projectId
* @return
* @return a tree with the diurectories and files of a project
* @throws GitLabApiException
*/
public List<TreeItem> getTree (Integer projectId) throws GitLabApiException {
ClientResponse response = put(ClientResponse.Status.OK, null, "projects", projectId, "repository", "tree");
return (response.getEntity(new GenericType<List<TreeItem>>() {}));
return (response.getEntity(new GenericType<List<TreeItem>>() {}));
}
......@@ -124,7 +124,7 @@ public class RepositoryApi extends AbstractApi {
*
* @param projectId
* @param commitOrBranchName
* @return
* @return a string with the file content for the specified file
* @throws GitLabApiException
*/
public String getRawFileContent (Integer projectId, String commitOrBranchName, String filepath) throws GitLabApiException {
......
......@@ -26,7 +26,7 @@ public class SessionApi extends AbstractApi {
* @param username
* @param email
* @param password
* @return
* @return a Session instance with info on the logged in user
* @throws GitLabApiException
*/
public Session login (String username, String email, String password) throws GitLabApiException {
......
......@@ -19,7 +19,7 @@ public class UserApi extends AbstractApi {
*
* GET /users
*
* @return
* @return a list of Users, this list will only contain the first 20 users in the system.
* @throws GitLabApiException
*/
public List<User> getUsers () throws GitLabApiException {
......@@ -35,7 +35,7 @@ public class UserApi extends AbstractApi {
*
* @param page
* @param perPage
* @return
* @return the list of Users in the specified range
* @throws GitLabApiException
*/
public List<User> getUsers (int page, int perPage) throws GitLabApiException {
......@@ -54,7 +54,7 @@ public class UserApi extends AbstractApi {
* GET /users/:id
*
* @param userId
* @return
* @return the User instance for the specified user ID
* @throws GitLabApiException
*/
public User getUser (int userId) throws GitLabApiException {
......@@ -84,7 +84,7 @@ public class UserApi extends AbstractApi {
* can_create_group (optional) - User can create groups - true or false
*
* @param user
* @return
* @return created User instance
* @throws GitLabApiException
*/
public User createUser (User user, String password, Integer projectsLimit) throws GitLabApiException {
......@@ -131,7 +131,7 @@ public class UserApi extends AbstractApi {
* can_create_group (optional) - User can create groups - true or false
*
* @param user
* @return
* @return the modified User instance
* @throws GitLabApiException
*/
public User modifyUser (User user, String password, Integer projectsLimit) throws GitLabApiException {
......
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