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 = $"{TWP_API_UTILS.ACCRUALS_ENDPOINT}?pageSize={API_PAGE_SIZE}"; if (asOfDate != null) { pagedURL += $"&asOfDate={TWP_API_UTILS.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 <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 DEBUG_MESSAGES Console.WriteLine("Sending API Request:"); Console.WriteLine($"{request.Method} {url}"); #endif if (content != null) { string stringContent = TWP_API_UTILS.SerializeAPIBody(content); using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(stringContent); streamWriter.Flush(); } #if DEBUG_MESSAGES Console.WriteLine($"Body Content:"); Console.WriteLine(stringContent); #endif } return((HttpWebResponse)(await request.GetResponseAsync())); }
public JWT_Payload(int partnerId, int siteId, APIProduct apiProduct) { Iss = partnerId; Exp = TWP_API_UTILS.GetUnixEpochTimestamp(DateTime.UtcNow.AddSeconds(JWT_EXPIRATION_SECONDS)); Sub = JWT_PARTNER_SUBJECT; SiteInfo.Type = JWT_SITE_TYPE_ID; SiteInfo.Id = siteId; Product = TWP_API_UTILS.APIProductToken[apiProduct]; }
public static async Task <JObject> GetTimecardDetails(int siteId, string apiToken, DateTime?payPeriodDate = null, List <string> employeeIds = null) { string dateParam = TWP_API_UTILS.FormatAPIDate(payPeriodDate ?? DateTime.Now); string timecardDetailsURL = $"{TWP_API_UTILS.TIMECARD_DETAILS_ENDPOINT}?periodDate={dateParam}"; if (employeeIds.SafeCount() > 0) { timecardDetailsURL += $"&ids={String.Join(",", employeeIds)}"; } string timecardDetailsJSON = await CallTWPAPI(siteId, apiToken, timecardDetailsURL); return(JObject.Parse(timecardDetailsJSON)); }
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 = $"{TWP_API_UTILS.ACCRUALS_ACTIVITY_ENDPOINT}?pageSize={API_PAGE_SIZE}"; if (startDate != null) { pagedURL += $"&startDate={TWP_API_UTILS.FormatAPIDate(startDate.Value)}"; } if (endDate != null) { pagedURL += $"&endDate={TWP_API_UTILS.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); }
public static async Task <TWP_PayrollActivities> GetPayrollActivities(int siteId, string apiToken, DateTime?payPeriodDate = null, List <string> employeeIds = null, string payrollFormat = null) { string dateParam = TWP_API_UTILS.FormatAPIDate(payPeriodDate ?? DateTime.Now); string payrollActivityURL = $"{TWP_API_UTILS.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); } return(JsonConvert.DeserializeObject <TWP_PayrollActivities>( await CallTWPAPI(siteId, apiToken, payrollActivityURL, HttpMethod.Post, requestBody))); }