diff --git a/.vs/Bamboo.Sharp.Api/v14/.suo b/.vs/Bamboo.Sharp.Api/v14/.suo new file mode 100644 index 0000000..877b85b Binary files /dev/null and b/.vs/Bamboo.Sharp.Api/v14/.suo differ diff --git a/Bamboo.Sharp.Api.sln b/Bamboo.Sharp.Api.sln index 18b38d2..50fb972 100644 --- a/Bamboo.Sharp.Api.sln +++ b/Bamboo.Sharp.Api.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bamboo.Sharp.Api", "Bamboo.Sharp.Api\Bamboo.Sharp.Api.csproj", "{09B2E97B-6103-4693-9EBB-0450DF36465B}" EndProject diff --git a/Bamboo.Sharp.Api/Bamboo.Sharp.Api.csproj b/Bamboo.Sharp.Api/Bamboo.Sharp.Api.csproj index 66c0c92..2be5350 100644 --- a/Bamboo.Sharp.Api/Bamboo.Sharp.Api.csproj +++ b/Bamboo.Sharp.Api/Bamboo.Sharp.Api.csproj @@ -54,8 +54,12 @@ + + + + @@ -85,6 +89,7 @@ + diff --git a/Bamboo.Sharp.Api/Clients/RequestClient.cs b/Bamboo.Sharp.Api/Clients/RequestClient.cs index 62ca1db..54fb61a 100644 --- a/Bamboo.Sharp.Api/Clients/RequestClient.cs +++ b/Bamboo.Sharp.Api/Clients/RequestClient.cs @@ -15,6 +15,8 @@ internal class RequestClient private RequestClient() { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + } internal static RequestClient Instance diff --git a/Bamboo.Sharp.Api/Model/Calendar.cs b/Bamboo.Sharp.Api/Model/Calendar.cs new file mode 100644 index 0000000..2fd4826 --- /dev/null +++ b/Bamboo.Sharp.Api/Model/Calendar.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RestSharp.Deserializers; + +namespace Bamboo.Sharp.Api.Model +{ + public class Calendar : BaseNode + { + public List WhosOut { get; set; } + } +} diff --git a/Bamboo.Sharp.Api/Model/Employee.cs b/Bamboo.Sharp.Api/Model/Employee.cs new file mode 100644 index 0000000..89e8463 --- /dev/null +++ b/Bamboo.Sharp.Api/Model/Employee.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; +using RestSharp.Deserializers; + +namespace Bamboo.Sharp.Api.Model +{ + public class Employee + { + [DeserializeAs(Name = "id", Attribute = true)] + public string Id { get; set; } + //[XmlText] + public string Value { get; set; } + + + public override string ToString() + { + return string.Format("({0}) - {1}", Id.ToString(), Value); + } + } +} diff --git a/Bamboo.Sharp.Api/Model/Holiday.cs b/Bamboo.Sharp.Api/Model/Holiday.cs new file mode 100644 index 0000000..9e9e289 --- /dev/null +++ b/Bamboo.Sharp.Api/Model/Holiday.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RestSharp.Deserializers; + +namespace Bamboo.Sharp.Api.Model +{ + public class Holiday + { + [DeserializeAs(Name = "id", Attribute = true)] + public string Id { get; set; } + //[XmlText] + public string Value { get; set; } + } +} diff --git a/Bamboo.Sharp.Api/Model/Item.cs b/Bamboo.Sharp.Api/Model/Item.cs new file mode 100644 index 0000000..fef99a4 --- /dev/null +++ b/Bamboo.Sharp.Api/Model/Item.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RestSharp.Deserializers; + +namespace Bamboo.Sharp.Api.Model +{ + public class item + { + public Employee Employee { get; set; } + + public Holiday Holiday { get; set; } + + [DeserializeAs(Name = "start")] + public DateTime StartDate { get; set; } + + [DeserializeAs(Name = "end")] + public DateTime EndDate { get; set; } + + public bool IsHoliday() + { + return this.Holiday != null; + } + public bool IsEmployee() + { + return this.Employee != null; + } + + } +} diff --git a/Bamboo.Sharp.Api/Services/TimeOffService.cs b/Bamboo.Sharp.Api/Services/TimeOffService.cs new file mode 100644 index 0000000..e85c1ae --- /dev/null +++ b/Bamboo.Sharp.Api/Services/TimeOffService.cs @@ -0,0 +1,41 @@ +using RestSharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Bamboo.Sharp.Api.Model; + +namespace Bamboo.Sharp.Api.Services +{ + public class TimeOffService : BaseService + { + public Calendar GetWhosOutToday(DateTime? startDate = null, DateTime? endDate = null) + { + //If there is an end date, must have a start date. + if (!startDate.HasValue && endDate.HasValue) + throw new DataMisalignedException("You must specify a Start Date if you specify an EndDate!"); + // End date has to be == or after the start date. + if (endDate.HasValue && startDate.HasValue && endDate.Value.Subtract(startDate.Value).TotalDays <= 0) + throw new DataMisalignedException("Your End Date must equal to or after your startDate"); + if(endDate.HasValue && (endDate.Value.Subtract(startDate.Value).TotalDays > 14) ) + throw new DataMisalignedException("Your entire search scope may only be up to 14 days from the start request!"); + + var start = startDate.HasValue == true ? startDate.Value.ToString("yyyy-M-d") : string.Empty; + var end = endDate.HasValue == true ? endDate.Value.ToString("yyyy-M-d") : string.Empty; + + var request = new RestRequest + { + Resource = "time_off/whos_out", + Method = Method.GET + }; + if(!string.IsNullOrEmpty(start)) + request.AddQueryParameter("start", start); + + if(!string.IsNullOrEmpty(end)) + request.AddQueryParameter("end", end); + + return Client.Execute(request); + } + } +}