@@ -27,6 +27,8 @@ func (c *Client) LogIn(username, pass string) (*AuthUser, error) { | |||||
return nil, fmt.Errorf("Wrong data returned from API.") | return nil, fmt.Errorf("Wrong data returned from API.") | ||||
} | } | ||||
u.BaseURL = c.BaseUrl() | |||||
status := env.Code | status := env.Code | ||||
if status != http.StatusOK { | if status != http.StatusOK { | ||||
if status == http.StatusBadRequest { | if status == http.StatusBadRequest { | ||||
@@ -8,6 +8,7 @@ type ( | |||||
// AuthUser represents a just-authenticated user. It contains information | // AuthUser represents a just-authenticated user. It contains information | ||||
// that'll only be returned once (now) per user session. | // that'll only be returned once (now) per user session. | ||||
AuthUser struct { | AuthUser struct { | ||||
BaseURL string `json:"baseUrl,omitempty"` | |||||
AccessToken string `json:"access_token,omitempty"` | AccessToken string `json:"access_token,omitempty"` | ||||
Password string `json:"password,omitempty"` | Password string `json:"password,omitempty"` | ||||
User *User `json:"user"` | User *User `json:"user"` | ||||
@@ -3,13 +3,15 @@ package writeas | |||||
import ( | import ( | ||||
"bytes" | "bytes" | ||||
"code.as/core/socks" | |||||
"encoding/json" | "encoding/json" | ||||
"fmt" | "fmt" | ||||
"github.com/writeas/impart" | |||||
"io" | "io" | ||||
"log" | |||||
"net/http" | "net/http" | ||||
"time" | "time" | ||||
"code.as/core/socks" | |||||
"github.com/writeas/impart" | |||||
) | ) | ||||
const ( | const ( | ||||
@@ -107,6 +109,17 @@ func (c *Client) Token() string { | |||||
return c.token | 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) { | func (c *Client) get(path string, r interface{}) (*impart.Envelope, error) { | ||||
method := "GET" | method := "GET" | ||||
if method != "GET" && method != "HEAD" { | if method != "GET" && method != "HEAD" { | ||||