diff --git a/auth.go b/auth.go index e66f0bb..ffba97d 100644 --- a/auth.go +++ b/auth.go @@ -27,6 +27,8 @@ func (c *Client) LogIn(username, pass string) (*AuthUser, error) { return nil, fmt.Errorf("Wrong data returned from API.") } + u.BaseURL = c.BaseUrl() + status := env.Code if status != http.StatusOK { if status == http.StatusBadRequest { diff --git a/user.go b/user.go index e10f3c8..dc4e6b9 100644 --- a/user.go +++ b/user.go @@ -8,6 +8,7 @@ type ( // AuthUser represents a just-authenticated user. It contains information // that'll only be returned once (now) per user session. AuthUser struct { + BaseURL string `json:"baseUrl,omitempty"` AccessToken string `json:"access_token,omitempty"` Password string `json:"password,omitempty"` User *User `json:"user"` diff --git a/writeas.go b/writeas.go index f31cfbc..02cd25e 100644 --- a/writeas.go +++ b/writeas.go @@ -3,13 +3,15 @@ package writeas import ( "bytes" - "code.as/core/socks" "encoding/json" "fmt" - "github.com/writeas/impart" "io" + "log" "net/http" "time" + + "code.as/core/socks" + "github.com/writeas/impart" ) const ( @@ -107,6 +109,17 @@ func (c *Client) Token() string { return c.token } +// SetBaseUrl sets the baseUrl for all future Client requests +func (c *Client) SetBaseUrl(baseUrl string) { + c.baseURL = baseUrl + + log.Println("url set to", c.baseURL) +} + +func (c *Client) BaseUrl() string { + return c.baseURL +} + func (c *Client) get(path string, r interface{}) (*impart.Envelope, error) { method := "GET" if method != "GET" && method != "HEAD" {