diff --git a/artists_test.go b/artists_test.go index a31d616..45000b0 100644 --- a/artists_test.go +++ b/artists_test.go @@ -8,17 +8,17 @@ import ( func TestArtistService_Artist(t *testing.T) { expectedId := 1000 - d := NewClient(testUserAgent, testToken) + d, _ := NewClient(&Options{}) artist, _, err := d.Artist.Artist(&ArtistParams{Artist_id: "1000"}) check(t, err) - assert(t, artist.Id == expectedId, fmt.Sprintf("Release.Title looked for %s, and received %s ", expectedId, artist.Id)) + assert(t, artist.Id == expectedId, fmt.Sprintf("Release.Title looked for %d, and received %d ", expectedId, artist.Id)) } func TestArtistService_Releases(t *testing.T) { expectedArtist := "Dave Clarke" - d := NewClient(testUserAgent, testToken) + d, _ := NewClient(&Options{}) 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 d540082..4c3e5bb 100644 --- a/discogs.go +++ b/discogs.go @@ -12,6 +12,7 @@ const ( ) type Options struct { + URL string Currency string UserAgent string Token string @@ -47,7 +48,7 @@ func NewClient(o *Options) (*Client, error) { } return &Client{ - Release: newReleaseService(header, cur), + Release: newReleaseService(o.URL+"/releases/", header, cur), Artist: newArtistService(base.New()), Label: newLabelService(base.New()), Master: newMasterService(base.New()), @@ -62,8 +63,9 @@ func currency(c string) (string, error) { switch c { case "USD", "GBP", "EUR", "CAD", "AUD", "JPY", "CHF", "MXN", "BRL", "NZD", "SEK", "ZAR": return c, nil + case "": + return "USD", nil default: return "", fmt.Errorf("%v\n", "Invalid currency abbreviation.") } - return "USD", nil } diff --git a/labels_test.go b/labels_test.go index a50413c..8084584 100644 --- a/labels_test.go +++ b/labels_test.go @@ -8,17 +8,17 @@ import ( func TestLabelService_Label(t *testing.T) { expectedId := 1000 - d := NewClient(testUserAgent, testToken) + d, _ := NewClient(&Options{}) label, _, err := d.Label.Label(&LabelParams{Label_id: "1000"}) check(t, err) - assert(t, label.Id == expectedId, fmt.Sprintf("Release.Title looked for %s, and received %s ", expectedId, label.Id)) + assert(t, label.Id == expectedId, fmt.Sprintf("Release.Title looked for %d, and received %d ", expectedId, label.Id)) } func TestLabelService_Releases(t *testing.T) { expectedId := "Ghetto Sol" - d := NewClient(testUserAgent, testToken) + d, _ := NewClient(&Options{}) label, _, err := d.Label.Releases(&LabelParams{Label_id: "1000"}) check(t, err) diff --git a/masters_test.go b/masters_test.go index 5a5a792..37a1c68 100644 --- a/masters_test.go +++ b/masters_test.go @@ -8,7 +8,7 @@ import ( func TestMasterService_Master(t *testing.T) { expectedTitle := "Elephant Riddim" - d := NewClient(testUserAgent, testToken) + d, _ := NewClient(nil) master, _, err := d.Master.Master(&MasterParams{Master_id: "960657"}) check(t, err) @@ -18,7 +18,7 @@ func TestMasterService_Master(t *testing.T) { func TestMasterService_Versions(t *testing.T) { expectedTitle := "Stardiver" - d := NewClient(testUserAgent, testToken) + d, _ := NewClient(nil) versions, _, err := d.Master.Versions(&MasterVersionParams{Master_id: "1000", Page: 1, Per_page: 1}) check(t, err) diff --git a/releases.go b/releases.go index 01789d9..9949701 100644 --- a/releases.go +++ b/releases.go @@ -51,12 +51,14 @@ type ReqRelease struct { // ReleaseService ... type ReleaseService struct { + url string header *http.Header currency string } -func newReleaseService(header *http.Header, currency string) *ReleaseService { +func newReleaseService(url string, header *http.Header, currency string) *ReleaseService { return &ReleaseService{ + url: url, header: header, currency: currency, } @@ -76,7 +78,7 @@ func (s *ReleaseService) Release(releaseID int) (*Release, error) { } func (s *ReleaseService) request(path string, params url.Values, resp interface{}) error { - r, err := http.NewRequest("GET", discogsAPI+"releases/"+path+"?"+params.Encode(), nil) + r, err := http.NewRequest("GET", s.url+path+"?"+params.Encode(), nil) if err != nil { return err } diff --git a/releases_test.go b/releases_test.go index ae6ae65..c9313b6 100644 --- a/releases_test.go +++ b/releases_test.go @@ -2,13 +2,27 @@ package discogs import ( "fmt" + "io" + "net/http" + "net/http/httptest" "testing" ) -func TestReleaseService_Release(t *testing.T) { +func ReleaseServer(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + io.WriteString(w, `{"title":"Elephant Riddim"}`) +} + +func TestReleaseServiceRelease(t *testing.T) { expectedTitle := "Elephant Riddim" - d := NewClient(testUserAgent, testToken) + ts := httptest.NewServer(http.HandlerFunc(ReleaseServer)) + defer ts.Close() + + d, err := NewClient(&Options{URL: ts.URL}) + if err != nil { + t.Fatalf("failed to create client: %s", err) + } release, err := d.Release.Release(8138518) check(t, err)