-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasq.go
57 lines (45 loc) · 1.12 KB
/
tasq.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
50
51
52
53
54
55
56
57
package tasq
import (
"golang.org/x/net/context"
"google.golang.org/api/option"
"google.golang.org/api/tasks/v1"
"time"
)
const (
QTasksReadOnlyScope = tasks.TasksReadonlyScope
QTasksReadWriteScope = tasks.TasksScope
)
type QConfig struct {
Credentials string
Scope string
}
type QService struct {
*tasks.Service
Tasklists *QTasklistsService
Tasks *QTasksService
}
func Init(cfg *QConfig) error {
return Auth.init(cfg)
}
func NewService(tokenString []byte) (*QService, error) {
tasqService := &QService{
Tasklists: &QTasklistsService{},
Tasks: &QTasksService{},
}
ctx := context.Background()
tokenSource, err := Auth.getTokenSource(ctx, tokenString)
if err != nil {
return tasqService, err
}
opt := option.WithTokenSource(tokenSource)
tasqService.Service, err = tasks.NewService(ctx, opt)
if err != nil {
return tasqService, err
}
tasqService.Tasklists.TasklistsService = tasqService.Service.Tasklists
tasqService.Tasks.TasksService = tasqService.Service.Tasks
return tasqService, nil
}
func Time(timeString string) (time.Time, error) {
return time.Parse(time.RFC3339, timeString)
}