/
api_op_create.go
86 lines (75 loc) · 3.36 KB
/
api_op_create.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
// Package factors contains auto-generated files. DO NOT MODIFY
package factors
import (
"context"
"net/http"
"time"
"github.com/RJPearson94/twilio-sdk-go/client"
)
type CreateFactorBindingInput struct {
Alg string `validate:"required" form:"Alg"`
PublicKey string `validate:"required" form:"PublicKey"`
}
type CreateFactorConfigInput struct {
AppId string `validate:"required" form:"AppId"`
NotificationPlatform string `validate:"required" form:"NotificationPlatform"`
NotificationToken string `validate:"required" form:"NotificationToken"`
SdkVersion *string `form:"SdkVersion,omitempty"`
}
// CreateFactorInput defines the input fields for creating a new factor
type CreateFactorInput struct {
Binding CreateFactorBindingInput `validate:"required" form:"Binding"`
Config CreateFactorConfigInput `validate:"required" form:"Config"`
FactorType string `validate:"required" form:"FactorType"`
FriendlyName string `validate:"required" form:"FriendlyName"`
}
type CreateFactorConfigResponse struct {
AppId string `json:"app_id"`
NotificationPlatform string `json:"notification_platform"`
NotificationToken string `json:"notification_token"`
SdkVersion *string `json:"sdk_version,omitempty"`
}
// CreateFactorResponse defines the response fields for the created factor
type CreateFactorResponse struct {
AccountSid string `json:"account_sid"`
Config CreateFactorConfigResponse `json:"config"`
DateCreated time.Time `json:"date_created"`
DateUpdated *time.Time `json:"date_updated,omitempty"`
EntitySid string `json:"entity_sid"`
FactorType string `json:"factor_type"`
FriendlyName string `json:"friendly_name"`
Identity string `json:"identity"`
ServiceSid string `json:"service_sid"`
Sid string `json:"sid"`
Status string `json:"status"`
URL string `json:"url"`
}
// Create creates a new factor
// See https://www.twilio.com/docs/verify/api/factor#create-a-factor-resource for more details
// Context is defaulted to Background. See https://golang.org/pkg/context/#Background for more information
// This resource is currently in beta and subject to change. Please use with caution
func (c Client) Create(input *CreateFactorInput) (*CreateFactorResponse, error) {
return c.CreateWithContext(context.Background(), input)
}
// CreateWithContext creates a new factor
// See https://www.twilio.com/docs/verify/api/factor#create-a-factor-resource for more details
// This resource is currently in beta and subject to change. Please use with caution
func (c Client) CreateWithContext(context context.Context, input *CreateFactorInput) (*CreateFactorResponse, error) {
op := client.Operation{
Method: http.MethodPost,
URI: "/Services/{serviceSid}/Entities/{identity}/Factors",
ContentType: client.URLEncoded,
PathParams: map[string]string{
"serviceSid": c.serviceSid,
"identity": c.identity,
},
}
if input == nil {
input = &CreateFactorInput{}
}
response := &CreateFactorResponse{}
if err := c.client.Send(context, op, input, response); err != nil {
return nil, err
}
return response, nil
}