add methods for brands
This commit is contained in:
@@ -51,7 +51,7 @@
|
|||||||
- [x] Decline a discount request
|
- [x] Decline a discount request
|
||||||
|
|
||||||
## Brand certificates
|
## Brand certificates
|
||||||
- [ ] List of certified brands
|
- [x] List of certified brands
|
||||||
|
|
||||||
## Quality certificates
|
## Quality certificates
|
||||||
- [ ] List of accordance types (version 1)
|
- [ ] List of accordance types (version 1)
|
||||||
|
|||||||
55
ozon/brands.go
Normal file
55
ozon/brands.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package ozon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
core "github.com/diphantxm/ozon-api-client"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Brands struct {
|
||||||
|
client *core.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListCertifiedBrandsParams struct {
|
||||||
|
// Number of the page returned in the request
|
||||||
|
Page int32 `json:"page"`
|
||||||
|
|
||||||
|
// Number of elements on the page
|
||||||
|
PageSize int32 `json:"page_size"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListCertifiedBrandsResponse struct {
|
||||||
|
core.CommonResponse
|
||||||
|
|
||||||
|
// Method result
|
||||||
|
Result struct {
|
||||||
|
// Certified brands details
|
||||||
|
BrandCertification []struct {
|
||||||
|
// Brand name
|
||||||
|
BrandName string `json:"brand_name"`
|
||||||
|
|
||||||
|
// Indication that the certificate is required:
|
||||||
|
// - true if the certificate is required;
|
||||||
|
// - false if not
|
||||||
|
HasCertificate bool `json:"has_certificate"`
|
||||||
|
} `json:"brand_certification"`
|
||||||
|
|
||||||
|
// Total number of brands
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
} `json:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List of certified brands
|
||||||
|
func (c Brands) List(params *ListCertifiedBrandsParams) (*ListCertifiedBrandsResponse, error) {
|
||||||
|
url := "/v1/brand/company-certification/list"
|
||||||
|
|
||||||
|
resp := &ListCertifiedBrandsResponse{}
|
||||||
|
|
||||||
|
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response.CopyCommonResponse(&resp.CommonResponse)
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
70
ozon/brands_test.go
Normal file
70
ozon/brands_test.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package ozon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
core "github.com/diphantxm/ozon-api-client"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestListCertifiedBrands(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
statusCode int
|
||||||
|
headers map[string]string
|
||||||
|
params *ListCertifiedBrandsParams
|
||||||
|
response string
|
||||||
|
}{
|
||||||
|
// Test Ok
|
||||||
|
{
|
||||||
|
http.StatusOK,
|
||||||
|
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||||
|
&ListCertifiedBrandsParams{
|
||||||
|
Page: 0,
|
||||||
|
PageSize: 0,
|
||||||
|
},
|
||||||
|
`{
|
||||||
|
"result": {
|
||||||
|
"brand_certification": [
|
||||||
|
{
|
||||||
|
"brand_id": 135476863,
|
||||||
|
"brand_name": "Sea of Spa",
|
||||||
|
"has_certificate": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"total": 1
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
// Test No Client-Id or Api-Key
|
||||||
|
{
|
||||||
|
http.StatusUnauthorized,
|
||||||
|
map[string]string{},
|
||||||
|
&ListCertifiedBrandsParams{},
|
||||||
|
`{
|
||||||
|
"code": 16,
|
||||||
|
"message": "Client-Id and Api-Key headers are required"
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
|
||||||
|
|
||||||
|
resp, err := c.Brands().List(test.params)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != test.statusCode {
|
||||||
|
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode == http.StatusOK {
|
||||||
|
if int64(len(resp.Result.BrandCertification)) != resp.Result.Total {
|
||||||
|
t.Errorf("Length of brands in response is not equal to total field in response")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ type Client struct {
|
|||||||
categories *Categories
|
categories *Categories
|
||||||
polygons *Polygons
|
polygons *Polygons
|
||||||
invoices *Invoices
|
invoices *Invoices
|
||||||
|
brands *Brands
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Analytics() *Analytics {
|
func (c Client) Analytics() *Analytics {
|
||||||
@@ -85,6 +86,10 @@ func (c Client) Invoices() *Invoices {
|
|||||||
return c.invoices
|
return c.invoices
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Client) Brands() *Brands {
|
||||||
|
return c.brands
|
||||||
|
}
|
||||||
|
|
||||||
func NewClient(clientId, apiKey string) *Client {
|
func NewClient(clientId, apiKey string) *Client {
|
||||||
coreClient := core.NewClient(DefaultAPIBaseUrl, map[string]string{
|
coreClient := core.NewClient(DefaultAPIBaseUrl, map[string]string{
|
||||||
"Client-Id": clientId,
|
"Client-Id": clientId,
|
||||||
@@ -107,6 +112,7 @@ func NewClient(clientId, apiKey string) *Client {
|
|||||||
categories: &Categories{client: coreClient},
|
categories: &Categories{client: coreClient},
|
||||||
polygons: &Polygons{client: coreClient},
|
polygons: &Polygons{client: coreClient},
|
||||||
invoices: &Invoices{client: coreClient},
|
invoices: &Invoices{client: coreClient},
|
||||||
|
brands: &Brands{client: coreClient},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,5 +135,6 @@ func NewMockClient(handler http.HandlerFunc) *Client {
|
|||||||
categories: &Categories{client: coreClient},
|
categories: &Categories{client: coreClient},
|
||||||
polygons: &Polygons{client: coreClient},
|
polygons: &Polygons{client: coreClient},
|
||||||
invoices: &Invoices{client: coreClient},
|
invoices: &Invoices{client: coreClient},
|
||||||
|
brands: &Brands{client: coreClient},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user