mirror of
https://github.com/plutov/paypal.git
synced 2025-02-02 15:10:36 +01:00
Add SetHTTPClient function to *Client
When we use GoogleAppEngine/Go environment, We should replace http.Client to urlfetch.Client.
This commit is contained in:
parent
f9536247c0
commit
c9eb8b7137
11
client.go
11
client.go
|
@ -19,7 +19,7 @@ func NewClient(clientID string, secret string, APIBase string) (*Client, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
client: &http.Client{},
|
Client: &http.Client{},
|
||||||
ClientID: clientID,
|
ClientID: clientID,
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
APIBase: APIBase,
|
APIBase: APIBase,
|
||||||
|
@ -50,6 +50,13 @@ func (c *Client) GetAccessToken() (*TokenResponse, error) {
|
||||||
return &t, err
|
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
|
// SetAccessToken sets saved token to current client
|
||||||
func (c *Client) SetAccessToken(token string) error {
|
func (c *Client) SetAccessToken(token string) error {
|
||||||
c.Token = &TokenResponse{
|
c.Token = &TokenResponse{
|
||||||
|
@ -85,7 +92,7 @@ func (c *Client) Send(req *http.Request, v interface{}) error {
|
||||||
req.Header.Set("Content-type", "application/json")
|
req.Header.Set("Content-type", "application/json")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err = c.client.Do(req)
|
resp, err = c.Client.Do(req)
|
||||||
c.log(req, resp)
|
c.log(req, resp)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
2
types.go
2
types.go
|
@ -107,7 +107,7 @@ type (
|
||||||
|
|
||||||
// Client represents a Paypal REST API Client
|
// Client represents a Paypal REST API Client
|
||||||
Client struct {
|
Client struct {
|
||||||
client *http.Client
|
Client *http.Client
|
||||||
ClientID string
|
ClientID string
|
||||||
Secret string
|
Secret string
|
||||||
APIBase string
|
APIBase string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user