public async Task ReturnTasksWithOverdues() { _tokenProviderMock.Setup(x => x.GetToken()).Returns(Guid.NewGuid().ToString()); DateTime dateTime = DateTime.Today; _dateTimeUtilsMock.Setup(x => x.GetEndOfDay(dateTime)).Returns(dateTime); _dateTimeUtilsMock.Setup(x => x.FormatLongUtc(dateTime)).Returns(It.IsAny <string>()); var tasksClient = new TasksClient(new MockHttpClientFactory(), _loggerMock.Object, _dateTimeUtilsMock.Object, _tokenProviderMock.Object); ResponseModel <TaskModel> tasks = await tasksClient.GetTasks(dueDatetime : dateTime, includeOverdues : true, fields : Constants.SelectedTaskFields); var taskModel = tasks.Value.First(); Assert.Equal(TestDataHelper.Tasks.Value.First().Subject, taskModel.Subject); }
private async Task <List <UsersClient> > GetResponsables(TasksClient task) { RequestHandler client = new RequestHandler(); List <UsersClient> usersList = new List <UsersClient>(); IEnumerable <UsersClient> users = await client.GetDataFromAPI <UsersClient>("Users"); IEnumerable <AssignmentsClient> assignments = await client.GetDataFromAPI <AssignmentsClient>("Assignments"); foreach (var user in users) { foreach (var assignment in assignments) { if (user.UserID == assignment.UserID && task.TaskID == assignment.TaskID) { usersList.Add(user); } } } return(usersList); }
/// <summary> /// /// </summary> /// <param name="token">OAuth 2.0 token obtained from Egnyte</param> /// <param name="domain">Domain on which you connect to egnyte, /// i.e.: domain is 'mydomain', when url looks like: mydomain.egnyte.com</param> /// <param name="httpClient">You can provide your own httpClient. Optional</param> /// <param name="requestTimeout">You can provide timeout for calling Egnyte API, /// by default it's 10 minutes. This parameter is optional</param> /// <param name="host">Full host name on which you connect to egnyte, /// i.e.: host is 'my.custom.host.com', when url looks like: my.custom.host.com</param> public EgnyteClient( string token, string domain = "", HttpClient httpClient = null, TimeSpan?requestTimeout = null, string host = "") { if (string.IsNullOrWhiteSpace(token)) { throw new ArgumentNullException(nameof(token)); } if (string.IsNullOrWhiteSpace(domain) && string.IsNullOrWhiteSpace(host)) { throw new ArgumentNullException("domain", "Domain or host has to specified"); } httpClient = httpClient ?? new HttpClient(); httpClient.Timeout = TimeSpan.FromMinutes(10); if (requestTimeout.HasValue) { httpClient.Timeout = requestTimeout.Value; } httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); Files = new FilesClient(httpClient, domain, host); Users = new UsersClient(httpClient, domain, host); Links = new LinksClient(httpClient, domain, host); Groups = new GroupsClient(httpClient, domain, host); Permissions = new PermissionsClient(httpClient, domain, host); Search = new SearchClient(httpClient, domain, host); Audit = new AuditClient(httpClient, domain, host); Tasks = new TasksClient(httpClient, domain, host); }
private async void doOAuth() { // Creates a redirect URI using an available port on the loopback address. string redirectURI = string.Format("http://{0}:{1}/", IPAddress.Loopback, GetRandomUnusedPort()); // Creates an HttpListener to listen for requests on that redirect URI. var http = new HttpListener(); http.Prefixes.Add(redirectURI); output("Listening.."); http.Start(); oAuthClient = new OAuthClient(APIConstants.ClientID, APIConstants.ClientSecret, redirectURI); string authorizationURL = oAuthClient.GenerateAuthorizationURL(); // Opens request in the browser. OpenBrowser(authorizationURL); // Waits for the OAuth authorization response. var context = await http.GetContextAsync(); // Brings the Console to Focus. //BringConsoleToFront(); // Sends an HTTP response to the browser. var response = context.Response; string responseString = string.Format("<html><head><meta http-equiv='refresh' content='10;url=https://google.com'></head><body>Please return to the app.</body></html>"); var buffer = System.Text.Encoding.UTF8.GetBytes(responseString); response.ContentLength64 = buffer.Length; var responseOutput = response.OutputStream; Task responseTask = responseOutput.WriteAsync(buffer, 0, buffer.Length).ContinueWith((task) => { responseOutput.Close(); http.Stop(); Console.WriteLine("HTTP server stopped."); }); Token token = await oAuthClient.FinishOAuthAsync(context.Request.QueryString); if (token != null) { //userinfoCall(token.AccessToken); TasksClient client = new TasksClient(APIConstants.ClientID, APIConstants.ClientSecret, token); var tasksListResult = await client.GetTaskListsAsync(); foreach (var item in tasksListResult.Items) { output($"{item.Title} Last Updated: {item.Updated}"); } //var tasksQuery = new TasksQuery(); //tasksQuery.DueMin = DateTime.UtcNow.Subtract(TimeSpan.FromDays(30)); //var tasksResult = await client.GetTasksAsync(tasksListResult.Items[0].ID, tasksQuery); var tasksResult = await client.GetTasksAsync(tasksListResult.Items[0].ID); foreach (var item in tasksResult.Items) { output($"{item.Title}"); } } }
public static TasksClient CreateTasksClient() { var client = new TasksClient(ServiceStarter.BaseUrl); return(client); }