-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdid.go
More file actions
164 lines (137 loc) · 6 KB
/
Copy pathdid.go
File metadata and controls
164 lines (137 loc) · 6 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package wavix
import (
"bytes"
"fmt"
"net/url"
"strconv"
"strings"
"github.com/wavix/sdk-go/utils"
)
type DidDestinationTransport int
type DidDocumentId int
const (
DidDestinationTransportSipURI DidDestinationTransport = 1
DidDestinationTransportPSTN DidDestinationTransport = 4
DidDestinationTransportSIPTrunk DidDestinationTransport = 5
)
const (
DidDocumentIdGeneral DidDocumentId = 1
DidDocumentAddress DidDocumentId = 2
DidDocumentLocalAddress DidDocumentId = 3
)
type DidServiceInterface interface {
GetAccountDids(params GetAccountDidsQueryParams) (*utils.PaginationResponse[DidItem], *utils.HttpErrorResponse)
UpdateDidDestinations(payload UpdateDidDestinationsPayload) (*utils.HttpSuccessBasicResponse, *utils.HttpErrorResponse)
UploadDidDocument(payload UploadDidDocumentPayload) (*utils.HttpSuccessBasicResponse, *utils.HttpErrorResponse)
ReturnDidsToStock(ids []string) (*utils.HttpSuccessBasicResponse, *utils.HttpErrorResponse)
}
type DidService struct {
httpConfig *utils.HttpConfig
}
type DidDestination struct {
Id int `json:"id"`
Destination string `json:"destination"`
Priority int `json:"priority"`
Transport int `json:"transport"`
TrunkId int `json:"trunk_id"`
TrunkLabel string `json:"trunk_label"`
}
type DidDocument struct {
Id int `json:"id"`
AllowReplace bool `json:"allow_replace"`
DidNumber string `json:"did_number"`
DocContentType string `json:"doc_content_type"`
DocFileName string `json:"doc_file_name"`
DocTypeId int `json:"doc_type_id"`
Status string `json:"status"`
Url string `json:"url"`
}
type DidItem struct {
Id int `json:"id"`
ActivationFee string `json:"activation_fee"`
Added string `json:"added"`
CallRecordingEnabled bool `json:"call_recording_enabled"`
Channels int `json:"channels"`
City string `json:"city"`
Cnam bool `json:"cnam"`
Country string `json:"country"`
CountryShortName string `json:"country_short_name"`
Destination []DidDestination `json:"destination"`
Documents []DidDocument `json:"documents"`
Label string `json:"label"`
MonthlyFee string `json:"monthly_fee"`
Number string `json:"number"`
PaidUntil string `json:"paid_until"`
PerMin string `json:"per_min"`
RequireDocs []string `json:"require_docs"`
Seconds string `json:"seconds"`
SmsEnabled bool `json:"sms_enabled"`
SmsRelayUrl string `json:"sms_relay_url"`
Status string `json:"status"`
TranscriptionEnabled bool `json:"transcription_enabled"`
TranscriptionThreshold int `json:"transcription_threshold"`
}
type GetAccountDidsQueryParams struct {
utils.PaginationParams
CityId int `url:"city_id,omitempty"`
Search string `url:"search,omitempty"`
Label string `url:"label,omitempty"`
LabelPresent string `url:"label_present,omitempty"`
}
type DidDestinationPayload struct {
Destination string `validate:"required" json:"destination"`
Transport int `validate:"required,oneof=1 4 5" json:"transport"`
TrunkId int `validate:"required" json:"trunk_id"`
Priority int `json:"priority,omitempty"`
}
type UpdateDidDestinationsPayload struct {
Ids []int `validate:"min=1" json:"ids"`
SmsRelayUrl string `validate:"omitempty,url" json:"sms_relay_url,omitempty"`
Destinations []DidDestinationPayload `validate:"omitempty,min=1,dive" json:"destinations,omitempty"`
}
type DidDocumentFile struct {
Data []byte `json:"data"`
Name string `json:"name"`
}
type UploadDidDocumentPayload struct {
DidIds []string `validate:"min=1" json:"did_ids"`
File DidDocumentFile `validate:"required" json:"file"`
DocId int `validate:"required,oneof=1 2 3" json:"doc_id"`
}
func (d UploadDidDocumentPayload) GetFileData() utils.File {
return utils.File{Reader: bytes.NewReader(d.File.Data), FileName: d.File.Name, FileKey: "doc_attachment"}
}
func (d UploadDidDocumentPayload) GetFormValues() url.Values {
return url.Values{
"did_ids": []string{strings.Join(d.DidIds, ",")},
"doc_id": []string{strconv.Itoa(d.DocId)},
}
}
func (s *DidService) GetAccountDids(params GetAccountDidsQueryParams) (*utils.PaginationResponse[DidItem], *utils.HttpErrorResponse) {
url := utils.BuildUrlWithQueryString("/v1/mydids", params)
return utils.Get[utils.PaginationResponse[DidItem]](*s.httpConfig, url, utils.PaginationResponse[DidItem]{})
}
func (s *DidService) UpdateDidDestinations(payload UpdateDidDestinationsPayload) (*utils.HttpSuccessBasicResponse, *utils.HttpErrorResponse) {
validate := utils.GetValidate()
err := validate.Struct(payload)
if err != nil {
return nil, &utils.HttpErrorResponse{Message: err.Error()}
}
return utils.Post[utils.HttpSuccessBasicResponse](*s.httpConfig, "/v1/mydids/update-destinations", payload, utils.HttpSuccessBasicResponse{})
}
func (s *DidService) UploadDidDocument(payload UploadDidDocumentPayload) (*utils.HttpSuccessBasicResponse, *utils.HttpErrorResponse) {
validate := utils.GetValidate()
err := validate.Struct(payload)
if err != nil {
return nil, &utils.HttpErrorResponse{Message: err.Error()}
}
return utils.Upload(*s.httpConfig, "/v1/mydids/papers", payload)
}
func (s *DidService) ReturnDidsToStock(ids []string) (*utils.HttpSuccessBasicResponse, *utils.HttpErrorResponse) {
queryStringSlice := make([]string, len(ids))
for index, id := range ids {
queryStringSlice[index] = fmt.Sprintf("ids[]=%v", id)
}
url := "/v1/mydids?" + strings.Join(queryStringSlice, "&")
return utils.Delete[utils.HttpSuccessBasicResponse](*s.httpConfig, url, utils.HttpSuccessBasicResponse{})
}