Skip to content

Commit

Permalink
feat: extend client to allow custom request objects
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzolino committed May 6, 2021
1 parent 5d84c62 commit 4b8eb41
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@ func (c *Client) WithCredentials(ctx context.Context, username, password string)
return c, nil
}

// Request performs an HTTP request to the tado° API
func (c *Client) Request(method, url string, body io.Reader) (*http.Response, error) {
req, err := http.NewRequest(method, url, body)
if err != nil {
return nil, fmt.Errorf("unable to create tado° API request: %w", err)
}
// Do sends the given HTTP request to the tado° API.
func (c *Client) Do(req *http.Request) (*http.Response, error) {
resp, err := c.http.Do(req)
if err != nil {
return nil, fmt.Errorf("unable to talk to tado° API: %w", err)
}
return resp, nil
}

// Request performs an HTTP request to the tado° API
func (c *Client) Request(method, url string, body io.Reader) (*http.Response, error) {
req, err := http.NewRequest(method, url, body)
if err != nil {
return nil, fmt.Errorf("unable to create http request: %w", err)
}
return c.Do(req)
}

0 comments on commit 4b8eb41

Please sign in to comment.