firest succesfull request

This commit is contained in:
irlndts 2016-03-04 19:48:26 +03:00
parent 7885a06b95
commit a38566e9d4
3 changed files with 30 additions and 10 deletions

View File

@ -1,7 +1,6 @@
package discogs package discogs
import ( import (
"fmt"
"github.com/irlndts/go-apirequest" "github.com/irlndts/go-apirequest"
"net/http" "net/http"
) )
@ -14,17 +13,15 @@ const (
// Client is a Discogs client for making Discogs API requests. // Client is a Discogs client for making Discogs API requests.
type Client struct { type Client struct {
api *apirequest.API api *apirequest.API
Releases *ReleaseService Release *ReleaseService
} }
// NewClient returns a new Client. // NewClient returns a new Client.
func NewClient(httpClient *http.Client) *Client { func NewClient(httpClient *http.Client) *Client {
base := apirequest.New().Client(httpClient).Base(discogsAPI).Add("User-Agent", useragent) base := apirequest.New().Client(httpClient).Base(discogsAPI).Add("User-Agent", useragent)
fmt.Println(base)
return &Client{ return &Client{
api: base, api: base,
Releases: newReleaseService(base.New()), Release: newReleaseService(base.New()),
} }
} }

View File

@ -2,13 +2,18 @@ package main
import ( import (
"fmt" "fmt"
"github.com/irlndts/go-discogs/discogs" "github.com/irlndts/go-discogs"
// "io/ioutil"
"net/http" "net/http"
) )
func main() { func main() {
client := &http.Client{} client := &http.Client{}
discogs := discogs.NewClient(client) d := discogs.NewClient(client)
fmt.Println(discogs) params := &discogs.ReleaseParams{12345}
release, resp, err := d.Release.Release(params)
fmt.Println(release.Title)
fmt.Println(resp)
fmt.Println(err)
} }

View File

@ -2,14 +2,32 @@ package discogs
import ( import (
"github.com/irlndts/go-apirequest" "github.com/irlndts/go-apirequest"
//"io/ioutil"
"net/http"
) )
type ReleaseService struct { type ReleaseService struct {
api *apirequest.API 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 { func newReleaseService(api *apirequest.API) *ReleaseService {
return &ReleaseService{ return &ReleaseService{
api: api.Path("releases/"), 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
}