diff --git a/modules/apiact/apiact.go b/modules/apiact/apiact.go index 428f333..5b5dde5 100644 --- a/modules/apiact/apiact.go +++ b/modules/apiact/apiact.go @@ -15,5 +15,14 @@ type RequestObject struct { // GetRequest - func GetRequest(r RequestObject) (req *http.Request, err error) { + req, err = http.NewRequest(r.Method, r.URL, r.Body) + if err != nil { + return + } + if len(r.Headers) > 0 { + for k, v := range r.Headers { + req.Header.Set(k, v) + } + } return } diff --git a/modules/apiact/tcgplayer.go b/modules/apiact/tcgplayer.go new file mode 100644 index 0000000..6b130f9 --- /dev/null +++ b/modules/apiact/tcgplayer.go @@ -0,0 +1,90 @@ +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 +} diff --git a/modules/config/config.go b/modules/config/config.go index 9fcfea3..cf4724f 100644 --- a/modules/config/config.go +++ b/modules/config/config.go @@ -29,6 +29,10 @@ type Config struct { Port int `yaml:"port"` Prefix string `yaml:"prefix"` } + TCGPlayer struct { + PublicKey string `yaml:"public_key"` + PrivateKey string `yaml:"private_key"` + } } var conf *Config