-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
49 lines (41 loc) · 1.08 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package awql
import (
"net/http"
"time"
"golang.org/x/net/context"
"golang.org/x/oauth2"
)
// HTTP client to post and get AWQL query.
type Client struct {
auth *Auth
client *http.Client
}
// Create a new client based on the provided auth configuration.
func NewClient(auth *Auth) *Client {
oauth2Token := &oauth2.Token{
AccessToken: auth.AccessToken,
TokenType: "Bearer",
RefreshToken: auth.RefreshToken,
Expiry: time.Now(),
}
oauth2Config := &oauth2.Config{
ClientID: auth.ClientId,
ClientSecret: auth.ClientSecret,
Scopes: []string{
"https://www.googleapis.com/auth/adwords",
},
Endpoint: oauth2.Endpoint{
AuthURL: "https://accounts.google.com/o/oauth2/auth",
TokenURL: "https://accounts.google.com/o/oauth2/token",
},
}
return &Client{auth, oauth2Config.Client(context.TODO(), oauth2Token)}
}
// Execute an AWQL query for a report.
func (c *Client) Query(q string) (Rows, error) {
return newReportQuery(c, q)
}
// Execute an AWQL query for a service.
func (c *Client) QueryService(q, s string) (Rows, error) {
return newServiceQuery(q, s)
}