add Reports list

This commit is contained in:
diPhantxm
2023-03-16 00:52:02 +03:00
parent dc6e28497a
commit 0704957432
4 changed files with 181 additions and 3 deletions

View File

@@ -128,8 +128,8 @@
- [ ] ETGB customs declarations - [ ] ETGB customs declarations
## Returns ## Returns
- [ ] Get information about FBO returns (version 3) - [x] Get information about FBO returns (version 3)
- [ ] Get information about FBS returns - [x] Get information about FBS returns
## Cancellations ## Cancellations
- [ ] Get information about a rFBS cancellation request - [ ] Get information about a rFBS cancellation request
@@ -153,7 +153,7 @@
## Reports ## Reports
- [ ] Report details - [ ] Report details
- [ ] Reports list - [x] Reports list
- [ ] Products report - [ ] Products report
- [ ] Prices report - [ ] Prices report
- [ ] Stocks report - [ ] Stocks report

View File

@@ -22,6 +22,7 @@ type Client struct {
rating *Rating rating *Rating
warehouses *Warehouses warehouses *Warehouses
returns *Returns returns *Returns
reports *Reports
} }
func (c Client) Analytics() *Analytics { func (c Client) Analytics() *Analytics {
@@ -60,6 +61,10 @@ func (c Client) Returns() *Returns {
return c.returns return c.returns
} }
func (c Client) Reports() *Reports {
return c.reports
}
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,
@@ -77,6 +82,7 @@ func NewClient(clientId, apiKey string) *Client {
rating: &Rating{client: coreClient}, rating: &Rating{client: coreClient},
warehouses: &Warehouses{client: coreClient}, warehouses: &Warehouses{client: coreClient},
returns: &Returns{client: coreClient}, returns: &Returns{client: coreClient},
reports: &Reports{client: coreClient},
} }
} }
@@ -94,5 +100,6 @@ func NewMockClient(handler http.HandlerFunc) *Client {
rating: &Rating{client: coreClient}, rating: &Rating{client: coreClient},
warehouses: &Warehouses{client: coreClient}, warehouses: &Warehouses{client: coreClient},
returns: &Returns{client: coreClient}, returns: &Returns{client: coreClient},
reports: &Reports{client: coreClient},
} }
} }

92
ozon/reports.go Normal file
View File

@@ -0,0 +1,92 @@
package ozon
import (
"net/http"
"time"
core "github.com/diphantxm/ozon-api-client"
)
type Reports struct {
client *core.Client
}
type GetReportsListParams struct {
// Page number
Page int32 `json:"page"`
// The number of values on the page:
// - default value is 100,
// - maximum value is 1000
PageSize int32 `json:"page_size"`
// Default: "ALL"
// Report type:
// - ALL — all reports,
// - SELLER_PRODUCTS — products report,,
// - SELLER_TRANSACTIONS — transactions report,
// - SELLER_PRODUCT_PRICES — product prices report,
// - SELLER_STOCK — stocks report,
// - SELLER_PRODUCT_MOVEMENT — products movement report,
// - SELLER_RETURNS — returns report,
// - SELLER_POSTINGS — shipments report,
// - SELLER_FINANCE — financial report
ReportType string `json:"report_type"`
}
type GetReportsListResponse struct {
core.CommonResponse
// Method result
Result struct {
// Unique report identifier
Code string `json:"code"`
// Report creation date
CreatedAt time.Time `json:"created_at"`
// Error code when generating the report
Error string `json:"error"`
// Link to CSV file
File string `json:"file"`
// Array with the filters specified when the seller created the report
Params struct {
} `json:"params"`
// Report type:
// - SELLER_PRODUCTS — products report,
// - SELLER_TRANSACTIONS — transactions report,
// - SELLER_PRODUCT_PRICES — product prices report,
// - SELLER_STOCK — stocks report,
// - SELLER_PRODUCT_MOVEMENT — products movement report,
// - SELLER_RETURNS — returns report,
// - SELLER_POSTINGS — shipments report,
// - SELLER_FINANCE — financial report
ReportType string `json:"report_type"`
// Report generation status
// - `success`
// - `failed`
Status string `json:"status"`
} `json:"result"`
// Total number of reports
Total int32 `json:"total"`
}
// Returns the list of reports that have been generated before
func (c Reports) GetList(params *GetReportsListParams) (*GetReportsListResponse, error) {
url := "/v1/report/list"
resp := &GetReportsListResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}

79
ozon/reports_test.go Normal file
View File

@@ -0,0 +1,79 @@
package ozon
import (
"net/http"
"testing"
core "github.com/diphantxm/ozon-api-client"
)
func TestGetList(t *testing.T) {
tests := []struct {
statusCode int
headers map[string]string
params *GetReportsListParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetReportsListParams{
ReportType: "ALL",
PageSize: 1000,
},
`{
"result": {
"reports": [
{
"code": "cd3f2c76-2b9a-4e77-a5a9-7ab52678b3bf",
"status": "success",
"error": "",
"file": "https://minio-production.s3.s.o3.ru:8000/sc-temporary/89/0e/890ef6e360a6396f.csv",
"report_type": "seller_products",
"params": {
"visibility": "3"
},
"created_at": "2019-02-06T12:09:47.258062Z"
},
{
"code": "c39f5fe4-c00b-4e95-a487-6ad34c1e34a3",
"status": "success",
"error": "",
"file": "https://minio-production.s3.s.o3.ru:8000/reports/a7/48/a7481a083873e164.csv",
"report_type": "seller_products",
"params": {
"visibility": "3"
},
"created_at": "2019-02-15T08:34:32.267178Z"
}
],
"total": 2
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetReportsListParams{},
`{
"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.Reports().GetList(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)
}
}
}