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,54 @@
|
||||
package mrktplaats
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// UserService handles user profiles and reviews.
|
||||
type UserService struct {
|
||||
t *transport
|
||||
}
|
||||
|
||||
// UserInfoResponse wraps the user profile.
|
||||
type UserInfoResponse struct {
|
||||
User User `json:"user"`
|
||||
}
|
||||
|
||||
// Me returns the authenticated user's profile.
|
||||
func (s *UserService) Me(ctx context.Context) (*User, error) {
|
||||
var resp UserInfoResponse
|
||||
if err := s.t.get(ctx, "/app/my-account/profile/v2/user-info/user", nil, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp.User, nil
|
||||
}
|
||||
|
||||
// ReviewsResponse contains reviews and summary statistics.
|
||||
type ReviewsResponse struct {
|
||||
Summary ReviewSummary `json:"summary"`
|
||||
Reviews []Review `json:"reviews"`
|
||||
}
|
||||
|
||||
// ReviewRole determines which reviews to fetch.
|
||||
type ReviewRole string
|
||||
|
||||
const (
|
||||
ReviewRoleAll ReviewRole = ""
|
||||
ReviewRoleReviewee ReviewRole = "reviewee"
|
||||
)
|
||||
|
||||
// Reviews returns reviews for a user, optionally filtered by role.
|
||||
func (s *UserService) Reviews(ctx context.Context, userID int, role ReviewRole) (*ReviewsResponse, error) {
|
||||
path := fmt.Sprintf("/app/user-review/v1/reviews/%d", userID)
|
||||
params := url.Values{}
|
||||
if role != "" {
|
||||
params.Set("role", string(role))
|
||||
}
|
||||
var resp ReviewsResponse
|
||||
if err := s.t.get(ctx, path, params, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user