Skip to content

Commit 0bfdb38

Browse files
shuklaalok7gmessner
authored andcommitted
Added support for Uncyclos API (#191)
1 parent 34cdc6a commit 0bfdb38

File tree

4 files changed

+465
-0
lines changed

4 files changed

+465
-0
lines changed

src/main/java/org/gitlab4j/api/GitLabApi.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public String getApiNamespace() {
7272
private NotesApi notesApi;
7373
private EventsApi eventsApi;
7474
private SnippetsApi snippetsApi;
75+
private UncyclosApi wikisApi;
7576

7677
/**
7778
* Get the GitLab4J shared Logger instance.
@@ -1295,4 +1296,22 @@ public SnippetsApi getSnippetApi() {
12951296

12961297
return snippetsApi;
12971298
}
1299+
1300+
/**
1301+
* Gets the UncyclosApi instance owned by this GitLabApi instance. The UncyclosApi is used to perform all wiki related API calls.
1302+
*
1303+
* @return the UncyclosApi instance owned by this GitLabApi instance
1304+
*/
1305+
public UncyclosApi getUncyclosApi() {
1306+
if (wikisApi == null) {
1307+
synchronized (this) {
1308+
if (wikisApi == null) {
1309+
wikisApi = new UncyclosApi(this);
1310+
}
1311+
}
1312+
}
1313+
1314+
return wikisApi;
1315+
}
1316+
12981317
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2017 Greg Messner <[email protected]>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
* this software and associated documentation files (the "Software"), to deal in
8+
* the Software without restriction, including without limitation the rights to
9+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10+
* the Software, and to permit persons to whom the Software is furnished to do so,
11+
* subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
package org.gitlab4j.api;
25+
26+
import org.gitlab4j.api.models.UncycloPage;
27+
28+
import javax.ws.rs.core.GenericType;
29+
import javax.ws.rs.core.Response;
30+
import java.util.List;
31+
import java.util.Optional;
32+
33+
/**
34+
* @author shuklaalok7 ([email protected])
35+
* @since v4.8.21 2018-06-5 1:26 AM IST
36+
*/
37+
public class UncyclosApi extends AbstractApi {
38+
39+
40+
public UncyclosApi(GitLabApi gitLabApi) {
41+
super(gitLabApi);
42+
}
43+
44+
/**
45+
* Get a list of pages in project wiki. This only returns the first page of wiki-pages.
46+
*
47+
* GET /projects/:id/wikis
48+
*
49+
* @param projectId the project ID to get the wiki-pages for
50+
* @return a list of pages in the project's wiki
51+
* @throws GitLabApiException if any exception occurs
52+
*/
53+
public List<UncycloPage> getPages(Integer projectId) throws GitLabApiException {
54+
return getPages(projectId, 1, this.getDefaultPerPage());
55+
}
56+
57+
/**
58+
* Get a list of project snippets. This only returns the first page of snippets.
59+
*
60+
* GET /projects/:id/wikis
61+
*
62+
* @param projectId the project ID to get the wiki pages for
63+
* @param page the page to get
64+
* @param perPage the number of wiki-pages per page
65+
* @return a list of pages in project's wiki for the specified range
66+
* @throws GitLabApiException if any exception occurs
67+
*/
68+
public List<UncycloPage> getPages(Integer projectId, int page, int perPage) throws GitLabApiException {
69+
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "wikis");
70+
return response.readEntity(new GenericType<List<UncycloPage>>() {});
71+
}
72+
73+
/**
74+
* Get a Pager of project's wiki pages.
75+
*
76+
* GET /projects/:id/wikis
77+
*
78+
* @param projectId the project ID to get the wiki-pages for
79+
* @param itemsPerPage the number of wiki-pages per page
80+
* @return the Pager of wiki-pages
81+
* @throws GitLabApiException if any exception occurs
82+
*/
83+
public Pager<UncycloPage> getPages(Integer projectId, int itemsPerPage) throws GitLabApiException {
84+
return (new Pager<>(this, UncycloPage.class, itemsPerPage, null, "projects", projectId, "wikis"));
85+
}
86+
87+
/**
88+
* Get a single page of project wiki.
89+
*
90+
* GET /projects/:id/wikis/:slug
91+
*
92+
* @param projectId the project ID to get the wiki page for
93+
* @param slug the slug of the project's wiki page
94+
* @return the specified project Snippet
95+
* @throws GitLabApiException if any exception occurs
96+
*/
97+
public UncycloPage getPage(Integer projectId, String slug) throws GitLabApiException {
98+
Response response = get(Response.Status.OK, null, "projects", projectId, "wikis", slug);
99+
return (response.readEntity(UncycloPage.class));
100+
}
101+
102+
/**
103+
* Get a single page of project wiki as an Optional instance.
104+
*
105+
* GET /projects/:id/wikis/:slug
106+
*
107+
* @param projectId the project ID to get the snippet for
108+
* @param slug the slug of the project's wiki page
109+
* @return the specified project Snippet as an Optional instance
110+
*/
111+
public Optional<UncycloPage> getOptionalPage(Integer projectId, String slug) {
112+
try {
113+
return (Optional.ofNullable(getPage(projectId, slug)));
114+
} catch (GitLabApiException glae) {
115+
return (GitLabApi.createOptionalFromException(glae));
116+
}
117+
}
118+
119+
/**
120+
* Creates a new project wiki page. The user must have permission to create new wiki page.
121+
*
122+
* POST /projects/:id/wikis
123+
*
124+
* @param projectId the ID of the project owned by the authenticated user, required
125+
* @param title the title of a snippet, required
126+
* @param content the content of a wiki page, required
127+
* @return a UncycloPage instance with info on the created page
128+
* @throws GitLabApiException if any exception occurs
129+
*/
130+
public UncycloPage createPage(Integer projectId, String title, String content) throws GitLabApiException {
131+
// one of title or content is required
132+
GitLabApiForm formData = new GitLabApiForm()
133+
.withParam("title", title)
134+
.withParam("content", content);
135+
136+
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "wikis");
137+
return (response.readEntity(UncycloPage.class));
138+
}
139+
140+
/**
141+
* Updates an existing project wiki page. The user must have permission to change an existing wiki page.
142+
*
143+
* PUT /projects/:id/wikis/:slug
144+
*
145+
* @param projectId the ID of the project owned by the authenticated user, required
146+
* @param slug the slug of the project's wiki page, required
147+
* @param title the title of a snippet, optional
148+
* @param content the content of a page, optional. Either title or content must be supplied.
149+
* @return a UncycloPage instance with info on the updated page
150+
* @throws GitLabApiException if any exception occurs
151+
*/
152+
public UncycloPage updatePage(Integer projectId, String slug, String title, String content) throws GitLabApiException {
153+
154+
GitLabApiForm formData = new GitLabApiForm()
155+
.withParam("title", title)
156+
.withParam("slug", slug, true)
157+
.withParam("content", content);
158+
159+
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "wikis", slug);
160+
return (response.readEntity(UncycloPage.class));
161+
}
162+
163+
/**
164+
* Deletes an existing project wiki page. This is an idempotent function and deleting a non-existent page does
165+
* not cause an error.
166+
*
167+
* DELETE /projects/:id/wikis/:slug
168+
*
169+
* @param projectId the project ID
170+
* @param slug the slug of the project's wiki page
171+
* @throws GitLabApiException if any exception occurs
172+
*/
173+
public void deletePage(Integer projectId, String slug) throws GitLabApiException {
174+
delete(Response.Status.NO_CONTENT, null, "projects", projectId, "wikis", slug);
175+
}
176+
177+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018 Greg Messner <[email protected]>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
* this software and associated documentation files (the "Software"), to deal in
8+
* the Software without restriction, including without limitation the rights to
9+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10+
* the Software, and to permit persons to whom the Software is furnished to do so,
11+
* subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
package org.gitlab4j.api.models;
25+
26+
import javax.xml.bind.annotation.XmlAccessType;
27+
import javax.xml.bind.annotation.XmlAccessorType;
28+
import javax.xml.bind.annotation.XmlRootElement;
29+
30+
@XmlRootElement
31+
@XmlAccessorType(XmlAccessType.FIELD)
32+
public class UncycloPage {
33+
34+
private String title;
35+
private String content;
36+
private String slug;
37+
private String format;
38+
39+
public UncycloPage() {
40+
}
41+
42+
public UncycloPage(String title, String slug, String content) {
43+
this.title = title;
44+
this.slug = slug;
45+
this.content = content;
46+
}
47+
48+
public String getTitle() {
49+
return this.title;
50+
}
51+
52+
public void setTitle(String title) {
53+
this.title = title;
54+
}
55+
56+
public String getContent() {
57+
return content;
58+
}
59+
60+
public void setContent(String content) {
61+
this.content = content;
62+
}
63+
64+
public String getSlug() {
65+
return slug;
66+
}
67+
68+
public void setSlug(String slug) {
69+
this.slug = slug;
70+
}
71+
72+
public String getFormat() {
73+
return format;
74+
}
75+
76+
public void setFormat(String format) {
77+
this.format = format;
78+
}
79+
}

0 commit comments

Comments
 (0)