public SSEClient <T> SubscribeToSSE <T>(string urlPattern, NameValueCollection pathNVC, QueryStringBuilder qsb) { ValidateAndProcessParams(ref urlPattern, ref pathNVC, ref qsb); var url = $"{baseSSEURL}{urlPattern}{qsb.Build()}"; return(new SSEClient <T>(Configuration.Builder(new Uri(url)).Build())); }
public async Task <IEXResponse <ReturnType> > ExecuteAsync <ReturnType>(string urlPattern, NameValueCollection pathNVC, QueryStringBuilder qsb) where ReturnType : class { ValidateAndProcessParams(ref urlPattern, ref pathNVC, ref qsb); if (!string.IsNullOrEmpty(publishableToken)) { qsb.Add("token", publishableToken); } var content = string.Empty; if (sign) { client.DefaultRequestHeaders.Remove("x-iex-date"); client.DefaultRequestHeaders.Remove("Authorization"); (string iexdate, string authorization_header)headers = signer.Sign(publishableToken, "GET", urlPattern, qsb.Build()); client.DefaultRequestHeaders.TryAddWithoutValidation("x-iex-date", headers.iexdate); client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", headers.authorization_header); } using (var responseContent = await client.GetAsync($"{urlPattern}{qsb.Build()}")) { try { content = await responseContent.Content.ReadAsStringAsync(); if (content.Length > 7 && content.Substring(startIndex: 0, length: 8) == "{\"error\"") { // {"error":"child \"token\" fails because [\"token\" must be a string]"} var token = JToken.Parse(content); return(new IEXResponse <ReturnType>() { ErrorMessage = token["error"].ToString() }); } else { return new IEXResponse <ReturnType>() { Data = JsonConvert.DeserializeObject <ReturnType>(content, jsonSerializerSettings) } }; } catch (JsonException ex) { throw new JsonException(content, ex); } } }
public async Task <ReturnType> ExecuteAsyncLegacy <ReturnType>(string urlPattern, NameValueCollection pathNVC, QueryStringBuilder qsb) where ReturnType : class { ValidateAndProcessParams(ref urlPattern, ref pathNVC, ref qsb); if (!string.IsNullOrEmpty(publishableToken)) { qsb.Add("token", publishableToken); } var content = string.Empty; if (sign) { client.DefaultRequestHeaders.Remove("x-iex-date"); client.DefaultRequestHeaders.Remove("Authorization"); (string iexdate, string authorization_header)headers = signer.Sign(publishableToken, "GET", urlPattern, qsb.Build()); client.DefaultRequestHeaders.TryAddWithoutValidation("x-iex-date", headers.iexdate); client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", headers.authorization_header); } using (var responseContent = await client.GetAsync($"{urlPattern}{qsb.Build()}")) { try { content = await responseContent.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <ReturnType>(content, jsonSerializerSettings)); } catch (JsonException ex) { throw new JsonException(content, ex); } } }