public static async Task <List <TWP_Accruals> > getAccruals(int siteId, string APIToken, DateTime?asOfDate = null, string category = null) { List <TWP_Accruals> allAccruals = new List <TWP_Accruals>(); string pagedURL = $"{TWPApiUtil.Accruals_EndPoint}?pageSize={API_Page_Size}"; if (asOfDate != null) { pagedURL += $"&asOfDate={TWPApiUtil.FormatAPIDate(asOfDate.Value)}"; } if (category != null) { pagedURL += $"&category={category}"; } while (!String.IsNullOrEmpty(pagedURL)) { string apiResponse = await CallTWPAPI(siteId, APIToken, pagedURL, HttpMethod.Get); TWP_API_List_Response result = JsonConvert.DeserializeObject <TWP_API_List_Response>(apiResponse); allAccruals.AddRange(result.Results.Select(accJson => accJson.ToObject <TWP_Accruals>())); pagedURL = result.NextPageLink; } return(allAccruals); }
public static async Task <TWP_PayrollActivities> GetPayrollActivities(int siteId, string APIToken, DateTime?payPeriodDate = null, List <string> employeeIds = null, string payrollFormat = null) { string dateParam = TWPApiUtil.FormatAPIDate(payPeriodDate ?? DateTime.Now); string payrollActivityURL = $"{TWPApiUtil.Payroll_Activities_EndPoint}?periodDate={dateParam}"; if (!String.IsNullOrEmpty(payrollFormat)) { payrollActivityURL += $"&format={payrollFormat}"; } TWP_PayrollActivitiesRequest requestBody = null; if (employeeIds.safeCount() > 0) { requestBody = new TWP_PayrollActivitiesRequest(employeeIds); } else { List <string> eeid = new List <string>(); var response = await ListEmployees(siteId, APIToken); foreach (TWP_Employee ee in response) { eeid.Add(ee.EmployeeCode); } requestBody = new TWP_PayrollActivitiesRequest(eeid); } return(JsonConvert.DeserializeObject <TWP_PayrollActivities>( await CallTWPAPI(siteId, APIToken, payrollActivityURL, HttpMethod.Post, requestBody))); }
public JWT_Payload(int partnerId, int siteId, APIProduct apiProduct) { Iss = partnerId; Exp = TWPApiUtil.GetUnixEpochTimeStamp(DateTime.UtcNow.AddSeconds(JWT_Expiration_Seconds)); Sub = JWT_Partner_Subject; SiteInfo.Type = JWT_Site_Type_ID; SiteInfo.Id = siteId; Product = TWPApiUtil.aPIProductToken[apiProduct]; }
public static async Task <TWP_PayrollActivities> getActivitiesBySDED(int siteId, string APIToken, DateTime?startDate = null, DateTime?endDate = null, string payrollFormat = null) { string startdate = TWPApiUtil.FormatAPIDate(startDate ?? DateTime.Now); string enddate = TWPApiUtil.FormatAPIDate(endDate ?? DateTime.Now); string payrollActivityURL = $"{TWPApiUtil.Payroll_Activities_EndPoint}?beginDate={startdate}&endDate={enddate}"; if (!string.IsNullOrEmpty(payrollFormat)) { payrollActivityURL += $"&format={payrollFormat}"; } return(JsonConvert.DeserializeObject <TWP_PayrollActivities>(await CallTWPAPI(siteId, APIToken, payrollActivityURL, HttpMethod.Post))); }
public static async Task <JObject> getTimeCardSum(int siteId, string APIToken, DateTime?payPeriodDate = null, List <string> employeeIds = null) { string dateParam = TWPApiUtil.FormatAPIDate(payPeriodDate ?? DateTime.Now); string timecardSumURL = $"{TWPApiUtil.getTimeCardSum}?periodDate={dateParam}"; if (employeeIds.safeCount() > 0) { timecardSumURL += $"&ids={String.Join(",", employeeIds)}"; } string timecardsumJSON = await CallTWPAPI(siteId, APIToken, timecardSumURL); return(JObject.Parse(timecardsumJSON)); }
public static async Task <HttpWebResponse> SendWebRequest(HttpMethod method, string url, string authToken, object content = null) { WebRequest request = WebRequest.Create(url); request.Method = method.ToString(); request.ContentType = "application/json"; request.Headers.Set("Authorization", String.Format("Bearer {0}", authToken)); if (content != null) { string stringContent = TWPApiUtil.SerializeAPIBody(content); using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(stringContent); streamWriter.Flush(); } } return((HttpWebResponse)(await request.GetResponseAsync())); }
public static async Task <List <TWP_AccrualActivities> > getAccrualActivity(int siteId, string APIToken, DateTime?startDate = null, DateTime?endDate = null, string category = null, List <string> employeeIds = null) { List <TWP_AccrualActivities> allAccruals = new List <TWP_AccrualActivities>(); string pagedURL = $"{TWPApiUtil.Accruals_Activity_EndPoint}?pageSize={API_Page_Size}"; if (startDate != null) { pagedURL += $"&startDate={TWPApiUtil.FormatAPIDate(startDate.Value)}"; } if (endDate != null) { pagedURL += $"&endDate={TWPApiUtil.FormatAPIDate(endDate.Value)}"; } if (category != null) { pagedURL += $"&category={category}"; } if (employeeIds.safeCount() > 0) { pagedURL += $"ids={String.Join(",", employeeIds)}"; } while (!String.IsNullOrEmpty(pagedURL)) { string apiResponse = await CallTWPAPI(siteId, APIToken, pagedURL, HttpMethod.Get); TWP_API_List_Response result = JsonConvert.DeserializeObject <TWP_API_List_Response>(apiResponse); allAccruals.AddRange(result.Results.Select(accJson => accJson.ToObject <TWP_AccrualActivities>())); pagedURL = result.NextPageLink; } return(allAccruals); }