diff --git a/zendesk/brand.go b/zendesk/brand.go index b74c54b4..01e790f1 100644 --- a/zendesk/brand.go +++ b/zendesk/brand.go @@ -30,6 +30,26 @@ type BrandAPI interface { CreateBrand(brand Brand) (Brand, error) } +// GetBrands fetches brand list +// https://developer.zendesk.com/rest_api/docs/support/brands#list-brands +func (z *Client) GetBrands() ([]Brand, Page, error) { + var data struct { + Brands []Brand `json:"brands"` + Page + } + + body, err := z.Get("/brands.json") + if err != nil { + return []Brand{}, Page{}, err + } + + err = json.Unmarshal(body, &data) + if err != nil { + return []Brand{}, Page{}, err + } + return data.Brands, data.Page, nil +} + // CreateBrand creates new brand // https://developer.zendesk.com/rest_api/docs/support/brands#create-brand func (z *Client) CreateBrand(brand Brand) (Brand, error) { diff --git a/zendesk/brand_test.go b/zendesk/brand_test.go index b3bcdcd0..cb0b4815 100644 --- a/zendesk/brand_test.go +++ b/zendesk/brand_test.go @@ -5,6 +5,21 @@ import ( "testing" ) +func TestGetBrands(t *testing.T) { + mockAPI := newMockAPI(http.MethodGet, "brands.json") + client := newTestClient(mockAPI) + defer mockAPI.Close() + + brands, _, err := client.GetBrands() + if err != nil { + t.Fatalf("Failed to get brands: %s", err) + } + + if len(brands) != 2 { + t.Fatalf("expected length of brands is 2, but got %d", len(brands)) + } +} + func TestCreateBrand(t *testing.T) { mockAPI := newMockAPIWithStatus(http.MethodPost, "brands.json", http.StatusCreated) client := newTestClient(mockAPI)