Skip to content

Commit e36777b

Browse files
author
Matt Tucker
committed
HelpCenter Subscriptions
1 parent 5a15f95 commit e36777b

File tree

4 files changed

+206
-0
lines changed

4 files changed

+206
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Here is the status of the various API components:
6464
* [Help Center Sections](https://developer.zendesk.com/rest_api/docs/help_center/sections)
6565
* [Help Center Articles](https://developer.zendesk.com/rest_api/docs/help_center/articles)
6666
* [Help Center Translations](https://developer.zendesk.com/rest_api/docs/help_center/translations) - Partial (List Translations, Update Translation)
67+
* [Help Center Subscriptions](https://developer.zendesk.com/rest_api/docs/help_center/subscriptions)
6768
* [Topic Votes](http://developer.zendesk.com/documentation/rest_api/topic_votes.html)
6869
* [Account Settings](http://developer.zendesk.com/documentation/rest_api/account_settings.html)
6970
* [Activity Stream](http://developer.zendesk.com/documentation/rest_api/activity_stream.html)

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.zendesk.client.v2.model.hc.ArticleAttachments;
5252
import org.zendesk.client.v2.model.hc.Category;
5353
import org.zendesk.client.v2.model.hc.Section;
54+
import org.zendesk.client.v2.model.hc.Subscription;
5455
import org.zendesk.client.v2.model.hc.Translation;
5556
import org.zendesk.client.v2.model.schedules.Holiday;
5657
import org.zendesk.client.v2.model.schedules.Schedule;
@@ -1604,6 +1605,37 @@ public void deleteSection(Section section) {
16041605
handleStatus()));
16051606
}
16061607

1608+
public Iterable<Subscription> getUserSubscriptions(User user) {
1609+
checkHasId(user);
1610+
return getUserSubscriptions(user.getId());
1611+
}
1612+
1613+
public Iterable<Subscription> getUserSubscriptions(Long userId) {
1614+
return new PagedIterable<Subscription>(
1615+
tmpl("/help_center/users/{userId}/subscriptions.json").set("userId", userId),
1616+
handleList(Subscription.class, "subscriptions"));
1617+
}
1618+
1619+
public Iterable<Subscription> getArticleSubscriptions(Long articleId) {
1620+
return getArticleSubscriptions(articleId, null);
1621+
}
1622+
1623+
public Iterable<Subscription> getArticleSubscriptions(Long articleId, String locale) {
1624+
return new PagedIterable<Subscription>(
1625+
tmpl("/help_center{/locale}/articles/{articleId}/subscriptions.json").set("locale", locale).set("articleId", articleId),
1626+
handleList(Subscription.class, "subscriptions"));
1627+
}
1628+
1629+
public Iterable<Subscription> getSectionSubscriptions(Long sectionId) {
1630+
return getSectionSubscriptions(sectionId, null);
1631+
}
1632+
1633+
public Iterable<Subscription> getSectionSubscriptions(Long sectionId, String locale) {
1634+
return new PagedIterable<Subscription>(
1635+
tmpl("/help_center{/locale}/sections/{sectionId}/subscriptions.json").set("locale", locale).set("sectionId", sectionId),
1636+
handleList(Subscription.class, "subscriptions"));
1637+
}
1638+
16071639
/**
16081640
* Get a list of the current business hours schedules
16091641
* @return A List of Schedules
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package org.zendesk.client.v2.model.hc;
2+
3+
import java.util.Date;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
public class Subscription {
8+
9+
/** Automatically assigned when the subscription is created */
10+
private Long id;
11+
12+
/** The API URL of the subscription */
13+
private String url;
14+
15+
/** The id of the user who has this subscription */
16+
@JsonProperty("user_id")
17+
private Long userId;
18+
19+
/** The id of the subscribed item */
20+
@JsonProperty("content_id")
21+
private Long contentId;
22+
23+
/** The type of the subscribed item */
24+
@JsonProperty("content_type")
25+
private String contentType;
26+
27+
/** The locale of the subscribed item */
28+
private String locale;
29+
30+
/** Subscribe also to article comments. Only for section subscriptions */
31+
@JsonProperty("include_comments")
32+
private boolean includeComments;
33+
34+
/** The time at which the subscription was created */
35+
@JsonProperty("created_at")
36+
private Date createdAt;
37+
38+
/** The time at which the subscription was last updated */
39+
@JsonProperty("updated_at")
40+
private Date updatedAt;
41+
42+
public Long getId() {
43+
return id;
44+
}
45+
46+
public void setId( Long id ) {
47+
this.id = id;
48+
}
49+
50+
public String getUrl() {
51+
return url;
52+
}
53+
54+
public void setUrl( String url ) {
55+
this.url = url;
56+
}
57+
58+
public Long getUserId() {
59+
return userId;
60+
}
61+
62+
public void setUserId( Long userId ) {
63+
this.userId = userId;
64+
}
65+
66+
public Long getContentId() {
67+
return contentId;
68+
}
69+
70+
public void setContentId( Long contentId ) {
71+
this.contentId = contentId;
72+
}
73+
74+
public String getContentType() {
75+
return contentType;
76+
}
77+
78+
public void setContentType( String contentType ) {
79+
this.contentType = contentType;
80+
}
81+
82+
public String getLocale() {
83+
return locale;
84+
}
85+
86+
public void setLocale( String locale ) {
87+
this.locale = locale;
88+
}
89+
90+
public boolean isIncludeComments() {
91+
return includeComments;
92+
}
93+
94+
public void setIncludeComments( boolean includeComments ) {
95+
this.includeComments = includeComments;
96+
}
97+
98+
public Date getCreatedAt() {
99+
return createdAt;
100+
}
101+
102+
public void setCreatedAt( Date createdAt ) {
103+
this.createdAt = createdAt;
104+
}
105+
106+
public Date getUpdatedAt() {
107+
return updatedAt;
108+
}
109+
110+
public void setUpdatedAt( Date updatedAt ) {
111+
this.updatedAt = updatedAt;
112+
}
113+
114+
@Override
115+
public String toString() {
116+
return "Subscription{" +
117+
"id=" + id +
118+
", url='" + url + '\'' +
119+
", userId='" + userId + '\'' +
120+
", contentId='" + contentId + '\'' +
121+
", contentType='" + contentType + '\'' +
122+
", locale='" + locale + '\'' +
123+
", includeComments='" + includeComments + '\'' +
124+
", createdAt=" + createdAt +
125+
", updatedAt=" + updatedAt +
126+
'}';
127+
}
128+
}

src/test/java/org/zendesk/client/v2/RealSmokeTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.zendesk.client.v2.model.hc.Article;
4646
import org.zendesk.client.v2.model.hc.Category;
4747
import org.zendesk.client.v2.model.hc.Section;
48+
import org.zendesk.client.v2.model.hc.Subscription;
4849
import org.zendesk.client.v2.model.hc.Translation;
4950
import org.zendesk.client.v2.model.schedules.Holiday;
5051
import org.zendesk.client.v2.model.schedules.Interval;
@@ -599,6 +600,28 @@ public void getArticles() throws Exception {
599600
}
600601
}
601602

603+
@Test
604+
public void getArticleSubscriptions() throws Exception {
605+
createClientWithTokenOrPassword();
606+
int articleCount = 0;
607+
int subCount = 0;
608+
for (Article t : instance.getArticles()) {
609+
if (++articleCount > 50) {
610+
break; // Stop if we're not finding articles with subscriptions
611+
}
612+
for (Subscription sub : instance.getArticleSubscriptions(t.getId())) {
613+
assertThat(sub.getId(), notNullValue());
614+
assertThat(sub.getUserId(), notNullValue());
615+
assertThat(sub.getContentId(), notNullValue());
616+
assertThat(sub.getCreatedAt(), notNullValue());
617+
assertThat(sub.getUpdatedAt(), notNullValue());
618+
if (++subCount > 10) {
619+
break;
620+
}
621+
}
622+
}
623+
}
624+
602625
@Test
603626
public void getArticleTranslations() throws Exception {
604627
createClientWithTokenOrPassword();
@@ -709,6 +732,28 @@ public void getSections() throws Exception {
709732
}
710733
}
711734

735+
@Test
736+
public void getSectionSubscriptions() throws Exception {
737+
createClientWithTokenOrPassword();
738+
int sectionCount = 0;
739+
int count = 0;
740+
for (Section s : instance.getSections()) {
741+
if (++sectionCount > 50) {
742+
break; // Stop if we're not finding sections with subscriptions
743+
}
744+
for (Subscription sub : instance.getSectionSubscriptions(s.getId())) {
745+
assertThat(sub.getId(), notNullValue());
746+
assertThat(sub.getUserId(), notNullValue());
747+
assertThat(sub.getContentId(), notNullValue());
748+
assertThat(sub.getCreatedAt(), notNullValue());
749+
assertThat(sub.getUpdatedAt(), notNullValue());
750+
if (++count > 10) {
751+
break;
752+
}
753+
}
754+
}
755+
}
756+
712757
@Test
713758
public void getSchedules() throws Exception {
714759
createClientWithTokenOrPassword();

0 commit comments

Comments
 (0)