Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support List Locales operation #619

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/zendesk/client/v2/Zendesk.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Locale> getLocales() {
return new PagedIterable<>(cnst("/locales.json"), handleList(Locale.class, "locales"));
}

// TODO search with query building API

//////////////////////////////////////////////////////////////////////
Expand Down
95 changes: 95 additions & 0 deletions src/main/java/org/zendesk/client/v2/model/Locale.java
Original file line number Diff line number Diff line change
@@ -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 <a
* href="https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/">
* Locales in Zendesk API </a>
*
* @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
+ '\''
+ '}';
}
}
14 changes: 14 additions & 0 deletions src/test/java/org/zendesk/client/v2/RealSmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2479,6 +2480,19 @@ public void getViewReturnsTheUnresolvedView() throws Exception {
assertTrue(maybeView.isPresent());
}

@Test
public void getLocalesReturnsLocales() throws Exception {
createClientWithTokenOrPassword();
Iterable<Locale> locales = instance.getLocales();
assertThat(locales, notNullValue());

int numLocales = 0;
for (Locale ignored : locales) {
++numLocales;
}
assertThat(numLocales, greaterThan(0));
}

// UTILITIES

/**
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/org/zendesk/client/v2/model/LocaleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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\","
+ "\"created_at\": \"2023-08-13T19:23:16Z\","
+ "\"updated_at\": \"2023-09-21T19:23:16Z\""
+ "}";

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.getCreatedAt().getTime(), is(1691954596000L));
assertThat(locale.getUpdatedAt().getTime(), is(1695324196000L));
}
}