diff --git a/.gitignore b/.gitignore index 4440932..f7f2951 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ Saasu.API.Client.IntegrationTests/bin/ *.bak *.orig Saasu.API.Core/Saasu.API.Core.csproj.user +/.vs/Saasu.API.Dotnet.Client/v15/Server/sqlite3 diff --git a/Saasu.API.Client.IntegrationTests/App.config b/Saasu.API.Client.IntegrationTests/App.config index f45aeed..7d922f5 100644 --- a/Saasu.API.Client.IntegrationTests/App.config +++ b/Saasu.API.Client.IntegrationTests/App.config @@ -48,9 +48,9 @@ - + - \ No newline at end of file + diff --git a/Saasu.API.Client.IntegrationTests/Saasu.API.Client.IntegrationTests.csproj b/Saasu.API.Client.IntegrationTests/Saasu.API.Client.IntegrationTests.csproj index ccf5b8b..7d734cf 100644 --- a/Saasu.API.Client.IntegrationTests/Saasu.API.Client.IntegrationTests.csproj +++ b/Saasu.API.Client.IntegrationTests/Saasu.API.Client.IntegrationTests.csproj @@ -11,7 +11,7 @@ Properties Saasu.API.Client.IntegrationTests Saasu.API.Client.IntegrationTests - v4.7.1 + v4.6.1 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} app.config @@ -60,8 +60,8 @@ ..\packages\Saasu.API.Dotnet.LegacyRestClient.1.0\lib\Netaccounts.Ola.RestClient.dll - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll ..\packages\NUnit.2.6.4\lib\nunit.framework.dll diff --git a/Saasu.API.Client.IntegrationTests/packages.config b/Saasu.API.Client.IntegrationTests/packages.config index 7a443b3..413c8c3 100755 --- a/Saasu.API.Client.IntegrationTests/packages.config +++ b/Saasu.API.Client.IntegrationTests/packages.config @@ -1,7 +1,7 @@  - + \ No newline at end of file diff --git a/Saasu.API.Client/App.config b/Saasu.API.Client/App.config index f596bd6..51db0a4 100644 --- a/Saasu.API.Client/App.config +++ b/Saasu.API.Client/App.config @@ -11,7 +11,7 @@ - false + true https://api.saasu.com/ @@ -41,9 +41,9 @@ - + - \ No newline at end of file + diff --git a/Saasu.API.Client/Config.Designer.cs b/Saasu.API.Client/Config.Designer.cs index 285bef9..1ae79a4 100644 --- a/Saasu.API.Client/Config.Designer.cs +++ b/Saasu.API.Client/Config.Designer.cs @@ -12,7 +12,7 @@ namespace Saasu.API.Client { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.5.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] internal sealed partial class Config : global::System.Configuration.ApplicationSettingsBase { private static Config defaultInstance = ((Config)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Config()))); diff --git a/Saasu.API.Client/Framework/BaseProxy.cs b/Saasu.API.Client/Framework/BaseProxy.cs index 861f748..0801010 100644 --- a/Saasu.API.Client/Framework/BaseProxy.cs +++ b/Saasu.API.Client/Framework/BaseProxy.cs @@ -1,4 +1,5 @@ -using Saasu.API.Core.Framework; +using System; +using Saasu.API.Core.Framework; using Saasu.API.Core.Globals; using Saasu.API.Core.Models.RequestFiltering; using System.IO; @@ -246,6 +247,14 @@ public virtual ProxyResponse GetResponse(string requestUrl) return new ProxyResponse(rawResponse, responseMsg.IsSuccessStatusCode, responseMsg.StatusCode, responseMsg.ReasonPhrase); } + public virtual ProxyResponse GetBinaryResponse(string requestUrl) + { + var responseMsg = GetResponseMessage(requestUrl); + var content = responseMsg.Content.ReadAsByteArrayAsync().Result; + var rawResponse = string.Empty; + return new ProxyResponse(rawResponse, content, responseMsg.IsSuccessStatusCode, responseMsg.StatusCode, responseMsg.ReasonPhrase); + } + public virtual ProxyResponse GetResponse(string requestUri) where T : class { return GetResponse(requestUri, null); @@ -292,57 +301,48 @@ protected virtual System.Net.Http.HttpResponseMessage GetResponseMessage(string { return GetResponseMessage(requestUri, null); } + protected virtual System.Net.Http.HttpResponseMessage GetResponseMessage(string requestUri, T postData) { - HttpClient client = new HttpClient(); - client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(ContentType.AsContentTypeString())); - if (AuthenticationMethod == AuthenticationType.OAuth && !string.IsNullOrEmpty(_bearerToken)) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _bearerToken); - } + return GetResponseMessage(requestUri, postData, ContentType.AsContentTypeString()); + } - MediaTypeFormatter mediaFormatter; + private static Lazy Client {get;} = new Lazy(() => + { + var client = new HttpClient(); + client.DefaultRequestHeaders.ConnectionClose = true; + return client; + }); + - if (ContentType == RequestContentType.ApplicationXml) - { - mediaFormatter = new System.Net.Http.Formatting.XmlMediaTypeFormatter(); + protected virtual HttpResponseMessage GetResponseMessage(string requestUri, T postData, string contentType) + { + var client = Client.Value; - } - else + using (var request = new HttpRequestMessage(OperationMethod, requestUri)) { - mediaFormatter = new System.Net.Http.Formatting.JsonMediaTypeFormatter(); - } - + + if (!string.IsNullOrEmpty(contentType)) + request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType)); - HttpResponseMessage responseMsg = null; - if (OperationMethod == HttpMethod.Get) - { - responseMsg = client.GetAsync(requestUri).Result; - } - else if (OperationMethod == HttpMethod.Delete && postData == null) - { - responseMsg = client.DeleteAsync(requestUri).Result; - } - else if (OperationMethod == HttpMethod.Head) - { - var rqstMsg = new HttpRequestMessage(HttpMethod.Head, requestUri); - responseMsg = client.SendAsync(rqstMsg).Result; - } - else - { - //Note: Need to explicitly specify the content type here otherwise this call fails. - if (OperationMethod == HttpMethod.Put) + if (AuthenticationMethod == AuthenticationType.OAuth && !string.IsNullOrEmpty(_bearerToken)) { - responseMsg = client.PutAsync(requestUri, postData, mediaFormatter).Result; + request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _bearerToken); } - else + + if (postData != null) { - responseMsg = client.PostAsync(requestUri, postData, mediaFormatter).Result; + request.Content = new ObjectContent(postData, ContentType == RequestContentType.ApplicationXml + ? (MediaTypeFormatter) new XmlMediaTypeFormatter() + : new JsonMediaTypeFormatter()); } + + return client.SendAsync(request).Result; + } - return responseMsg; } + public T Deserialise(string data) where T : class { diff --git a/Saasu.API.Client/Proxies/InvoiceProxy.cs b/Saasu.API.Client/Proxies/InvoiceProxy.cs index 93b40ab..8920599 100644 --- a/Saasu.API.Client/Proxies/InvoiceProxy.cs +++ b/Saasu.API.Client/Proxies/InvoiceProxy.cs @@ -5,6 +5,7 @@ using Saasu.API.Core.Models.Attachments; using Saasu.API.Core.Models.Invoices; using System.Net.Http; +using System.Text; namespace Saasu.API.Client.Proxies { @@ -110,5 +111,23 @@ public ProxyResponse EmailInvoice(int invoiceId) return base.GetResponse(uri); } + public ProxyResponse GenerateInvoicePdf(int invoiceId, int? templateId = null) + { + _requestPrefix = ResourceNames.Invoice; + RequestPostfix = ApiConstants.GenerateInvoicePdfPath; + OperationMethod = HttpMethod.Get; + PagingEnabled = false; + + var queryArgs = new StringBuilder(); + + if (templateId.HasValue) + { + AppendQueryArg(queryArgs, ApiConstants.FilterTemplateId, templateId.Value.ToString()); + } + + var uri = base.GetRequestUri(invoiceId.ToString()); + return base.GetBinaryResponse(uri); + } + } } diff --git a/Saasu.API.Client/Proxies/InvoicesProxy.cs b/Saasu.API.Client/Proxies/InvoicesProxy.cs index 9991165..f1cce9d 100644 --- a/Saasu.API.Client/Proxies/InvoicesProxy.cs +++ b/Saasu.API.Client/Proxies/InvoicesProxy.cs @@ -61,7 +61,7 @@ public ProxyResponse GetInvoices(int? pageNum { AppendQueryArg(queryArgs, ApiConstants.FilterTransactionTypeInvoices, transactionType); } - if (paymentStatus != null && paymentStatus > 0) + if (!string.IsNullOrWhiteSpace(invoiceStatus)) { AppendQueryArg(queryArgs, ApiConstants.FilterPaymentStatus, paymentStatus.ToString()); } diff --git a/Saasu.API.Client/Saasu.API.Client.csproj b/Saasu.API.Client/Saasu.API.Client.csproj index dab3bf4..0563f89 100644 --- a/Saasu.API.Client/Saasu.API.Client.csproj +++ b/Saasu.API.Client/Saasu.API.Client.csproj @@ -10,7 +10,7 @@ Properties Saasu.API.Client Saasu.API.Client - v4.7.1 + v4.6 512 @@ -53,8 +53,8 @@ false - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/Saasu.API.Client/Saasu.API.Client.nuspec b/Saasu.API.Client/Saasu.API.Client.nuspec index f338a1c..2ade112 100755 --- a/Saasu.API.Client/Saasu.API.Client.nuspec +++ b/Saasu.API.Client/Saasu.API.Client.nuspec @@ -3,9 +3,9 @@ Saasu.API.Dotnet.Sdk API SDK for the Saasu API - 1.1.7 + 1.1.7.2 Saasu - A client SDK for working with the Saasu API. + A client SDK for working with the Saasu API. Modified for Intellis internal use. A client SDK for working with the Saasu API. en-US https://github.com/saasu/api-sdk-dotnet diff --git a/Saasu.API.Client/Saasu.API.Dotnet.Sdk.1.1.7.1.nupkg b/Saasu.API.Client/Saasu.API.Dotnet.Sdk.1.1.7.1.nupkg new file mode 100644 index 0000000..37c8bf1 Binary files /dev/null and b/Saasu.API.Client/Saasu.API.Dotnet.Sdk.1.1.7.1.nupkg differ diff --git a/Saasu.API.Client/Saasu.API.Dotnet.Sdk.1.1.7.2.nupkg b/Saasu.API.Client/Saasu.API.Dotnet.Sdk.1.1.7.2.nupkg new file mode 100644 index 0000000..96e63f3 Binary files /dev/null and b/Saasu.API.Client/Saasu.API.Dotnet.Sdk.1.1.7.2.nupkg differ diff --git a/Saasu.API.Client/packages.config b/Saasu.API.Client/packages.config index bdeb34b..3d50c42 100755 --- a/Saasu.API.Client/packages.config +++ b/Saasu.API.Client/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/Saasu.API.Core/Globals/ApiConstants.cs b/Saasu.API.Core/Globals/ApiConstants.cs index ecd6353..5449967 100644 --- a/Saasu.API.Core/Globals/ApiConstants.cs +++ b/Saasu.API.Core/Globals/ApiConstants.cs @@ -16,6 +16,8 @@ public static class ApiConstants public const string IdQueryArgParameter = "{id}"; public const string ResetPasswordUrlPath = "reset-password/"; + + public const string GenerateInvoicePdfPath = "generate-pdf/"; public const string EmailInvoiceToContactUrlPath = "email-contact/"; public const string EmailInvoiceUrlPath = "email/"; public const string BuildComboItemPath = "build/"; @@ -92,6 +94,7 @@ public static class ApiConstants public const string FilterEmail = "Email"; public const string FilterExampleEmail = FilterEmail + "={" + FilterHelpEmail + "}"; public const string FilterContactId = "ContactId"; + public const string FilterTemplateId = "TemplateId"; public const string FilterExampleContactId = FilterContactId + "={" + FilterHelpText + "}"; public const string FilterInvoiceFromDate = "InvoiceFromDate"; public const string FilterExampleInvoiceFromDate = FilterInvoiceFromDate + "={" + FilterHelpDate + "}"; diff --git a/Saasu.API.Core/Models/Invoices/InvoicePdfResult.cs b/Saasu.API.Core/Models/Invoices/InvoicePdfResult.cs new file mode 100644 index 0000000..2198ac0 --- /dev/null +++ b/Saasu.API.Core/Models/Invoices/InvoicePdfResult.cs @@ -0,0 +1,11 @@ +namespace Saasu.API.Core.Models.Invoices +{ + public class InvoicePdfResult : BaseResponseModel + { + public int InvoiceId { get; set; } + + public byte[] Content { get; set; } + + + } +} diff --git a/Saasu.API.Core/Saasu.API.Core.csproj b/Saasu.API.Core/Saasu.API.Core.csproj index 6557545..7481652 100644 --- a/Saasu.API.Core/Saasu.API.Core.csproj +++ b/Saasu.API.Core/Saasu.API.Core.csproj @@ -10,7 +10,7 @@ Properties Saasu.API.Core Saasu.API.Core - v4.7.1 + v4.6 512 @@ -53,8 +53,8 @@ bin\Staging\Saasu.API.Core.XML - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll @@ -106,6 +106,7 @@ + diff --git a/Saasu.API.Core/app.config b/Saasu.API.Core/app.config index 195db1f..8e93db5 100755 --- a/Saasu.API.Core/app.config +++ b/Saasu.API.Core/app.config @@ -4,8 +4,8 @@ - + - \ No newline at end of file + diff --git a/Saasu.API.Core/packages.config b/Saasu.API.Core/packages.config index bba391f..02357c4 100755 --- a/Saasu.API.Core/packages.config +++ b/Saasu.API.Core/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file