66import com .fasterxml .jackson .databind .JavaType ;
77import com .fasterxml .jackson .databind .JsonNode ;
88import com .fasterxml .jackson .databind .ObjectMapper ;
9+ import com .fasterxml .jackson .databind .ObjectReader ;
910import com .fasterxml .jackson .databind .SerializationFeature ;
1011import com .fasterxml .jackson .databind .util .StdDateFormat ;
1112import java .io .Closeable ;
104105import org .zendesk .client .v2 .model .targets .Target ;
105106import org .zendesk .client .v2 .model .targets .TwitterTarget ;
106107import org .zendesk .client .v2 .model .targets .UrlTarget ;
108+ import org .zendesk .client .v2 .model .views .ExecutedViewPage ;
109+ import org .zendesk .client .v2 .model .views .ViewRow ;
107110
108111/**
109112 * @author stephenc
@@ -1034,6 +1037,17 @@ public Iterable<Ticket> getView(long id) {
10341037 tmpl ("/views/{id}/tickets.json" ).set ("id" , id ), handleList (Ticket .class , "tickets" ));
10351038 }
10361039
1040+ @ SuppressWarnings ("unchecked" )
1041+ public <V extends ViewRow > Optional <ExecutedViewPage <V >> executeView (long id , Class <V > clazz ) {
1042+ var objectReader =
1043+ mapper .readerFor (
1044+ mapper .getTypeFactory ().constructParametricType (ExecutedViewPage .class , clazz ));
1045+ return Optional .of (
1046+ complete (
1047+ submit (
1048+ req ("GET" , tmpl ("/views/{id}/execute.json" ).set ("id" , id )), handle (objectReader ))));
1049+ }
1050+
10371051 // Automations
10381052 public Iterable <Automation > getAutomations () {
10391053 return new PagedIterable <>(
@@ -2454,6 +2468,17 @@ public void deleteOrganizationMembership(long user_id, long organization_members
24542468 handleStatus ()));
24552469 }
24562470
2471+ public void unassignOrganizationMembership (long user_id , long organization_id ) {
2472+ complete (
2473+ submit (
2474+ req (
2475+ "DELETE" ,
2476+ tmpl ("/users/{uid}/organizations/{oid}.json" )
2477+ .set ("uid" , user_id )
2478+ .set ("oid" , organization_id )),
2479+ handleStatus ()));
2480+ }
2481+
24572482 public List <OrganizationMembership > setOrganizationMembershipAsDefault (
24582483 long user_id , OrganizationMembership organizationMembership ) {
24592484 checkHasId (organizationMembership );
@@ -2967,26 +2992,26 @@ public List<String> getHelpCenterLocales() {
29672992 */
29682993 public Iterable <Article > getArticles () {
29692994 return new PagedIterable <>(
2970- cnst ("/help_center/articles.json" ), handleList (Article .class , "articles" ));
2995+ cbp ("/help_center/articles.json" ), handleList (Article .class , "articles" ));
29712996 }
29722997
29732998 public Iterable <Article > getArticles (String locale ) {
29742999 return new PagedIterable <>(
2975- tmpl ("/help_center/{locale}/articles.json" ).set ("locale" , locale ),
3000+ cbp ("/help_center/{locale}/articles.json" ).set ("locale" , locale ),
29763001 handleList (Article .class , "articles" ));
29773002 }
29783003
29793004 public Iterable <Article > getArticles (Category category ) {
29803005 checkHasId (category );
29813006 return new PagedIterable <>(
2982- tmpl ("/help_center/categories/{id}/articles.json" ).set ("id" , category .getId ()),
3007+ cbp ("/help_center/categories/{id}/articles.json" ).set ("id" , category .getId ()),
29833008 handleList (Article .class , "articles" ));
29843009 }
29853010
29863011 public Iterable <Article > getArticles (Category category , String locale ) {
29873012 checkHasId (category );
29883013 return new PagedIterable <>(
2989- tmpl ("/help_center/{locale}/categories/{id}/articles.json" )
3014+ cbp ("/help_center/{locale}/categories/{id}/articles.json" )
29903015 .set ("id" , category .getId ())
29913016 .set ("locale" , locale ),
29923017 handleList (Article .class , "articles" ));
@@ -2995,14 +3020,14 @@ public Iterable<Article> getArticles(Category category, String locale) {
29953020 public Iterable <Article > getArticles (Section section ) {
29963021 checkHasId (section );
29973022 return new PagedIterable <>(
2998- tmpl ("/help_center/sections/{id}/articles.json" ).set ("id" , section .getId ()),
3023+ cbp ("/help_center/sections/{id}/articles.json" ).set ("id" , section .getId ()),
29993024 handleList (Article .class , "articles" ));
30003025 }
30013026
30023027 public Iterable <Article > getArticles (Section section , String locale ) {
30033028 checkHasId (section );
30043029 return new PagedIterable <>(
3005- tmpl ("/help_center/{locale}/sections/{id}/articles.json" )
3030+ cbp ("/help_center/{locale}/sections/{id}/articles.json" )
30063031 .set ("id" , section .getId ())
30073032 .set ("locale" , locale ),
30083033 handleList (Article .class , "articles" ));
@@ -3031,7 +3056,7 @@ public Article getArticle(long id) {
30313056
30323057 public Iterable <Translation > getArticleTranslations (Long articleId ) {
30333058 return new PagedIterable <>(
3034- tmpl ("/help_center/articles/{articleId}/translations.json" ).set ("articleId" , articleId ),
3059+ cbp ("/help_center/articles/{articleId}/translations.json" ).set ("articleId" , articleId ),
30353060 handleList (Translation .class , "translations" ));
30363061 }
30373062
@@ -3587,12 +3612,17 @@ public Void onCompleted(Response response) throws Exception {
35873612
35883613 @ SuppressWarnings ("unchecked" )
35893614 protected <T > ZendeskAsyncCompletionHandler <T > handle (final Class <T > clazz ) {
3615+ return handle (mapper .readerFor (clazz ));
3616+ }
3617+
3618+ @ SuppressWarnings ("unchecked" )
3619+ protected <T > ZendeskAsyncCompletionHandler <T > handle (ObjectReader reader ) {
35903620 return new ZendeskAsyncCompletionHandler <T >() {
35913621 @ Override
35923622 public T onCompleted (Response response ) throws Exception {
35933623 logResponse (response );
35943624 if (isStatus2xx (response )) {
3595- return ( T ) mapper . readerFor ( clazz ) .readValue (response .getResponseBodyAsStream ());
3625+ return reader .readValue (response .getResponseBodyAsStream ());
35963626 } else if (isRateLimitResponse (response )) {
35973627 throw new ZendeskResponseRateLimitException (response );
35983628 }
0 commit comments