|
37 | 37 | import org.zendesk.client.v2.model.TwitterMonitor;
|
38 | 38 | import org.zendesk.client.v2.model.User;
|
39 | 39 | 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; |
40 | 43 | import org.zendesk.client.v2.model.targets.BasecampTarget;
|
41 | 44 | import org.zendesk.client.v2.model.targets.CampfireTarget;
|
42 | 45 | import org.zendesk.client.v2.model.targets.EmailTarget;
|
@@ -1136,6 +1139,97 @@ public void updateInstallation(int id, String json) {
|
1136 | 1139 | // TODO search with sort order
|
1137 | 1140 | // TODO search with query building API
|
1138 | 1141 |
|
| 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 | + |
1139 | 1233 | //////////////////////////////////////////////////////////////////////
|
1140 | 1234 | // Helper methods
|
1141 | 1235 | //////////////////////////////////////////////////////////////////////
|
@@ -1505,6 +1599,30 @@ private void checkHasId(Topic topic) {
|
1505 | 1599 | }
|
1506 | 1600 | }
|
1507 | 1601 |
|
| 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 | + |
1508 | 1626 | private static void checkHasToken(Attachment.Upload upload) {
|
1509 | 1627 | if (upload.getToken() == null) {
|
1510 | 1628 | throw new IllegalArgumentException("Upload requires token");
|
|
0 commit comments