Пример #1
0
        static void Main(string[] args)
        {
            String apiKey = TogglToExcel.Properties.Resources.APIKey;
            var projectService = new Toggl.Services.ProjectService(apiKey);
            var timeService = new Toggl.Services.TimeEntryService(apiKey);
            var rte = new TimeEntryParams { StartDate = new DateTime(2015,11,9) , EndDate = DateTime.Now};
            var projectHash = GetProjectHash(timeService.List(rte), projectService.List());

            WriteHashToConsole(projectHash);
            WriteToExcel(projectHash);

            End();
        }
Пример #2
0
		public void GetTimeEntriesByDateRange()
		{
			var startDate = DateTime.Now.AddMonths(-2);
			var endDate = DateTime.Now.AddMonths(-1);

			for (int i = 0; i < 3; i++)
			{
				var te = TimeEntryService.Add(new TimeEntry()
				{
					IsBillable = true,
					CreatedWith = "TogglAPI.Net",
					Duration = 900,
					Start = startDate.AddMonths(i).ToIsoDateStr(),
					WorkspaceId = DefaultWorkspaceId
				});
				Assert.IsNotNull(te);
			}
	       
            var rte = new TimeEntryParams {StartDate = startDate, EndDate = endDate};
			Assert.AreEqual(2, TimeEntryService.List(rte).Count());
			rte = new TimeEntryParams { StartDate = startDate, EndDate = DateTime.Now };
			Assert.AreEqual(3, TimeEntryService.List(rte).Count());            
        }
        public void GetTimeEntriesByDateRange(DateTime from, DateTime to)
        {
            var rte = new TimeEntryParams();
            rte.StartDate = from;
            rte.EndDate = to;

            var entries = timeEntrySrv.List(rte);

            Assert.GreaterOrEqual(entries.Count(), 0);
        }
Пример #4
0
        public Task PushTime(AppSetting settings, DateTime startDate, DateTime endDate)
        {
            //tra-74

            if (settings == null)
                throw new Exception("No Jira or Toggl credentials provided.");
            this.VerifySetting(settings.JiraLogin, "JIRA login");
            this.VerifySetting(settings.JiraPassword, "JIRA password");
            this.VerifySetting(settings.JiraUrl, "JIRA URL");
            this.VerifySetting(settings.TogglApiKey, "Toggl API Key");

            var jira = new Jira(settings.JiraUrl, settings.JiraLogin, settings.JiraPassword);
            var toggl = new Toggl.Toggl(settings.TogglApiKey);

            return Task.Run(() =>
                {
                    var timeService = new TimeEntryService(settings.TogglApiKey);
                    var timeParams = new TimeEntryParams();

                    timeParams.StartDate = startDate.Date;
                    timeParams.EndDate = endDate.Date;

                    foreach (var te in timeService.List(timeParams).Where(w => (w.TagNames == null || !w.TagNames.Contains(POSTED_TAG))
                                                                                && !string.IsNullOrEmpty(w.Description)))
                    {
                        KeyValuePair<string, string> description = this.ParseDescription(te.Description);
                        if (string.IsNullOrEmpty(description.Key))
                            continue;

                        var issue = jira.GetIssue(description.Key);
                        issue.AddWorklog(new Worklog(this.GetMinutes(te.Duration.GetValueOrDefault()), DateTime.Parse(te.Start), description.Value));
                        if (te.TagNames == null)
                            te.TagNames = new List<string>();
                        te.TagNames.Add(POSTED_TAG);
                        timeService.Edit(te);
                    }
                });

            //return Task.Run(() =>
            //    {
            //        //Atlassian.Jira.Jira aa = new Atlassian.Jira.Jira("urlhere", "loginhere", "passwordhere");
            //        //var issue = aa.GetIssue("FLW6-2247");
            //        //issue.AddWorklog(new Atlassian.Jira.Worklog)

            //        //var apiKey = "apikeyhere";
            //        //var t = new Toggl.Toggl(apiKey);
            //        //var c = t.User.GetCurrent();

            //        //var timeSrv = new Toggl.Services.TimeEntryService(apiKey);
            //        //var prams = new Toggl.QueryObjects.TimeEntryParams();

            //        //// there is an issue with the date ranges have
            //        //// to step out of the range on the end.
            //        //// To capture the end of the billing range day + 1
            //        //prams.StartDate = DateTime.Now.AddMonths(-1);
            //        //prams.EndDate = DateTime.Now.AddMonths(1);

            //        //var hours = timeSrv.List(prams)
            //        //                        .Where(w => !string.IsNullOrEmpty(w.Description)).ToList();
            //    });
        }