forked from plivo/plivo-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoints.go
97 lines (84 loc) · 3.21 KB
/
endpoints.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
96
97
package plivo
type EndpointService struct {
client *Client
}
type Endpoint struct {
Alias string `json:"alias,omitempty" url:"alias,omitempty"`
EndpointID string `json:"endpoint_id,omitempty" url:"endpoint_id,omitempty"`
Password string `json:"password,omitempty" url:"password,omitempty"`
ResourceURI string `json:"resource_uri,omitempty" url:"resource_uri,omitempty"`
SIPURI string `json:"sip_uri,omitempty" url:"sip_uri,omitempty"`
Username string `json:"username,omitempty" url:"username,omitempty"`
// Optional field for Create call.
AppID string `json:"app_id,omitempty" url:"app_id,omitempty"`
}
type EndpointUpdateParams struct {
Alias string `json:"alias,omitempty" url:"alias,omitempty"`
Password string `json:"password,omitempty" url:"password,omitempty"`
AppID string `json:"app_id,omitempty" url:"app_id,omitempty"`
}
type EndpointCreateParams struct {
Alias string `json:"alias,omitempty" url:"alias,omitempty"`
Password string `json:"password,omitempty" url:"password,omitempty"`
AppID string `json:"app_id,omitempty" url:"app_id,omitempty"`
Username string `json:"username,omitempty" url:"username,omitempty"`
}
type EndpointCreateResponse struct {
BaseResponse
Alias string `json:"alias,omitempty" url:"alias,omitempty"`
EndpointID string `json:"endpoint_id,omitempty" url:"endpoint_id,omitempty"`
Username string `json:"username,omitempty" url:"username,omitempty"`
}
type EndpointListResponse struct {
BaseListResponse
Objects []*Endpoint `json:"objects" url:"objects"`
}
type EndpointUpdateResponse BaseResponse
type EndpointListParams struct {
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
}
func (service *EndpointService) Create(params EndpointCreateParams) (response *EndpointCreateResponse, err error) {
req, err := service.client.NewRequest("POST", params, "Endpoint")
if err != nil {
return
}
response = &EndpointCreateResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}
func (service *EndpointService) Get(endpointId string) (response *Endpoint, err error) {
req, err := service.client.NewRequest("GET", nil, "Endpoint/%s", endpointId)
if err != nil {
return
}
response = &Endpoint{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}
func (service *EndpointService) Delete(endpointId string) (err error) {
req, err := service.client.NewRequest("DELETE", nil, "Endpoint/%s", endpointId)
if err != nil {
return
}
err = service.client.ExecuteRequest(req, nil, isVoiceRequest())
return
}
func (service *EndpointService) Update(endpointId string, params EndpointUpdateParams) (response *EndpointUpdateResponse, err error) {
req, err := service.client.NewRequest("POST", params, "Endpoint/%s", endpointId)
if err != nil {
return
}
response = &EndpointUpdateResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}
func (service *EndpointService) List(params EndpointListParams) (response *EndpointListResponse, err error) {
req, err := service.client.NewRequest("GET", params, "Endpoint")
if err != nil {
return
}
response = &EndpointListResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}