69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
|
package coach_client
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
type PageDataResponse struct {
|
||
|
PageData struct {
|
||
|
Total int `json:"total"`
|
||
|
Page int `json:"page"`
|
||
|
TotalPages int `json:"totalPages"`
|
||
|
PageSize int `json:"pageSize"`
|
||
|
Products []Product `json:"products"`
|
||
|
} `json:"pageData"`
|
||
|
}
|
||
|
type Product struct {
|
||
|
Name string `json:"name"`
|
||
|
Colors []Color `json:"colors"`
|
||
|
VariantsOnSale []Variant `json:"variantsOnSale"`
|
||
|
}
|
||
|
|
||
|
type Color struct {
|
||
|
Id string `json:"id"` //"id": "IMDQC",
|
||
|
Text string `json:"text"` //颜色的描述
|
||
|
Orderable bool `json:"orderable"`
|
||
|
Media Media `json:"media"`
|
||
|
Url string `json:"url"` //"/products/eliza-flap-crossbody-bag-in-signature-canvas/CP009-IMDQC.html",
|
||
|
VgId string `json:"vgId"` // "vgId": "CP009-IMDQC",
|
||
|
MasterId string `json:"masterId"` //"masterId": "CP009"
|
||
|
}
|
||
|
|
||
|
type Media struct {
|
||
|
Thumbnail Thumbnail `json:"thumbnail"`
|
||
|
}
|
||
|
|
||
|
type Thumbnail struct {
|
||
|
Src string `json:"src"`
|
||
|
}
|
||
|
|
||
|
type Variant struct {
|
||
|
Id string `json:"id"`
|
||
|
OnSale bool `json:"onSale"`
|
||
|
Price Price `json:"price"`
|
||
|
}
|
||
|
|
||
|
type Price struct {
|
||
|
Sales Sales `json:"sales"`
|
||
|
MarkdownDiscPercent int `json:"markdownDiscPercent"`
|
||
|
}
|
||
|
|
||
|
type Sales struct {
|
||
|
Value float64 `json:"value"`
|
||
|
Currency string `json:"currency"`
|
||
|
Formatted string `json:"formatted"`
|
||
|
DecimalPrice string `json:"decimalPrice"`
|
||
|
}
|
||
|
|
||
|
func (c *Client) ViewAllBags(ctx context.Context, page int) (resp PageDataResponse, err error) {
|
||
|
if page < 1 {
|
||
|
page = 1
|
||
|
}
|
||
|
sctx, cancel := context.WithTimeout(ctx, c.defaultTimeOut)
|
||
|
defer cancel()
|
||
|
urlPath := fmt.Sprintf("https://www.coachoutlet.com/api/get-shop/bags/view-all?page=%d", page)
|
||
|
err = tryRequest(sctx, urlPath, &resp, c.pool.RandomIterator())
|
||
|
return
|
||
|
}
|