github.com/twilio/twilio-go@v1.20.1/rest/verify/v2/services_entities_challenges_notifications.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 'CreateNotification'
    25  type CreateNotificationParams struct {
    26  	// How long, in seconds, the notification is valid. Can be an integer between 0 and 300. Default is 300. Delivery is attempted until the TTL elapses, even if the device is offline. 0 means that the notification delivery is attempted immediately, only once, and is not stored for future delivery.
    27  	Ttl *int `json:"Ttl,omitempty"`
    28  }
    29  
    30  func (params *CreateNotificationParams) SetTtl(Ttl int) *CreateNotificationParams {
    31  	params.Ttl = &Ttl
    32  	return params
    33  }
    34  
    35  // Create a new Notification for the corresponding Challenge
    36  func (c *ApiService) CreateNotification(ServiceSid string, Identity string, ChallengeSid string, params *CreateNotificationParams) (*VerifyV2Notification, error) {
    37  	path := "/v2/Services/{ServiceSid}/Entities/{Identity}/Challenges/{ChallengeSid}/Notifications"
    38  	path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1)
    39  	path = strings.Replace(path, "{"+"Identity"+"}", Identity, -1)
    40  	path = strings.Replace(path, "{"+"ChallengeSid"+"}", ChallengeSid, -1)
    41  
    42  	data := url.Values{}
    43  	headers := make(map[string]interface{})
    44  
    45  	if params != nil && params.Ttl != nil {
    46  		data.Set("Ttl", fmt.Sprint(*params.Ttl))
    47  	}
    48  
    49  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  
    54  	defer resp.Body.Close()
    55  
    56  	ps := &VerifyV2Notification{}
    57  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    58  		return nil, err
    59  	}
    60  
    61  	return ps, err
    62  }