Skip to content

Commit 61a4e38

Browse files
author
Henrique Cabral
committed
Added Variant and updated client
1 parent 0a4d6bf commit 61a4e38

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
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.Item;
57+
import org.zendesk.client.v2.model.dynamic.Variant;
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;
@@ -1609,6 +1611,68 @@ public SatisfactionRating createSatisfactionRating(Ticket ticket, SatisfactionRa
16091611
return createSatisfactionRating(ticket.getId(), satisfactionRating);
16101612
}
16111613

1614+
//////////////////////////////////////////////////////////////////////
1615+
// Action methods for Dynamic Content - Items and Variants
1616+
//////////////////////////////////////////////////////////////////////
1617+
1618+
public Iterable<Item> getItems() {
1619+
return new PagedIterable<>(cnst("/dynamic_content/items.json"), handleList(Item.class, "items"));
1620+
}
1621+
1622+
public Item getItem(long id) {
1623+
return complete(submit(req("GET", tmpl("/dynamic_content/items/{id}.json").set("id", id)), handle(Item.class, "item")));
1624+
}
1625+
1626+
public Item createItem(Item item) {
1627+
return complete(submit(req("POST", cnst("/dynamic_content/items.json"), JSON, json(
1628+
Collections.singletonMap("item", item))), handle(Item.class, "item")));
1629+
}
1630+
1631+
public Item updateItem(Item item) {
1632+
checkHasId(item);
1633+
return complete(submit(req("PUT", tmpl("/dynamic_content/items/{id}.json").set("id", item.getId()),
1634+
JSON, json(Collections.singletonMap("item", item))), handle(Item.class, "item")));
1635+
}
1636+
1637+
public void deleteItem(Item item) {
1638+
checkHasId(item);
1639+
complete(submit(req("DELETE", tmpl("/dynamic_content/items/{id}.json").set("id", item.getId())),
1640+
handleStatus()));
1641+
}
1642+
1643+
/** VARIANTS */
1644+
1645+
public Iterable<Variant> getVariants(Item item) {
1646+
checkHasId(item);
1647+
return new PagedIterable<>(
1648+
tmpl("/dynamic_content/items/{id}/variants.json").set("id", item.getId()),
1649+
handleList(Variant.class, "variants"));
1650+
}
1651+
1652+
public Variant getVariant(Long itemId, long id) {
1653+
return complete(submit(req("GET", tmpl("/dynamic_content/items/{itemId}/variants/{id}.json").set("itemId", itemId).set("id", id)),
1654+
handle(Variant.class, "variant")));
1655+
}
1656+
1657+
public Variant createVariant(Long itemId, Variant variant) {
1658+
checkHasItemId(itemId);
1659+
return complete(submit(req("POST", tmpl("/dynamic_content/items/{id}/variants.json").set("id", itemId),
1660+
JSON, json(Collections.singletonMap("variant", variant))), handle(Variant.class, "variant")));
1661+
}
1662+
1663+
public Variant updateVariant(Long itemId, Variant variant) {
1664+
checkHasItemId(itemId);
1665+
checkHasId(variant);
1666+
return complete(submit(req("PUT", tmpl("/dynamic_content/items/{itemId}/variants/{id}.json").set("itemId", itemId).set("id", variant.getId()),
1667+
JSON, json(Collections.singletonMap("variant", variant))), handle(Variant.class, "variant")));
1668+
}
1669+
1670+
public void deleteVariant(Long itemId, Variant variant) {
1671+
checkHasItemId(itemId);
1672+
checkHasId(variant);
1673+
complete(submit(req("DELETE", tmpl("/dynamic_content/items/{itemId}/variants/{id}.json").set("itemId", itemId).set("id", variant.getId())), handleStatus()));
1674+
}
1675+
16121676
// TODO search with sort order
16131677
// TODO search with query building API
16141678

@@ -2353,6 +2417,24 @@ private static void checkHasId(Article article) {
23532417
}
23542418
}
23552419

2420+
private static void checkHasId(Item item) {
2421+
if (item.getId() == null) {
2422+
throw new IllegalArgumentException("Item requires id");
2423+
}
2424+
}
2425+
2426+
private static void checkHasId(Variant variant) {
2427+
if (variant.getId() == null) {
2428+
throw new IllegalArgumentException("Variant requires id");
2429+
}
2430+
}
2431+
2432+
private static void checkHasItemId(Long itemId) {
2433+
if (itemId == null) {
2434+
throw new IllegalArgumentException("Variant requires item id");
2435+
}
2436+
}
2437+
23562438
private static void checkHasSectionId(Article article) {
23572439
if (article.getSectionId() == null) {
23582440
throw new IllegalArgumentException("Article requires section id");

src/main/java/org/zendesk/client/v2/model/dynamic/Variant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.io.Serializable;
66
import java.util.Date;
7+
import java.util.Objects;
78

89
public class Variant implements Serializable {
910

0 commit comments

Comments
 (0)