github.com/twilio/twilio-go@v1.20.1/rest/insights/v1/conferences.go (about)

     1  /*
     2   * This code was generated by
     3   * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
     4   *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
     5   *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
     6   *
     7   * Twilio - Insights
     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  // Get a specific Conference Summary.
    27  func (c *ApiService) FetchConference(ConferenceSid string) (*InsightsV1Conference, error) {
    28  	path := "/v1/Conferences/{ConferenceSid}"
    29  	path = strings.Replace(path, "{"+"ConferenceSid"+"}", ConferenceSid, -1)
    30  
    31  	data := url.Values{}
    32  	headers := make(map[string]interface{})
    33  
    34  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    35  	if err != nil {
    36  		return nil, err
    37  	}
    38  
    39  	defer resp.Body.Close()
    40  
    41  	ps := &InsightsV1Conference{}
    42  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    43  		return nil, err
    44  	}
    45  
    46  	return ps, err
    47  }
    48  
    49  // Optional parameters for the method 'ListConference'
    50  type ListConferenceParams struct {
    51  	// The SID of the conference.
    52  	ConferenceSid *string `json:"ConferenceSid,omitempty"`
    53  	// Custom label for the conference resource, up to 64 characters.
    54  	FriendlyName *string `json:"FriendlyName,omitempty"`
    55  	// Conference status.
    56  	Status *string `json:"Status,omitempty"`
    57  	// Conferences created after the provided timestamp specified in ISO 8601 format
    58  	CreatedAfter *string `json:"CreatedAfter,omitempty"`
    59  	// Conferences created before the provided timestamp specified in ISO 8601 format.
    60  	CreatedBefore *string `json:"CreatedBefore,omitempty"`
    61  	// Twilio region where the conference media was mixed.
    62  	MixerRegion *string `json:"MixerRegion,omitempty"`
    63  	// Tags applied by Twilio for common potential configuration, quality, or performance issues.
    64  	Tags *string `json:"Tags,omitempty"`
    65  	// Account SID for the subaccount whose resources you wish to retrieve.
    66  	Subaccount *string `json:"Subaccount,omitempty"`
    67  	// Potential configuration, behavior, or performance issues detected during the conference.
    68  	DetectedIssues *string `json:"DetectedIssues,omitempty"`
    69  	// Conference end reason; e.g. last participant left, modified by API, etc.
    70  	EndReason *string `json:"EndReason,omitempty"`
    71  	// How many resources to return in each list page. The default is 50, and the maximum is 1000.
    72  	PageSize *int `json:"PageSize,omitempty"`
    73  	// Max number of records to return.
    74  	Limit *int `json:"limit,omitempty"`
    75  }
    76  
    77  func (params *ListConferenceParams) SetConferenceSid(ConferenceSid string) *ListConferenceParams {
    78  	params.ConferenceSid = &ConferenceSid
    79  	return params
    80  }
    81  func (params *ListConferenceParams) SetFriendlyName(FriendlyName string) *ListConferenceParams {
    82  	params.FriendlyName = &FriendlyName
    83  	return params
    84  }
    85  func (params *ListConferenceParams) SetStatus(Status string) *ListConferenceParams {
    86  	params.Status = &Status
    87  	return params
    88  }
    89  func (params *ListConferenceParams) SetCreatedAfter(CreatedAfter string) *ListConferenceParams {
    90  	params.CreatedAfter = &CreatedAfter
    91  	return params
    92  }
    93  func (params *ListConferenceParams) SetCreatedBefore(CreatedBefore string) *ListConferenceParams {
    94  	params.CreatedBefore = &CreatedBefore
    95  	return params
    96  }
    97  func (params *ListConferenceParams) SetMixerRegion(MixerRegion string) *ListConferenceParams {
    98  	params.MixerRegion = &MixerRegion
    99  	return params
   100  }
   101  func (params *ListConferenceParams) SetTags(Tags string) *ListConferenceParams {
   102  	params.Tags = &Tags
   103  	return params
   104  }
   105  func (params *ListConferenceParams) SetSubaccount(Subaccount string) *ListConferenceParams {
   106  	params.Subaccount = &Subaccount
   107  	return params
   108  }
   109  func (params *ListConferenceParams) SetDetectedIssues(DetectedIssues string) *ListConferenceParams {
   110  	params.DetectedIssues = &DetectedIssues
   111  	return params
   112  }
   113  func (params *ListConferenceParams) SetEndReason(EndReason string) *ListConferenceParams {
   114  	params.EndReason = &EndReason
   115  	return params
   116  }
   117  func (params *ListConferenceParams) SetPageSize(PageSize int) *ListConferenceParams {
   118  	params.PageSize = &PageSize
   119  	return params
   120  }
   121  func (params *ListConferenceParams) SetLimit(Limit int) *ListConferenceParams {
   122  	params.Limit = &Limit
   123  	return params
   124  }
   125  
   126  // Retrieve a single page of Conference records from the API. Request is executed immediately.
   127  func (c *ApiService) PageConference(params *ListConferenceParams, pageToken, pageNumber string) (*ListConferenceResponse, error) {
   128  	path := "/v1/Conferences"
   129  
   130  	data := url.Values{}
   131  	headers := make(map[string]interface{})
   132  
   133  	if params != nil && params.ConferenceSid != nil {
   134  		data.Set("ConferenceSid", *params.ConferenceSid)
   135  	}
   136  	if params != nil && params.FriendlyName != nil {
   137  		data.Set("FriendlyName", *params.FriendlyName)
   138  	}
   139  	if params != nil && params.Status != nil {
   140  		data.Set("Status", *params.Status)
   141  	}
   142  	if params != nil && params.CreatedAfter != nil {
   143  		data.Set("CreatedAfter", *params.CreatedAfter)
   144  	}
   145  	if params != nil && params.CreatedBefore != nil {
   146  		data.Set("CreatedBefore", *params.CreatedBefore)
   147  	}
   148  	if params != nil && params.MixerRegion != nil {
   149  		data.Set("MixerRegion", *params.MixerRegion)
   150  	}
   151  	if params != nil && params.Tags != nil {
   152  		data.Set("Tags", *params.Tags)
   153  	}
   154  	if params != nil && params.Subaccount != nil {
   155  		data.Set("Subaccount", *params.Subaccount)
   156  	}
   157  	if params != nil && params.DetectedIssues != nil {
   158  		data.Set("DetectedIssues", *params.DetectedIssues)
   159  	}
   160  	if params != nil && params.EndReason != nil {
   161  		data.Set("EndReason", *params.EndReason)
   162  	}
   163  	if params != nil && params.PageSize != nil {
   164  		data.Set("PageSize", fmt.Sprint(*params.PageSize))
   165  	}
   166  
   167  	if pageToken != "" {
   168  		data.Set("PageToken", pageToken)
   169  	}
   170  	if pageNumber != "" {
   171  		data.Set("Page", pageNumber)
   172  	}
   173  
   174  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
   175  	if err != nil {
   176  		return nil, err
   177  	}
   178  
   179  	defer resp.Body.Close()
   180  
   181  	ps := &ListConferenceResponse{}
   182  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   183  		return nil, err
   184  	}
   185  
   186  	return ps, err
   187  }
   188  
   189  // Lists Conference records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning.
   190  func (c *ApiService) ListConference(params *ListConferenceParams) ([]InsightsV1Conference, error) {
   191  	response, errors := c.StreamConference(params)
   192  
   193  	records := make([]InsightsV1Conference, 0)
   194  	for record := range response {
   195  		records = append(records, record)
   196  	}
   197  
   198  	if err := <-errors; err != nil {
   199  		return nil, err
   200  	}
   201  
   202  	return records, nil
   203  }
   204  
   205  // Streams Conference records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached.
   206  func (c *ApiService) StreamConference(params *ListConferenceParams) (chan InsightsV1Conference, chan error) {
   207  	if params == nil {
   208  		params = &ListConferenceParams{}
   209  	}
   210  	params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit))
   211  
   212  	recordChannel := make(chan InsightsV1Conference, 1)
   213  	errorChannel := make(chan error, 1)
   214  
   215  	response, err := c.PageConference(params, "", "")
   216  	if err != nil {
   217  		errorChannel <- err
   218  		close(recordChannel)
   219  		close(errorChannel)
   220  	} else {
   221  		go c.streamConference(response, params, recordChannel, errorChannel)
   222  	}
   223  
   224  	return recordChannel, errorChannel
   225  }
   226  
   227  func (c *ApiService) streamConference(response *ListConferenceResponse, params *ListConferenceParams, recordChannel chan InsightsV1Conference, errorChannel chan error) {
   228  	curRecord := 1
   229  
   230  	for response != nil {
   231  		responseRecords := response.Conferences
   232  		for item := range responseRecords {
   233  			recordChannel <- responseRecords[item]
   234  			curRecord += 1
   235  			if params.Limit != nil && *params.Limit < curRecord {
   236  				close(recordChannel)
   237  				close(errorChannel)
   238  				return
   239  			}
   240  		}
   241  
   242  		record, err := client.GetNext(c.baseURL, response, c.getNextListConferenceResponse)
   243  		if err != nil {
   244  			errorChannel <- err
   245  			break
   246  		} else if record == nil {
   247  			break
   248  		}
   249  
   250  		response = record.(*ListConferenceResponse)
   251  	}
   252  
   253  	close(recordChannel)
   254  	close(errorChannel)
   255  }
   256  
   257  func (c *ApiService) getNextListConferenceResponse(nextPageUrl string) (interface{}, error) {
   258  	if nextPageUrl == "" {
   259  		return nil, nil
   260  	}
   261  	resp, err := c.requestHandler.Get(nextPageUrl, nil, nil)
   262  	if err != nil {
   263  		return nil, err
   264  	}
   265  
   266  	defer resp.Body.Close()
   267  
   268  	ps := &ListConferenceResponse{}
   269  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   270  		return nil, err
   271  	}
   272  	return ps, nil
   273  }