-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_client.go
46 lines (38 loc) · 1.23 KB
/
api_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
package google
import (
"context"
"golang.org/x/oauth2"
"google.golang.org/api/indexing/v3"
"google.golang.org/api/option"
)
// APIClient is interface of client to request Google Indexing API
type APIClient interface {
Publish(u string, nt NotificationType) (result *indexing.PublishUrlNotificationResponse, err error)
}
// Client is defined parameters to request Google Indexing API
type Client struct {
Service *indexing.Service
}
// New creates new instance to request Google Indexing API
func New(ctx context.Context, authOption option.ClientOption) (c APIClient, err error) {
s, err := indexing.NewService(ctx, authOption)
if err != nil {
return
}
return &Client{
Service: s,
}, nil
}
func NewByWithCredentialsFile(ctx context.Context, fp string) (c APIClient, err error) {
return New(ctx, option.WithCredentialsFile(fp))
}
func NewByWithToken(ctx context.Context, token oauth2.TokenSource) (c APIClient, err error) {
return New(ctx, option.WithTokenSource(token))
}
// Execute Google Indexing API
func (c *Client) Publish(u string, nt NotificationType) (result *indexing.PublishUrlNotificationResponse, err error) {
return c.Service.UrlNotifications.Publish(&indexing.UrlNotification{
Url: u,
Type: string(nt),
}).Do()
}