Skip to content

Commit

Permalink
Bugfix query params
Browse files Browse the repository at this point in the history
  • Loading branch information
hayashiki committed Aug 24, 2020
1 parent 67d14f1 commit f8c5b69
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 21 deletions.
10 changes: 5 additions & 5 deletions comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func TestCommentService_Create(t *testing.T) {
ti, err := time.Parse(time.RFC3339, "2020-03-27T09:25:09+09:00")

want := &Comment{
ID: 1,
Body: "コメント",
ID: 1,
Body: "コメント",
CreatedAt: ti,
SimpleUser: SimpleUser{
ID: 1,
Name: "danny",
ID: 1,
Name: "danny",
ProfileImageURL: "https://image.docbase.io/uploads/aaa.gif",
},
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestCommentService_Delete(t *testing.T) {
defer teardown()

comment := &Comment{
ID: 1,
ID: 1,
}

mux.HandleFunc(fmt.Sprintf("/comments/%d", comment.ID), func(w http.ResponseWriter, r *http.Request) {
Expand Down
21 changes: 10 additions & 11 deletions docbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Client struct {
Client *http.Client

rateMu sync.Mutex
rateLimit Rate
rateLimit Rate

Posts PostService
Users UserService
Expand Down Expand Up @@ -210,7 +210,7 @@ func CheckResponse(r *http.Response) error {
return &RateLimitError{
Rate: parseRate(r),
Response: errorResponse.Response,
Messages: errorResponse.Messages,
Messages: errorResponse.Messages,
}
default:
return errorResponse
Expand Down Expand Up @@ -247,7 +247,6 @@ func parseRate(r *http.Response) Rate {
return rate
}


// checkRateLimitBeforeDo referenced from https://github.com/google/go-github/blob/master/github/github.go#L627
func (c *Client) checkRateLimitBeforeDo(req *http.Request) *RateLimitError {
c.rateMu.Lock()
Expand All @@ -265,7 +264,7 @@ func (c *Client) checkRateLimitBeforeDo(req *http.Request) *RateLimitError {
return &RateLimitError{
Rate: rate,
Response: resp,
Messages: []string{fmt.Sprintf("API rate limit of %v still exceeded until %v, not making remote request.", rate.Limit, rate.Reset.Time)},
Messages: []string{fmt.Sprintf("API rate limit of %v still exceeded until %v, not making remote request.", rate.Limit, rate.Reset.Time)},
}
}

Expand All @@ -274,17 +273,17 @@ func (c *Client) checkRateLimitBeforeDo(req *http.Request) *RateLimitError {

// Rate referenced from https://github.com/google/go-github/blob/master/github/github.go#L861
type Rate struct {
Limit int `json:"limit"`
Remaining int `json:"remaining"`
Reset Timestamp `json:"reset"`
err error
Limit int `json:"limit"`
Remaining int `json:"remaining"`
Reset Timestamp `json:"reset"`
err error
}

// RateLimitError referenced from https://github.com/google/go-github/blob/master/github/github.go#L687
type RateLimitError struct {
Rate Rate // Rate specifies last known rate limit for the client
Response *http.Response // HTTP response that caused this error
Messages []string `json:"message"` // error message
Messages []string `json:"message"` // error message
}

// Error referenced from https://github.com/google/go-github/blob/master/github/github.go#L693
Expand All @@ -310,8 +309,8 @@ func sanitizeURL(uri *url.URL) *url.URL {
// ErrorResponse referenced from https://github.com/google/go-github/blob/master/github/github.go#L655
type ErrorResponse struct {
Response *http.Response // HTTP response that caused this error
Messages []string `json:"messages"` // error message
ErrorStr string `json:"error"` // more detail about an error
Messages []string `json:"messages"` // error message
ErrorStr string `json:"error"` // more detail about an error
err error // CheckResponse error
}

Expand Down
2 changes: 1 addition & 1 deletion docbase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestClient_NewRequest(t *testing.T) {
outBody := `{"Foo":"Bar"}`

req, err := cli.NewRequest(method, inURL, inBody)

if err != nil {
t.Errorf("err")
}
Expand Down
1 change: 1 addition & 0 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (s *GroupCli) List(opts *GroupListOptions) (*GroupListResponse, *Response,
q.Set("per_page", strconv.Itoa(opts.PerPage))
q.Set("page", strconv.Itoa(opts.Page))
q.Set("q", opts.Name)
u.RawQuery = q.Encode()

req, err := s.client.NewRequest(http.MethodGet, u.String(), nil)

Expand Down
2 changes: 1 addition & 1 deletion group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestGroupCli_Create(t *testing.T) {
PostsCount: 0,
LastActivityAt: ti,
CreatedAt: ti,
Users: []SimpleUser{
Users: []SimpleUser{
SimpleUser{
ID: 1,
Name: "docbaseman",
Expand Down
1 change: 1 addition & 0 deletions post.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (s *PostCli) List(opts *PostListOptions) (*PostListResponse, *Response, err
q.Set("per_page", strconv.Itoa(opts.PerPage))
q.Set("page", strconv.Itoa(opts.Page))
q.Set("q", opts.Q)
u.RawQuery = q.Encode()

req, err := s.client.NewRequest(http.MethodGet, u.String(), nil)

Expand Down
4 changes: 2 additions & 2 deletions timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
package docbase

import (
"strconv"
"time"
"strconv"
"time"
)

// Timestamp represents a time that can be unmarshalled from a JSON string
Expand Down
1 change: 1 addition & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (s *UserCli) List(opts *UserListOptions) (*UserListResponse, *Response, err
q.Set("page", strconv.Itoa(opts.Page))
q.Set("q", opts.Q)
q.Set("include_user_groups", opts.Q)
u.RawQuery = q.Encode()

req, err := s.client.NewRequest(http.MethodGet, u.String(), nil)

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 = "0.1.0"
version = "0.1.1"
revision = "HEAD"
)

0 comments on commit f8c5b69

Please sign in to comment.