Skip to content

Commit 0672731

Browse files
authored
Merge pull request #293 from bureauworks/dynamic_content
Support for Dynamic Content
2 parents 9fda174 + 0908fcf commit 0672731

File tree

5 files changed

+554
-1
lines changed

5 files changed

+554
-1
lines changed

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
import org.zendesk.client.v2.model.User;
5454
import org.zendesk.client.v2.model.UserField;
5555
import org.zendesk.client.v2.model.UserRelatedInfo;
56+
import org.zendesk.client.v2.model.dynamic.DynamicContentItem;
57+
import org.zendesk.client.v2.model.dynamic.DynamicContentItemVariant;
5658
import org.zendesk.client.v2.model.hc.Article;
5759
import org.zendesk.client.v2.model.hc.ArticleAttachments;
5860
import org.zendesk.client.v2.model.hc.Category;
@@ -1616,6 +1618,68 @@ public SatisfactionRating createSatisfactionRating(Ticket ticket, SatisfactionRa
16161618
return createSatisfactionRating(ticket.getId(), satisfactionRating);
16171619
}
16181620

1621+
//////////////////////////////////////////////////////////////////////
1622+
// Action methods for Dynamic Content - Items and Variants
1623+
//////////////////////////////////////////////////////////////////////
1624+
1625+
public Iterable<DynamicContentItem> getDynamicContentItems() {
1626+
return new PagedIterable<>(cnst("/dynamic_content/items.json"), handleList(DynamicContentItem.class, "items"));
1627+
}
1628+
1629+
public DynamicContentItem getDynamicContentItem(long id) {
1630+
return complete(submit(req("GET", tmpl("/dynamic_content/items/{id}.json").set("id", id)), handle(DynamicContentItem.class, "item")));
1631+
}
1632+
1633+
public DynamicContentItem createDynamicContentItem(DynamicContentItem item) {
1634+
return complete(submit(req("POST", cnst("/dynamic_content/items.json"), JSON, json(
1635+
Collections.singletonMap("item", item))), handle(DynamicContentItem.class, "item")));
1636+
}
1637+
1638+
public DynamicContentItem updateDynamicContentItem(DynamicContentItem item) {
1639+
checkHasId(item);
1640+
return complete(submit(req("PUT", tmpl("/dynamic_content/items/{id}.json").set("id", item.getId()),
1641+
JSON, json(Collections.singletonMap("item", item))), handle(DynamicContentItem.class, "item")));
1642+
}
1643+
1644+
public void deleteDynamicContentItem(DynamicContentItem item) {
1645+
checkHasId(item);
1646+
complete(submit(req("DELETE", tmpl("/dynamic_content/items/{id}.json").set("id", item.getId())),
1647+
handleStatus()));
1648+
}
1649+
1650+
/** VARIANTS */
1651+
1652+
public Iterable<DynamicContentItemVariant> getDynamicContentItemVariants(DynamicContentItem item) {
1653+
checkHasId(item);
1654+
return new PagedIterable<>(
1655+
tmpl("/dynamic_content/items/{id}/variants.json").set("id", item.getId()),
1656+
handleList(DynamicContentItemVariant.class, "variants"));
1657+
}
1658+
1659+
public DynamicContentItemVariant getDynamicContentItemVariant(Long itemId, long id) {
1660+
return complete(submit(req("GET", tmpl("/dynamic_content/items/{itemId}/variants/{id}.json").set("itemId", itemId).set("id", id)),
1661+
handle(DynamicContentItemVariant.class, "variant")));
1662+
}
1663+
1664+
public DynamicContentItemVariant createDynamicContentItemVariant(Long itemId, DynamicContentItemVariant variant) {
1665+
checkHasItemId(itemId);
1666+
return complete(submit(req("POST", tmpl("/dynamic_content/items/{id}/variants.json").set("id", itemId),
1667+
JSON, json(Collections.singletonMap("variant", variant))), handle(DynamicContentItemVariant.class, "variant")));
1668+
}
1669+
1670+
public DynamicContentItemVariant updateDynamicContentItemVariant(Long itemId, DynamicContentItemVariant variant) {
1671+
checkHasItemId(itemId);
1672+
checkHasId(variant);
1673+
return complete(submit(req("PUT", tmpl("/dynamic_content/items/{itemId}/variants/{id}.json").set("itemId", itemId).set("id", variant.getId()),
1674+
JSON, json(Collections.singletonMap("variant", variant))), handle(DynamicContentItemVariant.class, "variant")));
1675+
}
1676+
1677+
public void deleteDynamicContentItemVariant(Long itemId, DynamicContentItemVariant variant) {
1678+
checkHasItemId(itemId);
1679+
checkHasId(variant);
1680+
complete(submit(req("DELETE", tmpl("/dynamic_content/items/{itemId}/variants/{id}.json").set("itemId", itemId).set("id", variant.getId())), handleStatus()));
1681+
}
1682+
16191683
// TODO search with sort order
16201684
// TODO search with query building API
16211685

@@ -2360,6 +2424,24 @@ private static void checkHasId(Article article) {
23602424
}
23612425
}
23622426

2427+
private static void checkHasId(DynamicContentItem item) {
2428+
if (item.getId() == null) {
2429+
throw new IllegalArgumentException("Item requires id");
2430+
}
2431+
}
2432+
2433+
private static void checkHasId(DynamicContentItemVariant variant) {
2434+
if (variant.getId() == null) {
2435+
throw new IllegalArgumentException("Variant requires id");
2436+
}
2437+
}
2438+
2439+
private static void checkHasItemId(Long itemId) {
2440+
if (itemId == null) {
2441+
throw new IllegalArgumentException("Variant requires item id");
2442+
}
2443+
}
2444+
23632445
private static void checkHasSectionId(Article article) {
23642446
if (article.getSectionId() == null) {
23652447
throw new IllegalArgumentException("Article requires section id");

src/main/java/org/zendesk/client/v2/model/Collaborator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public Collaborator() {
1717

1818
protected Collaborator(String name) {
1919
this.name = name;
20-
this.email = email;
2120
}
2221

2322
public Collaborator(String name, String email) {
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
package org.zendesk.client.v2.model.dynamic;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.io.Serializable;
6+
import java.util.Date;
7+
import java.util.List;
8+
import java.util.Objects;
9+
10+
public class DynamicContentItem implements Serializable {
11+
12+
private static final long serialVersionUID = 1L;
13+
14+
/** Automatically assigned when creating items */
15+
private Long id;
16+
17+
/** The API url of this item */
18+
private String url;
19+
20+
/** The unique name of the item */
21+
private String name;
22+
23+
/** Automatically generated placeholder for the item, derived from name */
24+
private String placeholder;
25+
26+
/** The default locale for the item. Must be one of the locales the account has active. */
27+
@JsonProperty("default_locale_id")
28+
private Long defaultLocaleId;
29+
30+
/** Indicates the item has outdated variants within it */
31+
private Boolean outdated;
32+
33+
/** When this record was created */
34+
@JsonProperty("created_at")
35+
private Date createdAt;
36+
37+
/** When this record last got updated */
38+
@JsonProperty("updated_at")
39+
private Date updatedAt;
40+
41+
/** All variants within this item */
42+
private List<DynamicContentItemVariant> variants;
43+
44+
public DynamicContentItem() {
45+
}
46+
47+
public DynamicContentItem(Long id, String url, String name, String placeholder, Long defaultLocaleId, Boolean outdated,
48+
Date createdAt, Date updatedAt, List<DynamicContentItemVariant> variants) {
49+
this.id = id;
50+
this.url = url;
51+
this.name = name;
52+
this.placeholder = placeholder;
53+
this.defaultLocaleId = defaultLocaleId;
54+
this.outdated = outdated;
55+
this.createdAt = createdAt;
56+
this.updatedAt = updatedAt;
57+
this.variants = variants;
58+
}
59+
60+
public Long getId() {
61+
return this.id;
62+
}
63+
64+
public void setId(Long id) {
65+
this.id = id;
66+
}
67+
68+
public String getUrl() {
69+
return this.url;
70+
}
71+
72+
public void setUrl(String url) {
73+
this.url = url;
74+
}
75+
76+
public String getName() {
77+
return this.name;
78+
}
79+
80+
public void setName(String name) {
81+
this.name = name;
82+
}
83+
84+
public String getPlaceholder() {
85+
return this.placeholder;
86+
}
87+
88+
public void setPlaceholder(String placeholder) {
89+
this.placeholder = placeholder;
90+
}
91+
92+
public Long getDefaultLocaleId() {
93+
return this.defaultLocaleId;
94+
}
95+
96+
public void setDefaultLocaleId(Long defaultLocaleId) {
97+
this.defaultLocaleId = defaultLocaleId;
98+
}
99+
100+
public Boolean isOutdated() {
101+
return this.outdated;
102+
}
103+
104+
public Boolean getOutdated() {
105+
return this.outdated;
106+
}
107+
108+
public void setOutdated(Boolean outdated) {
109+
this.outdated = outdated;
110+
}
111+
112+
public Date getCreatedAt() {
113+
return this.createdAt;
114+
}
115+
116+
public void setCreatedAt(Date createdAt) {
117+
this.createdAt = createdAt;
118+
}
119+
120+
public Date getUpdatedAt() {
121+
return this.updatedAt;
122+
}
123+
124+
public void setUpdatedAt(Date updatedAt) {
125+
this.updatedAt = updatedAt;
126+
}
127+
128+
public List<DynamicContentItemVariant> getVariants() {
129+
return this.variants;
130+
}
131+
132+
public void setVariants(List<DynamicContentItemVariant> variants) {
133+
this.variants = variants;
134+
}
135+
136+
public DynamicContentItem id(Long id) {
137+
this.id = id;
138+
return this;
139+
}
140+
141+
public DynamicContentItem url(String url) {
142+
this.url = url;
143+
return this;
144+
}
145+
146+
public DynamicContentItem name(String name) {
147+
this.name = name;
148+
return this;
149+
}
150+
151+
public DynamicContentItem placeholder(String placeholder) {
152+
this.placeholder = placeholder;
153+
return this;
154+
}
155+
156+
public DynamicContentItem defaultLocaleId(Long defaultLocaleId) {
157+
this.defaultLocaleId = defaultLocaleId;
158+
return this;
159+
}
160+
161+
public DynamicContentItem outdated(Boolean outdated) {
162+
this.outdated = outdated;
163+
return this;
164+
}
165+
166+
public DynamicContentItem createdAt(Date createdAt) {
167+
this.createdAt = createdAt;
168+
return this;
169+
}
170+
171+
public DynamicContentItem updatedAt(Date updatedAt) {
172+
this.updatedAt = updatedAt;
173+
return this;
174+
}
175+
176+
public DynamicContentItem variants(List<DynamicContentItemVariant> variants) {
177+
this.variants = variants;
178+
return this;
179+
}
180+
181+
@Override
182+
public boolean equals(Object o) {
183+
if (o == this)
184+
return true;
185+
if (!(o instanceof DynamicContentItem)) {
186+
return false;
187+
}
188+
DynamicContentItem item = (DynamicContentItem) o;
189+
return Objects.equals(id, item.id) && Objects.equals(url, item.url) && Objects.equals(name, item.name)
190+
&& Objects.equals(placeholder, item.placeholder)
191+
&& Objects.equals(defaultLocaleId, item.defaultLocaleId) && Objects.equals(outdated, item.outdated)
192+
&& Objects.equals(createdAt, item.createdAt) && Objects.equals(updatedAt, item.updatedAt)
193+
&& Objects.equals(variants, item.variants);
194+
}
195+
196+
@Override
197+
public int hashCode() {
198+
return Objects.hash(id, url, name, placeholder, defaultLocaleId, outdated, createdAt, updatedAt, variants);
199+
}
200+
201+
@Override
202+
public String toString() {
203+
return "{" +
204+
" id='" + getId() + "'" +
205+
", url='" + getUrl() + "'" +
206+
", name='" + getName() + "'" +
207+
", placeholder='" + getPlaceholder() + "'" +
208+
", defaultLocaleId='" + getDefaultLocaleId() + "'" +
209+
", outdated='" + isOutdated() + "'" +
210+
", createdAt='" + getCreatedAt() + "'" +
211+
", updatedAt='" + getUpdatedAt() + "'" +
212+
", variants='" + getVariants() + "'" +
213+
"}";
214+
}
215+
216+
217+
}

0 commit comments

Comments
 (0)