github.com/twilio/twilio-go@v1.20.1/rest/verify/v2/services_access_tokens.go (about)

     1  /*
     2   * This code was generated by
     3   * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
     4   *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
     5   *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
     6   *
     7   * Twilio - Verify
     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 'CreateAccessToken'
    25  type CreateAccessTokenParams struct {
    26  	// The unique external identifier for the Entity of the Service. This identifier should be immutable, not PII, and generated by your external system, such as your user's UUID, GUID, or SID.
    27  	Identity *string `json:"Identity,omitempty"`
    28  	//
    29  	FactorType *string `json:"FactorType,omitempty"`
    30  	// The friendly name of the factor that is going to be created with this access token
    31  	FactorFriendlyName *string `json:"FactorFriendlyName,omitempty"`
    32  	// How long, in seconds, the access token is valid. Can be an integer between 60 and 300. Default is 60.
    33  	Ttl *int `json:"Ttl,omitempty"`
    34  }
    35  
    36  func (params *CreateAccessTokenParams) SetIdentity(Identity string) *CreateAccessTokenParams {
    37  	params.Identity = &Identity
    38  	return params
    39  }
    40  func (params *CreateAccessTokenParams) SetFactorType(FactorType string) *CreateAccessTokenParams {
    41  	params.FactorType = &FactorType
    42  	return params
    43  }
    44  func (params *CreateAccessTokenParams) SetFactorFriendlyName(FactorFriendlyName string) *CreateAccessTokenParams {
    45  	params.FactorFriendlyName = &FactorFriendlyName
    46  	return params
    47  }
    48  func (params *CreateAccessTokenParams) SetTtl(Ttl int) *CreateAccessTokenParams {
    49  	params.Ttl = &Ttl
    50  	return params
    51  }
    52  
    53  // Create a new enrollment Access Token for the Entity
    54  func (c *ApiService) CreateAccessToken(ServiceSid string, params *CreateAccessTokenParams) (*VerifyV2AccessToken, error) {
    55  	path := "/v2/Services/{ServiceSid}/AccessTokens"
    56  	path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1)
    57  
    58  	data := url.Values{}
    59  	headers := make(map[string]interface{})
    60  
    61  	if params != nil && params.Identity != nil {
    62  		data.Set("Identity", *params.Identity)
    63  	}
    64  	if params != nil && params.FactorType != nil {
    65  		data.Set("FactorType", *params.FactorType)
    66  	}
    67  	if params != nil && params.FactorFriendlyName != nil {
    68  		data.Set("FactorFriendlyName", *params.FactorFriendlyName)
    69  	}
    70  	if params != nil && params.Ttl != nil {
    71  		data.Set("Ttl", fmt.Sprint(*params.Ttl))
    72  	}
    73  
    74  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
    75  	if err != nil {
    76  		return nil, err
    77  	}
    78  
    79  	defer resp.Body.Close()
    80  
    81  	ps := &VerifyV2AccessToken{}
    82  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    83  		return nil, err
    84  	}
    85  
    86  	return ps, err
    87  }
    88  
    89  // Fetch an Access Token for the Entity
    90  func (c *ApiService) FetchAccessToken(ServiceSid string, Sid string) (*VerifyV2AccessToken, error) {
    91  	path := "/v2/Services/{ServiceSid}/AccessTokens/{Sid}"
    92  	path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1)
    93  	path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)
    94  
    95  	data := url.Values{}
    96  	headers := make(map[string]interface{})
    97  
    98  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    99  	if err != nil {
   100  		return nil, err
   101  	}
   102  
   103  	defer resp.Body.Close()
   104  
   105  	ps := &VerifyV2AccessToken{}
   106  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   107  		return nil, err
   108  	}
   109  
   110  	return ps, err
   111  }