add price func struct

This commit is contained in:
Jay 2019-01-15 17:58:46 +08:00
parent 97af1343d4
commit 56bbdd1393
1 changed files with 38 additions and 19 deletions

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"strconv"
@ -61,7 +62,7 @@ func (p *TCGPlayer) getHeader() map[string]string {
// NewTCGApi -
func NewTCGApi(apiVersion string) (api *TCGPlayer, err error) {
if len(apiVersion) == 0 {
apiVersion = "1.19.0"
apiVersion = "v1.19.0"
}
api = &TCGPlayer{}
api.APIVersion = apiVersion
@ -122,16 +123,16 @@ func (p *TCGPlayer) GetToken() (err error) {
// 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"`
CaegoryID int `json:"categoryId"`
Name string `json:"name"`
DisplayName string `json:"displayName"`
ModifiedOn string `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 -
@ -197,18 +198,18 @@ func (p *TCGPlayer) ListCategory(limit, offset int) (category []*TCGPlayerCatego
// TCGPlayerCategoryGroup -
type TCGPlayerCategoryGroup struct {
GroupID int `json:"groupId"`
Name string `json:"name"`
Abbreviation string `json:"abbreviation"`
Supplemental bool `json:"supplemental"`
PublishedOn string `json:"publishedOn"`
ModifiedOn time.Time `json:"modifiedOn"`
Category TCGPlayerCategory `json:"category"`
GroupID int `json:"groupId"`
Name string `json:"name"`
Abbreviation string `json:"abbreviation"`
Supplemental bool `json:"supplemental"`
PublishedOn string `json:"publishedOn"`
ModifiedOn string `json:"modifiedOn"`
CategoryID int `json:"categoryId"`
}
// ListCategoryGroups -
func (p *TCGPlayer) ListCategoryGroups(categoryID, limit, offset int) (groups []*TCGPlayerCategoryGroup, err error) {
apiURL, err := p.getAPIURL(fmt.Sprintf("/catalog/categories/%d", categoryID), true)
apiURL, err := p.getAPIURL(fmt.Sprintf("/catalog/categories/%d/groups", categoryID), true)
if err != nil {
return nil, err
}
@ -254,6 +255,8 @@ func (p *TCGPlayer) ListCategoryGroups(categoryID, limit, offset int) (groups []
return nil, err
}
log.Println(string(respByte))
err = json.Unmarshal(respByte, &tmpStruct)
if err != nil {
return nil, err
@ -268,3 +271,19 @@ func (p *TCGPlayer) ListCategoryGroups(categoryID, limit, offset int) (groups []
return tmpStruct.Results, nil
}
// TCGPlayerProductPrice -
type TCGPlayerProductPrice struct {
ProductID int `json:"productId"`
LowPrice float32 `json:"lowPrice"`
MidPrice float32 `json:"midPrice"`
HighPrice float32 `json:"highPrice"`
MarketPrice float32 `json:"marketPrice"`
DirectLowPrice float32 `json:"directLowPrice"`
SubTypeName string `json:"subTypeName"`
}
// ListGroupProductPrice -
func (p *TCGPlayer) ListGroupProductPrice(groupID int) (prices []*TCGPlayerProductPrice, err error) {
return
}