From 765d405fe320875fe49ee5b4de9acb1e249d133d Mon Sep 17 00:00:00 2001 From: Vittorio Giovara Date: Fri, 16 Aug 2024 03:03:58 +0200 Subject: [PATCH] tcgplayer/api: Remove additional custom buylist code --- tcgplayer/api.go | 92 ------------------------------------------------ 1 file changed, 92 deletions(-) diff --git a/tcgplayer/api.go b/tcgplayer/api.go index 3079eed0..cfb242b2 100644 --- a/tcgplayer/api.go +++ b/tcgplayer/api.go @@ -8,7 +8,6 @@ import ( "io" "net/http" "net/url" - "strconv" "strings" "time" @@ -688,94 +687,3 @@ func TCGCreateCartKey(userId string) (string, error) { return response.Results[0].CartKey, nil } - -const TCGBuylistUpdateQtyURL = "https://store.tcgplayer.com/buylist/updatequantity" - -func (tcg *CookieClient) BuylistSetQuantity(skuId, qty int) (string, error) { - payload := url.Values{} - payload.Set("productConditionId", fmt.Sprint(skuId)) - payload.Set("reqQty", fmt.Sprint(qty)) - payload.Set("availQty", "0") - payload.Set("overrideQty", "true") - - req, err := http.NewRequest(http.MethodPost, TCGBuylistUpdateQtyURL, strings.NewReader(payload.Encode())) - if err != nil { - return "", err - } - req.Header.Add("Cookie", "TCGAuthTicket_Production="+tcg.authKey+";") - req.Header.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") - - resp, err := cleanhttp.DefaultClient().Do(req) - if err != nil { - return "", err - } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - return "", errors.New("buylist not ok") - } - - // Nothing interesting in the response - data, err := io.ReadAll(resp.Body) - if err != nil { - return "", err - } - response := string(data) - - return response, nil -} - -const TCGBuylistOffersURL = "https://store.tcgplayer.com/buylist/viewtopsellerprices?productConditionId=" - -type TCGBuylistOffer struct { - SkuId int - SellerName string - Price float64 - Quantity int -} - -func (tcg *CookieClient) BuylistViewOffers(skuId int) ([]TCGBuylistOffer, error) { - req, err := http.NewRequest(http.MethodGet, TCGBuylistOffersURL+fmt.Sprint(skuId), nil) - if err != nil { - return nil, err - } - req.Header.Add("Cookie", "TCGAuthTicket_Production="+tcg.authKey+";") - - resp, err := cleanhttp.DefaultClient().Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - - doc, err := goquery.NewDocumentFromReader(resp.Body) - if err != nil { - return nil, err - } - - var offers []TCGBuylistOffer - doc.Find(`tbody`).Find(`tr`).Each(func(i int, s *goquery.Selection) { - sellerName := strings.TrimSpace(s.Find("td:nth-child(1)").Text()) - offerPrice := strings.TrimSpace(s.Find("td:nth-child(2)").Text()) - offerQty := strings.TrimSpace(s.Find("td:nth-child(3)").Text()) - - price, _ := mtgmatcher.ParsePrice(offerPrice) - qty, _ := strconv.Atoi(offerQty) - - if price == 0 || qty == 0 { - return - } - - offers = append(offers, TCGBuylistOffer{ - SkuId: skuId, - SellerName: sellerName, - Price: price, - Quantity: qty, - }) - }) - - if len(offers) == 0 { - return nil, errors.New("no offers in buylist") - } - - return offers, nil -}