Files
Joren 25410749db Initial Marktplaats SDK scaffold
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.
2026-04-15 23:45:49 +02:00

103 lines
2.9 KiB
Go

package mrktplaats
import (
"context"
"fmt"
"net/url"
)
// MyAccountService handles the seller dashboard and profile updates.
type MyAccountService struct {
t *transport
}
// MyAd is a listing owned by the authenticated user.
type MyAd struct {
ItemID string `json:"itemId"`
Title string `json:"title"`
Status string `json:"status"`
PriceInCents int `json:"priceInCents"`
}
// MyAdTab describes a tab in the seller's ad dashboard.
type MyAdTab struct {
Title string `json:"title"`
Count int `json:"count"`
Status string `json:"status"`
}
// MyAdsResponse is the response from listing the seller's own ads.
type MyAdsResponse struct {
MyAds []MyAd `json:"myAds"`
MyAdsTotalCount int `json:"myAdsTotalCount"`
Tabs []MyAdTab `json:"tabs"`
}
// MyAdsOptions configures a my-ads list request.
type MyAdsOptions struct {
Status string // "active", "inactive", "sold"
Offset int
Limit int
Counts bool
}
// MyAds returns the authenticated user's own listings.
func (s *MyAccountService) MyAds(ctx context.Context, opts *MyAdsOptions) (*MyAdsResponse, error) {
params := url.Values{}
if opts != nil {
if opts.Status != "" {
params.Set("status", opts.Status)
}
if opts.Offset > 0 {
params.Set("offset", fmt.Sprintf("%d", opts.Offset))
}
if opts.Limit > 0 {
params.Set("limit", fmt.Sprintf("%d", opts.Limit))
}
if opts.Counts {
params.Set("counts", "true")
}
}
var resp MyAdsResponse
if err := s.t.get(ctx, "/app/my-account/v3/myads", params, &resp); err != nil {
return nil, err
}
return &resp, nil
}
// UpdateProfileRequest defines fields to update on the user profile.
type UpdateProfileRequest struct {
Name string `json:"name"`
PhoneNumber string `json:"phoneNumber"`
Postcode string `json:"postcode"`
NdfcDeclarationStatus string `json:"ndfcDeclarationStatus"`
}
// UpdateProfile updates the authenticated user's profile.
func (s *MyAccountService) UpdateProfile(ctx context.Context, req *UpdateProfileRequest) error {
return s.t.postJSON(ctx, "/app/my-account/profile/v2/user-info/user", nil, nil, req, nil)
}
// DeleteAdReason indicates why the authenticated user is removing a listing.
type DeleteAdReason int
const (
DeleteReasonSoldOnTweedehands DeleteAdReason = 1
DeleteReasonSoldElsewhere DeleteAdReason = 2
DeleteReasonNotSelling DeleteAdReason = 3
DeleteReasonOther DeleteAdReason = 4
)
// DeleteAds removes one or more of the authenticated user's listings.
// reason 4 (DeleteReasonOther) is the generic deletion reason.
func (s *MyAccountService) DeleteAds(ctx context.Context, itemIDs []string, reason DeleteAdReason) error {
body := struct {
ItemIDs []string `json:"itemIds"`
Reason int `json:"reason"`
}{
ItemIDs: itemIDs,
Reason: int(reason),
}
return s.t.deleteJSON(ctx, "/app/my-account/v3/myads", nil, body, nil)
}