From 3f358cfa10b2c258382efb5e290b30a031b2c6de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20P=C3=A9rez?= Date: Wed, 13 Sep 2023 00:44:35 +0200 Subject: [PATCH 1/5] Support List Locales operation --- README.md | 2 +- .../java/org/zendesk/client/v2/Zendesk.java | 15 +++ .../org/zendesk/client/v2/model/Locale.java | 95 +++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/zendesk/client/v2/model/Locale.java diff --git a/README.md b/README.md index a7214ef96..c8580a405 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ Here is the status of the various API components: * [Attachments](https://developer.zendesk.com/api-reference/ticketing/tickets/ticket-attachments/) ✓ * [Automations](https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/) ✓ * [Job Statuses](https://developer.zendesk.com/api-reference/ticketing/ticket-management/job_statuses/) ✓ -* [Locales](https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/) +* [Locales](https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/) - Partial (List Locales) * [Macros](https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/) ✓ *except for restrictions* * [Satisfaction Ratings](https://developer.zendesk.com/api-reference/ticketing/ticket-management/satisfaction_ratings/) ✓ * [Sharing Agreements](https://developer.zendesk.com/api-reference/ticketing/account-configuration/sharing_agreements/) diff --git a/src/main/java/org/zendesk/client/v2/Zendesk.java b/src/main/java/org/zendesk/client/v2/Zendesk.java index 90b95cfad..a7b43e015 100644 --- a/src/main/java/org/zendesk/client/v2/Zendesk.java +++ b/src/main/java/org/zendesk/client/v2/Zendesk.java @@ -55,6 +55,7 @@ import org.zendesk.client.v2.model.GroupMembership; import org.zendesk.client.v2.model.Identity; import org.zendesk.client.v2.model.JobStatus; +import org.zendesk.client.v2.model.Locale; import org.zendesk.client.v2.model.Macro; import org.zendesk.client.v2.model.Metric; import org.zendesk.client.v2.model.Organization; @@ -2643,6 +2644,20 @@ public void deleteDynamicContentItemVariant(Long itemId, DynamicContentItemVaria handleStatus())); } + ////////////////////////////////////////////////////////////////////// + // Action methods for Locales + ////////////////////////////////////////////////////////////////////// + + /** + * https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/#list-locales + * + * @return the translation locales available for the account. + * @since FIXME + */ + public Iterable getLocales() { + return new PagedIterable<>(cnst("/locales.json"), handleList(Locale.class, "locales")); + } + // TODO search with query building API ////////////////////////////////////////////////////////////////////// diff --git a/src/main/java/org/zendesk/client/v2/model/Locale.java b/src/main/java/org/zendesk/client/v2/model/Locale.java new file mode 100644 index 000000000..e99dc6766 --- /dev/null +++ b/src/main/java/org/zendesk/client/v2/model/Locale.java @@ -0,0 +1,95 @@ +package org.zendesk.client.v2.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import java.util.Date; + +/** + * See + * Locales in Zendesk API + * + * @since FIXME + */ +public class Locale implements Serializable { + + private static final long serialVersionUID = 1L; + + private Date createdAt; + private Long id; + private String locale; + private String name; + private Date updatedAt; + private String url; + + @JsonProperty("created_at") + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getLocale() { + return locale; + } + + public void setLocale(String locale) { + this.locale = locale; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @JsonProperty("updated_at") + public Date getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + @Override + public String toString() { + return "Locale{" + + "createdAt=" + + createdAt + + ", id=" + + id + + ", locale='" + + locale + + '\'' + + ", name='" + + name + + '\'' + + ", updatedAt=" + + updatedAt + + ", url='" + + url + + '\'' + + '}'; + } +} From c98eaf2cc12028065e3d5e0781e85e8bf7abcfda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20P=C3=A9rez?= Date: Sat, 23 Sep 2023 00:13:35 +0200 Subject: [PATCH 2/5] Add undocumented attributes to Locale --- .../org/zendesk/client/v2/model/Locale.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/main/java/org/zendesk/client/v2/model/Locale.java b/src/main/java/org/zendesk/client/v2/model/Locale.java index e99dc6766..ca07148d4 100644 --- a/src/main/java/org/zendesk/client/v2/model/Locale.java +++ b/src/main/java/org/zendesk/client/v2/model/Locale.java @@ -16,9 +16,13 @@ public class Locale implements Serializable { private static final long serialVersionUID = 1L; private Date createdAt; + private Boolean isDefault; private Long id; private String locale; private String name; + private String nativeName; + private String presentationName; + private Boolean rtl; private Date updatedAt; private String url; @@ -31,6 +35,14 @@ public void setCreatedAt(Date createdAt) { this.createdAt = createdAt; } + public Boolean isDefault() { + return isDefault; + } + + public void setDefault(Boolean isDefault) { + this.isDefault = isDefault; + } + public Long getId() { return id; } @@ -55,6 +67,32 @@ public void setName(String name) { this.name = name; } + @JsonProperty("native_name") + public String getNativeName() { + return nativeName; + } + + public void setNativeName(String nativeName) { + this.nativeName = nativeName; + } + + @JsonProperty("presentation_name") + public String getPresentationName() { + return presentationName; + } + + public void setPresentationName(String presentationName) { + this.presentationName = presentationName; + } + + public Boolean getRtl() { + return rtl; + } + + public void setRtl(Boolean rtl) { + this.rtl = rtl; + } + @JsonProperty("updated_at") public Date getUpdatedAt() { return updatedAt; @@ -77,6 +115,8 @@ public String toString() { return "Locale{" + "createdAt=" + createdAt + + ", isDefault=" + + isDefault + ", id=" + id + ", locale='" @@ -85,6 +125,14 @@ public String toString() { + ", name='" + name + '\'' + + ", nativeName='" + + nativeName + + '\'' + + ", presentationName='" + + presentationName + + '\'' + + ", rtl=" + + rtl + ", updatedAt=" + updatedAt + ", url='" From df14857d0268870fcf058f72122934f932c83a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20P=C3=A9rez?= Date: Sat, 23 Sep 2023 00:15:00 +0200 Subject: [PATCH 3/5] Add unit tests for List Locales operation --- .../org/zendesk/client/v2/RealSmokeTest.java | 17 ++++++++ .../zendesk/client/v2/model/LocaleTest.java | 39 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/test/java/org/zendesk/client/v2/model/LocaleTest.java diff --git a/src/test/java/org/zendesk/client/v2/RealSmokeTest.java b/src/test/java/org/zendesk/client/v2/RealSmokeTest.java index 459270f65..622ba64bd 100644 --- a/src/test/java/org/zendesk/client/v2/RealSmokeTest.java +++ b/src/test/java/org/zendesk/client/v2/RealSmokeTest.java @@ -69,6 +69,7 @@ import org.zendesk.client.v2.model.Identity; import org.zendesk.client.v2.model.JobResult; import org.zendesk.client.v2.model.JobStatus; +import org.zendesk.client.v2.model.Locale; import org.zendesk.client.v2.model.Organization; import org.zendesk.client.v2.model.OrganizationMembership; import org.zendesk.client.v2.model.Priority; @@ -2479,6 +2480,22 @@ public void getViewReturnsTheUnresolvedView() throws Exception { assertTrue(maybeView.isPresent()); } + @Test + public void getLocalesReturnsLocales() throws Exception { + createClientWithTokenOrPassword(); + Iterable locales = instance.getLocales(); + assertThat(locales, notNullValue()); + + int numLocales = 0; + boolean defaultLocaleIsPresent = false; + for (Locale locale : locales) { + defaultLocaleIsPresent |= locale.isDefault(); + ++numLocales; + } + assertThat(numLocales, greaterThan(0)); + assertThat(defaultLocaleIsPresent, is(true)); + } + // UTILITIES /** diff --git a/src/test/java/org/zendesk/client/v2/model/LocaleTest.java b/src/test/java/org/zendesk/client/v2/model/LocaleTest.java new file mode 100644 index 000000000..1cb304e91 --- /dev/null +++ b/src/test/java/org/zendesk/client/v2/model/LocaleTest.java @@ -0,0 +1,39 @@ +package org.zendesk.client.v2.model; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.Test; +import org.zendesk.client.v2.Zendesk; + +public class LocaleTest { + @Test + public void testLocaleDeserialization() throws Exception { + String json = + "{" + + "\"url\": \"https://acme.zendesk.com/api/v2/locales/en-US.json\"," + + "\"id\": 1," + + "\"locale\": \"en-US\"," + + "\"name\": \"English\"," + + "\"native_name\": \"English (United States)\"," + + "\"presentation_name\": \"English (United States)\"," + + "\"rtl\": false," + + "\"created_at\": \"2023-08-13T19:23:16Z\"," + + "\"updated_at\": \"2023-09-21T19:23:16Z\"," + + "\"default\": true" + + "}"; + + Locale locale = Zendesk.createMapper().readValue(json, Locale.class); + + assertThat(locale.getUrl(), is("https://acme.zendesk.com/api/v2/locales/en-US.json")); + assertThat(locale.getId(), is(1L)); + assertThat(locale.getLocale(), is("en-US")); + assertThat(locale.getName(), is("English")); + assertThat(locale.getNativeName(), is("English (United States)")); + assertThat(locale.getPresentationName(), is("English (United States)")); + assertThat(locale.getRtl(), is(false)); + assertThat(locale.getCreatedAt().getTime(), is(1691954596000L)); + assertThat(locale.getUpdatedAt().getTime(), is(1695324196000L)); + assertThat(locale.isDefault(), is(true)); + } +} From 85dbdb8dbe6930c35aed9eaa34f5532f22ce6e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20P=C3=A9rez?= Date: Thu, 26 Oct 2023 08:13:20 +0200 Subject: [PATCH 4/5] Revert "Add undocumented attributes to Locale" This reverts commit c98eaf2cc12028065e3d5e0781e85e8bf7abcfda. --- .../org/zendesk/client/v2/model/Locale.java | 48 ------------------- 1 file changed, 48 deletions(-) diff --git a/src/main/java/org/zendesk/client/v2/model/Locale.java b/src/main/java/org/zendesk/client/v2/model/Locale.java index ca07148d4..e99dc6766 100644 --- a/src/main/java/org/zendesk/client/v2/model/Locale.java +++ b/src/main/java/org/zendesk/client/v2/model/Locale.java @@ -16,13 +16,9 @@ public class Locale implements Serializable { private static final long serialVersionUID = 1L; private Date createdAt; - private Boolean isDefault; private Long id; private String locale; private String name; - private String nativeName; - private String presentationName; - private Boolean rtl; private Date updatedAt; private String url; @@ -35,14 +31,6 @@ public void setCreatedAt(Date createdAt) { this.createdAt = createdAt; } - public Boolean isDefault() { - return isDefault; - } - - public void setDefault(Boolean isDefault) { - this.isDefault = isDefault; - } - public Long getId() { return id; } @@ -67,32 +55,6 @@ public void setName(String name) { this.name = name; } - @JsonProperty("native_name") - public String getNativeName() { - return nativeName; - } - - public void setNativeName(String nativeName) { - this.nativeName = nativeName; - } - - @JsonProperty("presentation_name") - public String getPresentationName() { - return presentationName; - } - - public void setPresentationName(String presentationName) { - this.presentationName = presentationName; - } - - public Boolean getRtl() { - return rtl; - } - - public void setRtl(Boolean rtl) { - this.rtl = rtl; - } - @JsonProperty("updated_at") public Date getUpdatedAt() { return updatedAt; @@ -115,8 +77,6 @@ public String toString() { return "Locale{" + "createdAt=" + createdAt - + ", isDefault=" - + isDefault + ", id=" + id + ", locale='" @@ -125,14 +85,6 @@ public String toString() { + ", name='" + name + '\'' - + ", nativeName='" - + nativeName - + '\'' - + ", presentationName='" - + presentationName - + '\'' - + ", rtl=" - + rtl + ", updatedAt=" + updatedAt + ", url='" From 00adf89b16fe52187e20a93fbf9a5d93c8cd0f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20P=C3=A9rez?= Date: Thu, 26 Oct 2023 08:17:00 +0200 Subject: [PATCH 5/5] Remove undocumented Locale fields from tests --- src/test/java/org/zendesk/client/v2/RealSmokeTest.java | 5 +---- .../java/org/zendesk/client/v2/model/LocaleTest.java | 10 +--------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/zendesk/client/v2/RealSmokeTest.java b/src/test/java/org/zendesk/client/v2/RealSmokeTest.java index 622ba64bd..2ad448f02 100644 --- a/src/test/java/org/zendesk/client/v2/RealSmokeTest.java +++ b/src/test/java/org/zendesk/client/v2/RealSmokeTest.java @@ -2487,13 +2487,10 @@ public void getLocalesReturnsLocales() throws Exception { assertThat(locales, notNullValue()); int numLocales = 0; - boolean defaultLocaleIsPresent = false; - for (Locale locale : locales) { - defaultLocaleIsPresent |= locale.isDefault(); + for (Locale ignored : locales) { ++numLocales; } assertThat(numLocales, greaterThan(0)); - assertThat(defaultLocaleIsPresent, is(true)); } // UTILITIES diff --git a/src/test/java/org/zendesk/client/v2/model/LocaleTest.java b/src/test/java/org/zendesk/client/v2/model/LocaleTest.java index 1cb304e91..d3f275337 100644 --- a/src/test/java/org/zendesk/client/v2/model/LocaleTest.java +++ b/src/test/java/org/zendesk/client/v2/model/LocaleTest.java @@ -15,12 +15,8 @@ public void testLocaleDeserialization() throws Exception { + "\"id\": 1," + "\"locale\": \"en-US\"," + "\"name\": \"English\"," - + "\"native_name\": \"English (United States)\"," - + "\"presentation_name\": \"English (United States)\"," - + "\"rtl\": false," + "\"created_at\": \"2023-08-13T19:23:16Z\"," - + "\"updated_at\": \"2023-09-21T19:23:16Z\"," - + "\"default\": true" + + "\"updated_at\": \"2023-09-21T19:23:16Z\"" + "}"; Locale locale = Zendesk.createMapper().readValue(json, Locale.class); @@ -29,11 +25,7 @@ public void testLocaleDeserialization() throws Exception { assertThat(locale.getId(), is(1L)); assertThat(locale.getLocale(), is("en-US")); assertThat(locale.getName(), is("English")); - assertThat(locale.getNativeName(), is("English (United States)")); - assertThat(locale.getPresentationName(), is("English (United States)")); - assertThat(locale.getRtl(), is(false)); assertThat(locale.getCreatedAt().getTime(), is(1691954596000L)); assertThat(locale.getUpdatedAt().getTime(), is(1695324196000L)); - assertThat(locale.isDefault(), is(true)); } }