-
Notifications
You must be signed in to change notification settings - Fork 3
/
resource_taskrouter_activity_funcs.go
76 lines (52 loc) · 1.5 KB
/
resource_taskrouter_activity_funcs.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
package main
import (
"net/url"
"golang.org/x/net/context"
"github.com/hashicorp/terraform/helper/schema"
)
func activityCreate(d *schema.ResourceData, meta interface{}) error {
m := meta.(*twilioMeta)
data := url.Values{}
data.Set("FriendlyName", d.Get("friendly_name").(string))
data.Set("Available", d.Get("available").(string))
activity, err := m.Client.TaskRouter.Workspace(m.WorkspaceSid).Activities.Create(context.Background(), data)
if err != nil {
return err
}
d.SetId(activity.Sid)
return activityUpdate(d, meta)
}
func activityUpdate(d *schema.ResourceData, meta interface{}) error {
m := meta.(*twilioMeta)
data := url.Values{}
if d.HasChange("friendly_name") {
data.Set("FriendlyName", d.Get("friendly_name").(string))
}
_, err := m.Client.TaskRouter.Workspace(m.WorkspaceSid).Activities.Update(context.Background(), d.Id(), data)
if err != nil {
return err
}
return activityRead(d, meta)
}
func activityRead(d *schema.ResourceData, meta interface{}) error {
m := meta.(*twilioMeta)
activity, err := m.Client.TaskRouter.Workspace(m.WorkspaceSid).Activities.Get(context.Background(), d.Id())
if err != nil {
return err
}
if activity == nil {
d.SetId("")
return err
}
d.SetId(activity.Sid)
return nil
}
func activityDelete(d *schema.ResourceData, meta interface{}) error {
m := meta.(*twilioMeta)
err := m.Client.TaskRouter.Workspace(m.WorkspaceSid).Activities.Delete(context.Background(), d.Id())
if err != nil {
return err
}
d.SetId("")
return nil
}