Clone the twdehands SDK into mrktplaats and retarget naming and defaults for app.marktplaats.nl while keeping the same request/response bodies and endpoint behavior.
95 lines
3.1 KiB
Go
95 lines
3.1 KiB
Go
package mrktplaats
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// EnquiryService handles bidding on listings.
|
|
type EnquiryService struct {
|
|
t *transport
|
|
}
|
|
|
|
// PlaceBidRequest defines the payload for placing a bid.
|
|
type PlaceBidRequest struct {
|
|
AdURN string `json:"adUrn"`
|
|
Value int `json:"value"` // euro cents
|
|
PersonalMessage string `json:"personalMessage,omitempty"`
|
|
Phone string `json:"phone,omitempty"`
|
|
}
|
|
|
|
// Bid represents a bid on a listing.
|
|
type Bid struct {
|
|
ID int `json:"id"`
|
|
Value int `json:"value"`
|
|
Date string `json:"date"`
|
|
User BidUser `json:"user"`
|
|
}
|
|
|
|
// BidUser identifies the bidder.
|
|
type BidUser struct {
|
|
ID int `json:"id"`
|
|
Nickname string `json:"nickname"`
|
|
}
|
|
|
|
// BidsResponse contains the bids on a listing.
|
|
type BidsResponse struct {
|
|
Bids []Bid `json:"bids"`
|
|
CurrentMinimumBid int `json:"currentMinimumBid"`
|
|
}
|
|
|
|
// AskQuestionBody is the payload for contacting a seller about a listing.
|
|
type AskQuestionBody struct {
|
|
AdTitle *string `json:"adTitle"`
|
|
AdURN string `json:"adUrn"`
|
|
BidID *int `json:"bidId"`
|
|
BidValue float64 `json:"bidValue"`
|
|
Body string `json:"body"`
|
|
BuyerLocation *string `json:"buyerLocation"`
|
|
BuyerName *string `json:"buyerName"`
|
|
CallbackRequest *string `json:"callbackRequest"`
|
|
CategoryID int `json:"categoryId"`
|
|
FinancingInfoRequest bool `json:"financingInfoRequest"`
|
|
Phone *string `json:"phone"`
|
|
RecipientID string `json:"recipientId"`
|
|
RecipientName *string `json:"recipientName"`
|
|
TradeInRequest *string `json:"tradeInRequest"`
|
|
VisitOrTestDriveRequest *string `json:"visitOrTestDriveRequest"`
|
|
TradeInRequestAllowed bool `json:"tradeInRequestAllowed"`
|
|
}
|
|
|
|
// AskQuestion sends a message to the seller of a listing (the "Ask Seller a Question" / ASQ flow).
|
|
// sellerID is the numeric ID of the seller, available as detail.SellerInformation.ID from Listings.Get.
|
|
// Returns nil on success (the API responds with 204 No Content).
|
|
func (s *EnquiryService) AskQuestion(ctx context.Context, adURN, sellerID, text string) error {
|
|
body := AskQuestionBody{
|
|
AdURN: adURN,
|
|
BidValue: -1.0,
|
|
Body: text,
|
|
RecipientID: sellerID,
|
|
TradeInRequestAllowed: false,
|
|
}
|
|
return s.t.postJSON(ctx, "/app/enquiry/v1/question", nil, nil, body, nil)
|
|
}
|
|
|
|
// PlaceBid places a bid on a listing.
|
|
func (s *EnquiryService) PlaceBid(ctx context.Context, itemURN string, req *PlaceBidRequest) (*BidsResponse, error) {
|
|
path := fmt.Sprintf("/app/enquiry/v1/bids/item/%s", itemURN)
|
|
req.AdURN = itemURN
|
|
var resp BidsResponse
|
|
if err := s.t.postJSON(ctx, path, nil, nil, req, &resp); err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|
|
|
|
// RemoveBid deletes a bid by its ID.
|
|
func (s *EnquiryService) RemoveBid(ctx context.Context, bidID int) (*BidsResponse, error) {
|
|
path := fmt.Sprintf("/app/enquiry/v1/bids/bid/%d", bidID)
|
|
var resp BidsResponse
|
|
if err := s.t.delete(ctx, path, nil, &resp); err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|