Skip to content

Commit

Permalink
Add GetLocales()
Browse files Browse the repository at this point in the history
  • Loading branch information
nukosuke committed Dec 4, 2018
1 parent 9ad7d1f commit e212876
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions zendesk/locale.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package zendesk

import (
"encoding/json"
"time"
)

Expand All @@ -14,3 +15,22 @@ type Locale struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

// GetLocales lists the translation locales available for the account.
// https://developer.zendesk.com/rest_api/docs/support/locales#list-locales
func (z *Client) GetLocales() ([]Locale, error) {
var data struct {
Locales []Locale `json:"locales"`
}

body, err := z.Get("/locales.json")
if err != nil {
return nil, err
}

err = json.Unmarshal(body, &data)
if err != nil {
return nil, err
}
return data.Locales, nil
}
21 changes: 21 additions & 0 deletions zendesk/locale_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package zendesk

import (
"net/http"
"testing"
)

func TestGetLocales(t *testing.T) {
mockAPI := newMockAPI(http.MethodGet, "locales.json")
client := newTestClient(mockAPI)
defer mockAPI.Close()

locales, err := client.GetLocales()
if err != nil {
t.Fatalf("Failed to get locales: %s", err)
}

if len(locales) != 3 {
t.Fatalf("expected length of groups is 3, but got %d", len(locales))
}
}

0 comments on commit e212876

Please sign in to comment.