github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_calls_user_defined_message_subscriptions.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Api 8 * This is the public Twilio REST API. 9 * 10 * NOTE: This class is auto generated by OpenAPI Generator. 11 * https://openapi-generator.tech 12 * Do not edit the class manually. 13 */ 14 15 package openapi 16 17 import ( 18 "encoding/json" 19 "net/url" 20 "strings" 21 ) 22 23 // Optional parameters for the method 'CreateUserDefinedMessageSubscription' 24 type CreateUserDefinedMessageSubscriptionParams struct { 25 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that subscribed to the User Defined Messages. 26 PathAccountSid *string `json:"PathAccountSid,omitempty"` 27 // The URL we should call using the `method` to send user defined events to your application. URLs must contain a valid hostname (underscores are not permitted). 28 Callback *string `json:"Callback,omitempty"` 29 // A unique string value to identify API call. This should be a unique string value per API call and can be a randomly generated. 30 IdempotencyKey *string `json:"IdempotencyKey,omitempty"` 31 // The HTTP method Twilio will use when requesting the above `Url`. Either `GET` or `POST`. Default is `POST`. 32 Method *string `json:"Method,omitempty"` 33 } 34 35 func (params *CreateUserDefinedMessageSubscriptionParams) SetPathAccountSid(PathAccountSid string) *CreateUserDefinedMessageSubscriptionParams { 36 params.PathAccountSid = &PathAccountSid 37 return params 38 } 39 func (params *CreateUserDefinedMessageSubscriptionParams) SetCallback(Callback string) *CreateUserDefinedMessageSubscriptionParams { 40 params.Callback = &Callback 41 return params 42 } 43 func (params *CreateUserDefinedMessageSubscriptionParams) SetIdempotencyKey(IdempotencyKey string) *CreateUserDefinedMessageSubscriptionParams { 44 params.IdempotencyKey = &IdempotencyKey 45 return params 46 } 47 func (params *CreateUserDefinedMessageSubscriptionParams) SetMethod(Method string) *CreateUserDefinedMessageSubscriptionParams { 48 params.Method = &Method 49 return params 50 } 51 52 // Subscribe to User Defined Messages for a given Call SID. 53 func (c *ApiService) CreateUserDefinedMessageSubscription(CallSid string, params *CreateUserDefinedMessageSubscriptionParams) (*ApiV2010UserDefinedMessageSubscription, error) { 54 path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions.json" 55 if params != nil && params.PathAccountSid != nil { 56 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 57 } else { 58 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 59 } 60 path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1) 61 62 data := url.Values{} 63 headers := make(map[string]interface{}) 64 65 if params != nil && params.Callback != nil { 66 data.Set("Callback", *params.Callback) 67 } 68 if params != nil && params.IdempotencyKey != nil { 69 data.Set("IdempotencyKey", *params.IdempotencyKey) 70 } 71 if params != nil && params.Method != nil { 72 data.Set("Method", *params.Method) 73 } 74 75 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 76 if err != nil { 77 return nil, err 78 } 79 80 defer resp.Body.Close() 81 82 ps := &ApiV2010UserDefinedMessageSubscription{} 83 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 84 return nil, err 85 } 86 87 return ps, err 88 } 89 90 // Optional parameters for the method 'DeleteUserDefinedMessageSubscription' 91 type DeleteUserDefinedMessageSubscriptionParams struct { 92 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that subscribed to the User Defined Messages. 93 PathAccountSid *string `json:"PathAccountSid,omitempty"` 94 } 95 96 func (params *DeleteUserDefinedMessageSubscriptionParams) SetPathAccountSid(PathAccountSid string) *DeleteUserDefinedMessageSubscriptionParams { 97 params.PathAccountSid = &PathAccountSid 98 return params 99 } 100 101 // Delete a specific User Defined Message Subscription. 102 func (c *ApiService) DeleteUserDefinedMessageSubscription(CallSid string, Sid string, params *DeleteUserDefinedMessageSubscriptionParams) error { 103 path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions/{Sid}.json" 104 if params != nil && params.PathAccountSid != nil { 105 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 106 } else { 107 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 108 } 109 path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1) 110 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 111 112 data := url.Values{} 113 headers := make(map[string]interface{}) 114 115 resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) 116 if err != nil { 117 return err 118 } 119 120 defer resp.Body.Close() 121 122 return nil 123 }