github.com/twilio/twilio-go@v1.20.1/rest/verify/v2/attempts_summary.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  	"time"
    22  )
    23  
    24  // Optional parameters for the method 'FetchVerificationAttemptsSummary'
    25  type FetchVerificationAttemptsSummaryParams struct {
    26  	// Filter used to consider only Verification Attempts of the given verify service on the summary aggregation.
    27  	VerifyServiceSid *string `json:"VerifyServiceSid,omitempty"`
    28  	// Datetime filter used to consider only Verification Attempts created after this datetime on the summary aggregation. Given as GMT in ISO 8601 formatted datetime string: yyyy-MM-dd'T'HH:mm:ss'Z.
    29  	DateCreatedAfter *time.Time `json:"DateCreatedAfter,omitempty"`
    30  	// Datetime filter used to consider only Verification Attempts created before this datetime on the summary aggregation. Given as GMT in ISO 8601 formatted datetime string: yyyy-MM-dd'T'HH:mm:ss'Z.
    31  	DateCreatedBefore *time.Time `json:"DateCreatedBefore,omitempty"`
    32  	// Filter used to consider only Verification Attempts sent to the specified destination country on the summary aggregation.
    33  	Country *string `json:"Country,omitempty"`
    34  	// Filter Verification Attempts considered on the summary aggregation by communication channel. Valid values are `SMS`, `CALL` and `WHATSAPP`
    35  	Channel *string `json:"Channel,omitempty"`
    36  	// Filter the Verification Attempts considered on the summary aggregation by Destination prefix. It is the prefix of a phone number in E.164 format.
    37  	DestinationPrefix *string `json:"DestinationPrefix,omitempty"`
    38  }
    39  
    40  func (params *FetchVerificationAttemptsSummaryParams) SetVerifyServiceSid(VerifyServiceSid string) *FetchVerificationAttemptsSummaryParams {
    41  	params.VerifyServiceSid = &VerifyServiceSid
    42  	return params
    43  }
    44  func (params *FetchVerificationAttemptsSummaryParams) SetDateCreatedAfter(DateCreatedAfter time.Time) *FetchVerificationAttemptsSummaryParams {
    45  	params.DateCreatedAfter = &DateCreatedAfter
    46  	return params
    47  }
    48  func (params *FetchVerificationAttemptsSummaryParams) SetDateCreatedBefore(DateCreatedBefore time.Time) *FetchVerificationAttemptsSummaryParams {
    49  	params.DateCreatedBefore = &DateCreatedBefore
    50  	return params
    51  }
    52  func (params *FetchVerificationAttemptsSummaryParams) SetCountry(Country string) *FetchVerificationAttemptsSummaryParams {
    53  	params.Country = &Country
    54  	return params
    55  }
    56  func (params *FetchVerificationAttemptsSummaryParams) SetChannel(Channel string) *FetchVerificationAttemptsSummaryParams {
    57  	params.Channel = &Channel
    58  	return params
    59  }
    60  func (params *FetchVerificationAttemptsSummaryParams) SetDestinationPrefix(DestinationPrefix string) *FetchVerificationAttemptsSummaryParams {
    61  	params.DestinationPrefix = &DestinationPrefix
    62  	return params
    63  }
    64  
    65  // Get a summary of how many attempts were made and how many were converted.
    66  func (c *ApiService) FetchVerificationAttemptsSummary(params *FetchVerificationAttemptsSummaryParams) (*VerifyV2VerificationAttemptsSummary, error) {
    67  	path := "/v2/Attempts/Summary"
    68  
    69  	data := url.Values{}
    70  	headers := make(map[string]interface{})
    71  
    72  	if params != nil && params.VerifyServiceSid != nil {
    73  		data.Set("VerifyServiceSid", *params.VerifyServiceSid)
    74  	}
    75  	if params != nil && params.DateCreatedAfter != nil {
    76  		data.Set("DateCreatedAfter", fmt.Sprint((*params.DateCreatedAfter).Format(time.RFC3339)))
    77  	}
    78  	if params != nil && params.DateCreatedBefore != nil {
    79  		data.Set("DateCreatedBefore", fmt.Sprint((*params.DateCreatedBefore).Format(time.RFC3339)))
    80  	}
    81  	if params != nil && params.Country != nil {
    82  		data.Set("Country", *params.Country)
    83  	}
    84  	if params != nil && params.Channel != nil {
    85  		data.Set("Channel", *params.Channel)
    86  	}
    87  	if params != nil && params.DestinationPrefix != nil {
    88  		data.Set("DestinationPrefix", *params.DestinationPrefix)
    89  	}
    90  
    91  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    92  	if err != nil {
    93  		return nil, err
    94  	}
    95  
    96  	defer resp.Body.Close()
    97  
    98  	ps := &VerifyV2VerificationAttemptsSummary{}
    99  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   100  		return nil, err
   101  	}
   102  
   103  	return ps, err
   104  }