public async Task <IEnumerable <SelectListItem> > GetTypes() { var getTypesUri = ApiPaths.GetAllTypes(_remoteServiceBaseUrl); var dataString = await _apiClient.GetStringAsync(getTypesUri); var items = new List <SelectListItem> { new SelectListItem() { Value = null, Text = "All", Selected = true } }; var types = JArray.Parse(dataString); foreach (var type in types.Children <JObject>()) { items.Add(new SelectListItem() { Value = type.Value <string>("id"), Text = type.Value <string>("type") }); } return(items); }
// GET: api/Report/ThisWeek/{workspaceKey} public Report GetThisWeek(string workspaceKey) { string domain = Properties.Settings.Default.Domain; string workspaceEndpoint = Properties.Settings.Default.WorkspaceEndpoint; string reportEndpoint = Properties.Settings.Default.ReportEndpoint; string apiPassword = Properties.Settings.Default.DefaultApiPassword; string apiToken = WebUtil.GetHeader("ApiToken", Request.Headers); string email = WebUtil.GetHeader("Email", Request.Headers); var paths = new ApiPaths(domain, workspaceEndpoint, reportEndpoint); var parameters = new ApiParameters() { WorkspaceKey = workspaceKey, Since = DateTime.Today, Until = DateTime.Today.AddDays(7) }; var credentials = new ApiCredentials { ApiKey = apiToken, ApiPassword = apiPassword, Email = email }; var context = new ApiContext(paths, credentials, parameters); return(new TogglApiRequest(context).GetReport()); }
public async Task <UserPropertyViewModel> Save(ResponseViewModel model) { var uri = ApiPaths.UpdateProperty(ApiBaseUrl, model.Id); var dataString = await _apiClient.PutAsync(uri, model); var response = JsonConvert.DeserializeObject <UserPropertyViewModel>(dataString); return(response); }
public async Task <UserPropertyViewModel> GetAllItems() { var uri = ApiPaths.GetAllUserProperties(ApiBaseUrl); var dataString = await _apiClient.GetStringAsync(uri); var response = JsonConvert.DeserializeObject <UserPropertyViewModel>(dataString); return(response); }
public async Task <Catalog> GetCatalogItems(int page, int take, int?brand, int?type) { var allCatalogItemsUrl = ApiPaths.GetAllCatalogItems(_remoteServiceBaseUrl, page, take, brand, type); var dataString = await _apiClient.GetStringAsync(allCatalogItemsUrl); var response = JsonConvert.DeserializeObject <Catalog>(dataString); return(response); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services .UseDeepSleepJsonNegotiation() .UseDeepSleepServices((o) => { o.DefaultRequestConfiguration.AllowAnonymous = true; o.RoutePrefix = "v1"; o.IncludePaths = new string[] { ApiPaths.FromRoot("v1") }; }); }
// GET: api/Workspaces public Workspaces Get() { string domain = Properties.Settings.Default.Domain; string workspaceEndpoint = Properties.Settings.Default.WorkspaceEndpoint; string reportEndpoint = Properties.Settings.Default.ReportEndpoint; string apiPassword = Properties.Settings.Default.DefaultApiPassword; string apiToken = WebUtil.GetHeader("ApiToken", Request.Headers); var paths = new ApiPaths(domain, workspaceEndpoint, reportEndpoint); var credentials = new ApiCredentials { ApiKey = apiToken, ApiPassword = apiPassword }; var context = new ApiContext(paths, credentials); return(new TogglApiRequest(context).GetWorkspaces()); }
/// <summary>Uses the deep sleep services.</summary> /// <param name="services">The services.</param> /// <param name="configure">The configure.</param> /// <returns></returns> public static IServiceCollection UseDeepSleepServices(this IServiceCollection services, Action <IDeepSleepServiceConfiguration> configure = null) { var configuration = new DeepSleepServiceConfiguration { DefaultRequestConfiguration = ApiRequestContext.GetDefaultRequestConfiguration(), ExcludePaths = new List <string>(), IncludePaths = new List <string> { ApiPaths.All() }, WriteConsoleHeader = true, DiscoveryStrategies = new List <IDeepSleepDiscoveryStrategy>() }; if (configure != null) { configure(configuration); } configuration.DefaultRequestConfiguration = configuration.DefaultRequestConfiguration ?? ApiRequestContext.GetDefaultRequestConfiguration(); configuration.ExcludePaths = configuration.ExcludePaths ?? new List <string>(); configuration.IncludePaths = configuration.IncludePaths ?? new List <string>(); var routingTable = new ApiRoutingTable(routePrefix: configuration.RoutePrefix); services .AddScoped <IApiRequestContextResolver, ApiRequestContextResolver>() .AddScoped <IFormUrlEncodedObjectSerializer, FormUrlEncodedObjectSerializer>() .AddScoped <IUriRouteResolver, ApiRouteResolver>() .AddScoped <IMultipartStreamReader, MultipartStreamReader>() .AddScoped <IDeepSleepMediaSerializerFactory, DeepSleepMediaSerializerWriterFactory>() .AddScoped <IApiValidationProvider, ApiEndpointValidationProvider>() .AddSingleton <IApiRequestPipeline, IApiRequestPipeline>((p) => ApiRequestPipeline.GetDefaultRequestPipeline()) .AddSingleton <IDeepSleepRequestConfiguration, IDeepSleepRequestConfiguration>((p) => configuration.DefaultRequestConfiguration) .AddSingleton <IDeepSleepServiceConfiguration, IDeepSleepServiceConfiguration>((p) => configuration) .AddSingleton <IApiRoutingTable, IApiRoutingTable>((p) => routingTable); return(services); }
public WeatherForecastController(ApiPaths paths) { _paths = paths; _client = new HttpClient(); }
protected override void OnStartup(object sender, StartupEventArgs e) { ApiPaths.SetPaths(); DisplayRootViewFor <LoginViewModel>(); }