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.
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package mrktplaats
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// DiscoveryService handles home feed discovery.
|
||||
type DiscoveryService struct {
|
||||
t *transport
|
||||
}
|
||||
|
||||
// Feed describes an available content feed.
|
||||
type Feed struct {
|
||||
FeedID string `json:"feed_id"`
|
||||
DisplayTitle string `json:"display_title"`
|
||||
LoginRequired bool `json:"login_required"`
|
||||
LocationRequired bool `json:"location_required"`
|
||||
PageLocation string `json:"page_location"`
|
||||
AnalyticsLabel string `json:"analytics_label"`
|
||||
TargetingConfigurations []TargetingConfiguration `json:"targeting_configurations"`
|
||||
}
|
||||
|
||||
// TargetingConfiguration defines ad targeting for a feed position.
|
||||
type TargetingConfiguration struct {
|
||||
Position string `json:"position"`
|
||||
AdUnitID string `json:"ad_unit_id"`
|
||||
AdditionalParameters map[string][]string `json:"additional_parameters"`
|
||||
}
|
||||
|
||||
// FeedsResponse is the response from listing available feeds.
|
||||
type FeedsResponse struct {
|
||||
Feeds []Feed `json:"feeds"`
|
||||
}
|
||||
|
||||
// DiscoveryListing is a listing within a discovery feed (uses snake_case API3 format).
|
||||
type DiscoveryListing struct {
|
||||
URN string `json:"urn"`
|
||||
Title string `json:"title"`
|
||||
CategoryID int `json:"category_id"`
|
||||
Price DiscoveryPrice `json:"price"`
|
||||
Picture DiscoveryPicture `json:"picture"`
|
||||
}
|
||||
|
||||
// FeedListingsResponse is the response from fetching a feed's listings.
|
||||
type FeedListingsResponse struct {
|
||||
Listings []DiscoveryListing `json:"listings"`
|
||||
}
|
||||
|
||||
// Feeds returns the list of available content feeds.
|
||||
func (s *DiscoveryService) Feeds(ctx context.Context, desiredCount int) (*FeedsResponse, error) {
|
||||
params := url.Values{}
|
||||
if desiredCount > 0 {
|
||||
params.Set("desiredFeedCount", fmt.Sprintf("%d", desiredCount))
|
||||
}
|
||||
var resp FeedsResponse
|
||||
if err := s.t.get(ctx, "/api3/discovery/feeds.json", params, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// FeedListingsOptions configures a feed listing request.
|
||||
type FeedListingsOptions struct {
|
||||
Offset int
|
||||
Size int
|
||||
PageLocation string
|
||||
Latitude float64
|
||||
Longitude float64
|
||||
}
|
||||
|
||||
// FeedListings returns the listings for a specific feed.
|
||||
func (s *DiscoveryService) FeedListings(ctx context.Context, feedID string, opts *FeedListingsOptions) (*FeedListingsResponse, error) {
|
||||
path := fmt.Sprintf("/api3/discovery/feed/%s.json", feedID)
|
||||
offset := 0
|
||||
params := url.Values{}
|
||||
if opts != nil {
|
||||
offset = opts.Offset
|
||||
if opts.Size > 0 {
|
||||
params.Set("size", fmt.Sprintf("%d", opts.Size))
|
||||
}
|
||||
if opts.PageLocation != "" {
|
||||
params.Set("page_location", opts.PageLocation)
|
||||
}
|
||||
if opts.Latitude != 0 {
|
||||
params.Set("requestLatitude", fmt.Sprintf("%f", opts.Latitude))
|
||||
}
|
||||
if opts.Longitude != 0 {
|
||||
params.Set("requestLongitude", fmt.Sprintf("%f", opts.Longitude))
|
||||
}
|
||||
}
|
||||
params.Set("offset", fmt.Sprintf("%d", offset))
|
||||
var resp FeedListingsResponse
|
||||
if err := s.t.get(ctx, path, params, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user