forked from go-packages/paypal
Merge pull request #30 from vvakame/feature-http-client
Add SetHTTPClient function to *Client
This commit is contained in:
commit
6745ee0f80
11
client.go
11
client.go
|
@ -20,7 +20,7 @@ func NewClient(clientID string, secret string, APIBase string) (*Client, error)
|
|||
}
|
||||
|
||||
return &Client{
|
||||
client: &http.Client{},
|
||||
Client: &http.Client{},
|
||||
ClientID: clientID,
|
||||
Secret: secret,
|
||||
APIBase: APIBase,
|
||||
|
@ -52,6 +52,13 @@ func (c *Client) GetAccessToken() (*TokenResponse, error) {
|
|||
return &t, err
|
||||
}
|
||||
|
||||
// SetHTTPClient sets *http.Client to current client
|
||||
func (c *Client) SetHTTPClient(client *http.Client) error {
|
||||
c.Client = client
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// SetAccessToken sets saved token to current client
|
||||
func (c *Client) SetAccessToken(token string) error {
|
||||
c.Token = &TokenResponse{
|
||||
|
@ -88,7 +95,7 @@ func (c *Client) Send(req *http.Request, v interface{}) error {
|
|||
req.Header.Set("Content-type", "application/json")
|
||||
}
|
||||
|
||||
resp, err = c.client.Do(req)
|
||||
resp, err = c.Client.Do(req)
|
||||
c.log(req, resp)
|
||||
|
||||
if err != nil {
|
||||
|
|
12
types.go
12
types.go
|
@ -107,12 +107,12 @@ type (
|
|||
|
||||
// Client represents a Paypal REST API Client
|
||||
Client struct {
|
||||
client *http.Client
|
||||
ClientID string
|
||||
Secret string
|
||||
APIBase string
|
||||
Log io.Writer // If user set log file name all requests will be logged there
|
||||
Token *TokenResponse
|
||||
Client *http.Client
|
||||
ClientID string
|
||||
Secret string
|
||||
APIBase string
|
||||
Log io.Writer // If user set log file name all requests will be logged there
|
||||
Token *TokenResponse
|
||||
tokenExpiresAt time.Time
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user