From 7a047f6bd5e290c6a817ecf6827125202d8ec549 Mon Sep 17 00:00:00 2001 From: irlndts Date: Fri, 11 Mar 2016 17:47:23 +0300 Subject: [PATCH] net/http moved inside the lib --- artists_test.go | 7 ++----- discogs.go | 4 ++-- examples/discogs_example.go | 12 +++++------- labels_test.go | 7 ++----- masters_test.go | 7 ++----- releases_test.go | 4 +--- 6 files changed, 14 insertions(+), 27 deletions(-) diff --git a/artists_test.go b/artists_test.go index 7d31d66..85656ca 100644 --- a/artists_test.go +++ b/artists_test.go @@ -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) diff --git a/discogs.go b/discogs.go index b2a0aff..c458563 100644 --- a/discogs.go +++ b/discogs.go @@ -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, diff --git a/examples/discogs_example.go b/examples/discogs_example.go index dcb7529..f0f37f6 100644 --- a/examples/discogs_example.go +++ b/examples/discogs_example.go @@ -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) } diff --git a/labels_test.go b/labels_test.go index ff52695..cd40b78 100644 --- a/labels_test.go +++ b/labels_test.go @@ -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) diff --git a/masters_test.go b/masters_test.go index 8c22785..e2452ff 100644 --- a/masters_test.go +++ b/masters_test.go @@ -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) diff --git a/releases_test.go b/releases_test.go index f4c4d4c..12cbcbe 100644 --- a/releases_test.go +++ b/releases_test.go @@ -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)