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,62 @@
|
||||
package mrktplaats
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// FavoritesService handles saved/favorite ads.
|
||||
type FavoritesService struct {
|
||||
t *transport
|
||||
}
|
||||
|
||||
// FavoriteItem is a saved ad.
|
||||
type FavoriteItem struct {
|
||||
ItemID string `json:"itemId"`
|
||||
CreationDate string `json:"creationDate"`
|
||||
}
|
||||
|
||||
// FavoritesResponse is the response from listing favorite ads.
|
||||
type FavoritesResponse struct {
|
||||
Items []FavoriteItem `json:"items"`
|
||||
MoreItemsAvailable bool `json:"moreItemsAvailable"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
type modifyFavoritesRequest struct {
|
||||
AdURNs []string `json:"adUrns"`
|
||||
}
|
||||
|
||||
type modifyFavoritesResponse struct {
|
||||
Items []FavoriteItem `json:"items"`
|
||||
}
|
||||
|
||||
// List returns the authenticated user's favorite ads.
|
||||
func (s *FavoritesService) List(ctx context.Context, limit int) (*FavoritesResponse, error) {
|
||||
params := url.Values{}
|
||||
if limit > 0 {
|
||||
params.Set("limit", fmt.Sprintf("%d", limit))
|
||||
}
|
||||
var resp FavoritesResponse
|
||||
if err := s.t.get(ctx, "/app/favorites/v1/favorite-ads", params, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// Add saves one or more ads to favorites by their URNs.
|
||||
func (s *FavoritesService) Add(ctx context.Context, urns ...string) ([]FavoriteItem, error) {
|
||||
body := modifyFavoritesRequest{AdURNs: urns}
|
||||
var resp modifyFavoritesResponse
|
||||
if err := s.t.postJSON(ctx, "/app/favorites/v2/favorite-ads", nil, nil, body, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Items, nil
|
||||
}
|
||||
|
||||
// Remove deletes one or more ads from favorites by their URNs.
|
||||
func (s *FavoritesService) Remove(ctx context.Context, urns ...string) error {
|
||||
body := modifyFavoritesRequest{AdURNs: urns}
|
||||
return s.t.postJSON(ctx, "/app/favorites/v2/favorite-ads/delete", nil, nil, body, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user