Skip to content

Commit

Permalink
Refine client def
Browse files Browse the repository at this point in the history
  • Loading branch information
hayashiki committed Oct 4, 2020
1 parent 24558c1 commit 496cfd7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
24 changes: 4 additions & 20 deletions docbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package docbase
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
Expand Down Expand Up @@ -50,7 +49,7 @@ type Client struct {
Attachments AttachmentService
}

// Response is http response wrapper for Dobase
// Response is http response wrapper for DocBase
type Response struct {
*http.Response
Rate
Expand All @@ -64,7 +63,7 @@ func newResponse(r *http.Response) *Response {
}

// NewClient returns client API
func NewClient(httpClient *http.Client, team, token string, opts ...Option) *Client {
func NewClient(httpClient *http.Client, team, token string) *Client {
if httpClient == nil {
httpClient = http.DefaultClient
}
Expand All @@ -79,14 +78,7 @@ func NewClient(httpClient *http.Client, team, token string, opts ...Option) *Cli
AccessToken: token,
Team: team,
Client: httpClient,
}

for _, opt := range opts {
opt(cli)
}

if cli.BaseURL == nil {
cli.BaseURL = baseURL
BaseURL: baseURL,
}

cli.Posts = &postService{cli}
Expand All @@ -100,14 +92,6 @@ func NewClient(httpClient *http.Client, team, token string, opts ...Option) *Cli
return cli
}

type Option func(client *Client)

func OptionDocBaseURL(url *url.URL) Option {
return func(client *Client) {
client.BaseURL = url
}
}

// NewRequest creates a API request with HTTP method, endpoint path and payload
func (c *Client) NewRequest(method, path string, body interface{}) (*http.Request, error) {

Expand Down Expand Up @@ -203,7 +187,7 @@ func CheckResponse(r *http.Response) error {
if err == nil && data != nil {
err = json.Unmarshal(data, errorResponse)
if err != nil {
errorResponse.err = errors.New("Not JSON")
errorResponse.err = fmt.Errorf("not json structure")
}
}
switch r.StatusCode {
Expand Down
3 changes: 2 additions & 1 deletion docbase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func setup() {
server = httptest.NewServer(mux)
url, _ := url.Parse(server.URL)

client = NewClient(nil, "dummyTeam", "dummyToken", OptionDocBaseURL(url))
client = NewClient(nil, "dummyTeam", "dummyToken")
client.BaseURL = url
}

func teardown() {
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package docbase

const (
version = "1.0.1"
version = "1.0.2"
revision = "HEAD"
)

0 comments on commit 496cfd7

Please sign in to comment.