forked from nukosuke/go-zendesk
/
locale.go
42 lines (36 loc) · 1.01 KB
/
locale.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package zendesk
import (
"context"
"encoding/json"
"time"
)
// Locale is zendesk locale JSON payload format
// https://developer.zendesk.com/rest_api/docs/support/locales
type Locale struct {
ID int64 `json:"id"`
URL string `json:"url"`
Locale string `json:"locale"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// LocaleAPI an interface containing all of the local related zendesk methods
type LocaleAPI interface {
GetLocales(ctx context.Context) ([]Locale, error)
}
// GetLocales lists the translation locales available for the account.
// https://developer.zendesk.com/rest_api/docs/support/locales#list-locales
func (z *Client) GetLocales(ctx context.Context) ([]Locale, error) {
var data struct {
Locales []Locale `json:"locales"`
}
body, err := z.get(ctx, "/locales.json")
if err != nil {
return nil, err
}
err = json.Unmarshal(body, &data)
if err != nil {
return nil, err
}
return data.Locales, nil
}