Browse Source

Add option to change baseUrl

pull/16/head
Aaron Ogle 5 years ago
parent
commit
e490fb3a58
No known key found for this signature in database GPG Key ID: 87F6DE6202656163
3 changed files with 18 additions and 2 deletions
  1. +2
    -0
      auth.go
  2. +1
    -0
      user.go
  3. +15
    -2
      writeas.go

+ 2
- 0
auth.go View File

@@ -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 {


+ 1
- 0
user.go View File

@@ -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"`


+ 15
- 2
writeas.go View File

@@ -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" {


Loading…
Cancel
Save