Przeglądaj źródła

change NewClient to take baseURL

this changes both NewClient and NewTorClient to take a required
parameter for baseURL. removing hard coded api URLS. both still default
to write.as api URLs.

NewDevClient was removed as the base URL can now be provided

one test was still using the production server for tests, changed to dev
pull/17/head
Rob Loranger 4 lat temu
rodzic
commit
d622687fa8
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: D6F1633A4F0903B8
4 zmienionych plików z 19 dodań i 20 usunięć
  1. +1
    -1
      auth_test.go
  2. +5
    -5
      collection_test.go
  3. +3
    -3
      post_test.go
  4. +10
    -11
      writeas.go

+ 1
- 1
auth_test.go Wyświetl plik

@@ -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")


+ 5
- 5
collection_test.go Wyświetl plik

@@ -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)


+ 3
- 3
post_test.go Wyświetl plik

@@ -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{


+ 10
- 11
writeas.go Wyświetl plik

@@ -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.


Ładowanie…
Anuluj
Zapisz