private void List(string spaceId, string personId, string personEmail, int?max, Action <WebexApiEventArgs <List <Membership> > > completionHandler) { ServiceRequest request = BuildRequest(); request.Method = HttpMethod.GET; request.RootElement = "items"; if (spaceId != null) { request.AddQueryParameters("roomId", spaceId); } if (personId != null) { request.AddQueryParameters("personId", personId); } if (personEmail != null) { request.AddQueryParameters("personEmail", personEmail); } if (max != null) { request.AddQueryParameters("max", max.ToString()); } request.Execute <List <InternalMembership> >(r => { List <Membership> m = null; if (r.IsSuccess) { m = new List <Membership>(); foreach (var item in r.Data) { m.Add(ConvertToMembership(item)); } } completionHandler?.Invoke(new WebexApiEventArgs <List <Membership> >(r.IsSuccess, r.Error, m)); }); }
public void Execute <T>(ServiceRequest serviceRequest, Action <ServiceRequest.Response <T> > completedhandler) where T : new() { if (serviceRequest == null) { SdkLogger.Instance.Error("serviceRequest is null."); completedhandler?.Invoke(new ServiceRequest.Response <T>() { StatusCode = 0 }); return; } RestRequest request = new RestRequest(serviceRequest.Resource, (Method)serviceRequest.Method); if (serviceRequest.AccessToken != null) { request.AddHeader("Authorization", "Bearer " + serviceRequest.AccessToken); } foreach (var pair in serviceRequest.Headers) { request.AddHeader(pair.Key, pair.Value); } foreach (var pair in serviceRequest.QueryParameters) { request.AddParameter(pair.Key, pair.Value, ParameterType.GetOrPost); } foreach (var pair in serviceRequest.BodyParameters) { request.AddParameter(pair.Key, pair.Value, ParameterType.GetOrPost); } if (serviceRequest.RootElement.Length != 0) { request.RootElement = serviceRequest.RootElement; } //Cisco Webex platform is dropping support for TLS 1.0 as of March 16, 2018 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11; var client = new RestClient() { BaseUrl = new System.Uri(serviceRequest.BaseUri) }; SdkLogger.Instance.Info($"http request[{serviceRequest.Method.ToString()}]: {serviceRequest.BaseUri + request.Resource}"); client.ExecuteAsync <T>(request, response => { var r = new ServiceRequest.Response <T> { StatusCode = (int)response.StatusCode, StatusDescription = response.StatusDescription, Headers = new List <KeyValuePair <string, object> >() }; foreach (var i in response.Headers) { r.Headers.Add(new KeyValuePair <string, object>(i.Name, i.Value)); } r.Data = response.Data; completedhandler?.Invoke(r); }); }