add get available promotions method
This commit is contained in:
		@@ -37,7 +37,7 @@
 | 
				
			|||||||
- [ ] Set a discount on a markdown product
 | 
					- [ ] Set a discount on a markdown product
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Promotions
 | 
					## Promotions
 | 
				
			||||||
- [ ] Available promotions
 | 
					- [x] Available promotions
 | 
				
			||||||
- [ ] Products that can participate in a promotion
 | 
					- [ ] Products that can participate in a promotion
 | 
				
			||||||
- [ ] Products in a promotion
 | 
					- [ ] Products in a promotion
 | 
				
			||||||
- [ ] Add products to promotion
 | 
					- [ ] Add products to promotion
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										80
									
								
								ozon/promotions.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								ozon/promotions.go
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										56
									
								
								ozon/promotions_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								ozon/promotions_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -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)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -174,7 +174,7 @@ func (c Client) GetSellerRatingInfoForPeriod(params *GetSellerRatingInfoForPerio
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	resp := &GetSellerRatingInfoPeriodResponse{}
 | 
						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 {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user