github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_tokens.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  	"fmt"
    20  	"net/url"
    21  	"strings"
    22  )
    23  
    24  // Optional parameters for the method 'CreateToken'
    25  type CreateTokenParams struct {
    26  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that will create the resource.
    27  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
    28  	// The duration in seconds for which the generated credentials are valid. The default value is 86400 (24 hours).
    29  	Ttl *int `json:"Ttl,omitempty"`
    30  }
    31  
    32  func (params *CreateTokenParams) SetPathAccountSid(PathAccountSid string) *CreateTokenParams {
    33  	params.PathAccountSid = &PathAccountSid
    34  	return params
    35  }
    36  func (params *CreateTokenParams) SetTtl(Ttl int) *CreateTokenParams {
    37  	params.Ttl = &Ttl
    38  	return params
    39  }
    40  
    41  // Create a new token for ICE servers
    42  func (c *ApiService) CreateToken(params *CreateTokenParams) (*ApiV2010Token, error) {
    43  	path := "/2010-04-01/Accounts/{AccountSid}/Tokens.json"
    44  	if params != nil && params.PathAccountSid != nil {
    45  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
    46  	} else {
    47  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
    48  	}
    49  
    50  	data := url.Values{}
    51  	headers := make(map[string]interface{})
    52  
    53  	if params != nil && params.Ttl != nil {
    54  		data.Set("Ttl", fmt.Sprint(*params.Ttl))
    55  	}
    56  
    57  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
    58  	if err != nil {
    59  		return nil, err
    60  	}
    61  
    62  	defer resp.Body.Close()
    63  
    64  	ps := &ApiV2010Token{}
    65  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    66  		return nil, err
    67  	}
    68  
    69  	return ps, err
    70  }