refactoring. put methods to individual structures

This commit is contained in:
diPhantxm
2023-03-15 21:38:17 +03:00
parent 2e60a17c56
commit 2566f85da3
17 changed files with 148 additions and 55 deletions

View File

@@ -7,6 +7,10 @@ import (
core "github.com/diphantxm/ozon-api-client" core "github.com/diphantxm/ozon-api-client"
) )
type Analytics struct {
client *core.Client
}
type GetAnalyticsDataParams struct { type GetAnalyticsDataParams struct {
// Date from which the data will be in the report // Date from which the data will be in the report
DateFrom time.Time `json:"date_from"` DateFrom time.Time `json:"date_from"`
@@ -90,7 +94,7 @@ type GetAnalyticsDataResponse struct {
} }
// Specify the period and metrics that are required. The response will contain analytical data grouped by the `dimensions` parameter. // Specify the period and metrics that are required. The response will contain analytical data grouped by the `dimensions` parameter.
func (c Client) GetAnalyticsData(params *GetAnalyticsDataParams) (*GetAnalyticsDataResponse, error) { func (c Analytics) GetAnalyticsData(params *GetAnalyticsDataParams) (*GetAnalyticsDataResponse, error) {
url := "/v1/analytics/data" url := "/v1/analytics/data"
resp := &GetAnalyticsDataResponse{} resp := &GetAnalyticsDataResponse{}
@@ -152,7 +156,7 @@ type GetStocksOnWarehousesResponse struct {
} }
// Report on stocks and products movement at Ozon warehouses // Report on stocks and products movement at Ozon warehouses
func (c Client) GetStocksOnWarehouses(params *GetStocksOnWarehousesParams) (*GetStocksOnWarehousesResponse, error) { func (c Analytics) GetStocksOnWarehouses(params *GetStocksOnWarehousesParams) (*GetStocksOnWarehousesResponse, error) {
url := "/v2/analytics/stock_on_warehouses" url := "/v2/analytics/stock_on_warehouses"
resp := &GetStocksOnWarehousesResponse{} resp := &GetStocksOnWarehousesResponse{}

View File

@@ -57,7 +57,7 @@ func TestGetAnalyticsData(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetAnalyticsData(test.params) resp, err := c.Analytics().GetAnalyticsData(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -115,7 +115,7 @@ func TestGetStocksOnWarehouses(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetStocksOnWarehouses(test.params) resp, err := c.Analytics().GetStocksOnWarehouses(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View File

@@ -7,6 +7,10 @@ import (
core "github.com/diphantxm/ozon-api-client" core "github.com/diphantxm/ozon-api-client"
) )
type FBO struct {
client *core.Client
}
type GetFBOShipmentsListParams struct { type GetFBOShipmentsListParams struct {
// Sorting direction // Sorting direction
Direction string `json:"dir"` Direction string `json:"dir"`
@@ -151,7 +155,7 @@ type GetFBOShipmentsListResponse struct {
} }
// Returns a list of shipments for a specified period of time. You can additionally filter the shipments by their status // Returns a list of shipments for a specified period of time. You can additionally filter the shipments by their status
func (c Client) GetFBOShipmentsList(params *GetFBOShipmentsListParams) (*GetFBOShipmentsListResponse, error) { func (c FBO) GetFBOShipmentsList(params *GetFBOShipmentsListParams) (*GetFBOShipmentsListResponse, error) {
url := "/v2/posting/fbo/list" url := "/v2/posting/fbo/list"
resp := &GetFBOShipmentsListResponse{} resp := &GetFBOShipmentsListResponse{}

View File

@@ -131,7 +131,7 @@ func TestGetFBOShipmentsList(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetFBOShipmentsList(test.params) resp, err := c.FBO().GetFBOShipmentsList(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View File

@@ -7,6 +7,10 @@ import (
core "github.com/diphantxm/ozon-api-client" core "github.com/diphantxm/ozon-api-client"
) )
type FBS struct {
client *core.Client
}
type ListUnprocessedShipmentsParams struct { type ListUnprocessedShipmentsParams struct {
Direction string `json:"dir"` Direction string `json:"dir"`
Filter ListUnprocessedShipmentsFilter `json:"filter"` Filter ListUnprocessedShipmentsFilter `json:"filter"`
@@ -190,7 +194,7 @@ type FinancialDataProduct struct {
TotalDiscountValue float64 `json:"total_discount_value"` TotalDiscountValue float64 `json:"total_discount_value"`
} }
func (c Client) ListUnprocessedShipments(params *ListUnprocessedShipmentsParams) (*ListUnprocessedShipmentsResponse, error) { func (c FBS) ListUnprocessedShipments(params *ListUnprocessedShipmentsParams) (*ListUnprocessedShipmentsResponse, error) {
url := "/v3/posting/fbs/unfulfilled/list" url := "/v3/posting/fbs/unfulfilled/list"
resp := &ListUnprocessedShipmentsResponse{} resp := &ListUnprocessedShipmentsResponse{}
@@ -289,7 +293,7 @@ type GetFBSShipmentsListResponse struct {
// You can filter shipments by their status. The list of available statuses is specified in the description of the filter.status parameter. // You can filter shipments by their status. The list of available statuses is specified in the description of the filter.status parameter.
// //
// The true value of the has_next parameter in the response means there is not the entire array of shipments in the response. To get information on the remaining shipments, make a new request with a different offset value. // The true value of the has_next parameter in the response means there is not the entire array of shipments in the response. To get information on the remaining shipments, make a new request with a different offset value.
func (c Client) GetFBSShipmentsList(params *GetFBSShipmentsListParams) (*GetFBSShipmentsListResponse, error) { func (c FBS) GetFBSShipmentsList(params *GetFBSShipmentsListParams) (*GetFBSShipmentsListResponse, error) {
url := "/v3/posting/fbs/list" url := "/v3/posting/fbs/list"
resp := &GetFBSShipmentsListResponse{} resp := &GetFBSShipmentsListResponse{}
@@ -358,7 +362,7 @@ type PackOrderResponse struct {
// Differs from /v2/posting/fbs/ship by the presence of the field exemplar_info in the request. // Differs from /v2/posting/fbs/ship by the presence of the field exemplar_info in the request.
// //
// If necessary, specify the number of the cargo customs declaration in the gtd parameter. If it is missing, pass the value is_gtd_absent = true // If necessary, specify the number of the cargo customs declaration in the gtd parameter. If it is missing, pass the value is_gtd_absent = true
func (c Client) PackOrder(params *PackOrderParams) (*PackOrderResponse, error) { func (c FBS) PackOrder(params *PackOrderParams) (*PackOrderResponse, error) {
url := "/v4/posting/fbs/ship" url := "/v4/posting/fbs/ship"
resp := &PackOrderResponse{} resp := &PackOrderResponse{}

View File

@@ -165,7 +165,7 @@ func TestListUnprocessedShipments(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.ListUnprocessedShipments(test.params) resp, err := c.FBS().ListUnprocessedShipments(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -274,7 +274,7 @@ func TestGetFBSShipmentsList(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetFBSShipmentsList(test.params) resp, err := c.FBS().GetFBSShipmentsList(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -333,7 +333,7 @@ func TestPackOrder(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.PackOrder(test.params) resp, err := c.FBS().PackOrder(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View File

@@ -7,6 +7,10 @@ import (
core "github.com/diphantxm/ozon-api-client" core "github.com/diphantxm/ozon-api-client"
) )
type Finance struct {
client *core.Client
}
type ReportOnSoldProductsParams struct { type ReportOnSoldProductsParams struct {
// Time period in the `YYYY-MM` format // Time period in the `YYYY-MM` format
Date string `json:"date"` Date string `json:"date"`
@@ -141,7 +145,7 @@ type ReportOnSoldProductsResponse struct {
// Returns information on products sold and returned within a month. Canceled or non-purchased products are not included. // Returns information on products sold and returned within a month. Canceled or non-purchased products are not included.
// //
// Report is returned no later than the 5th day of the next month // Report is returned no later than the 5th day of the next month
func (c Client) ReportOnSoldProducts(params *ReportOnSoldProductsParams) (*ReportOnSoldProductsResponse, error) { func (c Finance) ReportOnSoldProducts(params *ReportOnSoldProductsParams) (*ReportOnSoldProductsResponse, error) {
url := "/v1/finance/realization" url := "/v1/finance/realization"
resp := &ReportOnSoldProductsResponse{} resp := &ReportOnSoldProductsResponse{}
@@ -229,7 +233,7 @@ type GetTotalTransactionsSumResponse struct {
} }
// Returns total sums for transactions for specified period // Returns total sums for transactions for specified period
func (c Client) GetTotalTransactionsSum(params *GetTotalTransactionsSumParams) (*GetTotalTransactionsSumResponse, error) { func (c Finance) GetTotalTransactionsSum(params *GetTotalTransactionsSumParams) (*GetTotalTransactionsSumResponse, error) {
url := "/v3/finance/transaction/totals" url := "/v3/finance/transaction/totals"
resp := &GetTotalTransactionsSumResponse{} resp := &GetTotalTransactionsSumResponse{}

View File

@@ -88,7 +88,7 @@ func TestReportOnSoldProducts(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.ReportOnSoldProducts(test.params) resp, err := c.Finance().ReportOnSoldProducts(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -154,7 +154,7 @@ func TestGetTotalTransactionsSum(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetTotalTransactionsSum(test.params) resp, err := c.Finance().GetTotalTransactionsSum(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View File

@@ -12,19 +12,80 @@ const (
type Client struct { type Client struct {
client *core.Client client *core.Client
analytics *Analytics
fbo *FBO
fbs *FBS
finance *Finance
products *Products
promotions *Promotions
rating *Rating
warehouses *Warehouses
}
func (c Client) Analytics() *Analytics {
return c.analytics
}
func (c Client) FBO() *FBO {
return c.fbo
}
func (c Client) FBS() *FBS {
return c.fbs
}
func (c Client) Finance() *Finance {
return c.finance
}
func (c Client) Products() *Products {
return c.products
}
func (c Client) Promotions() *Promotions {
return c.promotions
}
func (c Client) Rating() *Rating {
return c.rating
}
func (c Client) Warehouses() *Warehouses {
return c.warehouses
} }
func NewClient(clientId, apiKey string) *Client { func NewClient(clientId, apiKey string) *Client {
return &Client{ coreClient := core.NewClient(DefaultAPIBaseUrl, map[string]string{
client: core.NewClient(DefaultAPIBaseUrl, map[string]string{
"Client-Id": clientId, "Client-Id": clientId,
"Api-Key": apiKey, "Api-Key": apiKey,
}), })
return &Client{
client: coreClient,
analytics: &Analytics{client: coreClient},
fbo: &FBO{client: coreClient},
fbs: &FBS{client: coreClient},
finance: &Finance{client: coreClient},
products: &Products{client: coreClient},
promotions: &Promotions{client: coreClient},
rating: &Rating{client: coreClient},
warehouses: &Warehouses{client: coreClient},
} }
} }
func NewMockClient(handler http.HandlerFunc) *Client { func NewMockClient(handler http.HandlerFunc) *Client {
coreClient := core.NewMockClient(handler)
return &Client{ return &Client{
client: core.NewMockClient(handler), client: coreClient,
analytics: &Analytics{client: coreClient},
fbo: &FBO{client: coreClient},
fbs: &FBS{client: coreClient},
finance: &Finance{client: coreClient},
products: &Products{client: coreClient},
promotions: &Promotions{client: coreClient},
rating: &Rating{client: coreClient},
warehouses: &Warehouses{client: coreClient},
} }
} }

View File

@@ -7,6 +7,10 @@ import (
core "github.com/diphantxm/ozon-api-client" core "github.com/diphantxm/ozon-api-client"
) )
type Products struct {
client *core.Client
}
type GetStocksInfoParams struct { type GetStocksInfoParams struct {
// Identifier of the last value on the page. Leave this field blank in the first request. // Identifier of the last value on the page. Leave this field blank in the first request.
// //
@@ -72,7 +76,7 @@ type GetStocksInfoResponse struct {
// * how many items are available, // * how many items are available,
// //
// * how many are reserved by customers. // * how many are reserved by customers.
func (c Client) GetStocksInfo(params *GetStocksInfoParams) (*GetStocksInfoResponse, error) { func (c Products) GetStocksInfo(params *GetStocksInfoParams) (*GetStocksInfoResponse, error) {
url := "/v3/product/info/stocks" url := "/v3/product/info/stocks"
resp := &GetStocksInfoResponse{} resp := &GetStocksInfoResponse{}
@@ -350,7 +354,7 @@ type GetProductDetailsResponseItemError struct {
} }
// Get product details // Get product details
func (c Client) GetProductDetails(params *GetProductDetailsParams) (*GetProductDetailsResponse, error) { func (c Products) GetProductDetails(params *GetProductDetailsParams) (*GetProductDetailsResponse, error) {
url := "/v2/product/info" url := "/v2/product/info"
resp := &GetProductDetailsResponse{} resp := &GetProductDetailsResponse{}
@@ -411,7 +415,7 @@ type UpdateStocksResponse struct {
// With one request you can change the availability for 100 products. You can send up to 80 requests in a minute. // With one request you can change the availability for 100 products. You can send up to 80 requests in a minute.
// //
// Availability can only be set after the product status has been changed to processed. // Availability can only be set after the product status has been changed to processed.
func (c Client) UpdateStocks(params *UpdateStocksParams) (*UpdateStocksResponse, error) { func (c Products) UpdateStocks(params *UpdateStocksParams) (*UpdateStocksResponse, error) {
url := "/v1/product/import/stocks" url := "/v1/product/import/stocks"
resp := &UpdateStocksResponse{} resp := &UpdateStocksResponse{}
@@ -481,7 +485,7 @@ type UpdateQuantityStockProductsResponse struct {
// Availability can only be set after the product status has been changed to processed. // Availability can only be set after the product status has been changed to processed.
// //
// Bulky products stock can only be updated in the warehouses for bulky products. // Bulky products stock can only be updated in the warehouses for bulky products.
func (c Client) UpdateQuantityStockProducts(params *UpdateQuantityStockProductsParams) (*UpdateQuantityStockProductsResponse, error) { func (c Products) UpdateQuantityStockProducts(params *UpdateQuantityStockProductsParams) (*UpdateQuantityStockProductsResponse, error) {
url := "/v2/products/stocks" url := "/v2/products/stocks"
resp := &UpdateQuantityStockProductsResponse{} resp := &UpdateQuantityStockProductsResponse{}
@@ -530,7 +534,7 @@ type StocksInSellersWarehouseResponse struct {
} }
// Get stocks in seller's warehouse // Get stocks in seller's warehouse
func (c Client) StocksInSellersWarehouse(params *StocksInSellersWarehouseParams) (*StocksInSellersWarehouseResponse, error) { func (c Products) StocksInSellersWarehouse(params *StocksInSellersWarehouseParams) (*StocksInSellersWarehouseResponse, error) {
url := "/v1/product/info/stocks-by-warehouse/fbs" url := "/v1/product/info/stocks-by-warehouse/fbs"
resp := &StocksInSellersWarehouseResponse{} resp := &StocksInSellersWarehouseResponse{}
@@ -603,7 +607,7 @@ type UpdatePricesResponse struct {
// To reset old_price or premium_price set these parameters to 0. // To reset old_price or premium_price set these parameters to 0.
// //
// A new price must differ from the old one by at least 5%. // A new price must differ from the old one by at least 5%.
func (c Client) UpdatePrices(params *UpdatePricesParams) (*UpdatePricesResponse, error) { func (c Products) UpdatePrices(params *UpdatePricesParams) (*UpdatePricesResponse, error) {
url := "/v1/product/import/prices" url := "/v1/product/import/prices"
resp := &UpdatePricesResponse{} resp := &UpdatePricesResponse{}
@@ -776,7 +780,7 @@ type CreateOrUpdateProductResponse struct {
} }
// This method allows you to create products and update their details // This method allows you to create products and update their details
func (c Client) CreateOrUpdateProduct(params *CreateOrUpdateProductParams) (*CreateOrUpdateProductResponse, error) { func (c Products) CreateOrUpdateProduct(params *CreateOrUpdateProductParams) (*CreateOrUpdateProductResponse, error) {
url := "/v2/product/import" url := "/v2/product/import"
resp := &CreateOrUpdateProductResponse{} resp := &CreateOrUpdateProductResponse{}
@@ -838,7 +842,7 @@ type GetListOfProductsResponse struct {
} `json:"result"` } `json:"result"`
} }
func (c Client) GetListOfProducts(params *GetListOfProductsParams) (*GetListOfProductsResponse, error) { func (c Products) GetListOfProducts(params *GetListOfProductsParams) (*GetListOfProductsResponse, error) {
url := "/v2/product/list" url := "/v2/product/list"
resp := &GetListOfProductsResponse{} resp := &GetListOfProductsResponse{}
@@ -913,7 +917,7 @@ type GetProductsRatingBySKUResponse struct {
} }
// Method for getting products' content rating and recommendations on how to increase it // Method for getting products' content rating and recommendations on how to increase it
func (c Client) GetProductsRatingBySKU(params *GetProductsRatingBySKUParams) (*GetProductsRatingBySKUResponse, error) { func (c Products) GetProductsRatingBySKU(params *GetProductsRatingBySKUParams) (*GetProductsRatingBySKUResponse, error) {
url := "/v1/product/rating-by-sku" url := "/v1/product/rating-by-sku"
resp := &GetProductsRatingBySKUResponse{} resp := &GetProductsRatingBySKUResponse{}

View File

@@ -67,7 +67,7 @@ func TestGetStocksInfo(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetStocksInfo(test.params) resp, err := c.Products().GetStocksInfo(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -231,7 +231,7 @@ func TestGetProductDetails(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetProductDetails(test.params) resp, err := c.Products().GetProductDetails(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -288,7 +288,7 @@ func TestUpdateStocks(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.UpdateStocks(test.params) resp, err := c.Products().UpdateStocks(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -341,7 +341,7 @@ func TestStocksInSellersWarehouse(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.StocksInSellersWarehouse(test.params) resp, err := c.Products().StocksInSellersWarehouse(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -401,7 +401,7 @@ func TestUpdatePrices(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.UpdatePrices(test.params) resp, err := c.Products().UpdatePrices(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -460,7 +460,7 @@ func TestUpdateQuantityStockProducts(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.UpdateQuantityStockProducts(test.params) resp, err := c.Products().UpdateQuantityStockProducts(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -575,7 +575,7 @@ func TestCreateOrUpdateProduct(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.CreateOrUpdateProduct(test.params) resp, err := c.Products().CreateOrUpdateProduct(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -634,7 +634,7 @@ func TestGetListOfProducts(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetListOfProducts(test.params) resp, err := c.Products().GetListOfProducts(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -861,7 +861,7 @@ func TestGetProductsRatingBySKU(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetProductsRatingBySKU(test.params) resp, err := c.Products().GetProductsRatingBySKU(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View File

@@ -6,6 +6,10 @@ import (
core "github.com/diphantxm/ozon-api-client" core "github.com/diphantxm/ozon-api-client"
) )
type Promotions struct {
client *core.Client
}
type GetAvailablePromotionsResponse struct { type GetAvailablePromotionsResponse struct {
core.CommonResponse core.CommonResponse
@@ -65,7 +69,7 @@ type GetAvailablePromotionsResponse struct {
} `json:"result"` } `json:"result"`
} }
func (c Client) GetAvailablePromotions() (*GetAvailablePromotionsResponse, error) { func (c Promotions) GetAvailablePromotions() (*GetAvailablePromotionsResponse, error) {
url := "/v1/actions" url := "/v1/actions"
resp := &GetAvailablePromotionsResponse{} resp := &GetAvailablePromotionsResponse{}

View File

@@ -54,7 +54,7 @@ func TestGetAvailablePromotions(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetAvailablePromotions() resp, err := c.Promotions().GetAvailablePromotions()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View File

@@ -7,6 +7,10 @@ import (
core "github.com/diphantxm/ozon-api-client" core "github.com/diphantxm/ozon-api-client"
) )
type Rating struct {
client *core.Client
}
type GetCurrentSellerRatingInfoResponse struct { type GetCurrentSellerRatingInfoResponse struct {
core.CommonResponse core.CommonResponse
@@ -80,7 +84,7 @@ type GetCurrentSellerRatingInfoResponse struct {
} `json:"groups"` } `json:"groups"`
} }
func (c Client) GetCurrentSellerRatingInfo() (*GetCurrentSellerRatingInfoResponse, error) { func (c Rating) GetCurrentSellerRatingInfo() (*GetCurrentSellerRatingInfoResponse, error) {
url := "/v1/rating/summary" url := "/v1/rating/summary"
resp := &GetCurrentSellerRatingInfoResponse{} resp := &GetCurrentSellerRatingInfoResponse{}
@@ -169,7 +173,7 @@ type GetSellerRatingInfoPeriodResponse struct {
} `json:"ratings"` } `json:"ratings"`
} }
func (c Client) GetSellerRatingInfoForPeriod(params *GetSellerRatingInfoForPeriodParams) (*GetSellerRatingInfoPeriodResponse, error) { func (c Rating) GetSellerRatingInfoForPeriod(params *GetSellerRatingInfoForPeriodParams) (*GetSellerRatingInfoPeriodResponse, error) {
url := "/v1/rating/history" url := "/v1/rating/history"
resp := &GetSellerRatingInfoPeriodResponse{} resp := &GetSellerRatingInfoPeriodResponse{}

View File

@@ -56,7 +56,7 @@ func TestGetCurrentRatingInfo(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetCurrentSellerRatingInfo() resp, err := c.Rating().GetCurrentSellerRatingInfo()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -134,7 +134,7 @@ func TestGetRatingInfoForPeriod(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetSellerRatingInfoForPeriod(test.params) resp, err := c.Rating().GetSellerRatingInfoForPeriod(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View File

@@ -7,6 +7,10 @@ import (
core "github.com/diphantxm/ozon-api-client" core "github.com/diphantxm/ozon-api-client"
) )
type Warehouses struct {
client *core.Client
}
type GetListOfWarehousesResponse struct { type GetListOfWarehousesResponse struct {
core.CommonResponse core.CommonResponse
@@ -76,8 +80,8 @@ type GetListOfWarehousesResponse struct {
} `json:"resulCommonResponse"` } `json:"resulCommonResponse"`
} }
// You do not need to specify any parameters in the request. Your company will be identified by the Client ID // You do not need to specify any parameters in the request. Your company will be identified by the Warehouses ID
func (c Client) GetListOfWarehouses() (*GetListOfWarehousesResponse, error) { func (c Warehouses) GetListOfWarehouses() (*GetListOfWarehousesResponse, error) {
url := "/v1/warehouse/list" url := "/v1/warehouse/list"
resp := &GetListOfWarehousesResponse{} resp := &GetListOfWarehousesResponse{}
@@ -165,7 +169,7 @@ type GetListOfDeliveryMethodsResponse struct {
} }
// This methods allows you to get list of all delivery methods that can be applied for this warehouse // This methods allows you to get list of all delivery methods that can be applied for this warehouse
func (c Client) GetListOfDeliveryMethods(params *GetListOfDeliveryMethodsParams) (*GetListOfDeliveryMethodsResponse, error) { func (c Warehouses) GetListOfDeliveryMethods(params *GetListOfDeliveryMethodsParams) (*GetListOfDeliveryMethodsResponse, error) {
url := "/v1/delivery-method/list" url := "/v1/delivery-method/list"
resp := &GetListOfDeliveryMethodsResponse{} resp := &GetListOfDeliveryMethodsResponse{}

View File

@@ -56,7 +56,7 @@ func TestGetListOfWarehouses(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetListOfWarehouses() resp, err := c.Warehouses().GetListOfWarehouses()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -118,7 +118,7 @@ func TestGetListOfDeliveryMethods(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers)) c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetListOfDeliveryMethods(test.params) resp, err := c.Warehouses().GetListOfDeliveryMethods(test.params)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }