github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_balance.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  	"net/url"
    20  	"strings"
    21  )
    22  
    23  // Optional parameters for the method 'FetchBalance'
    24  type FetchBalanceParams struct {
    25  	// The unique SID identifier of the Account.
    26  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
    27  }
    28  
    29  func (params *FetchBalanceParams) SetPathAccountSid(PathAccountSid string) *FetchBalanceParams {
    30  	params.PathAccountSid = &PathAccountSid
    31  	return params
    32  }
    33  
    34  // Fetch the balance for an Account based on Account Sid. Balance changes may not be reflected immediately. Child accounts do not contain balance information
    35  func (c *ApiService) FetchBalance(params *FetchBalanceParams) (*ApiV2010Balance, error) {
    36  	path := "/2010-04-01/Accounts/{AccountSid}/Balance.json"
    37  	if params != nil && params.PathAccountSid != nil {
    38  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
    39  	} else {
    40  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
    41  	}
    42  
    43  	data := url.Values{}
    44  	headers := make(map[string]interface{})
    45  
    46  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    47  	if err != nil {
    48  		return nil, err
    49  	}
    50  
    51  	defer resp.Body.Close()
    52  
    53  	ps := &ApiV2010Balance{}
    54  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    55  		return nil, err
    56  	}
    57  
    58  	return ps, err
    59  }