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.
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package mrktplaats
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/url"
|
|
)
|
|
|
|
// RelevantService retrieves similar/related listings.
|
|
type RelevantService struct {
|
|
t *transport
|
|
}
|
|
|
|
// SimilarAdCore is the ad core from the older API3 format (snake_case).
|
|
type SimilarAdCore struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Picture DiscoveryPicture `json:"picture"`
|
|
Price DiscoveryPrice `json:"price"`
|
|
}
|
|
|
|
// SimilarItem is a related listing.
|
|
type SimilarItem struct {
|
|
AdCore SimilarAdCore `json:"ad_core"`
|
|
PageLocation string `json:"page_location"`
|
|
}
|
|
|
|
// SimilarAdsResponse contains similar listings.
|
|
type SimilarAdsResponse struct {
|
|
Items []SimilarItem `json:"items"`
|
|
ResultType string `json:"result_type"`
|
|
}
|
|
|
|
// Get returns similar/related listings for a given listing.
|
|
func (s *RelevantService) Get(ctx context.Context, listingID string, sellerID string, categoryID int) (*SimilarAdsResponse, error) {
|
|
path := fmt.Sprintf("/api3/ads/relevant/%s.json", listingID)
|
|
params := url.Values{}
|
|
if sellerID != "" {
|
|
params.Set("seller_id", sellerID)
|
|
}
|
|
params.Set("category_id", fmt.Sprintf("%d", categoryID))
|
|
var resp SimilarAdsResponse
|
|
if err := s.t.get(ctx, path, params, &resp); err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|