diff --git a/.DS_Store b/.DS_Store index 48890d4..5008ddf 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/common.go b/common.go index 5089331..703669b 100644 --- a/common.go +++ b/common.go @@ -8,6 +8,11 @@ type Meta struct { Limit int64 } +type BaseListParams struct { + Limit int `json:"limit,omitempty" url:"limit,omitempty"` + Offset int `json:"offset,omitempty" url:"offset,omitempty"` +} + type BaseListResponse struct { ApiID string `json:"api_id" url:"api_id"` Meta Meta `json:"meta" url:"meta"` diff --git a/compliance_applications.go b/compliance_applications.go new file mode 100644 index 0000000..d16284e --- /dev/null +++ b/compliance_applications.go @@ -0,0 +1,163 @@ +package plivo + +import "time" + +type ComplianceApplicationService struct { + client *Client +} + +type SubmitComplianceApplicationResponse struct { + APIID string `json:"api_id"` + CreatedAt time.Time `json:"created_at"` + ComplianceApplicationID string `json:"compliance_application_id"` + Alias string `json:"alias"` + Status string `json:"status"` + EndUserType string `json:"end_user_type"` + CountryIso2 string `json:"country_iso2"` + NumberType string `json:"number_type"` + EndUserID string `json:"end_user_id"` + ComplianceRequirementID string `json:"compliance_requirement_id"` + Documents []struct { + DocumentID string `json:"document_id"` + Name string `json:"name"` + DocumentName string `json:"document_name,omitempty"` + DocumentTypeID string `json:"document_type_id,omitempty"` + DocumentTypeName string `json:"document_type_name,omitempty"` + Scope string `json:"scope,omitempty"` + } `json:"documents"` +} + +type UpdateComplianceApplicationParams struct { + ComplianceApplicationId string `json:"compliance_application_id"` + DocumentIds []string `json:"document_ids"` +} + +type UpdateComplianceApplicationResponse BaseResponse + +type CreateComplianceApplicationParams struct { + ComplianceRequirementId string `json:"compliance_requirement_id,omitempty" url:"compliance_requirement_id,omitempty"` + EndUserId string `json:"end_user_id,omitempty" url:"end_user_id,omitempty"` + DocumentIds []string `json:"document_ids,omitempty" url:"document_ids, omitempty"` + Alias string `json:"alias,omitempty" url:"alias, omitempty"` + EndUserType string `json:"end_user_type,omitempty" url:"end_user_type, omitempty"` + CountryIso2 string `json:"country_iso2,omitempty" url:"country_iso2, omitempty"` + NumberType string `json:"number_type,omitempty" url:"number_type, omitempty"` +} + +type ComplianceApplicationResponse struct { + APIID string `json:"api_id"` + CreatedAt time.Time `json:"created_at"` + ComplianceApplicationID string `json:"compliance_application_id"` + Alias string `json:"alias"` + Status string `json:"status"` + EndUserType string `json:"end_user_type"` + CountryIso2 string `json:"country_iso2"` + NumberType string `json:"number_type"` + EndUserID string `json:"end_user_id"` + ComplianceRequirementID string `json:"compliance_requirement_id"` + Documents []struct { + DocumentID string `json:"document_id"` + Name string `json:"name"` + DocumentName string `json:"document_name,omitempty"` + DocumentTypeID string `json:"document_type_id,omitempty"` + DocumentTypeName string `json:"document_type_name,omitempty"` + Scope string `json:"scope,omitempty"` + } `json:"documents"` +} + +type ComplianceApplicationListParams struct { + Limit int `json:"limit,omitempty" url:"limit,omitempty"` + Offset int `json:"offset,omitempty" url:"offset,omitempty"` + EndUserID string `json:"end_user_id,omitempty" url:"end_user_id,omitempty"` + Country string `json:"country,omitempty" url:"country,omitempty"` + NumberType string `json:"number_type,omitempty" url:"number_type,omitempty"` + EndUserType string `json:"end_user_type,omitempty" url:"end_user_type,omitempty"` + Alias string `json:"alias,omitempty" url:"alias,omitempty"` + Status string `json:"status,omitempty" url:"status,omitempty"` +} + +type ListComplianceApplicationResponse struct { + APIID string `json:"api_id"` + Meta struct { + Limit int `json:"limit"` + Next string `json:"next"` + Offset int `json:"offset"` + Previous interface{} `json:"previous"` + TotalCount int `json:"total_count"` + } `json:"meta"` + Objects []struct { + CreatedAt time.Time `json:"created_at"` + ComplianceApplicationID string `json:"compliance_application_id"` + Alias string `json:"alias"` + Status string `json:"status"` + EndUserType string `json:"end_user_type"` + CountryIso2 string `json:"country_iso2"` + NumberType string `json:"number_type"` + EndUserID string `json:"end_user_id"` + ComplianceRequirementID string `json:"compliance_requirement_id"` + Documents []struct { + DocumentID string `json:"document_id"` + Name string `json:"name"` + DocumentName string `json:"document_name"` + DocumentTypeID string `json:"document_type_id"` + DocumentTypeName string `json:"document_type_name"` + Scope string `json:"scope"` + } `json:"documents"` + } `json:"objects"` +} + +func (service *ComplianceApplicationService) Get(complianceApplicationId string) (response *ComplianceApplicationResponse, err error) { + req, err := service.client.NewRequest("GET", nil, "ComplianceApplication/%s", complianceApplicationId) + response = &ComplianceApplicationResponse{} + err = service.client.ExecuteRequest(req, response) + return +} + +func (service *ComplianceApplicationService) List(params ComplianceApplicationListParams) (response *ListComplianceApplicationResponse, err error) { + request, err := service.client.NewRequest("GET", params, "ComplianceApplication") + if err != nil { + return + } + response = &ListComplianceApplicationResponse{} + err = service.client.ExecuteRequest(request, response) + return +} + +func (service *ComplianceApplicationService) Create(params CreateComplianceApplicationParams) (response *ComplianceApplicationResponse, err error) { + request, err := service.client.NewRequest("POST", params, "ComplianceApplication") + if err != nil { + return + } + response = &ComplianceApplicationResponse{} + err = service.client.ExecuteRequest(request, response) + return +} + +func (service *ComplianceApplicationService) Update(params UpdateComplianceApplicationParams) (response *UpdateComplianceApplicationResponse, err error) { + request, err := service.client.NewRequest("POST", params, "ComplianceApplication/%s", params.ComplianceApplicationId) + if err != nil { + return + } + response = &UpdateComplianceApplicationResponse{} + err = service.client.ExecuteRequest(request, response) + return +} + +func (service *ComplianceApplicationService) Delete(complianceApplicationId string) (err error) { + req, err := service.client.NewRequest("DELETE", nil, "ComplianceApplication/%s", complianceApplicationId) + if err != nil { + return + } + err = service.client.ExecuteRequest(req, nil) + return +} + +func (service *ComplianceApplicationService) Submit(complianceApplicationId string) (response *SubmitComplianceApplicationResponse, err error) { + req, err := service.client.NewRequest("POST", nil, "ComplianceApplication/%s/Submit", complianceApplicationId) + if err != nil { + return + } + response = &SubmitComplianceApplicationResponse{} + err = service.client.ExecuteRequest(req, response) + return +} diff --git a/compliance_document_types.go b/compliance_document_types.go new file mode 100644 index 0000000..be04f1b --- /dev/null +++ b/compliance_document_types.go @@ -0,0 +1,71 @@ +package plivo + +import "time" + +type ComplianceDocumentTypeService struct { + client *Client +} + +type GetComplianceDocumentTypeResponse struct { + APIID string `json:"api_id"` + CreatedAt time.Time `json:"created_at"` + Description string `json:"description"` + DocumentName string `json:"document_name"` + DocumentTypeID string `json:"document_type_id"` + Information []struct { + FieldName string `json:"field_name"` + FieldType string `json:"field_type"` + FriendlyName string `json:"friendly_name"` + HelpText string `json:"help_text,omitempty"` + MaxLength int `json:"max_length,omitempty"` + MinLength int `json:"min_length,omitempty"` + Format string `json:"format,omitempty"` + Enums []string `json:"enums,omitempty"` + } `json:"information"` + ProofRequired interface{} `json:"proof_required"` +} + +type ListComplianceDocumentTypeResponse struct { + APIID string `json:"api_id"` + Meta struct { + Limit int `json:"limit"` + Next interface{} `json:"next"` + Offset int `json:"offset"` + Previous interface{} `json:"previous"` + TotalCount int `json:"total_count"` + } `json:"meta"` + Objects []struct { + CreatedAt time.Time `json:"created_at"` + Description string `json:"description"` + DocumentName string `json:"document_name"` + DocumentTypeID string `json:"document_type_id"` + Information []struct { + FieldName string `json:"field_name"` + FieldType string `json:"field_type"` + Format string `json:"format,omitempty"` + FriendlyName string `json:"friendly_name"` + MaxLength int `json:"max_length,omitempty"` + MinLength int `json:"min_length,omitempty"` + HelpText string `json:"help_text,omitempty"` + Enums []string `json:"enums,omitempty"` + } `json:"information"` + ProofRequired interface{} `json:"proof_required"` + } `json:"objects"` +} + +func (service *ComplianceDocumentTypeService) Get(docId string) (response *GetComplianceDocumentTypeResponse, err error) { + req, err := service.client.NewRequest("GET", nil, "ComplianceDocumentType/%s", docId) + response = &GetComplianceDocumentTypeResponse{} + err = service.client.ExecuteRequest(req, response) + return +} + +func (service *ComplianceDocumentTypeService) List(params BaseListParams) (response *ListComplianceDocumentTypeResponse, err error) { + request, err := service.client.NewRequest("GET", params, "ComplianceDocumentType") + if err != nil { + return + } + response = &ListComplianceDocumentTypeResponse{} + err = service.client.ExecuteRequest(request, response) + return +} diff --git a/compliance_documents.go b/compliance_documents.go new file mode 100644 index 0000000..790bd46 --- /dev/null +++ b/compliance_documents.go @@ -0,0 +1,247 @@ +package plivo + +import ( + "bytes" + "fmt" + "io/ioutil" + "mime/multipart" + "net/http" + "os" + "reflect" + "strings" + "time" +) + +type ComplianceDocumentService struct { + client *Client +} + +type GetComplianceDocumentResponse struct { + APIID string `json:"api_id"` + DocumentID string `json:"document_id"` + EndUserID string `json:"end_user_id"` + DocumentTypeID string `json:"document_type_id"` + Alias string `json:"alias"` + FileName string `json:"file_name"` + MetaInformation struct { + LastName string `json:"last_name,omitempty"` + FirstName string `json:"first_name,omitempty"` + DateOfBirth string `json:"date_of_birth,omitempty"` + AddressLine1 string `json:"address_line_1,omitempty"` + AddressLine2 string `json:"address_line_2,omitempty"` + City string `json:"city,omitempty"` + Country string `json:"country,omitempty"` + PostalCode string `json:"postal_code,omitempty"` + UniqueIdentificationNumber string `json:"unique_identification_number,omitempty"` + Nationality string `json:"nationality,omitempty"` + PlaceOfBirth string `json:"place_of_birth,omitempty"` + DateOfIssue string `json:"date_of_issue,omitempty"` + DateOfExpiration string `json:"date_of_expiration,omitempty"` + TypeOfUtility string `json:"type_of_utility,omitempty"` + BillingId string `json:"billing_id,omitempty"` + BillingDate string `json:"billing_date,omitempty"` + BusinessName string `json:"business_name,omitempty"` + TypeOfId string `json:"type_of_id,omitempty"` + } `json:"meta_information"` + CreatedAt string `json:"created_at"` +} + +type ComplianceDocumentListParams struct { + Limit int `json:"limit,omitempty" url:"limit,omitempty"` + Offset int `json:"offset,omitempty" url:"offset,omitempty"` + EndUserID string `json:"end_user_id,omitempty" url:"end_user_id,omitempty"` + DocumentTypeID string `json:"document_type_id,omitempty" url:"document_type_id,omitempty"` + Alias string `json:"alias,omitempty" url:"alias,omitempty"` +} + +type ListComplianceDocumentResponse struct { + APIID string `json:"api_id"` + Meta struct { + Limit int `json:"limit"` + Next string `json:"next"` + Offset int `json:"offset"` + Previous interface{} `json:"previous"` + TotalCount int `json:"total_count"` + } `json:"meta"` + Objects []struct { + CreatedAt time.Time `json:"created_at"` + ComplianceDocumentID string `json:"compliance_document_id"` + Alias string `json:"alias"` + MetaInformation struct { + LastName string `json:"last_name,omitempty"` + FirstName string `json:"first_name,omitempty"` + DateOfBirth string `json:"date_of_birth,omitempty"` + AddressLine1 string `json:"address_line_1,omitempty"` + AddressLine2 string `json:"address_line_2,omitempty"` + City string `json:"city,omitempty"` + Country string `json:"country,omitempty"` + PostalCode string `json:"postal_code,omitempty"` + UniqueIdentificationNumber string `json:"unique_identification_number,omitempty"` + Nationality string `json:"nationality,omitempty"` + PlaceOfBirth string `json:"place_of_birth,omitempty"` + DateOfIssue string `json:"date_of_issue,omitempty"` + DateOfExpiration string `json:"date_of_expiration,omitempty"` + TypeOfUtility string `json:"type_of_utility,omitempty"` + BillingId string `json:"billing_id,omitempty"` + BillingDate string `json:"billing_date,omitempty"` + BusinessName string `json:"business_name,omitempty"` + TypeOfId string `json:"type_of_id,omitempty"` + } `json:"meta_information"` + File string `json:"file,omitempty"` + EndUserID string `json:"end_user_id"` + DocumentTypeID string `json:"document_type_id"` + } `json:"objects"` +} + +type CreateComplianceDocumentParams struct { + File string `json:"file,omitempty"` + EndUserID string `json:"end_user_id,omitempty"` + DocumentTypeID string `json:"document_type_id,omitempty"` + Alias string `json:"alias,omitempty"` + LastName string `json:"last_name,omitempty"` + FirstName string `json:"first_name,omitempty"` + DateOfBirth string `json:"date_of_birth,omitempty"` + AddressLine1 string `json:"address_line_1,omitempty"` + AddressLine2 string `json:"address_line_2,omitempty"` + City string `json:"city,omitempty"` + Country string `json:"country,omitempty"` + PostalCode string `json:"postal_code,omitempty"` + UniqueIdentificationNumber string `json:"unique_identification_number,omitempty"` + Nationality string `json:"nationality,omitempty"` + PlaceOfBirth string `json:"place_of_birth,omitempty"` + DateOfIssue string `json:"date_of_issue,omitempty"` + DateOfExpiration string `json:"date_of_expiration,omitempty"` + TypeOfUtility string `json:"type_of_utility,omitempty"` + BillingId string `json:"billing_id,omitempty"` + BillingDate string `json:"billing_date,omitempty"` + BusinessName string `json:"business_name,omitempty"` + TypeOfId string `json:"type_of_id,omitempty"` +} + +type UpdateComplianceDocumentParams struct { + ComplianceDocumentID string `json:compliance_document_id` + CreateComplianceDocumentParams +} + +type UpdateComplianceDocumentResponse BaseResponse + +func (service *ComplianceDocumentService) Get(complianceDocumentId string) (response *GetComplianceDocumentResponse, err error) { + req, err := service.client.NewRequest("GET", nil, "ComplianceDocument/%s", complianceDocumentId) + response = &GetComplianceDocumentResponse{} + err = service.client.ExecuteRequest(req, response) + return +} + +func (service *ComplianceDocumentService) List(params ComplianceDocumentListParams) (response *ListComplianceDocumentResponse, err error) { + request, err := service.client.NewRequest("GET", params, "ComplianceDocument") + if err != nil { + return + } + response = &ListComplianceDocumentResponse{} + err = service.client.ExecuteRequest(request, response) + return +} + +func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) { + body := new(bytes.Buffer) + writer := multipart.NewWriter(body) + if path != "" { + file, err := os.Open(path) + if err != nil { + return nil, err + } + fileContents, err := ioutil.ReadAll(file) + if err != nil { + return nil, err + } + fi, err := file.Stat() + if err != nil { + return nil, err + } + file.Close() + + part, err := writer.CreateFormFile(paramName, fi.Name()) + if err != nil { + return nil, err + } + part.Write(fileContents) + } + + for key, val := range params { + _ = writer.WriteField(key, val) + } + err := writer.Close() + if err != nil { + return nil, err + } + request, err := http.NewRequest("POST", uri, body) + if err != nil { + return request, err + } + request.Header.Set("Content-Type", writer.FormDataContentType()) + + return request, nil +} + +func (service *ComplianceDocumentService) Create(params CreateComplianceDocumentParams) (response *GetComplianceDocumentResponse, err error) { + requestUrl := service.client.BaseUrl + requestUrl.Path = fmt.Sprintf(baseRequestString, fmt.Sprintf(service.client.AuthId+"/ComplianceDocument")) + + requestParams := make(map[string]string) + fields := reflect.TypeOf(params) + values := reflect.ValueOf(params) + num := fields.NumField() + for i:=0; i