-
Notifications
You must be signed in to change notification settings - Fork 23
/
applications.go
134 lines (118 loc) · 6.1 KB
/
applications.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package plivo
type ApplicationService struct {
client *Client
}
type Application struct {
FallbackMethod string `json:"fallback_method,omitempty" url:"fallback_method,omitempty"`
DefaultApp bool `json:"default_app,omitempty" url:"default_app,omitempty"`
AppName string `json:"app_name,omitempty" url:"app_name,omitempty"`
ProductionApp bool `json:"production_app,omitempty" url:"production_app,omitempty"`
AppID string `json:"app_id,omitempty" url:"app_id,omitempty"`
HangupURL string `json:"hangup_url,omitempty" url:"hangup_url,omitempty"`
AnswerURL string `json:"answer_url,omitempty" url:"answer_url,omitempty"`
MessageURL string `json:"message_url,omitempty" url:"message_url,omitempty"`
ResourceURI string `json:"resource_uri,omitempty" url:"resource_uri,omitempty"`
HangupMethod string `json:"hangup_method,omitempty" url:"hangup_method,omitempty"`
MessageMethod string `json:"message_method,omitempty" url:"message_method,omitempty"`
FallbackAnswerURL string `json:"fallback_answer_url,omitempty" url:"fallback_answer_url,omitempty"`
AnswerMethod string `json:"answer_method,omitempty" url:"answer_method,omitempty"`
ApiID string `json:"api_id,omitempty" url:"api_id,omitempty"`
LogIncomingMessages bool `json:"log_incoming_messages,omitempty" url:"log_incoming_messages,omitempty"`
PublicURI bool `json:"public_uri,omitempty" url:"public_uri,omitempty"`
// Additional fields for Modify calls
DefaultNumberApp bool `json:"default_number_app,omitempty" url:"default_number_app,omitempty"`
DefaultEndpointApp bool `json:"default_endpoint_app,omitempty" url:"default_endpoint_app,omitempty"`
}
//TODO Verify against docs
type ApplicationCreateParams struct {
FallbackMethod string `json:"fallback_method,omitempty" url:"fallback_method,omitempty"`
DefaultApp bool `json:"default_app,omitempty" url:"default_app,omitempty"`
AppName string `json:"app_name,omitempty" url:"app_name,omitempty"`
ProductionApp bool `json:"production_app,omitempty" url:"production_app,omitempty"`
AppID string `json:"app_id,omitempty" url:"app_id,omitempty"`
HangupURL string `json:"hangup_url,omitempty" url:"hangup_url,omitempty"`
AnswerURL string `json:"answer_url,omitempty" url:"answer_url,omitempty"`
MessageURL string `json:"message_url,omitempty" url:"message_url,omitempty"`
ResourceURI string `json:"resource_uri,omitempty" url:"resource_uri,omitempty"`
HangupMethod string `json:"hangup_method,omitempty" url:"hangup_method,omitempty"`
MessageMethod string `json:"message_method,omitempty" url:"message_method,omitempty"`
FallbackAnswerURL string `json:"fallback_answer_url,omitempty" url:"fallback_answer_url,omitempty"`
AnswerMethod string `json:"answer_method,omitempty" url:"answer_method,omitempty"`
ApiID string `json:"api_id,omitempty" url:"api_id,omitempty"`
LogIncomingMessages bool `json:"log_incoming_messages,omitempty" url:"log_incoming_messages,omitempty"`
PublicURI bool `json:"public_uri,omitempty" url:"public_uri,omitempty"`
// Additional fields for Modify calls
DefaultNumberApp bool `json:"default_number_app,omitempty" url:"default_number_app,omitempty"`
DefaultEndpointApp bool `json:"default_endpoint_app,omitempty" url:"default_endpoint_app,omitempty"`
}
// TODO Check against docs
type ApplicationUpdateParams ApplicationCreateParams
// Stores response for Create call
type ApplicationCreateResponseBody struct {
Message string `json:"message" url:"message"`
ApiID string `json:"api_id" url:"api_id"`
AppID string `json:"app_id" url:"app_id"`
}
type ApplicationListParams struct {
Subaccount string `url:"subaccount,omitempty"`
AppName string `url:"app_name,omitempty"`
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
}
type ApplicationList struct {
BaseListResponse
Objects []Application `json:"objects" url:"objects"`
}
type ApplicationDeleteParams struct {
Cascade bool `json:"cascade" url:"cascade"` // Specify if the Application should be cascade deleted or not. Takes a value of True or False
NewEndpointApplication string `json:"new_endpoint_application,omitempty" url:"new_endpoint_application,omitempty"`
}
type ApplicationUpdateResponse BaseResponse
func (service *ApplicationService) Create(params ApplicationCreateParams) (response *ApplicationCreateResponseBody, err error) {
request, err := service.client.NewRequest("POST", params, "Application")
if err != nil {
return
}
response = &ApplicationCreateResponseBody{}
err = service.client.ExecuteRequest(request, response, isVoiceRequest())
return
}
func (service *ApplicationService) List(params ApplicationListParams) (response *ApplicationList, err error) {
request, err := service.client.NewRequest("GET", params, "Application")
if err != nil {
return
}
response = &ApplicationList{}
err = service.client.ExecuteRequest(request, response, isVoiceRequest())
return
}
func (service *ApplicationService) Get(appId string) (response *Application, err error) {
request, err := service.client.NewRequest("GET", nil, "Application/%s", appId)
if err != nil {
return
}
response = &Application{}
err = service.client.ExecuteRequest(request, response, isVoiceRequest())
return
}
func (service *ApplicationService) Update(appId string, params ApplicationUpdateParams) (response *ApplicationUpdateResponse, err error) {
request, err := service.client.NewRequest("POST", params, "Application/%s", appId)
if err != nil {
return
}
response = &ApplicationUpdateResponse{}
err = service.client.ExecuteRequest(request, response, isVoiceRequest())
return
}
func (service *ApplicationService) Delete(appId string, data ...ApplicationDeleteParams) (err error) {
var optionalParams interface{}
if data != nil {
optionalParams = data[0]
}
request, err := service.client.NewRequest("DELETE", optionalParams, "Application/%s", appId)
if err != nil {
return
}
err = service.client.ExecuteRequest(request, nil, isVoiceRequest())
return
}