91 lines
2.0 KiB
Go
91 lines
2.0 KiB
Go
|
package apiact
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/url"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// TCGPlayer -
|
||
|
type TCGPlayer struct {
|
||
|
URL string
|
||
|
APIVersion string
|
||
|
AccessToken string
|
||
|
UserName string
|
||
|
Expire time.Time
|
||
|
}
|
||
|
|
||
|
func (p *TCGPlayer) getAPIURL(urlPath string) (apiURL string, err error) {
|
||
|
u, err := url.Parse(p.URL)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
u, err = u.Parse(p.APIVersion)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
u, err = u.Parse(urlPath)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return u.String(), nil
|
||
|
}
|
||
|
|
||
|
func (p *TCGPlayer) getHeader() map[string]string {
|
||
|
m := make(map[string]string)
|
||
|
|
||
|
m["Content-Type"] = "application/json"
|
||
|
m["Authorization"] = fmt.Sprintf("Bearer %s", p.AccessToken)
|
||
|
|
||
|
return m
|
||
|
}
|
||
|
|
||
|
// NewTCGApi -
|
||
|
func NewTCGApi(apiVersion string) (api *TCGPlayer, err error) {
|
||
|
if len(apiVersion) == 0 {
|
||
|
apiVersion = "1.19.0"
|
||
|
}
|
||
|
api = &TCGPlayer{}
|
||
|
api.APIVersion = apiVersion
|
||
|
api.URL = "https://api.tcgplayer.com"
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// GetToken -
|
||
|
func (p *TCGPlayer) GetToken() (err error) {
|
||
|
apiURL, err := p.getAPIURL("/token")
|
||
|
_ = apiURL
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// TCGPlayerCategory -
|
||
|
type TCGPlayerCategory struct {
|
||
|
CaegoryID int `json:"categoryId"`
|
||
|
Name string `json:"name"`
|
||
|
DisplayName string `json:"displayName"`
|
||
|
ModifiedOn time.Time `json:"modifiedOn"`
|
||
|
SEOCategoryName string `json:"seoCategoryName"`
|
||
|
SealedLabel string `json:"sealedLabel"`
|
||
|
NonSealedLabel string `json:"nonSealedLabel"`
|
||
|
ConditionGuideURL string `json:"conditionGuideUrl"`
|
||
|
IsScannable bool `json:"isScannable"`
|
||
|
Popularity int `json:"popularity"`
|
||
|
}
|
||
|
|
||
|
// ListCategory -
|
||
|
func (p *TCGPlayer) ListCategory(limit, offset int) (category []*TCGPlayerCategory, err error) {
|
||
|
apiURL, err := p.getAPIURL("/catalog/categories")
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
_ = apiURL
|
||
|
tmpStruct := struct {
|
||
|
Success string `json:"success"`
|
||
|
Errors []string `json:"errors"`
|
||
|
Results []TCGPlayerCategory `json:"results"`
|
||
|
}{}
|
||
|
_ = tmpStruct
|
||
|
return
|
||
|
}
|