Skip to content

Commit 5cb86f9

Browse files
committed
Merge pull request cloudbees-oss#54 from ydubreuil/help-center-api
Implement Help Center API
2 parents 59b0919 + a1720ee commit 5cb86f9

File tree

4 files changed

+697
-0
lines changed

4 files changed

+697
-0
lines changed

src/main/java/org/zendesk/client/v2/Zendesk.java

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
import org.zendesk.client.v2.model.TwitterMonitor;
3838
import org.zendesk.client.v2.model.User;
3939
import org.zendesk.client.v2.model.UserField;
40+
import org.zendesk.client.v2.model.hc.Article;
41+
import org.zendesk.client.v2.model.hc.Category;
42+
import org.zendesk.client.v2.model.hc.Section;
4043
import org.zendesk.client.v2.model.targets.BasecampTarget;
4144
import org.zendesk.client.v2.model.targets.CampfireTarget;
4245
import org.zendesk.client.v2.model.targets.EmailTarget;
@@ -1136,6 +1139,97 @@ public void updateInstallation(int id, String json) {
11361139
// TODO search with sort order
11371140
// TODO search with query building API
11381141

1142+
//////////////////////////////////////////////////////////////////////
1143+
// Action methods for Help Center
1144+
//////////////////////////////////////////////////////////////////////
1145+
1146+
public List<Article> getArticles() {
1147+
return complete(submit(req("GET", cnst("/help_center/articles.json")),
1148+
handleList(Article.class, "articles")));
1149+
}
1150+
1151+
public Article getArticle(int id) {
1152+
return complete(submit(req("GET", tmpl("/help_center/articles/{id}.json").set("id", id)),
1153+
handle(Article.class, "article")));
1154+
}
1155+
1156+
public Article createArticle(Article article) {
1157+
checkHasSectionId(article);
1158+
return complete(submit(req("POST", tmpl("/help_center/sections/{id}/articles.json").set("id", article.getSectionId()),
1159+
JSON, json(Collections.singletonMap("article", article))), handle(Article.class, "article")));
1160+
}
1161+
1162+
public Article updateArticle(Article article) {
1163+
checkHasId(article);
1164+
return complete(submit(req("PUT", tmpl("/help_center/articles/{id}.json").set("id", article.getId()),
1165+
JSON, json(Collections.singletonMap("article", article))), handle(Article.class, "article")));
1166+
}
1167+
1168+
public void deleteArticle(Article article) {
1169+
checkHasId(article);
1170+
complete(submit(req("DELETE", tmpl("/help_center/articles/{id}.json").set("id", article.getId())),
1171+
handleStatus()));
1172+
}
1173+
1174+
public List<Category> getCategories() {
1175+
return complete(submit(req("GET", cnst("/help_center/categories.json")),
1176+
handleList(Category.class, "categories")));
1177+
}
1178+
1179+
public Category getCategory(int id) {
1180+
return complete(submit(req("GET", tmpl("/help_center/categories/{id}.json").set("id", id)),
1181+
handle(Category.class, "category")));
1182+
}
1183+
1184+
public Category createCategory(Category category) {
1185+
return complete(submit(req("POST", cnst("/help_center/categories.json"),
1186+
JSON, json(Collections.singletonMap("category", category))), handle(Category.class, "category")));
1187+
}
1188+
1189+
public Category updateCategory(Category category) {
1190+
checkHasId(category);
1191+
return complete(submit(req("PUT", tmpl("/help_center/categories/{id}.json").set("id", category.getId()),
1192+
JSON, json(Collections.singletonMap("category", category))), handle(Category.class, "category")));
1193+
}
1194+
1195+
public void deleteCategory(Category category) {
1196+
checkHasId(category);
1197+
complete(submit(req("DELETE", tmpl("/help_center/categories/{id}.json").set("id", category.getId())),
1198+
handleStatus()));
1199+
}
1200+
1201+
public List<Section> getSections() {
1202+
return complete(submit(req("GET", cnst("/help_center/sections.json")), handleList(Section.class, "sections")));
1203+
}
1204+
1205+
public List<Section> getSections(Category category) {
1206+
checkHasId(category);
1207+
return complete(submit(req("GET", tmpl("/help_center/categories/{id}/sections.json").set("id", category.getId())),
1208+
handleList(Section.class, "sections")));
1209+
}
1210+
1211+
public Section getSection(int id) {
1212+
return complete(submit(req("GET", tmpl("/help_center/sections/{id}.json").set("id", id)),
1213+
handle(Section.class, "section")));
1214+
}
1215+
1216+
public Section createSection(Section section) {
1217+
return complete(submit(req("POST", cnst("/help_center/sections.json"), JSON,
1218+
json(Collections.singletonMap("section", section))), handle(Section.class, "section")));
1219+
}
1220+
1221+
public Section updateSection(Section section) {
1222+
checkHasId(section);
1223+
return complete(submit(req("PUT", tmpl("/help_center/sections/{id}.json").set("id", section.getId()),
1224+
JSON, json(Collections.singletonMap("section", section))), handle(Section.class, "section")));
1225+
}
1226+
1227+
public void deleteSection(Section section) {
1228+
checkHasId(section);
1229+
complete(submit(req("DELETE", tmpl("/help_center/sections/{id}.json").set("id", section.getId())),
1230+
handleStatus()));
1231+
}
1232+
11391233
//////////////////////////////////////////////////////////////////////
11401234
// Helper methods
11411235
//////////////////////////////////////////////////////////////////////
@@ -1505,6 +1599,30 @@ private void checkHasId(Topic topic) {
15051599
}
15061600
}
15071601

1602+
private static void checkHasId(Article article) {
1603+
if (article.getId() == null) {
1604+
throw new IllegalArgumentException("Article requires id");
1605+
}
1606+
}
1607+
1608+
private static void checkHasSectionId(Article article) {
1609+
if (article.getSectionId() == null) {
1610+
throw new IllegalArgumentException("Article requires section id");
1611+
}
1612+
}
1613+
1614+
private static void checkHasId(Category category) {
1615+
if (category.getId() == null) {
1616+
throw new IllegalArgumentException("Category requires id");
1617+
}
1618+
}
1619+
1620+
private static void checkHasId(Section section) {
1621+
if (section.getId() == null) {
1622+
throw new IllegalArgumentException("Section requires id");
1623+
}
1624+
}
1625+
15081626
private static void checkHasToken(Attachment.Upload upload) {
15091627
if (upload.getToken() == null) {
15101628
throw new IllegalArgumentException("Upload requires token");
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
package org.zendesk.client.v2.model.hc;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.util.Date;
6+
import java.util.List;
7+
8+
public class Article {
9+
/** Automatically assigned when the article is created */
10+
private Long id;
11+
12+
/** The API url of the article */
13+
private String url;
14+
15+
/** The url of the article in Help Center */
16+
@JsonProperty("html_url")
17+
private String htmlUrl;
18+
19+
/** The title of the article */
20+
private String title;
21+
22+
/** The HTML body of the article */
23+
private String body;
24+
25+
/** The locale that the article is being displayed in */
26+
private String locale;
27+
28+
/** The source (default) locale of the article */
29+
@JsonProperty("source_locale")
30+
private String sourceLocale;
31+
32+
/** The id of the user who wrote the article (set to the user who made the request on create by default) */
33+
@JsonProperty("author_id")
34+
private Long authorId;
35+
36+
/** True if comments are disabled; false otherwise */
37+
@JsonProperty("comments_disabled")
38+
private Boolean commentsDisabled;
39+
40+
/** Whether the source (default) translation of the article is out of date */
41+
private Boolean outdated;
42+
43+
/** An array of label names associated with this article. By default no label names are used. Only available on certain plans */
44+
@JsonProperty("label_names")
45+
private List<String> labelNames;
46+
47+
/** True if the translation for the current locale is a draft; false otherwise. false by default. */
48+
private Boolean draft;
49+
50+
/** True if this article is promoted; false otherwise. false by default */
51+
private Boolean promoted;
52+
53+
/** The position of this article in the article list. 0 by default */
54+
private Long position;
55+
56+
/** The total sum of votes on this article */
57+
@JsonProperty("vote_sum")
58+
private Long voteSum;
59+
60+
/** The number of votes cast on this article */
61+
@JsonProperty("vote_count")
62+
private Long voteCount;
63+
64+
/** The id of the section to which this article belongs */
65+
@JsonProperty("section_id")
66+
private Long sectionId;
67+
68+
/** The time the article was created */
69+
@JsonProperty("created_at")
70+
private Date createdAt;
71+
72+
/** The time the article was last updated */
73+
@JsonProperty("updated_at")
74+
private Date updatedAt;
75+
76+
public Long getId() {
77+
return id;
78+
}
79+
80+
public void setId(Long id) {
81+
this.id = id;
82+
}
83+
84+
public String getUrl() {
85+
return url;
86+
}
87+
88+
public void setUrl(String url) {
89+
this.url = url;
90+
}
91+
92+
public String getHtmlUrl() {
93+
return htmlUrl;
94+
}
95+
96+
public void setHtmlUrl(String htmlUrl) {
97+
this.htmlUrl = htmlUrl;
98+
}
99+
100+
public String getTitle() {
101+
return title;
102+
}
103+
104+
public void setTitle(String title) {
105+
this.title = title;
106+
}
107+
108+
public String getBody() {
109+
return body;
110+
}
111+
112+
public void setBody(String body) {
113+
this.body = body;
114+
}
115+
116+
public String getLocale() {
117+
return locale;
118+
}
119+
120+
public void setLocale(String locale) {
121+
this.locale = locale;
122+
}
123+
124+
public String getSourceLocale() {
125+
return sourceLocale;
126+
}
127+
128+
public void setSourceLocale(String sourceLocale) {
129+
this.sourceLocale = sourceLocale;
130+
}
131+
132+
public Long getAuthorId() {
133+
return authorId;
134+
}
135+
136+
public void setAuthorId(Long authorId) {
137+
this.authorId = authorId;
138+
}
139+
140+
public Boolean getCommentsDisabled() {
141+
return commentsDisabled;
142+
}
143+
144+
public void setCommentsDisabled(Boolean commentsDisabled) {
145+
this.commentsDisabled = commentsDisabled;
146+
}
147+
148+
public Boolean getOutdated() {
149+
return outdated;
150+
}
151+
152+
public void setOutdated(Boolean outdated) {
153+
this.outdated = outdated;
154+
}
155+
156+
public List<String> getLabelNames() {
157+
return labelNames;
158+
}
159+
160+
public void setLabelNames(List<String> labelNames) {
161+
this.labelNames = labelNames;
162+
}
163+
164+
public Boolean getDraft() {
165+
return draft;
166+
}
167+
168+
public void setDraft(Boolean draft) {
169+
this.draft = draft;
170+
}
171+
172+
public Boolean getPromoted() {
173+
return promoted;
174+
}
175+
176+
public void setPromoted(Boolean promoted) {
177+
this.promoted = promoted;
178+
}
179+
180+
public Long getPosition() {
181+
return position;
182+
}
183+
184+
public void setPosition(Long position) {
185+
this.position = position;
186+
}
187+
188+
public Long getVoteSum() {
189+
return voteSum;
190+
}
191+
192+
public void setVoteSum(Long voteSum) {
193+
this.voteSum = voteSum;
194+
}
195+
196+
public Long getVoteCount() {
197+
return voteCount;
198+
}
199+
200+
public void setVoteCount(Long voteCount) {
201+
this.voteCount = voteCount;
202+
}
203+
204+
public Long getSectionId() {
205+
return sectionId;
206+
}
207+
208+
public void setSectionId(Long sectionId) {
209+
this.sectionId = sectionId;
210+
}
211+
212+
public Date getCreatedAt() {
213+
return createdAt;
214+
}
215+
216+
public void setCreatedAt(Date createdAt) {
217+
this.createdAt = createdAt;
218+
}
219+
220+
public Date getUpdatedAt() {
221+
return updatedAt;
222+
}
223+
224+
public void setUpdatedAt(Date updatedAt) {
225+
this.updatedAt = updatedAt;
226+
}
227+
228+
@Override
229+
public String toString() {
230+
return "Article{" +
231+
"id=" + id +
232+
", url='" + url + '\'' +
233+
", htmlUrl='" + htmlUrl + '\'' +
234+
", title='" + title + '\'' +
235+
", body='" + body + '\'' +
236+
", locale='" + locale + '\'' +
237+
", sourceLocale='" + sourceLocale + '\'' +
238+
", authorId=" + authorId +
239+
", commentsDisabled=" + commentsDisabled +
240+
", outdated=" + outdated +
241+
", labelNames=" + labelNames +
242+
", draft=" + draft +
243+
", promoted=" + promoted +
244+
", position=" + position +
245+
", voteSum=" + voteSum +
246+
", voteCount=" + voteCount +
247+
", sectionId=" + sectionId +
248+
", createdAt=" + createdAt +
249+
", updatedAt=" + updatedAt +
250+
'}';
251+
}
252+
}

0 commit comments

Comments
 (0)