Skip to content

Commit

Permalink
Merge pull request #200 from yyuc/master
Browse files Browse the repository at this point in the history
Add fetch translation metadata capability when getting locales
  • Loading branch information
mozts2005 committed Jan 15, 2016
2 parents 73b2672 + a8dd50e commit 6c26966
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 60 deletions.
10 changes: 10 additions & 0 deletions Tests/LocaleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ public void CanGetLocales()

var specific = api.Locales.GetLocaleById(all.Locales[0].Id);
Assert.AreEqual(specific.Locale.Id, all.Locales[0].Id);
Assert.IsNull(specific.Locale.Translations);

var specificWithTranslation = api.Locales.GetLocaleById(all.Locales[0].Id, true);
Assert.AreEqual(specificWithTranslation.Locale.Id, all.Locales[0].Id);
Assert.IsNotNull(specificWithTranslation.Locale.Translations);

var current = api.Locales.GetCurrentLocale();
Assert.Greater(current.Locale.Id, 0);
Assert.IsNull(current.Locale.Translations);

var currentWithTranslation = api.Locales.GetCurrentLocale(true);
Assert.Greater(currentWithTranslation.Locale.Id, 0);
Assert.IsNotNull(currentWithTranslation.Locale.Translations);
}
}
}
3 changes: 3 additions & 0 deletions ZendeskApi_v2/Models/Locales/Locale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ public class Locale
[JsonProperty("updated_at")]
[JsonConverter(typeof(IsoDateTimeConverter))]
public DateTimeOffset? UpdatedAt { get; set; }

[JsonProperty("translations")]
public Dictionary<string, object> Translations { get; set; }
}
}
119 changes: 59 additions & 60 deletions ZendeskApi_v2/Requests/Locales.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,63 @@

namespace ZendeskApi_v2.Requests
{
public interface ILocales : ICore
{
public interface ILocales : ICore
{
#if SYNC
/// <summary>
/// This lists the translation locales that are available for the account.
/// </summary>
/// <returns></returns>
GroupLocaleResponse GetAllLocales();

/// <summary>
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
GroupLocaleResponse GetLocalesForAgents();

/// <summary>
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
IndividualLocaleResponse GetLocaleById(long id);

/// <summary>
/// This works exactly like show, but instead of taking an id as argument, it renders the locale of the user performing the request.
/// </summary>
/// <returns></returns>
IndividualLocaleResponse GetCurrentLocale();
/// <summary>
/// This lists the translation locales that are available for the account.
/// </summary>
/// <returns></returns>
GroupLocaleResponse GetAllLocales();

/// <summary>
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
GroupLocaleResponse GetLocalesForAgents();

/// <summary>
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
IndividualLocaleResponse GetLocaleById(long id, bool translation = false);

/// <summary>
/// This works exactly like show, but instead of taking an id as argument, it renders the locale of the user performing the request.
/// </summary>
/// <returns></returns>
IndividualLocaleResponse GetCurrentLocale(bool translation = false);
#endif

#if ASYNC
/// <summary>
/// This lists the translation locales that are available for the account.
/// </summary>
/// <returns></returns>
Task<GroupLocaleResponse> GetAllLocalesAsync();

/// <summary>
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
Task<GroupLocaleResponse> GetLocalesForAgentsAsync();

/// <summary>
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
Task<IndividualLocaleResponse> GetLocaleByIdAsync(long id);

/// <summary>
/// This works exactly like show, but instead of taking an id as argument, it renders the locale of the user performing the request.
/// </summary>
/// <returns></returns>
Task<IndividualLocaleResponse> GetCurrentLocaleAsync();
/// <summary>
/// This lists the translation locales that are available for the account.
/// </summary>
/// <returns></returns>
Task<GroupLocaleResponse> GetAllLocalesAsync();

/// <summary>
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
Task<GroupLocaleResponse> GetLocalesForAgentsAsync();

/// <summary>
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
Task<IndividualLocaleResponse> GetLocaleByIdAsync(long id, bool translation = false);

/// <summary>
/// This works exactly like show, but instead of taking an id as argument, it renders the locale of the user performing the request.
/// </summary>
/// <returns></returns>
Task<IndividualLocaleResponse> GetCurrentLocaleAsync(bool translation = false);
#endif
}
}

public class Locales : Core, ILocales
{
public class Locales : Core, ILocales
{

public Locales(string yourZendeskUrl, string user, string password, string apiToken, string p_OAuthToken)
: base(yourZendeskUrl, user, password, apiToken, p_OAuthToken)
Expand Down Expand Up @@ -91,20 +91,19 @@ public GroupLocaleResponse GetLocalesForAgents()
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
public IndividualLocaleResponse GetLocaleById(long id)
public IndividualLocaleResponse GetLocaleById(long id, bool translation = false)
{
return GenericGet<IndividualLocaleResponse>(string.Format("locales/{0}.json", id));
return GenericGet<IndividualLocaleResponse>(string.Format("locales/{0}.json{1}", id, (translation ? "?include=translations" : null)));
}

/// <summary>
/// This works exactly like show, but instead of taking an id as argument, it renders the locale of the user performing the request.
/// </summary>
/// <returns></returns>
public IndividualLocaleResponse GetCurrentLocale()
public IndividualLocaleResponse GetCurrentLocale(bool translation = false)
{
return GenericGet<IndividualLocaleResponse>(string.Format("locales/current.json"));
return GenericGet<IndividualLocaleResponse>(string.Format("locales/current.json{0}", (translation ? "?include=translations" : null)));
}

#endif

#if ASYNC
Expand All @@ -130,18 +129,18 @@ public async Task<GroupLocaleResponse> GetLocalesForAgentsAsync()
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
public async Task<IndividualLocaleResponse> GetLocaleByIdAsync(long id)
public async Task<IndividualLocaleResponse> GetLocaleByIdAsync(long id, bool translation = false)
{
return await GenericGetAsync<IndividualLocaleResponse>(string.Format("locales/{0}.json", id));
return await GenericGetAsync<IndividualLocaleResponse>(string.Format("locales/{0}.json{1}", id, (translation ? "?include=translations" : null)));
}

/// <summary>
/// This works exactly like show, but instead of taking an id as argument, it renders the locale of the user performing the request.
/// </summary>
/// <returns></returns>
public async Task<IndividualLocaleResponse> GetCurrentLocaleAsync()
public async Task<IndividualLocaleResponse> GetCurrentLocaleAsync(bool translation = false)
{
return await GenericGetAsync<IndividualLocaleResponse>(string.Format("locales/current.json"));
return await GenericGetAsync<IndividualLocaleResponse>(string.Format("locales/current.json{0}", (translation ? "?include=translations" : null)));
}
#endif
}
Expand Down

0 comments on commit 6c26966

Please sign in to comment.