-
Notifications
You must be signed in to change notification settings - Fork 5
/
browse.go
690 lines (657 loc) · 25.1 KB
/
browse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
package ebay
import (
"context"
"fmt"
"net/http"
"net/url"
"strconv"
"time"
)
// BrowseService handles communication with the Browse API.
//
// eBay API docs: https://developer.ebay.com/api-docs/buy/browse/overview.html
type BrowseService service
// Valid values for the "buyingOptions" item field.
const (
BrowseBuyingOptionAuction = "AUCTION"
BrowseBuyingOptionFixedPrice = "FIXED_PRICE"
)
// OptBrowseContextualLocation adds the header containing contextualLocation.
// It is strongly recommended that you use it when submitting Browse API methods.
//
// eBay API docs: https://developer.ebay.com/api-docs/buy/static/api-browse.html#Headers
func OptBrowseContextualLocation(country, zip string) func(*http.Request) {
return func(req *http.Request) {
const headerEndUserCtx = "X-EBAY-C-ENDUSERCTX"
v := req.Header.Get(headerEndUserCtx)
if len(v) > 0 {
v += ","
}
v += "contextualLocation=" + url.QueryEscape(fmt.Sprintf("country=%s,zip=%s", country, zip))
req.Header.Set(headerEndUserCtx, v)
}
}
// LegacyItem represents the legacy representation of an eBay item.
type LegacyItem 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"`
StateOrProvince string `json:"stateOrProvince"`
PostalCode string `json:"postalCode"`
Country string `json:"country"`
} `json:"itemLocation"`
Image struct {
ImageURL string `json:"imageUrl"`
} `json:"image"`
AdditionalImages []struct {
ImageURL string `json:"imageUrl"`
} `json:"additionalImages"`
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"`
Gtin string `json:"gtin"`
EstimatedAvailabilities []struct {
DeliveryOptions []string `json:"deliveryOptions"`
EstimatedAvailabilityStatus string `json:"estimatedAvailabilityStatus"`
EstimatedAvailableQuantity int `json:"estimatedAvailableQuantity"`
EstimatedSoldQuantity int `json:"estimatedSoldQuantity"`
} `json:"estimatedAvailabilities"`
ShippingOptions []struct {
ShippingServiceCode string `json:"shippingServiceCode"`
TrademarkSymbol string `json:"trademarkSymbol"`
ShippingCarrierCode string `json:"shippingCarrierCode"`
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 {
PostalCode string `json:"postalCode"`
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"`
RestockingFeePercentage string `json:"restockingFeePercentage"`
} `json:"returnTerms"`
Taxes []struct {
TaxJurisdiction struct {
Region struct {
RegionName string `json:"regionName"`
RegionType string `json:"regionType"`
} `json:"region"`
TaxJurisdictionID string `json:"taxJurisdictionId"`
} `json:"taxJurisdiction"`
TaxType string `json:"taxType"`
TaxPercentage string `json:"taxPercentage"`
ShippingAndHandlingTaxed bool `json:"shippingAndHandlingTaxed"`
IncludedInPrice bool `json:"includedInPrice"`
} `json:"taxes"`
LocalizedAspects []struct {
Type string `json:"type"`
Name string `json:"name"`
Value string `json:"value"`
} `json:"localizedAspects"`
PrimaryProductReviewRating struct {
ReviewCount int `json:"reviewCount"`
AverageRating string `json:"averageRating"`
RatingHistograms []struct {
Rating string `json:"rating"`
Count int `json:"count"`
} `json:"ratingHistograms"`
} `json:"primaryProductReviewRating"`
TopRatedBuyingExperience bool `json:"topRatedBuyingExperience"`
BuyingOptions []string `json:"buyingOptions"`
ItemAffiliateWebURL string `json:"itemAffiliateWebUrl"`
ItemWebURL string `json:"itemWebUrl"`
Description string `json:"description"`
EnabledForGuestCheckout bool `json:"enabledForGuestCheckout"`
AdultOnly bool `json:"adultOnly"`
CategoryID string `json:"categoryId"`
}
// GetItemByLegacyID retrieves an item by legacy ID.
// The itemID will be available in the "itemId" field:
// https://developer.ebay.com/api-docs/buy/static/api-browse.html#Legacy
//
// eBay API docs: https://developer.ebay.com/api-docs/buy/browse/resources/item/methods/getItemByLegacyId
func (s *BrowseService) GetItemByLegacyID(ctx context.Context, itemLegacyID string, opts ...Opt) (CompactItem, error) {
u := fmt.Sprintf("buy/browse/v1/item/get_item_by_legacy_id?legacy_item_id=%s", itemLegacyID)
req, err := s.client.NewRequest(http.MethodGet, u, nil, opts...)
if err != nil {
return CompactItem{}, err
}
var it CompactItem
return it, s.client.Do(ctx, req, &it)
}
// CompactItem represents the "COMPACT" version of an eBay item.
type CompactItem struct {
ItemID string `json:"itemId"`
SellerItemRevision string `json:"sellerItemRevision"`
Price struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"price"`
EstimatedAvailabilities []struct {
AvailabilityThresholdType string `json:"availabilityThresholdType"`
AvailabilityThreshold int `json:"availabilityThreshold"`
EstimatedAvailabilityStatus string `json:"estimatedAvailabilityStatus"`
EstimatedSoldQuantity int `json:"estimatedSoldQuantity"`
} `json:"estimatedAvailabilities"`
TopRatedBuyingExperience bool `json:"topRatedBuyingExperience"`
}
// GetCompactItem retrieves the compact version of a specific item.
//
// eBay API docs: https://developer.ebay.com/api-docs/buy/browse/resources/item/methods/getItem
func (s *BrowseService) GetCompactItem(ctx context.Context, itemID string, opts ...Opt) (CompactItem, error) {
u := fmt.Sprintf("buy/browse/v1/item/%s?fieldgroups=COMPACT", itemID)
req, err := s.client.NewRequest(http.MethodGet, u, nil, opts...)
if err != nil {
return CompactItem{}, err
}
var it CompactItem
return it, s.client.Do(ctx, req, &it)
}
// Item represents an eBay item.
type Item struct {
ItemID string `json:"itemId"`
SellerItemRevision string `json:"sellerItemRevision"`
Title string `json:"title"`
Subtitle string `json:"subtitle"`
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"`
AdditionalImages []struct {
ImageURL string `json:"imageUrl"`
} `json:"additionalImages"`
MarketingPrice struct {
OriginalPrice struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"originalPrice"`
DiscountPercentage string `json:"discountPercentage"`
DiscountAmount struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"discountAmount"`
} `json:"marketingPrice"`
Color string `json:"color"`
Brand string `json:"brand"`
Seller struct {
Username string `json:"username"`
FeedbackPercentage string `json:"feedbackPercentage"`
FeedbackScore int `json:"feedbackScore"`
} `json:"seller"`
Gtin string `json:"gtin"`
Mpn string `json:"mpn"`
Epid string `json:"epid"`
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"`
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"`
ReturnInstructions string `json:"returnInstructions"`
RestockingFeePercentage string `json:"restockingFeePercentage"`
} `json:"returnTerms"`
Taxes []struct {
TaxJurisdiction struct {
Region struct {
RegionName string `json:"regionName"`
RegionType string `json:"regionType"`
} `json:"region"`
TaxJurisdictionID string `json:"taxJurisdictionId"`
} `json:"taxJurisdiction"`
TaxType string `json:"taxType"`
TaxPercentage string `json:"taxPercentage"`
ShippingAndHandlingTaxed bool `json:"shippingAndHandlingTaxed"`
IncludedInPrice bool `json:"includedInPrice"`
} `json:"taxes"`
LocalizedAspects []struct {
Type string `json:"type"`
Name string `json:"name"`
Value string `json:"value"`
} `json:"localizedAspects"`
QuantityLimitPerBuyer int `json:"quantityLimitPerBuyer"`
PrimaryProductReviewRating struct {
ReviewCount int `json:"reviewCount"`
AverageRating string `json:"averageRating"`
RatingHistograms []struct {
Rating string `json:"rating"`
Count int `json:"count"`
} `json:"ratingHistograms"`
} `json:"primaryProductReviewRating"`
TopRatedBuyingExperience bool `json:"topRatedBuyingExperience"`
BuyingOptions []string `json:"buyingOptions"`
ItemAffiliateWebURL string `json:"itemAffiliateWebUrl"`
ItemWebURL string `json:"itemWebUrl"`
Description string `json:"description"`
Product struct {
AspectGroups []struct {
LocalizedGroupName string `json:"localizedGroupName"`
Aspects []struct {
LocalizedName string `json:"localizedName"`
LocalizedValues []string `json:"localizedValues"`
} `json:"aspects"`
} `json:"aspectGroups"`
Title string `json:"title"`
Description string `json:"description"`
Image struct {
ImageURL string `json:"imageUrl"`
} `json:"image"`
Gtins []string `json:"gtins"`
Brand string `json:"brand"`
Mpns []string `json:"mpns"`
AdditionalProductIdentities []struct {
ProductIdentity []struct {
IdentifierType string `json:"identifierType"`
IdentifierValue string `json:"identifierValue"`
} `json:"productIdentity"`
} `json:"additionalProductIdentities"`
} `json:"product"`
EnabledForGuestCheckout bool `json:"enabledForGuestCheckout"`
AdultOnly bool `json:"adultOnly"`
CategoryID string `json:"categoryId"`
// Fields not present in the json sample provided by eBay:
ItemEndDate time.Time `json:"itemEndDate"`
MinimumPriceToBid struct {
Currency string `json:"currency"`
Value string `json:"value"`
} `json:"minimumPriceToBid"`
CurrentBidPrice struct {
Currency string `json:"currency"`
Value string `json:"value"`
} `json:"currentBidPrice"`
UniqueBidderCount int `json:"uniqueBidderCount"`
}
// GetItem retrieves the details of a specific item.
//
// eBay API docs: https://developer.ebay.com/api-docs/buy/browse/resources/item/methods/getItem
func (s *BrowseService) GetItem(ctx context.Context, itemID string, opts ...Opt) (Item, error) {
u := fmt.Sprintf("buy/browse/v1/item/%s?fieldgroups=PRODUCT", itemID)
req, err := s.client.NewRequest(http.MethodGet, u, nil, opts...)
if err != nil {
return Item{}, err
}
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)
}
// Search represents the result of an eBay search.
type Search struct {
Href string `json:"href"`
Total int `json:"total"`
Next string `json:"next"`
Limit int `json:"limit"`
Offset int `json:"offset"`
ItemSummaries []struct {
ItemID string `json:"itemId"`
Title string `json:"title"`
Image struct {
ImageURL string `json:"imageUrl"`
} `json:"image"`
Price struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"price"`
ItemHref string `json:"itemHref"`
Seller struct {
Username string `json:"username"`
FeedbackPercentage string `json:"feedbackPercentage"`
FeedbackScore int `json:"feedbackScore"`
} `json:"seller"`
MarketingPrice struct {
OriginalPrice struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"originalPrice"`
DiscountPercentage string `json:"discountPercentage"`
DiscountAmount struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"discountAmount"`
} `json:"marketingPrice"`
Condition string `json:"condition"`
ConditionID string `json:"conditionId"`
ThumbnailImages []struct {
ImageURL string `json:"imageUrl"`
} `json:"thumbnailImages"`
ShippingOptions []struct {
ShippingCostType string `json:"shippingCostType"`
ShippingCost struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"shippingCost"`
} `json:"shippingOptions"`
BuyingOptions []string `json:"buyingOptions"`
CurrentBidPrice struct {
Value string `json:"value"`
Currency string `json:"currency"`
} `json:"currentBidPrice"`
Epid string `json:"epid"`
ItemWebURL string `json:"itemWebUrl"`
ItemLocation struct {
PostalCode string `json:"postalCode"`
Country string `json:"country"`
} `json:"itemLocation"`
Categories []struct {
CategoryID string `json:"categoryId"`
} `json:"categories"`
AdditionalImages []struct {
ImageURL string `json:"imageUrl"`
} `json:"additionalImages"`
AdultOnly bool `json:"adultOnly"`
} `json:"itemSummaries"`
}
func optSearch(param string) func(v string) func(*http.Request) {
return func(v string) func(*http.Request) {
return func(req *http.Request) {
query := req.URL.Query()
query.Add(param, v)
req.URL.RawQuery = query.Encode()
}
}
}
// Several query parameters to use with the Search method.
func OptBrowseSearch(v string) func(*http.Request) {
return optSearch("q")(v)
}
func OptBrowseSearchGtin(v string) func(*http.Request) {
return optSearch("gtin")(v)
}
func OptBrowseSearchCharityIDs(v string) func(*http.Request) {
return optSearch("charity_ids")(v)
}
func OptBrowseSearchFieldgroups(v string) func(*http.Request) {
return optSearch("fieldgroups")(v)
}
func OptBrowseSearchCompatibilityFilter(v string) func(*http.Request) {
return optSearch("compatibility_filter")(v)
}
func OptBrowseSearchCategoryID(v string) func(*http.Request) {
return optSearch("category_ids")(v)
}
func OptBrowseSearchFilter(v string) func(*http.Request) {
return optSearch("filter")(v)
}
func OptBrowseSearchSort(v string) func(*http.Request) {
return optSearch("sort")(v)
}
func OptBrowseSearchLimit(limit int) func(*http.Request) {
return optSearch("limit")(strconv.Itoa(limit))
}
func OptBrowseSearchOffset(offset int) func(*http.Request) {
return optSearch("offset")(strconv.Itoa(offset))
}
func OptBrowseSearchAspectFilter(v string) func(*http.Request) {
return optSearch("aspect_filter")(v)
}
func OptBrowseSearchEPID(epid int) func(*http.Request) {
return optSearch("epid")(strconv.Itoa(epid))
}
// Search searches for eBay items.
//
// eBay API docs: https://developer.ebay.com/api-docs/buy/browse/resources/item_summary/methods/search
func (s *BrowseService) Search(ctx context.Context, opts ...Opt) (Search, error) {
u := "buy/browse/v1/item_summary/search"
req, err := s.client.NewRequest(http.MethodGet, u, nil, opts...)
if err != nil {
return Search{}, err
}
var search Search
return search, s.client.Do(ctx, req, &search)
}