Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to change baseUrl #16

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions auth.go
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions user.go
Expand Up @@ -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"`
Expand Down
17 changes: 15 additions & 2 deletions writeas.go
Expand Up @@ -3,13 +3,14 @@ package writeas

import (
"bytes"
"code.as/core/socks"
"encoding/json"
"fmt"
"github.com/writeas/impart"
"io"
"net/http"
"time"

"code.as/core/socks"
"github.com/writeas/impart"
)

const (
Expand Down Expand Up @@ -107,6 +108,18 @@ func (c *Client) Token() string {
return c.token
}

// SetBaseUrl sets the baseUrl for all future Client requests
func (c *Client) SetBaseUrl(baseUrl string) {
if baseUrl != "" {
c.baseURL = baseUrl
}
}

// BaseUrl returns the set 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" {
Expand Down