github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_calls_user_defined_messages.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 'CreateUserDefinedMessage'
    24  type CreateUserDefinedMessageParams struct {
    25  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created User Defined Message.
    26  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
    27  	// The User Defined Message in the form of URL-encoded JSON string.
    28  	Content *string `json:"Content,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  }
    32  
    33  func (params *CreateUserDefinedMessageParams) SetPathAccountSid(PathAccountSid string) *CreateUserDefinedMessageParams {
    34  	params.PathAccountSid = &PathAccountSid
    35  	return params
    36  }
    37  func (params *CreateUserDefinedMessageParams) SetContent(Content string) *CreateUserDefinedMessageParams {
    38  	params.Content = &Content
    39  	return params
    40  }
    41  func (params *CreateUserDefinedMessageParams) SetIdempotencyKey(IdempotencyKey string) *CreateUserDefinedMessageParams {
    42  	params.IdempotencyKey = &IdempotencyKey
    43  	return params
    44  }
    45  
    46  // Create a new User Defined Message for the given Call SID.
    47  func (c *ApiService) CreateUserDefinedMessage(CallSid string, params *CreateUserDefinedMessageParams) (*ApiV2010UserDefinedMessage, error) {
    48  	path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessages.json"
    49  	if params != nil && params.PathAccountSid != nil {
    50  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
    51  	} else {
    52  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
    53  	}
    54  	path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1)
    55  
    56  	data := url.Values{}
    57  	headers := make(map[string]interface{})
    58  
    59  	if params != nil && params.Content != nil {
    60  		data.Set("Content", *params.Content)
    61  	}
    62  	if params != nil && params.IdempotencyKey != nil {
    63  		data.Set("IdempotencyKey", *params.IdempotencyKey)
    64  	}
    65  
    66  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
    67  	if err != nil {
    68  		return nil, err
    69  	}
    70  
    71  	defer resp.Body.Close()
    72  
    73  	ps := &ApiV2010UserDefinedMessage{}
    74  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    75  		return nil, err
    76  	}
    77  
    78  	return ps, err
    79  }