public void EmitsAnOfflineExceptionIfTheApiClientThrowsAnHttpRequestException() { Exception caughtException = null; var httpRequestException = new HttpRequestException(); apiClient.Send(Arg.Any <Request>()).Returns <IResponse>(_ => throw httpRequestException); var credentials = Credentials.None; var endpoint = Endpoint.Get(BaseUrls.ForApi(ApiEnvironment.Staging), ""); var testApi = new TestApi(endpoint, apiClient, serializer, credentials, endpoint); try { testApi.TestCreateObservable <string>(endpoint, Enumerable.Empty <HttpHeader>(), "").Wait(); } catch (Exception e) { caughtException = e; } caughtException.Should().NotBeNull(); caughtException.Should().BeOfType <OfflineException>(); caughtException.InnerException.Should().Be(httpRequestException); }
public Endpoints(ApiEnvironment environment) { baseUrl = BaseUrls.ForApi(environment); ReportsEndpoints = new ReportsEndpoints(environment); }
public string GetBaseUrl(Environment environment) { return(BaseUrls .FirstOrDefault(item => item.EnvironmentName.Equals(environment)) ?.Url); }
// clients want to access resources (aka scopes) public static IEnumerable <Client> GetClients(BaseUrls baseUrls, IHostingEnvironment environment) { var clients = new List <Client> { // GraphQL Playground Client new Client { ClientId = "graphqlPlaygroundJs", ClientName = "GraphQL Playground Client", AllowedGrantTypes = GrantTypes.Implicit, AllowAccessTokensViaBrowser = true, RequireConsent = false, RedirectUris = { $"{baseUrls.GraphqlPlaygroundJsClient}/Home/GraphqlPlaygroundAuthCallback" }, PostLogoutRedirectUris = { $"{baseUrls.GraphqlPlaygroundJsClient}/Home/GraphqlPlayground" }, AllowedCorsOrigins = { baseUrls.GraphqlPlaygroundJsClient }, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, ApiResources.ReactAdvantageApi } }, // React Client new Client { ClientId = "react", ClientName = "React Client", AllowedGrantTypes = GrantTypes.Implicit, AllowAccessTokensViaBrowser = true, RequireConsent = false, RedirectUris = { $"{baseUrls.ReactClient}/authentication/callback", $"{baseUrls.ReactClient}/authentication/silentCallback" }, PostLogoutRedirectUris = { $"{baseUrls.ReactClient}/" }, AllowedCorsOrigins = { baseUrls.ReactClient }, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, ApiResources.ReactAdvantageApi } } }; if (!string.IsNullOrEmpty(baseUrls.ReactClientLocal)) { // Additional React Client for local development, if different from regular react client clients.Add(new Client { ClientId = "reactLocal", ClientName = "React Client", AllowedGrantTypes = GrantTypes.Implicit, AllowAccessTokensViaBrowser = true, RequireConsent = false, RedirectUris = { $"{baseUrls.ReactClientLocal}/authentication/callback", $"{baseUrls.ReactClientLocal}/authentication/silentCallback" }, PostLogoutRedirectUris = { $"{baseUrls.ReactClientLocal}/" }, AllowedCorsOrigins = { baseUrls.ReactClientLocal }, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, ApiResources.ReactAdvantageApi } }); } if (environment.IsEnvironment("Test")) { //Client for Integration Tests clients.Add(new Client { ClientId = "testClient", AllowedGrantTypes = GrantTypes.ClientCredentials, ClientSecrets = { new Secret("secret".Sha256()) }, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, ApiResources.ReactAdvantageApi } }); } return(clients); }
public Endpoints(ApiEnvironment environment) { baseUrl = BaseUrls.ForReports(environment); }
public static Uri GetURI(TimeSeriesParameters parameters, BaseUrls baseUrls, string apiKey) { string url = $"{baseUrls.TimeSeriesUrl}{parameters.DatabaseCode}"; if (!string.IsNullOrEmpty(parameters.DatasetCode)) { if (parameters.Metadata.HasValue) { url += parameters.Metadata.Value ? $"/{parameters.DatasetCode}/metadata" : $"/{parameters.DatasetCode}/data"; } else { url += $"/{parameters.DatasetCode}"; } } url += $".{GetReturnFormat(parameters.ReturnFormat)}"; UriBuilder uriBuilder = new UriBuilder(url); string uriQuery = $"api_key={apiKey}"; if (parameters.Limit.HasValue) { uriQuery += $"&limit={parameters.Limit}"; } if (parameters.ColumnIndex.HasValue) { uriQuery += $"&column_index={parameters.ColumnIndex}"; } if (parameters.StartDate.HasValue) { uriQuery += $"&start_date={parameters.StartDate.Value.ToString("yyyy-MM-dd")}"; } if (parameters.EndDate.HasValue) { uriQuery += $"&end_date={parameters.EndDate.Value.ToString("yyyy-MM-dd")}"; } if (parameters.Order != Order.None) { uriQuery += $"&order={GetOrder(parameters.Order)}"; } if (parameters.Collapse != Collapse.None) { uriQuery += $"&collapse={GetCollapse(parameters.Collapse)}"; } if (parameters.Transform != Transform.None) { uriQuery += $"&transform={GetTransform(parameters.Transform)}"; } uriBuilder.Query = uriQuery; return(uriBuilder.Uri); }