Commit 5373879f authored by Greg Messner's avatar Greg Messner
Browse files

Fixed issues related to HTTP status (#29, #31).

parent 0ce0ccf6
package org.gitlab4j.api; package org.gitlab4j.api;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Group; import org.gitlab4j.api.models.Group;
import org.gitlab4j.api.models.Member; import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Project;
...@@ -167,7 +168,8 @@ public class GroupApi extends AbstractApi { ...@@ -167,7 +168,8 @@ public class GroupApi extends AbstractApi {
throw new RuntimeException("groupId cannot be null"); throw new RuntimeException("groupId cannot be null");
} }
delete(Response.Status.OK, null, "groups", groupId); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "groups", groupId);
} }
/** /**
...@@ -213,7 +215,7 @@ public class GroupApi extends AbstractApi { ...@@ -213,7 +215,7 @@ public class GroupApi extends AbstractApi {
Form formData = new Form(); Form formData = new Form();
formData.param("user_id", userId.toString()); formData.param("user_id", userId.toString());
formData.param("access_level", accessLevel.toString()); formData.param("access_level", accessLevel.toString());
Response response = post(Response.Status.OK, formData, "groups", groupId, "members"); Response response = post(Response.Status.CREATED, formData, "groups", groupId, "members");
return (response.readEntity(Member.class)); return (response.readEntity(Member.class));
} }
...@@ -227,6 +229,7 @@ public class GroupApi extends AbstractApi { ...@@ -227,6 +229,7 @@ public class GroupApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void removeMember(Integer projectId, Integer userId) throws GitLabApiException { public void removeMember(Integer projectId, Integer userId) throws GitLabApiException {
delete(Response.Status.OK, null, "groups", projectId, "members", userId); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "groups", projectId, "members", userId);
} }
} }
\ No newline at end of file
...@@ -568,7 +568,8 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -568,7 +568,8 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void removeMember(Integer projectId, Integer userId) throws GitLabApiException { public void removeMember(Integer projectId, Integer userId) throws GitLabApiException {
delete(Response.Status.OK, null, "projects", projectId, "members", userId); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", projectId, "members", userId);
} }
/** /**
...@@ -765,7 +766,8 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -765,7 +766,8 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void deleteHook(Integer projectId, Integer hookId) throws GitLabApiException { public void deleteHook(Integer projectId, Integer hookId) throws GitLabApiException {
delete(Response.Status.OK, null, "projects", projectId, "hooks", hookId); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", projectId, "hooks", hookId);
} }
/** /**
......
...@@ -204,7 +204,8 @@ public class RepositoryApi extends AbstractApi { ...@@ -204,7 +204,8 @@ public class RepositoryApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void deleteTag(Integer projectId, String tagName) throws GitLabApiException { public void deleteTag(Integer projectId, String tagName) throws GitLabApiException {
delete(Response.Status.OK, null, "projects", projectId, "repository", "tags", tagName); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", projectId, "repository", "tags", tagName);
} }
/** /**
......
...@@ -133,7 +133,8 @@ public class RepositoryFileApi extends AbstractApi { ...@@ -133,7 +133,8 @@ public class RepositoryFileApi extends AbstractApi {
addFormParam(form, "file_path", filePath, true); addFormParam(form, "file_path", filePath, true);
addFormParam(form, isApiVersion(ApiVersion.V3) ? "branch_name" : "branch", branchName, true); addFormParam(form, isApiVersion(ApiVersion.V3) ? "branch_name" : "branch", branchName, true);
addFormParam(form, "commit_message", commitMessage, true); addFormParam(form, "commit_message", commitMessage, true);
delete(Response.Status.OK, form.asMap(), "projects", projectId, "repository", "files"); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, form.asMap(), "projects", projectId, "repository", "files");
} }
private Form file2form(RepositoryFile file, String branchName, String commitMessage) { private Form file2form(RepositoryFile file, String branchName, String commitMessage) {
......
...@@ -3,6 +3,7 @@ package org.gitlab4j.api; ...@@ -3,6 +3,7 @@ package org.gitlab4j.api;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Form;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Project;
/** /**
...@@ -55,7 +56,8 @@ public class ServicesApi extends AbstractApi { ...@@ -55,7 +56,8 @@ public class ServicesApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void deleteGitLabCI(Integer projectId) throws GitLabApiException { public void deleteGitLabCI(Integer projectId) throws GitLabApiException {
delete(Response.Status.OK, null, "projects", projectId, "services", "gitlab-ci"); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", projectId, "services", "gitlab-ci");
} }
/** /**
...@@ -110,7 +112,8 @@ public class ServicesApi extends AbstractApi { ...@@ -110,7 +112,8 @@ public class ServicesApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void deleteHipChat(Integer projectId) throws GitLabApiException { public void deleteHipChat(Integer projectId) throws GitLabApiException {
delete(Response.Status.OK, null, "projects", projectId, "services", "hipchat"); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", projectId, "services", "hipchat");
} }
/** /**
......
...@@ -6,6 +6,7 @@ import javax.ws.rs.core.Form; ...@@ -6,6 +6,7 @@ import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.User; import org.gitlab4j.api.models.User;
/** /**
...@@ -159,7 +160,8 @@ public class UserApi extends AbstractApi { ...@@ -159,7 +160,8 @@ public class UserApi extends AbstractApi {
throw new RuntimeException("userId cannot be null"); throw new RuntimeException("userId cannot be null");
} }
delete(Response.Status.OK, null, "users", userId); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "users", userId);
} }
/** /**
......
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