forked from saintpete/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 69
/
task_router_activity.go
93 lines (80 loc) · 2.79 KB
/
task_router_activity.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
package twilio
import (
"context"
"net/url"
)
const activityPathPart = "Activities"
type ActivityService struct {
client *Client
workspaceSid string
}
type Activity struct {
Sid string `json:"sid"`
AccountSid string `json:"account_sid"`
FriendlyName string `json:"friendly_name"`
Available bool `json:"available"`
DateCreated TwilioTime `json:"date_created"`
DateUpdated TwilioTime `json:"date_updated"`
URL string `json:"url"`
WorkspaceSid string `json:"workspace_sid"`
}
type ActivityPage struct {
Page
Activities []*Activity `json:"activities"`
}
// Get retrieves an Activity by its sid.
//
// See https://www.twilio.com/docs/taskrouter/api/activities#action-get for
// more.
func (r *ActivityService) Get(ctx context.Context, sid string) (*Activity, error) {
activity := new(Activity)
err := r.client.GetResource(ctx, "Workspaces/"+r.workspaceSid+"/"+activityPathPart, sid, activity)
return activity, err
}
// Create creates a new Activity.
//
// For a list of valid parameters see
// https://www.twilio.com/docs/taskrouter/api/activities#action-create.
func (r *ActivityService) Create(ctx context.Context, data url.Values) (*Activity, error) {
activity := new(Activity)
err := r.client.CreateResource(ctx, "Workspaces/"+r.workspaceSid+"/"+activityPathPart, data, activity)
return activity, err
}
// Delete deletes an Activity.
//
// See https://www.twilio.com/docs/taskrouter/api/activities#action-delete for
// more.
func (r *ActivityService) Delete(ctx context.Context, sid string) error {
return r.client.DeleteResource(ctx, "Workspaces/"+r.workspaceSid+"/"+activityPathPart, sid)
}
func (ipn *ActivityService) Update(ctx context.Context, sid string, data url.Values) (*Activity, error) {
activity := new(Activity)
err := ipn.client.UpdateResource(ctx, "Workspaces/"+ipn.workspaceSid+"/"+activityPathPart, sid, data, activity)
return activity, err
}
// GetPage retrieves an ActivityPage, filtered by the given data.
func (ins *ActivityService) GetPage(ctx context.Context, data url.Values) (*ActivityPage, error) {
iter := ins.GetPageIterator(data)
return iter.Next(ctx)
}
type ActivityPageIterator struct {
p *PageIterator
}
// GetPageIterator returns an iterator which can be used to retrieve pages.
func (c *ActivityService) GetPageIterator(data url.Values) *ActivityPageIterator {
iter := NewPageIterator(c.client, data, "Workspaces/"+c.workspaceSid+"/"+activityPathPart)
return &ActivityPageIterator{
p: iter,
}
}
// Next returns the next page of resources. If there are no more resources,
// NoMoreResults is returned.
func (c *ActivityPageIterator) Next(ctx context.Context) (*ActivityPage, error) {
cp := new(ActivityPage)
err := c.p.Next(ctx, cp)
if err != nil {
return nil, err
}
c.p.SetNextPageURI(cp.NextPageURI)
return cp, nil
}