Skip to content

Commit 08e4801

Browse files
committed
Merge pull request cloudbees-oss#70 from christ66/downloadAllArticles
Download Zendesk article attachments and get articles from next page
2 parents d2882c3 + b4576ce commit 08e4801

File tree

2 files changed

+181
-0
lines changed

2 files changed

+181
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.zendesk.client.v2.model.User;
4141
import org.zendesk.client.v2.model.UserField;
4242
import org.zendesk.client.v2.model.hc.Article;
43+
import org.zendesk.client.v2.model.hc.ArticleAttachments;
4344
import org.zendesk.client.v2.model.hc.Category;
4445
import org.zendesk.client.v2.model.hc.Section;
4546
import org.zendesk.client.v2.model.targets.BasecampTarget;
@@ -281,6 +282,11 @@ public Iterable<Article> getArticleFromSearch(String searchTerm) {
281282
handleList(Article.class, "results"));
282283
}
283284

285+
public List<ArticleAttachments> getAttachmentsFromArticle(Long articleID) {
286+
return complete(submit(req("GET", tmpl("/help_center/articles/{?query}/attachments.json").set("query", articleID)),
287+
handleList(ArticleAttachments.class, "articles")));
288+
}
289+
284290
public List<Ticket> getTickets(long id, long... ids) {
285291
return complete(submit(req("GET", tmpl("/tickets/show_many.json{?ids}").set("ids", idArray(id, ids))),
286292
handleList(Ticket.class, "tickets")));
@@ -1193,11 +1199,23 @@ public void updateInstallation(int id, String json) {
11931199
// Action methods for Help Center
11941200
//////////////////////////////////////////////////////////////////////
11951201

1202+
/**
1203+
* Get first page of articles from help center.
1204+
*
1205+
* @deprecated use #getArticlesFromPage(int). Same as #getArticlesFromPage(0)
1206+
* @return List of Articles.
1207+
*/
1208+
@Deprecated
11961209
public List<Article> getArticles() {
11971210
return complete(submit(req("GET", cnst("/help_center/articles.json")),
11981211
handleList(Article.class, "articles")));
11991212
}
12001213

1214+
public List<Article> getArticlesFromPage(int page) {
1215+
return complete(submit(req("GET", tmpl("/help_center/articles.json?page={page}").set("page", page)),
1216+
handleList(Article.class, "articles")));
1217+
}
1218+
12011219
public Article getArticle(int id) {
12021220
return complete(submit(req("GET", tmpl("/help_center/articles/{id}.json").set("id", id)),
12031221
handle(Article.class, "article")));
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
package org.zendesk.client.v2.model.hc;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.util.Date;
6+
7+
public class ArticleAttachments {
8+
9+
/**
10+
* Automatically assigned when the article attachment is created
11+
*/
12+
private int id;
13+
14+
/**
15+
* The API url of this article attachment
16+
*/
17+
private String url;
18+
19+
/**
20+
* Id of the associated article, if present
21+
*/
22+
private int articleId;
23+
24+
/**
25+
* The name of the file
26+
*/
27+
private String fileName;
28+
29+
/**
30+
* A full URL where the attachment file can be downloaded
31+
*/
32+
private String contentUrl;
33+
34+
/**
35+
* The content type of the file. Example: image/png
36+
*/
37+
private String contentType;
38+
39+
/**
40+
* The size of the attachment file in bytes
41+
*/
42+
private int size;
43+
44+
/**
45+
* If true, the attached file is shown in the dedicated admin UI for inline attachments and
46+
* its url can be referenced in the HTML body of the article.
47+
* If false, the attachment is listed in the list of attachments. Default is false
48+
*/
49+
private boolean inline;
50+
51+
/**
52+
* The time at which the article attachment was created
53+
*/
54+
private Date createdAt;
55+
56+
/**
57+
* The time at which the article attachment was last updated
58+
*/
59+
private Date updatedAt;
60+
61+
public int getId() {
62+
return id;
63+
}
64+
65+
public void setId(int id) {
66+
this.id = id;
67+
}
68+
69+
public String getUrl() {
70+
return url;
71+
}
72+
73+
public void setUrl(String url) {
74+
this.url = url;
75+
}
76+
77+
@JsonProperty("article_id")
78+
public int getArticleId() {
79+
return articleId;
80+
}
81+
82+
public void setArticleId(int articleId) {
83+
this.articleId = articleId;
84+
}
85+
86+
@JsonProperty("file_name")
87+
public String getFileName() {
88+
return fileName;
89+
}
90+
91+
public void setFileName(String fileName) {
92+
this.fileName = fileName;
93+
}
94+
95+
@JsonProperty("content_url")
96+
public String getContentUrl() {
97+
return contentUrl;
98+
}
99+
100+
public void setContentUrl(String contentUrl) {
101+
this.contentUrl = contentUrl;
102+
}
103+
104+
@JsonProperty("content_type")
105+
public String getContentType() {
106+
return contentType;
107+
}
108+
109+
public void setContentType(String contentType) {
110+
this.contentType = contentType;
111+
}
112+
113+
public int getSize() {
114+
return size;
115+
}
116+
117+
public void setSize(int size) {
118+
this.size = size;
119+
}
120+
121+
@JsonProperty("inline")
122+
public boolean isInline() {
123+
return inline;
124+
}
125+
126+
public void setInline(boolean inline) {
127+
this.inline = inline;
128+
}
129+
130+
@JsonProperty("created_at")
131+
public Date getCreatedAt() {
132+
return createdAt;
133+
}
134+
135+
public void setCreatedAt(Date createdAt) {
136+
this.createdAt = createdAt;
137+
}
138+
139+
@JsonProperty("updated_at")
140+
public Date getUpdatedAt() {
141+
return updatedAt;
142+
}
143+
144+
public void setUpdatedAt(Date updatedAt) {
145+
this.updatedAt = updatedAt;
146+
}
147+
148+
@Override
149+
public String toString() {
150+
return "ArticleAttachments{" +
151+
"id=" + id +
152+
", url='" + url + '\'' +
153+
", articleId=" + articleId +
154+
", fileName='" + fileName + '\'' +
155+
", contentUrl='" + contentUrl + '\'' +
156+
", contentType='" + contentType + '\'' +
157+
", size=" + size +
158+
", inline=" + inline +
159+
", createdAt=" + createdAt +
160+
", updatedAt=" + updatedAt +
161+
'}';
162+
}
163+
}

0 commit comments

Comments
 (0)