github.com/twilio/twilio-go@v1.20.1/rest/insights/v1/conferences_participants.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 // Optional parameters for the method 'FetchConferenceParticipant' 27 type FetchConferenceParticipantParams struct { 28 // Conference events generated by application or participant activity; e.g. `hold`, `mute`, etc. 29 Events *string `json:"Events,omitempty"` 30 // Object. Contains participant call quality metrics. 31 Metrics *string `json:"Metrics,omitempty"` 32 } 33 34 func (params *FetchConferenceParticipantParams) SetEvents(Events string) *FetchConferenceParticipantParams { 35 params.Events = &Events 36 return params 37 } 38 func (params *FetchConferenceParticipantParams) SetMetrics(Metrics string) *FetchConferenceParticipantParams { 39 params.Metrics = &Metrics 40 return params 41 } 42 43 // Get a specific Conference Participant Summary for a Conference. 44 func (c *ApiService) FetchConferenceParticipant(ConferenceSid string, ParticipantSid string, params *FetchConferenceParticipantParams) (*InsightsV1ConferenceParticipant, error) { 45 path := "/v1/Conferences/{ConferenceSid}/Participants/{ParticipantSid}" 46 path = strings.Replace(path, "{"+"ConferenceSid"+"}", ConferenceSid, -1) 47 path = strings.Replace(path, "{"+"ParticipantSid"+"}", ParticipantSid, -1) 48 49 data := url.Values{} 50 headers := make(map[string]interface{}) 51 52 if params != nil && params.Events != nil { 53 data.Set("Events", *params.Events) 54 } 55 if params != nil && params.Metrics != nil { 56 data.Set("Metrics", *params.Metrics) 57 } 58 59 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 60 if err != nil { 61 return nil, err 62 } 63 64 defer resp.Body.Close() 65 66 ps := &InsightsV1ConferenceParticipant{} 67 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 68 return nil, err 69 } 70 71 return ps, err 72 } 73 74 // Optional parameters for the method 'ListConferenceParticipant' 75 type ListConferenceParticipantParams struct { 76 // The unique SID identifier of the Participant. 77 ParticipantSid *string `json:"ParticipantSid,omitempty"` 78 // User-specified label for a participant. 79 Label *string `json:"Label,omitempty"` 80 // Conference events generated by application or participant activity; e.g. `hold`, `mute`, etc. 81 Events *string `json:"Events,omitempty"` 82 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 83 PageSize *int `json:"PageSize,omitempty"` 84 // Max number of records to return. 85 Limit *int `json:"limit,omitempty"` 86 } 87 88 func (params *ListConferenceParticipantParams) SetParticipantSid(ParticipantSid string) *ListConferenceParticipantParams { 89 params.ParticipantSid = &ParticipantSid 90 return params 91 } 92 func (params *ListConferenceParticipantParams) SetLabel(Label string) *ListConferenceParticipantParams { 93 params.Label = &Label 94 return params 95 } 96 func (params *ListConferenceParticipantParams) SetEvents(Events string) *ListConferenceParticipantParams { 97 params.Events = &Events 98 return params 99 } 100 func (params *ListConferenceParticipantParams) SetPageSize(PageSize int) *ListConferenceParticipantParams { 101 params.PageSize = &PageSize 102 return params 103 } 104 func (params *ListConferenceParticipantParams) SetLimit(Limit int) *ListConferenceParticipantParams { 105 params.Limit = &Limit 106 return params 107 } 108 109 // Retrieve a single page of ConferenceParticipant records from the API. Request is executed immediately. 110 func (c *ApiService) PageConferenceParticipant(ConferenceSid string, params *ListConferenceParticipantParams, pageToken, pageNumber string) (*ListConferenceParticipantResponse, error) { 111 path := "/v1/Conferences/{ConferenceSid}/Participants" 112 113 path = strings.Replace(path, "{"+"ConferenceSid"+"}", ConferenceSid, -1) 114 115 data := url.Values{} 116 headers := make(map[string]interface{}) 117 118 if params != nil && params.ParticipantSid != nil { 119 data.Set("ParticipantSid", *params.ParticipantSid) 120 } 121 if params != nil && params.Label != nil { 122 data.Set("Label", *params.Label) 123 } 124 if params != nil && params.Events != nil { 125 data.Set("Events", *params.Events) 126 } 127 if params != nil && params.PageSize != nil { 128 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 129 } 130 131 if pageToken != "" { 132 data.Set("PageToken", pageToken) 133 } 134 if pageNumber != "" { 135 data.Set("Page", pageNumber) 136 } 137 138 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 139 if err != nil { 140 return nil, err 141 } 142 143 defer resp.Body.Close() 144 145 ps := &ListConferenceParticipantResponse{} 146 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 147 return nil, err 148 } 149 150 return ps, err 151 } 152 153 // Lists ConferenceParticipant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 154 func (c *ApiService) ListConferenceParticipant(ConferenceSid string, params *ListConferenceParticipantParams) ([]InsightsV1ConferenceParticipant, error) { 155 response, errors := c.StreamConferenceParticipant(ConferenceSid, params) 156 157 records := make([]InsightsV1ConferenceParticipant, 0) 158 for record := range response { 159 records = append(records, record) 160 } 161 162 if err := <-errors; err != nil { 163 return nil, err 164 } 165 166 return records, nil 167 } 168 169 // Streams ConferenceParticipant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 170 func (c *ApiService) StreamConferenceParticipant(ConferenceSid string, params *ListConferenceParticipantParams) (chan InsightsV1ConferenceParticipant, chan error) { 171 if params == nil { 172 params = &ListConferenceParticipantParams{} 173 } 174 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 175 176 recordChannel := make(chan InsightsV1ConferenceParticipant, 1) 177 errorChannel := make(chan error, 1) 178 179 response, err := c.PageConferenceParticipant(ConferenceSid, params, "", "") 180 if err != nil { 181 errorChannel <- err 182 close(recordChannel) 183 close(errorChannel) 184 } else { 185 go c.streamConferenceParticipant(response, params, recordChannel, errorChannel) 186 } 187 188 return recordChannel, errorChannel 189 } 190 191 func (c *ApiService) streamConferenceParticipant(response *ListConferenceParticipantResponse, params *ListConferenceParticipantParams, recordChannel chan InsightsV1ConferenceParticipant, errorChannel chan error) { 192 curRecord := 1 193 194 for response != nil { 195 responseRecords := response.Participants 196 for item := range responseRecords { 197 recordChannel <- responseRecords[item] 198 curRecord += 1 199 if params.Limit != nil && *params.Limit < curRecord { 200 close(recordChannel) 201 close(errorChannel) 202 return 203 } 204 } 205 206 record, err := client.GetNext(c.baseURL, response, c.getNextListConferenceParticipantResponse) 207 if err != nil { 208 errorChannel <- err 209 break 210 } else if record == nil { 211 break 212 } 213 214 response = record.(*ListConferenceParticipantResponse) 215 } 216 217 close(recordChannel) 218 close(errorChannel) 219 } 220 221 func (c *ApiService) getNextListConferenceParticipantResponse(nextPageUrl string) (interface{}, error) { 222 if nextPageUrl == "" { 223 return nil, nil 224 } 225 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 226 if err != nil { 227 return nil, err 228 } 229 230 defer resp.Body.Close() 231 232 ps := &ListConferenceParticipantResponse{} 233 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 234 return nil, err 235 } 236 return ps, nil 237 }