Skip to content

Commit ab1dd27

Browse files
Merge branch 'getinput_ssml' into get-input
2 parents 651b82a + ef87a06 commit ab1dd27

18 files changed

+1435
-18
lines changed

Diff for: address.go

+253
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
package plivo
2+
3+
import (
4+
"errors"
5+
"os"
6+
"path/filepath"
7+
)
8+
9+
type AddressService struct {
10+
client *Client
11+
SalutationType addressSalutationRegistry
12+
NumberType addressNumberTypeRegistry
13+
ProofType addressProofTypeRegistry
14+
FileType addressFileTypeRegistry
15+
}
16+
17+
type AddressCreateParams struct {
18+
PhoneNumberCountry string `json:"phone_number_country,omitempty" url:"phone_number_country,omitempty"`
19+
NumberType string `json:"number_type,omitempty" url:"number_type,omitempty"`
20+
Salutation string `json:"salutation,omitempty" url:"salutation,omitempty"`
21+
FirstName string `json:"first_name,omitempty" url:"first_name,omitempty"`
22+
LastName string `json:"last_name,omitempty" url:"last_name,omitempty"`
23+
AddressLine1 string `json:"address_line1,omitempty" url:"address_line1,omitempty"`
24+
AddressLine2 string `json:"address_line2,omitempty" url:"address_line2,omitempty"`
25+
City string `json:"city,omitempty" url:"city,omitempty"`
26+
Region string `json:"region,omitempty" url:"region,omitempty"`
27+
PostalCode string `json:"postal_code,omitempty" url:"postal_code,omitempty"`
28+
CountryIso string `json:"country_iso,omitempty" url:"country_iso,omitempty"`
29+
CallBackUrl string `json:"callback_url,omitempty" url:"callback_url,omitempty"`
30+
Alias string `json:"alias,omitempty" url:"alias,omitempty"`
31+
File interface{} `json:"file,omitempty" url:"file,omitempty"`
32+
AutoCorrectAddress string `json:"autoCorrectAddress,omitempty" url:"autoCorrectAddress,omitempty"`
33+
AddressProofType string `json:"proof_type,omitempty" url:"proof_type,omitempty"`
34+
IdNumber string `json:"id_number,omitempty" url:"id_number,omitempty"`
35+
FiscalIdentificationCode string `json:"fiscal_identification_code,omitempty" url:"fiscal_identification_code,omitempty"`
36+
StreetCode string `json:"street_code,omitempty" url:"street_code,omitempty"`
37+
MunicipalCode string `json:"municipal_code,omitempty" url:"municipal_code,omitempty"`
38+
}
39+
40+
type Address struct {
41+
Account string `json:"account,omitempty" url:"account,omitempty"`
42+
AddressLine1 string `json:"address_line1,omitempty" url:"address_line1,omitempty"`
43+
AddressLine2 string `json:"address_line2,omitempty" url:"address_line2,omitempty"`
44+
Alias string `json:"alias,omitempty" url:"alias,omitempty"`
45+
StreetCode string `json:"street_code,omitempty" url:"street_code,omitempty"`
46+
City string `json:"city,omitempty" url:"city,omitempty"`
47+
CountryIso string `json:"country_iso,omitempty" url:"country_iso,omitempty"`
48+
DocumentDetails map[string]interface{} `json:"document_details,omitempty" url:"document_details,omitempty"`
49+
FirstName string `json:"first_name,omitempty" url:"first_name,omitempty"`
50+
LastName string `json:"last_name,omitempty" url:"last_name,omitempty"`
51+
ID string `json:"id,omitempty" url:"id,omitempty"`
52+
ApiID string `json:"api_id,omitempty" url:"api_id,omitempty"`
53+
Region string `json:"region,omitempty" url:"region,omitempty"`
54+
PostalCode string `json:"postal_code,omitempty" url:"postal_code,omitempty"`
55+
Salutation string `json:"salutation,omitempty" url:"salutation,omitempty"`
56+
FiscalIdentificationCode string `json:"fiscal_identification_code,omitempty" url:"fiscal_identification_code,omitempty"`
57+
Url string `json:"url,omitempty" url:"url,omitempty"`
58+
Subaccount string `json:"subaccount,omitempty" url:"subaccount,omitempty"`
59+
MunicipalCode string `json:"municipal_code,omitempty" url:"municipal_code,omitempty"`
60+
ValidationStatus string `json:"validation_status,omitempty" url:"validation_status,omitempty"`
61+
AddressProofType string `json:"proof_type,omitempty" url:"proof_type,omitempty"`
62+
VerificationStatus string `json:"verification_status,omitempty" url:"verification_status,omitempty"`
63+
}
64+
65+
type AddressUpdateParams struct {
66+
67+
PhoneNumberCountry string `json:"phone_number_country,omitempty" url:"phone_number_country,omitempty"`
68+
NumberType string `json:"number_type,omitempty" url:"number_type,omitempty"`
69+
Salutation string `json:"salutation,omitempty" url:"salutation,omitempty"`
70+
FirstName string `json:"first_name,omitempty" url:"first_name,omitempty"`
71+
LastName string `json:"last_name,omitempty" url:"last_name,omitempty"`
72+
AddressLine1 string `json:"address_line1,omitempty" url:"address_line1,omitempty"`
73+
AddressLine2 string `json:"address_line2,omitempty" url:"address_line2,omitempty"`
74+
City string `json:"city,omitempty" url:"city,omitempty"`
75+
Region string `json:"region,omitempty" url:"region,omitempty"`
76+
PostalCode string `json:"postal_code,omitempty" url:"postal_code,omitempty"`
77+
CountryIso string `json:"country_iso,omitempty" url:"country_iso,omitempty"`
78+
CallBackUrl string `json:"callback_url,omitempty" url:"callback_url,omitempty"`
79+
Alias string `json:"alias,omitempty" url:"alias,omitempty"`
80+
File interface{} `json:"file,omitempty" url:"file,omitempty"`
81+
AutoCorrectAddress bool `json:"autoCorrectAddress,omitempty" url:"autoCorrectAddress,omitempty"`
82+
AddressProofType string `json:"proof_type,omitempty" url:"proof_type,omitempty"`
83+
FiscalIdentificationCode string `json:"fiscal_identification_code,omitempty" url:"fiscal_identification_code,omitempty"`
84+
StreetCode string `json:"street_code,omitempty" url:"street_code,omitempty"`
85+
MunicipalCode string `json:"municipal_code,omitempty" url:"municipal_code,omitempty"`
86+
87+
}
88+
89+
var AddressSalutationType = &addressSalutationRegistry{
90+
MR: "Mr",
91+
MRS: "Mrs",
92+
}
93+
94+
var AddressNumberType = &addressNumberTypeRegistry{
95+
LOCAL: "local",
96+
NATIONAL: "national",
97+
MOBILE: "mobile",
98+
TOLLFREE: "tollfree",
99+
}
100+
101+
var AddressProofType = &addressProofTypeRegistry{
102+
NATIONALID: "national_id",
103+
PASSPORT: "passport",
104+
BUSINESSID: "business_id",
105+
NIF: "NIF",
106+
NIE :"NIE",
107+
DNI:"DNI",
108+
}
109+
110+
var AddressFileType = &addressFileTypeRegistry{
111+
PNG: "png",
112+
JPG: "jpg",
113+
PDF: "pdf",
114+
}
115+
116+
type addressSalutationRegistry struct {
117+
MR string
118+
MRS string
119+
}
120+
121+
type addressNumberTypeRegistry struct {
122+
LOCAL string
123+
NATIONAL string
124+
MOBILE string
125+
TOLLFREE string
126+
}
127+
128+
type addressProofTypeRegistry struct {
129+
NATIONALID string
130+
PASSPORT string
131+
BUSINESSID string
132+
NIF string
133+
NIE string
134+
DNI string
135+
}
136+
137+
type addressFileTypeRegistry struct {
138+
PNG string
139+
JPG string
140+
PDF string
141+
}
142+
143+
type AddressListParams struct {
144+
Limit int `url:"limit,omitempty"`
145+
Offset int `url:"offset,omitempty"`
146+
}
147+
148+
149+
// Stores response for Create call
150+
type AddressCreateResponseBody struct {
151+
Message string `json:"message" url:"message"`
152+
ApiID string `json:"api_id" url:"api_id"`
153+
}
154+
155+
type AddressList struct {
156+
BaseListResponse
157+
Objects []Address `json:"objects" url:"objects"`
158+
}
159+
type AddressUpdateResponse BaseResponse
160+
161+
func addressCreateParamsNotNull(params AddressCreateParams) bool{
162+
if len(params.PhoneNumberCountry) == 0 || len(params.NumberType) == 0 || len(params.Salutation) == 0 ||
163+
len(params.FirstName) == 0 || len(params.LastName) == 0 || len(params.AddressLine1) == 0 ||
164+
len(params.AddressLine2) == 0 || len(params.City) == 0 || len(params.Region) == 0 || len(params.PostalCode) == 0 ||
165+
len(params.CountryIso) == 0 {
166+
return false
167+
}
168+
return true
169+
}
170+
171+
172+
173+
func (service *AddressService) Create(params AddressCreateParams)(response *AddressCreateResponseBody, err error){
174+
if !addressCreateParamsNotNull(params) {
175+
err = errors.New("PhoneNumberCountry, numberType, salutation, firstName, lastName," +
176+
"addressLine1, addressLine2, city, region, postalCode and countryIso must not be empty")
177+
return
178+
}
179+
err = IsValidCountryParams(params.CountryIso,params.FiscalIdentificationCode,params.StreetCode,params.MunicipalCode)
180+
if err != nil {
181+
return
182+
}
183+
if (params.File != nil){
184+
err = IsValidFile(params.File.(string))
185+
if err != nil {
186+
return
187+
}
188+
targetFilePath := filepath.Join(params.File.(string), "./")
189+
file, _ := os.Stat(targetFilePath)
190+
params.File = file
191+
}
192+
request, err := service.client.NewRequest("POST", params, "Verification/Address")
193+
if err != nil {
194+
return
195+
}
196+
response = &AddressCreateResponseBody{}
197+
err = service.client.ExecuteRequest(request, response)
198+
return
199+
}
200+
201+
func (service *AddressService) List(params AddressListParams) (response *AddressList, err error) {
202+
request, err := service.client.NewRequest("GET", params, "Verification/Address/")
203+
if err != nil {
204+
return
205+
}
206+
response = &AddressList{}
207+
err = service.client.ExecuteRequest(request, response)
208+
return
209+
}
210+
211+
212+
func (service *AddressService) Get(documentID string) (response *Address, err error) {
213+
request, err := service.client.NewRequest("GET", nil, "Verification/Address/%s",documentID)
214+
if err != nil {
215+
return
216+
}
217+
response = &Address{}
218+
err = service.client.ExecuteRequest(request, response)
219+
return
220+
}
221+
222+
223+
func (service *AddressService) Delete(documentID string) (err error) {
224+
request, err := service.client.NewRequest("DELETE", nil, "Verification/Address/%s",documentID)
225+
if err != nil {
226+
return
227+
}
228+
err = service.client.ExecuteRequest(request, nil)
229+
return
230+
}
231+
232+
func (service *AddressService) Update(documentID string, params AddressUpdateParams) (response *AddressUpdateResponse, err error) {
233+
err = IsValidCountryParams(params.CountryIso,params.FiscalIdentificationCode,params.StreetCode,params.MunicipalCode)
234+
if err != nil {
235+
return
236+
}
237+
if (params.File != nil){
238+
err = IsValidFile(params.File.(string))
239+
if err != nil {
240+
return
241+
}
242+
targetFilePath := filepath.Join(params.File.(string), "./")
243+
file, _ := os.Stat(targetFilePath)
244+
params.File = file
245+
}
246+
request, err := service.client.NewRequest("POST", params, "Verification/Address/%s",documentID)
247+
if err != nil {
248+
return
249+
}
250+
response = &AddressUpdateResponse{}
251+
err = service.client.ExecuteRequest(request, response)
252+
return
253+
}

Diff for: address_test.go

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package plivo
2+
3+
import (
4+
"errors"
5+
"github.com/stretchr/testify/assert"
6+
"testing"
7+
)
8+
9+
func TestAddressService_Create(t *testing.T) {
10+
expectResponse("addressCreateResponse.json", 202)
11+
12+
if _, err := client.Addresses.Create(AddressCreateParams{
13+
PhoneNumberCountry: "test",
14+
NumberType: AddressNumberType.LOCAL,
15+
Salutation: AddressSalutationType.MR,
16+
AddressLine1: "test",
17+
FirstName: "test",
18+
LastName: "test",
19+
AddressLine2: "test",
20+
City: "test",
21+
Region: "test",
22+
PostalCode: "test",
23+
CountryIso: "IN",
24+
},); err != nil {
25+
panic(err)
26+
}
27+
28+
cl := client.httpClient
29+
client.httpClient = nil
30+
_, err := client.Addresses.Create(AddressCreateParams{})
31+
if err == nil {
32+
client.httpClient = cl
33+
panic(errors.New("error expected"))
34+
}
35+
client.httpClient = cl
36+
37+
assertRequest(t, "POST", "Verification/Address")
38+
}
39+
40+
func TestAddressService_Get(t *testing.T) {
41+
expectResponse("addressGetResponse.json", 202)
42+
documentID := "documentID"
43+
44+
address, err := client.Addresses.Get(documentID)
45+
assert.Equal(t, address.DocumentID(), address.ID)
46+
if err != nil {
47+
panic(err)
48+
}
49+
50+
cl := client.httpClient
51+
client.httpClient = nil
52+
_, err = client.Addresses.Get(documentID)
53+
if err == nil {
54+
client.httpClient = cl
55+
panic(errors.New("error expected"))
56+
}
57+
client.httpClient = cl
58+
59+
assertRequest(t, "GET", "Verification/Address/%s", documentID)
60+
}
61+
62+
func TestAddressService_Update(t *testing.T) {
63+
expectResponse("addressModifyResponse.json", 202)
64+
documentID := "documentID"
65+
66+
if _, err := client.Addresses.Update(documentID, AddressUpdateParams{}); err != nil {
67+
panic(err)
68+
}
69+
70+
cl := client.httpClient
71+
client.httpClient = nil
72+
_, err := client.Addresses.Update(documentID, AddressUpdateParams{})
73+
if err == nil {
74+
client.httpClient = cl
75+
panic(errors.New("error expected"))
76+
}
77+
client.httpClient = cl
78+
79+
assertRequest(t, "POST", "Verification/Address/%s", documentID)
80+
}
81+
82+
func TestAddressService_Delete(t *testing.T) {
83+
expectResponse("", 204)
84+
documentID := "documentID"
85+
86+
if err := client.Addresses.Delete(documentID); err != nil {
87+
panic(err)
88+
}
89+
90+
cl := client.httpClient
91+
client.httpClient = nil
92+
err := client.Addresses.Delete(documentID)
93+
if err == nil {
94+
client.httpClient = cl
95+
panic(errors.New("error expected"))
96+
}
97+
client.httpClient = cl
98+
99+
assertRequest(t, "DELETE", "Verification/Address/%s", documentID)
100+
}
101+
102+
func TestAddressService_List(t *testing.T) {
103+
expectResponse("addressListResponse.json", 200)
104+
105+
if _, err := client.Addresses.List(AddressListParams{}); err != nil {
106+
panic(err)
107+
}
108+
109+
cl := client.httpClient
110+
client.httpClient = nil
111+
_, err := client.Addresses.List(AddressListParams{})
112+
if err == nil {
113+
client.httpClient = cl
114+
panic(errors.New("error expected"))
115+
}
116+
client.httpClient = cl
117+
118+
assertRequest(t, "GET", "Verification/Address/")
119+
}

Diff for: applications.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Application struct {
1919
FallbackAnswerURL string `json:"fallback_answer_url,omitempty" url:"fallback_answer_url,omitempty"`
2020
AnswerMethod string `json:"answer_method,omitempty" url:"answer_method,omitempty"`
2121
ApiID string `json:"api_id,omitempty" url:"api_id,omitempty"`
22-
LogIncomingMessages bool `json:"log_incoming_messages,omitempty" url:"log_incoming_messages,omitempty"`
22+
LogIncomingMessages bool `json:"log_incoming_message,omitempty" url:"log_incoming_message,omitempty"`
2323

2424
// Additional fields for Modify calls
2525
DefaultNumberApp bool `json:"default_number_app,omitempty" url:"default_number_app,omitempty"`
@@ -42,7 +42,7 @@ type ApplicationCreateParams struct {
4242
FallbackAnswerURL string `json:"fallback_answer_url,omitempty" url:"fallback_answer_url,omitempty"`
4343
AnswerMethod string `json:"answer_method,omitempty" url:"answer_method,omitempty"`
4444
ApiID string `json:"api_id,omitempty" url:"api_id,omitempty"`
45-
LogIncomingMessages bool `json:"log_incoming_messages,omitempty" url:"log_incoming_messages,omitempty"`
45+
LogIncomingMessages bool `json:"log_incoming_message,omitempty" url:"log_incoming_message,omitempty"`
4646

4747
// Additional fields for Modify calls
4848
DefaultNumberApp bool `json:"default_number_app,omitempty" url:"default_number_app,omitempty"`

0 commit comments

Comments
 (0)