/// <summary> /// create a new IEXCloudClient /// </summary> /// <param name="publishableToken">publishable token</param> /// <param name="secretToken">secret token (only used for SCALE and GROW users)</param> /// <param name="signRequest">only SCALE and GROW users should set this to true</param> /// <param name="useSandBox">whether or not to use the sandbox endpoint</param> /// <param name="version">whether to use stable or beta endpoint</param> /// <param name="retryPolicy">which backoff policy to use - applies only REST calls (not SSE)</param> public IEXCloudClient(string publishableToken, string secretToken, bool signRequest, bool useSandBox, APIVersion version = APIVersion.stable, RetryPolicy retryPolicy = RetryPolicy.Exponential) { if (string.IsNullOrWhiteSpace(publishableToken)) { throw new ArgumentException("publishableToken cannot be null"); } this.publishableToken = publishableToken; this.secretToken = secretToken; this.signRequest = signRequest; var baseAddress = useSandBox ? "https://sandbox.iexapis.com/" : "https://cloud.iexapis.com/"; baseAddress += version.ToString() + "/"; baseSSEURL = useSandBox ? "https://sandbox-sse.iexapis.com/" : "https://cloud-sse.iexapis.com/"; baseSSEURL += version.ToString() + "/"; client = new HttpClient { BaseAddress = new Uri(baseAddress) }; client.DefaultRequestHeaders.Add("User-Agent", "VSLee.IEXSharp IEX Cloud .Net"); executor = new ExecutorREST(client, publishableToken, secretToken, signRequest, retryPolicy); executorSSE = new ExecutorSSE(baseSSEURL, publishableToken, secretToken); }
public LoginInfo LoginEx(string username, string password, string clientId, APIVersion required) { LoginInfo retVal = new LoginInfo(); retVal.APIVersion = new APIVersion(APIVersion.CURRENT_VERSION); retVal.ServerVersion = Assembly.GetExecutingAssembly().GetName().Version; if ((required != null) && ((required.Major > retVal.APIVersion.Major) || ((required.Major == retVal.APIVersion.Major) && (required.Minor > retVal.APIVersion.Minor)))) { retVal.ErrorType = "ActionNotSupportedException"; retVal.ErrorMessage = String.Format( "This client uses a modSIC API version ({0}) not supported by this modSIC Server ({1}).", required.ToString(), retVal.APIVersion); //retVal.ErrorMessage = "Client requires API " + required.ToString() + "; Server supports " + retVal.APIVersion; } else { var result = CollectController.Login(username, password, clientId); if (result == null) { retVal.ErrorType = "UnauthorizedAccessException"; retVal.ErrorMessage = "Invalid username or password"; } else { retVal.Token = result; } } return(retVal); }