Browse Source

Move `token` NewClient param to setter

pull/6/head
Matt Baer 7 years ago
parent
commit
0376852c2f
2 changed files with 7 additions and 4 deletions
  1. +2
    -2
      post_test.go
  2. +5
    -2
      writeas.go

+ 2
- 2
post_test.go View File

@@ -7,7 +7,7 @@ import (
)

func TestCreatePost(t *testing.T) {
wac := NewClient("")
wac := NewClient()
p, err := wac.CreatePost(&PostParams{
Title: "Title!",
Content: "This is a post.",
@@ -21,7 +21,7 @@ func TestCreatePost(t *testing.T) {
}

func TestGetPost(t *testing.T) {
wac := NewClient("")
wac := NewClient()

res, err := wac.GetPost("zekk5r9apum6p")
if err != nil {


+ 5
- 2
writeas.go View File

@@ -27,14 +27,17 @@ type Client struct {
// defaultHTTPTimeout is the default http.Client timeout.
const defaultHTTPTimeout = 10 * time.Second

func NewClient(token string) *Client {
func NewClient() *Client {
return &Client{
token: token,
client: &http.Client{Timeout: defaultHTTPTimeout},
baseURL: apiURL,
}
}

func (c *Client) SetToken(token string) {
c.token = token
}

func (c *Client) get(path string, r interface{}) (*impart.Envelope, error) {
method := "GET"
if method != "GET" && method != "HEAD" {


Loading…
Cancel
Save