github.com/twilio/twilio-go@v1.20.1/rest/messaging/v1/link_shortening_domains_config.go (about)

     1  /*
     2   * This code was generated by
     3   * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
     4   *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
     5   *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
     6   *
     7   * Twilio - Messaging
     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  //
    25  func (c *ApiService) FetchDomainConfig(DomainSid string) (*MessagingV1DomainConfig, error) {
    26  	path := "/v1/LinkShortening/Domains/{DomainSid}/Config"
    27  	path = strings.Replace(path, "{"+"DomainSid"+"}", DomainSid, -1)
    28  
    29  	data := url.Values{}
    30  	headers := make(map[string]interface{})
    31  
    32  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	defer resp.Body.Close()
    38  
    39  	ps := &MessagingV1DomainConfig{}
    40  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    41  		return nil, err
    42  	}
    43  
    44  	return ps, err
    45  }
    46  
    47  // Optional parameters for the method 'UpdateDomainConfig'
    48  type UpdateDomainConfigParams struct {
    49  	// Any requests we receive to this domain that do not match an existing shortened message will be redirected to the fallback url. These will likely be either expired messages, random misdirected traffic, or intentional scraping.
    50  	FallbackUrl *string `json:"FallbackUrl,omitempty"`
    51  	// URL to receive click events to your webhook whenever the recipients click on the shortened links
    52  	CallbackUrl *string `json:"CallbackUrl,omitempty"`
    53  	// Boolean field to set customer delivery preference when there is a failure in linkShortening service
    54  	ContinueOnFailure *bool `json:"ContinueOnFailure,omitempty"`
    55  	// Customer's choice to send links with/without \\\"https://\\\" attached to shortened url. If true, messages will not be sent with https:// at the beginning of the url. If false, messages will be sent with https:// at the beginning of the url. False is the default behavior if it is not specified.
    56  	DisableHttps *bool `json:"DisableHttps,omitempty"`
    57  }
    58  
    59  func (params *UpdateDomainConfigParams) SetFallbackUrl(FallbackUrl string) *UpdateDomainConfigParams {
    60  	params.FallbackUrl = &FallbackUrl
    61  	return params
    62  }
    63  func (params *UpdateDomainConfigParams) SetCallbackUrl(CallbackUrl string) *UpdateDomainConfigParams {
    64  	params.CallbackUrl = &CallbackUrl
    65  	return params
    66  }
    67  func (params *UpdateDomainConfigParams) SetContinueOnFailure(ContinueOnFailure bool) *UpdateDomainConfigParams {
    68  	params.ContinueOnFailure = &ContinueOnFailure
    69  	return params
    70  }
    71  func (params *UpdateDomainConfigParams) SetDisableHttps(DisableHttps bool) *UpdateDomainConfigParams {
    72  	params.DisableHttps = &DisableHttps
    73  	return params
    74  }
    75  
    76  //
    77  func (c *ApiService) UpdateDomainConfig(DomainSid string, params *UpdateDomainConfigParams) (*MessagingV1DomainConfig, error) {
    78  	path := "/v1/LinkShortening/Domains/{DomainSid}/Config"
    79  	path = strings.Replace(path, "{"+"DomainSid"+"}", DomainSid, -1)
    80  
    81  	data := url.Values{}
    82  	headers := make(map[string]interface{})
    83  
    84  	if params != nil && params.FallbackUrl != nil {
    85  		data.Set("FallbackUrl", *params.FallbackUrl)
    86  	}
    87  	if params != nil && params.CallbackUrl != nil {
    88  		data.Set("CallbackUrl", *params.CallbackUrl)
    89  	}
    90  	if params != nil && params.ContinueOnFailure != nil {
    91  		data.Set("ContinueOnFailure", fmt.Sprint(*params.ContinueOnFailure))
    92  	}
    93  	if params != nil && params.DisableHttps != nil {
    94  		data.Set("DisableHttps", fmt.Sprint(*params.DisableHttps))
    95  	}
    96  
    97  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
    98  	if err != nil {
    99  		return nil, err
   100  	}
   101  
   102  	defer resp.Body.Close()
   103  
   104  	ps := &MessagingV1DomainConfig{}
   105  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   106  		return nil, err
   107  	}
   108  
   109  	return ps, err
   110  }