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

View File

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

View File

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

View File

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

View File

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

View File

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