common/pkg/coach-client/inventory.go

38 lines
1.1 KiB
Go
Raw Normal View History

2024-05-21 15:36:51 +08:00
package coach_client
import (
"context"
"fmt"
"net/url"
"time"
)
type Inventory struct {
Id string `json:"id"`
Ats int `json:"ats"`
PreOrderable bool `json:"preorderable"`
BackOrderable bool `json:"backorderable"`
Orderable bool `json:"orderable"`
AllocationResetDate time.Time `json:"allocationResetDate,omitempty"`
Perpetual bool `json:"perpetual"`
StockLevel int `json:"stockLevel"`
}
type InventoryResponse struct {
Inventory struct {
Status string `json:"status"`
InventoryListID string `json:"inventoryListID"`
InventoryInfo Inventory `json:"inventoryInfo"`
} `json:"inventory"`
}
func (c *Client) RequestInventory(ctx context.Context, pid string) (inv Inventory, err error) {
sctx, cancel := context.WithTimeout(ctx, c.defaultTimeOut)
defer cancel()
var resp InventoryResponse
urlPath := fmt.Sprintf("https://www.coachoutlet.com/api/inventory?vgId=%s&includeVariantData=false", url.QueryEscape(pid))
err = tryRequest(sctx, urlPath, &resp, c.pool.RandomIterator())
inv = resp.Inventory.InventoryInfo
return
}