Add CheckCompatibility and GetItemByGroupID

This commit is contained in:
JBP
2019-08-18 19:08:21 +02:00
parent 7484ba3df6
commit 345ff16666
7 changed files with 236 additions and 48 deletions

172
browse.go
View File

@@ -375,3 +375,175 @@ func (s *BrowseService) GetItem(ctx context.Context, itemID string, opts ...Opt)
var it Item
return it, s.client.Do(ctx, req, &it)
}
// ItemsByGroup represents eBay items by group.
type ItemsByGroup struct {
Items []struct {
ItemID string `json:"itemId"`
SellerItemRevision string `json:"sellerItemRevision"`
Title string `json:"title"`
ShortDescription string `json:"shortDescription"`
Price struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"price"`
CategoryPath string `json:"categoryPath"`
Condition string `json:"condition"`
ConditionID string `json:"conditionId"`
ItemLocation struct {
City string `json:"city"`
Country string `json:"country"`
} `json:"itemLocation"`
Image struct {
ImageURL string `json:"imageUrl"`
} `json:"image"`
Color string `json:"color"`
Material string `json:"material"`
Pattern string `json:"pattern"`
SizeType string `json:"sizeType"`
Brand string `json:"brand"`
ItemEndDate time.Time `json:"itemEndDate"`
Seller struct {
Username string `json:"username"`
FeedbackPercentage string `json:"feedbackPercentage"`
FeedbackScore int `json:"feedbackScore"`
} `json:"seller"`
EstimatedAvailabilities []struct {
DeliveryOptions []string `json:"deliveryOptions"`
AvailabilityThresholdType string `json:"availabilityThresholdType"`
AvailabilityThreshold int `json:"availabilityThreshold"`
EstimatedAvailabilityStatus string `json:"estimatedAvailabilityStatus"`
EstimatedSoldQuantity int `json:"estimatedSoldQuantity"`
} `json:"estimatedAvailabilities"`
ShippingOptions []struct {
ShippingServiceCode string `json:"shippingServiceCode"`
TrademarkSymbol string `json:"trademarkSymbol,omitempty"`
ShippingCarrierCode string `json:"shippingCarrierCode,omitempty"`
Type string `json:"type"`
ShippingCost struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"shippingCost"`
QuantityUsedForEstimate int `json:"quantityUsedForEstimate"`
MinEstimatedDeliveryDate time.Time `json:"minEstimatedDeliveryDate"`
MaxEstimatedDeliveryDate time.Time `json:"maxEstimatedDeliveryDate"`
ShipToLocationUsedForEstimate struct {
Country string `json:"country"`
} `json:"shipToLocationUsedForEstimate"`
AdditionalShippingCostPerUnit struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"additionalShippingCostPerUnit"`
ShippingCostType string `json:"shippingCostType"`
} `json:"shippingOptions"`
ShipToLocations struct {
RegionIncluded []struct {
RegionName string `json:"regionName"`
RegionType string `json:"regionType"`
} `json:"regionIncluded"`
RegionExcluded []struct {
RegionName string `json:"regionName"`
RegionType string `json:"regionType"`
} `json:"regionExcluded"`
} `json:"shipToLocations"`
ReturnTerms struct {
ReturnsAccepted bool `json:"returnsAccepted"`
RefundMethod string `json:"refundMethod"`
ReturnMethod string `json:"returnMethod"`
ReturnShippingCostPayer string `json:"returnShippingCostPayer"`
ReturnPeriod struct {
Value int `json:"value"`
Unit string `json:"unit"`
} `json:"returnPeriod"`
} `json:"returnTerms"`
LocalizedAspects []struct {
Type string `json:"type"`
Name string `json:"name"`
Value string `json:"value"`
} `json:"localizedAspects"`
TopRatedBuyingExperience bool `json:"topRatedBuyingExperience"`
BuyingOptions []string `json:"buyingOptions"`
PrimaryItemGroup struct {
ItemGroupID string `json:"itemGroupId"`
ItemGroupType string `json:"itemGroupType"`
ItemGroupHref string `json:"itemGroupHref"`
ItemGroupTitle string `json:"itemGroupTitle"`
ItemGroupImage struct {
ImageURL string `json:"imageUrl"`
} `json:"itemGroupImage"`
ItemGroupAdditionalImages []struct {
ImageURL string `json:"imageUrl"`
} `json:"itemGroupAdditionalImages"`
} `json:"primaryItemGroup"`
EnabledForGuestCheckout bool `json:"enabledForGuestCheckout"`
AdultOnly bool `json:"adultOnly"`
CategoryID string `json:"categoryId"`
} `json:"items"`
CommonDescriptions []struct {
Description string `json:"description"`
ItemIds []string `json:"itemIds"`
} `json:"commonDescriptions"`
}
// GetItemByGroupID retrieves the details of the individual items in an item group.
//
// eBay API docs: https://developer.ebay.com/api-docs/buy/browse/resources/item/methods/getItemsByItemGroup
func (s *BrowseService) GetItemByGroupID(ctx context.Context, groupID string, opts ...Opt) (ItemsByGroup, error) {
u := fmt.Sprintf("buy/browse/v1/item/get_items_by_item_group?item_group_id=%s", groupID)
req, err := s.client.NewRequest(http.MethodGet, u, nil, opts...)
if err != nil {
return ItemsByGroup{}, err
}
var it ItemsByGroup
return it, s.client.Do(ctx, req, &it)
}
// CompatibilityProperty represents a product property.
type CompatibilityProperty struct {
Name string `json:"name"`
Value string `json:"value"`
}
// Compatibility represents an item compatibility.
type Compatibility struct {
CompatibilityStatus string `json:"compatibilityStatus"`
Warnings []struct {
Category string `json:"category"`
Domain string `json:"domain"`
ErrorID int `json:"errorId"`
InputRefIds []string `json:"inputRefIds"`
LongMessage string `json:"longMessage"`
Message string `json:"message"`
OutputRefIds []string `json:"outputRefIds"`
Parameters []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"parameters"`
Subdomain string `json:"subdomain"`
} `json:"warnings"`
}
// Valid values for the "compatibilityStatus" compatibility field.
const (
BrowseCheckComoatibilityCompatible = "COMPATIBLE"
BrowseCheckComoatibilityNotCompatible = "NOT_COMPATIBLE"
BrowseCheckComoatibilityUndertermined = "UNDETERMINED"
)
// CheckCompatibility checks a product is compatible with the specified item.
//
// eBay API docs: https://developer.ebay.com/api-docs/buy/browse/resources/item/methods/checkCompatibility
func (s *BrowseService) CheckCompatibility(ctx context.Context, itemID, marketplaceID string, properties []CompatibilityProperty, opts ...Opt) (Compatibility, error) {
type payload struct {
CompatibilityProperties []CompatibilityProperty `json:"compatibilityProperties"`
}
pl := payload{properties}
u := fmt.Sprintf("buy/browse/v1/item/%s/check_compatibility", itemID)
opts = append(opts, OptBuyMarketplace(marketplaceID))
req, err := s.client.NewRequest(http.MethodPost, u, &pl, opts...)
if err != nil {
return Compatibility{}, err
}
var c Compatibility
return c, s.client.Do(ctx, req, &c)
}