From 0376852c2fc076feb502507ba2911a342b276ffd Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sun, 4 Sep 2016 20:17:33 -0400 Subject: [PATCH] Move `token` NewClient param to setter --- post_test.go | 4 ++-- writeas.go | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/post_test.go b/post_test.go index 80a890c..6c4ad14 100644 --- a/post_test.go +++ b/post_test.go @@ -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 { diff --git a/writeas.go b/writeas.go index e6f4f53..97bfbb8 100644 --- a/writeas.go +++ b/writeas.go @@ -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" {