forked from kevinburke/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_router_worker.go
95 lines (82 loc) · 2.77 KB
/
task_router_worker.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package twilio
import (
"context"
"net/url"
)
const WorkersPathPart = "Workers"
type WorkerService struct {
client *Client
workspaceSid string
}
type Worker struct {
Sid string `json:"sid"`
AccountSid string `json:"account_sid"`
FriendlyName string `json:"friendly_name"`
// A string that contains JSON attributes, for example:
// `{"type": "support"}`
Attributes string `json:"attributes"`
ActivityName string `json:"activity_name"`
ActivitySid string `json:"activity_sid"`
Available bool `json:"available"`
DateCreated TwilioTime `json:"date_created"`
DateUpdated TwilioTime `json:"date_updated"`
URL string `json:"url"`
WorkspaceSid string `json:"workspace_sid"`
}
type WorkerPage struct {
Page
Workers []*Worker `json:"workers"`
}
// Get retrieves a Worker by its sid.
//
// See https://www.twilio.com/docs/taskrouter/api/workers#action-get for more.
func (r *WorkerService) Get(ctx context.Context, sid string) (*Worker, error) {
worker := new(Worker)
err := r.client.GetResource(ctx, "Workspaces/"+r.workspaceSid+"/"+WorkersPathPart, sid, worker)
return worker, err
}
// Create creates a new Worker.
//
// For a list of valid parameters see
// https://www.twilio.com/docs/taskrouter/api/workers#action-create.
func (r *WorkerService) Create(ctx context.Context, data url.Values) (*Worker, error) {
worker := new(Worker)
err := r.client.CreateResource(ctx, "Workspaces/"+r.workspaceSid+"/"+WorkersPathPart, data, worker)
return worker, err
}
// Delete deletes a Worker.
//
// See https://www.twilio.com/docs/taskrouter/api/workers#action-delete for more.
func (r *WorkerService) Delete(ctx context.Context, sid string) error {
return r.client.DeleteResource(ctx, "Workspaces/"+r.workspaceSid+"/"+WorkersPathPart, sid)
}
// Update updates a Workers.
//
// See https://www.twilio.com/docs/taskrouter/api/workers#update-a-worker for more.
func (ipn *WorkerService) Update(ctx context.Context, sid string, data url.Values) (*Worker, error) {
worker := new(Worker)
err := ipn.client.UpdateResource(ctx, "Workspaces/"+ipn.workspaceSid+"/"+WorkersPathPart, sid, data, worker)
return worker, err
}
func (ins *WorkerService) GetPage(ctx context.Context, data url.Values) (*WorkerPage, error) {
iter := ins.GetPageIterator(data)
return iter.Next(ctx)
}
type WorkerPageIterator struct {
p *PageIterator
}
func (c *WorkerService) GetPageIterator(data url.Values) *WorkerPageIterator {
iter := NewPageIterator(c.client, data, "Workspaces/"+c.workspaceSid+"/"+WorkersPathPart)
return &WorkerPageIterator{
p: iter,
}
}
func (c *WorkerPageIterator) Next(ctx context.Context) (*WorkerPage, error) {
cp := new(WorkerPage)
err := c.p.Next(ctx, cp)
if err != nil {
return nil, err
}
c.p.SetNextPageURI(cp.NextPageURI)
return cp, nil
}