net/http moved inside the lib

This commit is contained in:
irlndts 2016-03-11 17:47:23 +03:00
parent de1e81b89d
commit 7a047f6bd5
6 changed files with 14 additions and 27 deletions

View File

@ -2,15 +2,13 @@ package discogs
import (
"fmt"
"net/http"
"testing"
)
func TestArtistService_Artist(t *testing.T) {
expectedId := 1000
client := &http.Client{}
d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
d := NewClient().UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
artist, _, err := d.Artist.Artist(&ArtistParams{Artist_id: "1000"})
check(t, err)
@ -20,8 +18,7 @@ func TestArtistService_Artist(t *testing.T) {
func TestArtistService_Releases(t *testing.T) {
expectedArtist := "Dave Clarke"
client := &http.Client{}
d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
d := NewClient().UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
releases, _, err := d.Artist.Releases(&ArtistParams{Artist_id: "1000", Sort: "year", Sort_order: "desc"})
check(t, err)

View File

@ -20,8 +20,8 @@ type Client struct {
}
// NewClient returns a new Client.
func NewClient(httpClient *http.Client) *Client {
base := apirequest.New().Client(httpClient).Base(discogsAPI).Add("User-Agent", useragent)
func NewClient() *Client {
base := apirequest.New().Client(&http.Client{}).Base(discogsAPI).Add("User-Agent", useragent)
return &Client{
api: base,

View File

@ -3,25 +3,23 @@ package main
import (
"fmt"
"github.com/irlndts/go-discogs"
"net/http"
)
func main() {
client := &http.Client{}
d := discogs.NewClient(client).UserAgent("TestDiscogsClient/0.0.1 +http://irlndts.moscow")
d := discogs.NewClient().UserAgent("TestDiscogsClient/0.0.1 +http://irlndts.moscow")
/*
params := &discogs.ReleaseParams{Release_id: "8138518"}
release, _, err := d.Release.Release(params)
*/
params := &discogs.LabelParams{Label_id: "1000"}
params := &discogs.LabelParams{Label_id: "890477", Page: 2, Per_page: 3}
label, _, err := d.Label.Releases(params)
if err != nil {
fmt.Println(err)
} else {
//fmt.Println(release.Title)
fmt.Println(label.Releases[0].Title)
for _, release := range label.Releases {
fmt.Println(release.Title)
}
}
//fmt.Println(resp)
}

View File

@ -2,15 +2,13 @@ package discogs
import (
"fmt"
"net/http"
"testing"
)
func TestLabelService_Label(t *testing.T) {
expectedId := 1000
client := &http.Client{}
d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
d := NewClient().UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
label, _, err := d.Label.Label(&LabelParams{Label_id: "1000"})
check(t, err)
@ -20,8 +18,7 @@ func TestLabelService_Label(t *testing.T) {
func TestLabelService_Releases(t *testing.T) {
expectedId := "Good Time"
client := &http.Client{}
d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
d := NewClient().UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
label, _, err := d.Label.Releases(&LabelParams{Label_id: "1000"})
check(t, err)

View File

@ -2,15 +2,13 @@ package discogs
import (
"fmt"
"net/http"
"testing"
)
func TestMasterService_Master(t *testing.T) {
expectedTitle := "Elephant Riddim"
client := &http.Client{}
d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
d := NewClient().UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
master, _, err := d.Master.Master(&MasterParams{Master_id: "960657"})
check(t, err)
@ -20,8 +18,7 @@ func TestMasterService_Master(t *testing.T) {
func TestMasterService_Versions(t *testing.T) {
expectedTitle := "Stardiver"
client := &http.Client{}
d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
d := NewClient().UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
versions, _, err := d.Master.Versions(&MasterVersionParams{Master_id: "1000", Page: 1, Per_page: 1})
check(t, err)

View File

@ -2,15 +2,13 @@ package discogs
import (
"fmt"
"net/http"
"testing"
)
func TestReleaseService_Release(t *testing.T) {
expectedTitle := "Elephant Riddim"
client := &http.Client{}
d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
d := NewClient().UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
release, _, err := d.Release.Release(&ReleaseParams{Release_id: "8138518"})
check(t, err)