firest succesfull request
This commit is contained in:
parent
7885a06b95
commit
a38566e9d4
11
discogs.go
11
discogs.go
@ -1,7 +1,6 @@
|
||||
package discogs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/irlndts/go-apirequest"
|
||||
"net/http"
|
||||
)
|
||||
@ -13,18 +12,16 @@ const (
|
||||
|
||||
// Client is a Discogs client for making Discogs API requests.
|
||||
type Client struct {
|
||||
api *apirequest.API
|
||||
Releases *ReleaseService
|
||||
api *apirequest.API
|
||||
Release *ReleaseService
|
||||
}
|
||||
|
||||
// NewClient returns a new Client.
|
||||
func NewClient(httpClient *http.Client) *Client {
|
||||
base := apirequest.New().Client(httpClient).Base(discogsAPI).Add("User-Agent", useragent)
|
||||
|
||||
fmt.Println(base)
|
||||
|
||||
return &Client{
|
||||
api: base,
|
||||
Releases: newReleaseService(base.New()),
|
||||
api: base,
|
||||
Release: newReleaseService(base.New()),
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,18 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/irlndts/go-discogs/discogs"
|
||||
"github.com/irlndts/go-discogs"
|
||||
// "io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := &http.Client{}
|
||||
discogs := discogs.NewClient(client)
|
||||
fmt.Println(discogs)
|
||||
d := discogs.NewClient(client)
|
||||
params := &discogs.ReleaseParams{12345}
|
||||
release, resp, err := d.Release.Release(params)
|
||||
fmt.Println(release.Title)
|
||||
fmt.Println(resp)
|
||||
fmt.Println(err)
|
||||
|
||||
}
|
||||
|
18
releases.go
18
releases.go
@ -2,14 +2,32 @@ package discogs
|
||||
|
||||
import (
|
||||
"github.com/irlndts/go-apirequest"
|
||||
//"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ReleaseService struct {
|
||||
api *apirequest.API
|
||||
}
|
||||
|
||||
type ReleaseParams struct {
|
||||
Release_id int
|
||||
}
|
||||
|
||||
type Release struct {
|
||||
Title string `json:"title"`
|
||||
//id int
|
||||
//data_quality string
|
||||
}
|
||||
|
||||
func newReleaseService(api *apirequest.API) *ReleaseService {
|
||||
return &ReleaseService{
|
||||
api: api.Path("releases/"),
|
||||
}
|
||||
}
|
||||
|
||||
func (self *ReleaseService) Release(params *ReleaseParams) (*Release, *http.Response, error) {
|
||||
release := new(Release)
|
||||
resp, err := self.api.New().Get("248504").QueryStruct(params).Receive(release, nil)
|
||||
return release, resp, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user