wip integration bidding

This commit is contained in:
JBP
2019-08-16 21:28:25 +02:00
parent bc5c9ef1e3
commit 22c6e9d1bd
7 changed files with 251 additions and 81 deletions
+47
View File
@@ -1,7 +1,10 @@
package ebay
import (
"context"
"fmt"
"net/http"
"time"
)
// OfferService handles communication with the Offer API
@@ -22,6 +25,11 @@ const (
BuyMarketplaceUSA = "EBAY_US"
)
// Valid values for the "auctionStatus" Bidding field.
const (
BiddingAuctionStatusEnded = "ENDED"
)
// OptBuyMarketplace adds the header containing the marketplace id:
// https://developer.ebay.com/api-docs/buy/static/ref-marketplace-supported.html
//
@@ -31,3 +39,42 @@ func OptBuyMarketplace(marketplaceID string) func(*http.Request) {
req.Header.Set("X-EBAY-C-MARKETPLACE-ID", marketplaceID)
}
}
// Bidding represents an eBay item bidding.
type Bidding struct {
AuctionStatus string `json:"auctionStatus"`
AuctionEndDate time.Time `json:"auctionEndDate"`
ItemID string `json:"itemId"`
CurrentPrice struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"currentPrice"`
BidCount int `json:"bidCount"`
HighBidder bool `json:"highBidder"`
ReservePriceMet bool `json:"reservePriceMet"`
SuggestedBidAmounts []struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"suggestedBidAmounts"`
CurrentProxyBid struct {
ProxyBidID string `json:"proxyBidId"`
MaxAmount struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"maxAmount"`
} `json:"currentProxyBid"`
}
// GetBidding retrieves the buyer's bidding details on an auction.
//
// eBay API docs: https://developer.ebay.com/api-docs/buy/offer/resources/bidding/methods/getBidding
func (s *OfferService) GetBidding(ctx context.Context, itemID, marketplaceID string, opts ...Opt) (Item, error) {
u := fmt.Sprintf("buy/offer/v1_beta/bidding/%s", itemID)
opts = append(opts, OptBuyMarketplace(marketplaceID))
req, err := s.client.NewRequest(http.MethodGet, u, opts...)
if err != nil {
return Item{}, err
}
var it Item
return it, s.client.Do(ctx, req, &it)
}