Skip to content

Implement Help Center API #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Implement Help Center API
  • Loading branch information
ydubreuil committed Jun 30, 2015
commit a1720eec9283ee941cf41ccffb82e8b981f62e78
118 changes: 118 additions & 0 deletions src/main/java/org/zendesk/client/v2/Zendesk.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import org.zendesk.client.v2.model.TwitterMonitor;
import org.zendesk.client.v2.model.User;
import org.zendesk.client.v2.model.UserField;
import org.zendesk.client.v2.model.hc.Article;
import org.zendesk.client.v2.model.hc.Category;
import org.zendesk.client.v2.model.hc.Section;
import org.zendesk.client.v2.model.targets.BasecampTarget;
import org.zendesk.client.v2.model.targets.CampfireTarget;
import org.zendesk.client.v2.model.targets.EmailTarget;
Expand Down Expand Up @@ -1136,6 +1139,97 @@ public void updateInstallation(int id, String json) {
// TODO search with sort order
// TODO search with query building API

//////////////////////////////////////////////////////////////////////
// Action methods for Help Center
//////////////////////////////////////////////////////////////////////

public List<Article> getArticles() {
return complete(submit(req("GET", cnst("/help_center/articles.json")),
handleList(Article.class, "articles")));
}

public Article getArticle(int id) {
return complete(submit(req("GET", tmpl("/help_center/articles/{id}.json").set("id", id)),
handle(Article.class, "article")));
}

public Article createArticle(Article article) {
checkHasSectionId(article);
return complete(submit(req("POST", tmpl("/help_center/sections/{id}/articles.json").set("id", article.getSectionId()),
JSON, json(Collections.singletonMap("article", article))), handle(Article.class, "article")));
}

public Article updateArticle(Article article) {
checkHasId(article);
return complete(submit(req("PUT", tmpl("/help_center/articles/{id}.json").set("id", article.getId()),
JSON, json(Collections.singletonMap("article", article))), handle(Article.class, "article")));
}

public void deleteArticle(Article article) {
checkHasId(article);
complete(submit(req("DELETE", tmpl("/help_center/articles/{id}.json").set("id", article.getId())),
handleStatus()));
}

public List<Category> getCategories() {
return complete(submit(req("GET", cnst("/help_center/categories.json")),
handleList(Category.class, "categories")));
}

public Category getCategory(int id) {
return complete(submit(req("GET", tmpl("/help_center/categories/{id}.json").set("id", id)),
handle(Category.class, "category")));
}

public Category createCategory(Category category) {
return complete(submit(req("POST", cnst("/help_center/categories.json"),
JSON, json(Collections.singletonMap("category", category))), handle(Category.class, "category")));
}

public Category updateCategory(Category category) {
checkHasId(category);
return complete(submit(req("PUT", tmpl("/help_center/categories/{id}.json").set("id", category.getId()),
JSON, json(Collections.singletonMap("category", category))), handle(Category.class, "category")));
}

public void deleteCategory(Category category) {
checkHasId(category);
complete(submit(req("DELETE", tmpl("/help_center/categories/{id}.json").set("id", category.getId())),
handleStatus()));
}

public List<Section> getSections() {
return complete(submit(req("GET", cnst("/help_center/sections.json")), handleList(Section.class, "sections")));
}

public List<Section> getSections(Category category) {
checkHasId(category);
return complete(submit(req("GET", tmpl("/help_center/categories/{id}/sections.json").set("id", category.getId())),
handleList(Section.class, "sections")));
}

public Section getSection(int id) {
return complete(submit(req("GET", tmpl("/help_center/sections/{id}.json").set("id", id)),
handle(Section.class, "section")));
}

public Section createSection(Section section) {
return complete(submit(req("POST", cnst("/help_center/sections.json"), JSON,
json(Collections.singletonMap("section", section))), handle(Section.class, "section")));
}

public Section updateSection(Section section) {
checkHasId(section);
return complete(submit(req("PUT", tmpl("/help_center/sections/{id}.json").set("id", section.getId()),
JSON, json(Collections.singletonMap("section", section))), handle(Section.class, "section")));
}

public void deleteSection(Section section) {
checkHasId(section);
complete(submit(req("DELETE", tmpl("/help_center/sections/{id}.json").set("id", section.getId())),
handleStatus()));
}

//////////////////////////////////////////////////////////////////////
// Helper methods
//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1505,6 +1599,30 @@ private void checkHasId(Topic topic) {
}
}

private static void checkHasId(Article article) {
if (article.getId() == null) {
throw new IllegalArgumentException("Article requires id");
}
}

private static void checkHasSectionId(Article article) {
if (article.getSectionId() == null) {
throw new IllegalArgumentException("Article requires section id");
}
}

private static void checkHasId(Category category) {
if (category.getId() == null) {
throw new IllegalArgumentException("Category requires id");
}
}

private static void checkHasId(Section section) {
if (section.getId() == null) {
throw new IllegalArgumentException("Section requires id");
}
}

private static void checkHasToken(Attachment.Upload upload) {
if (upload.getToken() == null) {
throw new IllegalArgumentException("Upload requires token");
Expand Down
252 changes: 252 additions & 0 deletions src/main/java/org/zendesk/client/v2/model/hc/Article.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
package org.zendesk.client.v2.model.hc;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Date;
import java.util.List;

public class Article {
/** Automatically assigned when the article is created */
private Long id;

/** The API url of the article */
private String url;

/** The url of the article in Help Center */
@JsonProperty("html_url")
private String htmlUrl;

/** The title of the article */
private String title;

/** The HTML body of the article */
private String body;

/** The locale that the article is being displayed in */
private String locale;

/** The source (default) locale of the article */
@JsonProperty("source_locale")
private String sourceLocale;

/** The id of the user who wrote the article (set to the user who made the request on create by default) */
@JsonProperty("author_id")
private Long authorId;

/** True if comments are disabled; false otherwise */
@JsonProperty("comments_disabled")
private Boolean commentsDisabled;

/** Whether the source (default) translation of the article is out of date */
private Boolean outdated;

/** An array of label names associated with this article. By default no label names are used. Only available on certain plans */
@JsonProperty("label_names")
private List<String> labelNames;

/** True if the translation for the current locale is a draft; false otherwise. false by default. */
private Boolean draft;

/** True if this article is promoted; false otherwise. false by default */
private Boolean promoted;

/** The position of this article in the article list. 0 by default */
private Long position;

/** The total sum of votes on this article */
@JsonProperty("vote_sum")
private Long voteSum;

/** The number of votes cast on this article */
@JsonProperty("vote_count")
private Long voteCount;

/** The id of the section to which this article belongs */
@JsonProperty("section_id")
private Long sectionId;

/** The time the article was created */
@JsonProperty("created_at")
private Date createdAt;

/** The time the article was last updated */
@JsonProperty("updated_at")
private Date updatedAt;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getHtmlUrl() {
return htmlUrl;
}

public void setHtmlUrl(String htmlUrl) {
this.htmlUrl = htmlUrl;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getBody() {
return body;
}

public void setBody(String body) {
this.body = body;
}

public String getLocale() {
return locale;
}

public void setLocale(String locale) {
this.locale = locale;
}

public String getSourceLocale() {
return sourceLocale;
}

public void setSourceLocale(String sourceLocale) {
this.sourceLocale = sourceLocale;
}

public Long getAuthorId() {
return authorId;
}

public void setAuthorId(Long authorId) {
this.authorId = authorId;
}

public Boolean getCommentsDisabled() {
return commentsDisabled;
}

public void setCommentsDisabled(Boolean commentsDisabled) {
this.commentsDisabled = commentsDisabled;
}

public Boolean getOutdated() {
return outdated;
}

public void setOutdated(Boolean outdated) {
this.outdated = outdated;
}

public List<String> getLabelNames() {
return labelNames;
}

public void setLabelNames(List<String> labelNames) {
this.labelNames = labelNames;
}

public Boolean getDraft() {
return draft;
}

public void setDraft(Boolean draft) {
this.draft = draft;
}

public Boolean getPromoted() {
return promoted;
}

public void setPromoted(Boolean promoted) {
this.promoted = promoted;
}

public Long getPosition() {
return position;
}

public void setPosition(Long position) {
this.position = position;
}

public Long getVoteSum() {
return voteSum;
}

public void setVoteSum(Long voteSum) {
this.voteSum = voteSum;
}

public Long getVoteCount() {
return voteCount;
}

public void setVoteCount(Long voteCount) {
this.voteCount = voteCount;
}

public Long getSectionId() {
return sectionId;
}

public void setSectionId(Long sectionId) {
this.sectionId = sectionId;
}

public Date getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}

public Date getUpdatedAt() {
return updatedAt;
}

public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}

@Override
public String toString() {
return "Article{" +
"id=" + id +
", url='" + url + '\'' +
", htmlUrl='" + htmlUrl + '\'' +
", title='" + title + '\'' +
", body='" + body + '\'' +
", locale='" + locale + '\'' +
", sourceLocale='" + sourceLocale + '\'' +
", authorId=" + authorId +
", commentsDisabled=" + commentsDisabled +
", outdated=" + outdated +
", labelNames=" + labelNames +
", draft=" + draft +
", promoted=" + promoted +
", position=" + position +
", voteSum=" + voteSum +
", voteCount=" + voteCount +
", sectionId=" + sectionId +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
'}';
}
}
Loading