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,64 @@
|
||||
package mrktplaats
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// CategoryService handles category browsing.
|
||||
type CategoryService struct {
|
||||
t *transport
|
||||
}
|
||||
|
||||
// Category represents a node in the category tree (snake_case API3 format).
|
||||
type Category struct {
|
||||
CategoryID int `json:"category_id"`
|
||||
Name string `json:"name"`
|
||||
Children []Category `json:"children"`
|
||||
PlaceAdAllowed bool `json:"place_ad_allowed"`
|
||||
NumberOfImages int `json:"number_of_images"`
|
||||
RunningSubscriptions []any `json:"running_subscriptions"`
|
||||
FeaturesDuration map[string]int `json:"features_duration"`
|
||||
SYIAttributes []any `json:"syi_attributes"`
|
||||
}
|
||||
|
||||
// CategoriesResponse is the full category tree.
|
||||
type CategoriesResponse struct {
|
||||
Categories []Category `json:"categories"`
|
||||
}
|
||||
|
||||
// CategoryBucket groups related subcategories.
|
||||
type CategoryBucket struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Categories []BucketCategory `json:"categories"`
|
||||
}
|
||||
|
||||
// BucketCategory is a leaf category within a bucket.
|
||||
type BucketCategory struct {
|
||||
ID int `json:"id"`
|
||||
Key string `json:"key"`
|
||||
ParentID int `json:"parentId"`
|
||||
ParentKey string `json:"parentKey"`
|
||||
Name string `json:"name"`
|
||||
ShortName string `json:"shortName"`
|
||||
}
|
||||
|
||||
// All returns the full category tree.
|
||||
func (s *CategoryService) All(ctx context.Context) (*CategoriesResponse, error) {
|
||||
var resp CategoriesResponse
|
||||
if err := s.t.get(ctx, "/api3/categories.json", nil, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// Buckets returns the subcategory buckets for a parent category.
|
||||
func (s *CategoryService) Buckets(ctx context.Context, categoryID int) ([]CategoryBucket, error) {
|
||||
path := fmt.Sprintf("/app/l1/v1/category-buckets/%d", categoryID)
|
||||
var resp []CategoryBucket
|
||||
if err := s.t.get(ctx, path, nil, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user