diff --git a/auth_test.go b/auth_test.go index a9ece6f..6706db5 100644 --- a/auth_test.go +++ b/auth_test.go @@ -3,7 +3,7 @@ package writeas import "testing" func TestAuthentication(t *testing.T) { - dwac := NewDevClient() + dwac := NewClient(devAPIURL) // Log in _, err := dwac.LogIn("demo", "demo") diff --git a/collection_test.go b/collection_test.go index d6bb49b..f3356b6 100644 --- a/collection_test.go +++ b/collection_test.go @@ -8,7 +8,7 @@ import ( ) func TestGetCollection(t *testing.T) { - dwac := NewDevClient() + dwac := NewClient(devAPIURL) res, err := dwac.GetCollection("tester") if err != nil { @@ -20,7 +20,7 @@ func TestGetCollection(t *testing.T) { } func TestGetCollectionPosts(t *testing.T) { - dwac := NewDevClient() + dwac := NewClient(devAPIURL) posts := []Post{} t.Run("Get all posts in collection", func(t *testing.T) { @@ -50,7 +50,7 @@ func TestGetCollectionPosts(t *testing.T) { } func TestGetUserCollections(t *testing.T) { - wac := NewDevClient() + wac := NewClient(devAPIURL) _, err := wac.LogIn("demo", "demo") if err != nil { t.Fatalf("Unable to log in: %v", err) @@ -69,7 +69,7 @@ func TestGetUserCollections(t *testing.T) { } func TestCreateAndDeleteCollection(t *testing.T) { - wac := NewDevClient() + wac := NewClient(devAPIURL) _, err := wac.LogIn("demo", "demo") if err != nil { t.Fatalf("Unable to log in: %v", err) @@ -92,7 +92,7 @@ func TestCreateAndDeleteCollection(t *testing.T) { } func TestDeleteCollectionUnauthenticated(t *testing.T) { - wac := NewDevClient() + wac := NewClient(devAPIURL) now := time.Now().Unix() alias := fmt.Sprintf("test-collection-does-not-exist-%v", now) diff --git a/post_test.go b/post_test.go index 9d2fb47..304dd45 100644 --- a/post_test.go +++ b/post_test.go @@ -7,7 +7,7 @@ import ( func TestPostRoundTrip(t *testing.T) { var id, token string - dwac := NewClient() + dwac := NewClient(devAPIURL) t.Run("Create post", func(t *testing.T) { p, err := dwac.CreatePost(&PostParams{ Title: "Title!", @@ -53,7 +53,7 @@ func TestPostRoundTrip(t *testing.T) { } func TestPinUnPin(t *testing.T) { - dwac := NewDevClient() + dwac := NewClient(devAPIURL) _, err := dwac.LogIn("demo", "demo") if err != nil { t.Fatalf("Unable to log in: %v", err) @@ -75,7 +75,7 @@ func TestPinUnPin(t *testing.T) { } func ExampleClient_CreatePost() { - dwac := NewDevClient() + dwac := NewClient(devAPIURL) // Publish a post p, err := dwac.CreatePost(&PostParams{ diff --git a/writeas.go b/writeas.go index fa87ae1..3c15de9 100644 --- a/writeas.go +++ b/writeas.go @@ -44,22 +44,21 @@ const defaultHTTPTimeout = 10 * time.Second // // c := writeas.NewClient() // c.SetToken("00000000-0000-0000-0000-000000000000") -func NewClient() *Client { - return NewClientWith(Config{URL: apiURL}) +func NewClient(baseURL string) *Client { + if baseURL == "" { + baseURL = apiURL + } + return NewClientWith(Config{URL: baseURL}) } // NewTorClient creates a new API client for communicating with the Write.as // Tor hidden service, using the given port to connect to the local SOCKS // proxy. -func NewTorClient(port int) *Client { - return NewClientWith(Config{URL: torAPIURL, TorPort: port}) -} - -// NewDevClient creates a new API client for development and testing. It'll -// communicate with our development servers, and SHOULD NOT be used in -// production. -func NewDevClient() *Client { - return NewClientWith(Config{URL: devAPIURL}) +func NewTorClient(baseURL string, port int) *Client { + if baseURL == "" { + baseURL = torAPIURL + } + return NewClientWith(Config{URL: baseURL, TorPort: port}) } // Config configures a Write.as client.