diff --git a/ENDPOINTS.md b/ENDPOINTS.md index 8e2a749..b292a05 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -37,7 +37,7 @@ - [ ] Set a discount on a markdown product ## Promotions -- [ ] Available promotions +- [x] Available promotions - [ ] Products that can participate in a promotion - [ ] Products in a promotion - [ ] Add products to promotion diff --git a/ozon/promotions.go b/ozon/promotions.go new file mode 100644 index 0000000..fae5cb9 --- /dev/null +++ b/ozon/promotions.go @@ -0,0 +1,80 @@ +package ozon + +import ( + "net/http" + + core "github.com/diphantxm/ozon-api-client" +) + +type GetAvailablePromotionsResponse struct { + core.CommonResponse + + // Method result + Result []struct { + // Promotion identifier + Id float64 `json:"id"` + + // Promotion name + Title string `json:"title"` + + // Promotion type + ActionType string `json:"action_type"` + + // Promotion description + Description string `json:"description"` + + // Promotion start date + DateStart string `json:"date_start"` + + // Promotion end date + DateEnd string `json:"date_end"` + + // Promotion freeze date. + // + // If the field is filled, the seller can't increase prices, change the list of products, or decrease the number of product units in the promotion. + // + // The seller can lower prices and increase the product units number in the promotion + FreezeDate string `json:"freeze_date"` + + // Number of products that can participate in the promotion + PotentialProductsCount float64 `json:"potential_products_count"` + + // Number of products that participate in the promotion + ParticipatingProductsCount float64 `json:"participating_products_count"` + + // Whether or not you participate in the promotion + IsParticipating bool `json:"participating"` + + // Indication that customers need a promo code to participate in the promotion + IsVoucherAction bool `json:"is_voucher_action"` + + // Number of blocked products + BannedProductsCount float64 `json:"banned_products_count"` + + // Indication of the promotion is with the target audience + WithTargeting bool `json:"with_targeting"` + + // Order amount + OrderAmount float64 `json:"order_amount"` + + // Discount type + DiscountType string `json:"discount_type"` + + // Discount size + DiscountValue float64 `json:"discount_value"` + } `json:"result"` +} + +func (c Client) GetAvailablePromotions() (*GetAvailablePromotionsResponse, error) { + url := "/v1/actions" + + resp := &GetAvailablePromotionsResponse{} + + response, err := c.client.Request(http.MethodGet, url, nil, resp) + if err != nil { + return nil, err + } + response.CopyCommonResponse(&resp.CommonResponse) + + return resp, nil +} diff --git a/ozon/promotions_test.go b/ozon/promotions_test.go new file mode 100644 index 0000000..b75c369 --- /dev/null +++ b/ozon/promotions_test.go @@ -0,0 +1,56 @@ +package ozon + +import ( + "net/http" + "testing" + + core "github.com/diphantxm/ozon-api-client" +) + +func TestGetAvailablePromotions(t *testing.T) { + tests := []struct { + statusCode int + headers map[string]string + response string + }{ + { + http.StatusOK, + map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, + `{ + "result": [ + { + "id": 71342, + "title": "test voucher #2", + "date_start": "2021-11-22T09:46:38Z", + "date_end": "2021-11-30T20:59:59Z", + "potential_products_count": 0, + "is_participating": true, + "participating_products_count": 5, + "description": "", + "action_type": "DISCOUNT", + "banned_products_count": 0, + "with_targeting": false, + "discount_type": "UNKNOWN", + "discount_value": 0, + "order_amount": 0, + "freeze_date": "", + "is_voucher_action": true + } + ] + }`, + }, + } + + for _, test := range tests { + c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) + + resp, err := c.GetAvailablePromotions() + 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) + } + } +} diff --git a/ozon/rating.go b/ozon/rating.go index 48becc0..6bf7bdb 100644 --- a/ozon/rating.go +++ b/ozon/rating.go @@ -174,7 +174,7 @@ func (c Client) GetSellerRatingInfoForPeriod(params *GetSellerRatingInfoForPerio resp := &GetSellerRatingInfoPeriodResponse{} - response, err := c.client.Request(http.MethodPost, url, nil, resp) + response, err := c.client.Request(http.MethodPost, url, params, resp) if err != nil { return nil, err }