Files
mrktplaats/mrktplaats.go
T
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

134 lines
3.7 KiB
Go

package mrktplaats
import "net/http"
// Client is the top-level API client for marktplaats.nl.
// Use NewClient to create one, then access sub-services via the exported fields.
type Client struct {
Auth *AuthService
Search *SearchService
Listings *ListingService
Discovery *DiscoveryService
Categories *CategoryService
Messaging *MessagingService
Favorites *FavoritesService
Users *UserService
MyAccount *MyAccountService
SYI *SYIService
Saleability *SaleabilityService
Enquiry *EnquiryService
Relevant *RelevantService
Notifications *NotificationService
Payments *PaymentService
Config *ConfigService
transport *transport
}
// NewClient creates a new marktplaats API client.
func NewClient(opts ...Option) *Client {
t := newTransport()
c := &Client{transport: t}
for _, opt := range opts {
opt(c)
}
c.Auth = &AuthService{t: t}
c.Search = &SearchService{t: t}
c.Listings = &ListingService{t: t}
c.Discovery = &DiscoveryService{t: t}
c.Categories = &CategoryService{t: t}
c.Messaging = &MessagingService{t: t}
c.Favorites = &FavoritesService{t: t}
c.Users = &UserService{t: t}
c.MyAccount = &MyAccountService{t: t}
c.SYI = &SYIService{t: t}
c.Saleability = &SaleabilityService{t: t}
c.Enquiry = &EnquiryService{t: t}
c.Relevant = &RelevantService{t: t}
c.Notifications = &NotificationService{t: t}
c.Payments = &PaymentService{t: t}
c.Config = &ConfigService{t: t}
return c
}
// SetAccessToken sets the bearer token for authenticated requests.
// This is called automatically after a successful Auth.VerifyCode.
func (c *Client) SetAccessToken(token string) {
c.transport.setAccessToken(token)
}
// SessionParams contains the per-session identifiers that the API expects to
// remain constant across related requests (e.g. login → 2FA verify-code).
type SessionParams struct {
Session string `json:"session"`
GAClientID string `json:"gaClientId"`
MagicNumber string `json:"magicNumber"`
ThreatMetrixSessionID string `json:"threatMetrixSessionId"`
}
// SessionParams returns the current session identifiers used by the client.
// Useful for persisting them between process invocations (e.g. CLI 2FA flow).
func (c *Client) SessionParams() SessionParams {
return SessionParams{
Session: c.transport.session,
GAClientID: c.transport.gaClientID,
MagicNumber: c.transport.magicNumber,
ThreatMetrixSessionID: c.transport.threatMetrixSessionID,
}
}
// Option configures a Client.
type Option func(*Client)
// WithHTTPClient sets a custom http.Client for all requests.
func WithHTTPClient(hc *http.Client) Option {
return func(c *Client) {
c.transport.httpClient = hc
}
}
// WithAccessToken sets an initial bearer token.
func WithAccessToken(token string) Option {
return func(c *Client) {
c.transport.setAccessToken(token)
}
}
// WithSession sets the session UUID sent with every request.
func WithSession(id string) Option {
return func(c *Client) {
c.transport.session = id
}
}
// WithGAClientID sets the Google Analytics client ID.
func WithGAClientID(id string) Option {
return func(c *Client) {
c.transport.gaClientID = id
}
}
// WithMagicNumber sets the magic_number query parameter.
func WithMagicNumber(n string) Option {
return func(c *Client) {
c.transport.magicNumber = n
}
}
// WithBaseURL overrides the default base URL (useful for testing).
func WithBaseURL(u string) Option {
return func(c *Client) {
c.transport.baseURL = u
}
}
// WithThreatMetrixSessionID sets the X-Threatmetrix-Session-Id header.
func WithThreatMetrixSessionID(id string) Option {
return func(c *Client) {
c.transport.setThreatMetrixSessionID(id)
}
}