-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmarketplace.go
72 lines (61 loc) · 2.02 KB
/
marketplace.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
package discogs
import (
"net/url"
"strconv"
)
const (
priceSuggestionsURI = "/price_suggestions/"
releaseStatsURI = "/stats/"
)
type marketPlaceService struct {
url string
currency string
}
type MarketPlaceService interface {
// The best price suggestions according to grading
// Authentication is required.
PriceSuggestions(releaseID int) (*PriceListing, error)
// Short summary of marketplace listings
// Authentication is optional.
ReleaseStatistics(releaseID int) (*Stats, error)
}
func newMarketPlaceService(url string, currency string) MarketPlaceService {
return &marketPlaceService{
url: url,
currency: currency,
}
}
// Listing is a marketplace listing with the user's currency and a price value
type Listing struct {
Currency string `json:"currency"`
Value float64 `json:"value"`
}
// PriceListings are Listings per grading quality
type PriceListing struct {
VeryGood *Listing `json:"Very Good (VG),omitempty"`
GoodPlus *Listing `json:"Good Plus (G+),omitempty"`
NearMint *Listing `json:"Near Mint (NM or M-)"`
Good *Listing `json:"Good (G),omitempty"`
VeryGoodPlus *Listing `json:"Very Good Plus (VG+),omitempty"`
Mint *Listing `json:"Mint (M),omitempty"`
Fair *Listing `json:"Fair (F),omitempty"`
Poor *Listing `json:"Poor (P),omitempty"`
}
// Stats returns the marketplace stats summary for a release containing
type Stats struct {
LowestPrice *Listing `json:"lowest_price"`
ForSale int `json:"num_for_sale"`
Blocked bool `json:"blocked_from_sale"`
}
func (s *marketPlaceService) ReleaseStatistics(releaseID int) (*Stats, error) {
params := url.Values{}
params.Set("curr_abbr", s.currency)
var stats *Stats
err := request(s.url+releaseStatsURI+strconv.Itoa(releaseID), params, &stats)
return stats, err
}
func (s *marketPlaceService) PriceSuggestions(releaseID int) (*PriceListing, error) {
var listings *PriceListing
err := request(s.url+priceSuggestionsURI+strconv.Itoa(releaseID), nil, &listings)
return listings, err
}