github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_conferences.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  	"fmt"
    20  	"net/url"
    21  	"strings"
    22  
    23  	"github.com/twilio/twilio-go/client"
    24  )
    25  
    26  // Optional parameters for the method 'FetchConference'
    27  type FetchConferenceParams struct {
    28  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Conference resource(s) to fetch.
    29  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
    30  }
    31  
    32  func (params *FetchConferenceParams) SetPathAccountSid(PathAccountSid string) *FetchConferenceParams {
    33  	params.PathAccountSid = &PathAccountSid
    34  	return params
    35  }
    36  
    37  // Fetch an instance of a conference
    38  func (c *ApiService) FetchConference(Sid string, params *FetchConferenceParams) (*ApiV2010Conference, error) {
    39  	path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json"
    40  	if params != nil && params.PathAccountSid != nil {
    41  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
    42  	} else {
    43  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
    44  	}
    45  	path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)
    46  
    47  	data := url.Values{}
    48  	headers := make(map[string]interface{})
    49  
    50  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    51  	if err != nil {
    52  		return nil, err
    53  	}
    54  
    55  	defer resp.Body.Close()
    56  
    57  	ps := &ApiV2010Conference{}
    58  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    59  		return nil, err
    60  	}
    61  
    62  	return ps, err
    63  }
    64  
    65  // Optional parameters for the method 'ListConference'
    66  type ListConferenceParams struct {
    67  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Conference resource(s) to read.
    68  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
    69  	// Only include conferences that were created on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only conferences that were created on this date. You can also specify an inequality, such as `DateCreated<=YYYY-MM-DD`, to read conferences that were created on or before midnight of this date, and `DateCreated>=YYYY-MM-DD` to read conferences that were created on or after midnight of this date.
    70  	DateCreated *string `json:"DateCreated,omitempty"`
    71  	// Only include conferences that were created on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only conferences that were created on this date. You can also specify an inequality, such as `DateCreated<=YYYY-MM-DD`, to read conferences that were created on or before midnight of this date, and `DateCreated>=YYYY-MM-DD` to read conferences that were created on or after midnight of this date.
    72  	DateCreatedBefore *string `json:"DateCreated&lt;,omitempty"`
    73  	// Only include conferences that were created on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only conferences that were created on this date. You can also specify an inequality, such as `DateCreated<=YYYY-MM-DD`, to read conferences that were created on or before midnight of this date, and `DateCreated>=YYYY-MM-DD` to read conferences that were created on or after midnight of this date.
    74  	DateCreatedAfter *string `json:"DateCreated&gt;,omitempty"`
    75  	// Only include conferences that were last updated on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only conferences that were last updated on this date. You can also specify an inequality, such as `DateUpdated<=YYYY-MM-DD`, to read conferences that were last updated on or before midnight of this date, and `DateUpdated>=YYYY-MM-DD` to read conferences that were last updated on or after midnight of this date.
    76  	DateUpdated *string `json:"DateUpdated,omitempty"`
    77  	// Only include conferences that were last updated on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only conferences that were last updated on this date. You can also specify an inequality, such as `DateUpdated<=YYYY-MM-DD`, to read conferences that were last updated on or before midnight of this date, and `DateUpdated>=YYYY-MM-DD` to read conferences that were last updated on or after midnight of this date.
    78  	DateUpdatedBefore *string `json:"DateUpdated&lt;,omitempty"`
    79  	// Only include conferences that were last updated on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only conferences that were last updated on this date. You can also specify an inequality, such as `DateUpdated<=YYYY-MM-DD`, to read conferences that were last updated on or before midnight of this date, and `DateUpdated>=YYYY-MM-DD` to read conferences that were last updated on or after midnight of this date.
    80  	DateUpdatedAfter *string `json:"DateUpdated&gt;,omitempty"`
    81  	// The string that identifies the Conference resources to read.
    82  	FriendlyName *string `json:"FriendlyName,omitempty"`
    83  	// The status of the resources to read. Can be: `init`, `in-progress`, or `completed`.
    84  	Status *string `json:"Status,omitempty"`
    85  	// How many resources to return in each list page. The default is 50, and the maximum is 1000.
    86  	PageSize *int `json:"PageSize,omitempty"`
    87  	// Max number of records to return.
    88  	Limit *int `json:"limit,omitempty"`
    89  }
    90  
    91  func (params *ListConferenceParams) SetPathAccountSid(PathAccountSid string) *ListConferenceParams {
    92  	params.PathAccountSid = &PathAccountSid
    93  	return params
    94  }
    95  func (params *ListConferenceParams) SetDateCreated(DateCreated string) *ListConferenceParams {
    96  	params.DateCreated = &DateCreated
    97  	return params
    98  }
    99  func (params *ListConferenceParams) SetDateCreatedBefore(DateCreatedBefore string) *ListConferenceParams {
   100  	params.DateCreatedBefore = &DateCreatedBefore
   101  	return params
   102  }
   103  func (params *ListConferenceParams) SetDateCreatedAfter(DateCreatedAfter string) *ListConferenceParams {
   104  	params.DateCreatedAfter = &DateCreatedAfter
   105  	return params
   106  }
   107  func (params *ListConferenceParams) SetDateUpdated(DateUpdated string) *ListConferenceParams {
   108  	params.DateUpdated = &DateUpdated
   109  	return params
   110  }
   111  func (params *ListConferenceParams) SetDateUpdatedBefore(DateUpdatedBefore string) *ListConferenceParams {
   112  	params.DateUpdatedBefore = &DateUpdatedBefore
   113  	return params
   114  }
   115  func (params *ListConferenceParams) SetDateUpdatedAfter(DateUpdatedAfter string) *ListConferenceParams {
   116  	params.DateUpdatedAfter = &DateUpdatedAfter
   117  	return params
   118  }
   119  func (params *ListConferenceParams) SetFriendlyName(FriendlyName string) *ListConferenceParams {
   120  	params.FriendlyName = &FriendlyName
   121  	return params
   122  }
   123  func (params *ListConferenceParams) SetStatus(Status string) *ListConferenceParams {
   124  	params.Status = &Status
   125  	return params
   126  }
   127  func (params *ListConferenceParams) SetPageSize(PageSize int) *ListConferenceParams {
   128  	params.PageSize = &PageSize
   129  	return params
   130  }
   131  func (params *ListConferenceParams) SetLimit(Limit int) *ListConferenceParams {
   132  	params.Limit = &Limit
   133  	return params
   134  }
   135  
   136  // Retrieve a single page of Conference records from the API. Request is executed immediately.
   137  func (c *ApiService) PageConference(params *ListConferenceParams, pageToken, pageNumber string) (*ListConferenceResponse, error) {
   138  	path := "/2010-04-01/Accounts/{AccountSid}/Conferences.json"
   139  
   140  	if params != nil && params.PathAccountSid != nil {
   141  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
   142  	} else {
   143  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
   144  	}
   145  
   146  	data := url.Values{}
   147  	headers := make(map[string]interface{})
   148  
   149  	if params != nil && params.DateCreated != nil {
   150  		data.Set("DateCreated", fmt.Sprint(*params.DateCreated))
   151  	}
   152  	if params != nil && params.DateCreatedBefore != nil {
   153  		data.Set("DateCreated<", fmt.Sprint(*params.DateCreatedBefore))
   154  	}
   155  	if params != nil && params.DateCreatedAfter != nil {
   156  		data.Set("DateCreated>", fmt.Sprint(*params.DateCreatedAfter))
   157  	}
   158  	if params != nil && params.DateUpdated != nil {
   159  		data.Set("DateUpdated", fmt.Sprint(*params.DateUpdated))
   160  	}
   161  	if params != nil && params.DateUpdatedBefore != nil {
   162  		data.Set("DateUpdated<", fmt.Sprint(*params.DateUpdatedBefore))
   163  	}
   164  	if params != nil && params.DateUpdatedAfter != nil {
   165  		data.Set("DateUpdated>", fmt.Sprint(*params.DateUpdatedAfter))
   166  	}
   167  	if params != nil && params.FriendlyName != nil {
   168  		data.Set("FriendlyName", *params.FriendlyName)
   169  	}
   170  	if params != nil && params.Status != nil {
   171  		data.Set("Status", *params.Status)
   172  	}
   173  	if params != nil && params.PageSize != nil {
   174  		data.Set("PageSize", fmt.Sprint(*params.PageSize))
   175  	}
   176  
   177  	if pageToken != "" {
   178  		data.Set("PageToken", pageToken)
   179  	}
   180  	if pageNumber != "" {
   181  		data.Set("Page", pageNumber)
   182  	}
   183  
   184  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
   185  	if err != nil {
   186  		return nil, err
   187  	}
   188  
   189  	defer resp.Body.Close()
   190  
   191  	ps := &ListConferenceResponse{}
   192  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   193  		return nil, err
   194  	}
   195  
   196  	return ps, err
   197  }
   198  
   199  // Lists Conference records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning.
   200  func (c *ApiService) ListConference(params *ListConferenceParams) ([]ApiV2010Conference, error) {
   201  	response, errors := c.StreamConference(params)
   202  
   203  	records := make([]ApiV2010Conference, 0)
   204  	for record := range response {
   205  		records = append(records, record)
   206  	}
   207  
   208  	if err := <-errors; err != nil {
   209  		return nil, err
   210  	}
   211  
   212  	return records, nil
   213  }
   214  
   215  // Streams Conference records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached.
   216  func (c *ApiService) StreamConference(params *ListConferenceParams) (chan ApiV2010Conference, chan error) {
   217  	if params == nil {
   218  		params = &ListConferenceParams{}
   219  	}
   220  	params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit))
   221  
   222  	recordChannel := make(chan ApiV2010Conference, 1)
   223  	errorChannel := make(chan error, 1)
   224  
   225  	response, err := c.PageConference(params, "", "")
   226  	if err != nil {
   227  		errorChannel <- err
   228  		close(recordChannel)
   229  		close(errorChannel)
   230  	} else {
   231  		go c.streamConference(response, params, recordChannel, errorChannel)
   232  	}
   233  
   234  	return recordChannel, errorChannel
   235  }
   236  
   237  func (c *ApiService) streamConference(response *ListConferenceResponse, params *ListConferenceParams, recordChannel chan ApiV2010Conference, errorChannel chan error) {
   238  	curRecord := 1
   239  
   240  	for response != nil {
   241  		responseRecords := response.Conferences
   242  		for item := range responseRecords {
   243  			recordChannel <- responseRecords[item]
   244  			curRecord += 1
   245  			if params.Limit != nil && *params.Limit < curRecord {
   246  				close(recordChannel)
   247  				close(errorChannel)
   248  				return
   249  			}
   250  		}
   251  
   252  		record, err := client.GetNext(c.baseURL, response, c.getNextListConferenceResponse)
   253  		if err != nil {
   254  			errorChannel <- err
   255  			break
   256  		} else if record == nil {
   257  			break
   258  		}
   259  
   260  		response = record.(*ListConferenceResponse)
   261  	}
   262  
   263  	close(recordChannel)
   264  	close(errorChannel)
   265  }
   266  
   267  func (c *ApiService) getNextListConferenceResponse(nextPageUrl string) (interface{}, error) {
   268  	if nextPageUrl == "" {
   269  		return nil, nil
   270  	}
   271  	resp, err := c.requestHandler.Get(nextPageUrl, nil, nil)
   272  	if err != nil {
   273  		return nil, err
   274  	}
   275  
   276  	defer resp.Body.Close()
   277  
   278  	ps := &ListConferenceResponse{}
   279  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   280  		return nil, err
   281  	}
   282  	return ps, nil
   283  }
   284  
   285  // Optional parameters for the method 'UpdateConference'
   286  type UpdateConferenceParams struct {
   287  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Conference resource(s) to update.
   288  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
   289  	//
   290  	Status *string `json:"Status,omitempty"`
   291  	// The URL we should call to announce something into the conference. The URL may return an MP3 file, a WAV file, or a TwiML document that contains `<Play>`, `<Say>`, `<Pause>`, or `<Redirect>` verbs.
   292  	AnnounceUrl *string `json:"AnnounceUrl,omitempty"`
   293  	// The HTTP method used to call `announce_url`. Can be: `GET` or `POST` and the default is `POST`
   294  	AnnounceMethod *string `json:"AnnounceMethod,omitempty"`
   295  }
   296  
   297  func (params *UpdateConferenceParams) SetPathAccountSid(PathAccountSid string) *UpdateConferenceParams {
   298  	params.PathAccountSid = &PathAccountSid
   299  	return params
   300  }
   301  func (params *UpdateConferenceParams) SetStatus(Status string) *UpdateConferenceParams {
   302  	params.Status = &Status
   303  	return params
   304  }
   305  func (params *UpdateConferenceParams) SetAnnounceUrl(AnnounceUrl string) *UpdateConferenceParams {
   306  	params.AnnounceUrl = &AnnounceUrl
   307  	return params
   308  }
   309  func (params *UpdateConferenceParams) SetAnnounceMethod(AnnounceMethod string) *UpdateConferenceParams {
   310  	params.AnnounceMethod = &AnnounceMethod
   311  	return params
   312  }
   313  
   314  //
   315  func (c *ApiService) UpdateConference(Sid string, params *UpdateConferenceParams) (*ApiV2010Conference, error) {
   316  	path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json"
   317  	if params != nil && params.PathAccountSid != nil {
   318  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
   319  	} else {
   320  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
   321  	}
   322  	path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)
   323  
   324  	data := url.Values{}
   325  	headers := make(map[string]interface{})
   326  
   327  	if params != nil && params.Status != nil {
   328  		data.Set("Status", *params.Status)
   329  	}
   330  	if params != nil && params.AnnounceUrl != nil {
   331  		data.Set("AnnounceUrl", *params.AnnounceUrl)
   332  	}
   333  	if params != nil && params.AnnounceMethod != nil {
   334  		data.Set("AnnounceMethod", *params.AnnounceMethod)
   335  	}
   336  
   337  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
   338  	if err != nil {
   339  		return nil, err
   340  	}
   341  
   342  	defer resp.Body.Close()
   343  
   344  	ps := &ApiV2010Conference{}
   345  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   346  		return nil, err
   347  	}
   348  
   349  	return ps, err
   350  }