Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions Saasu.API.Client.IntegrationTests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

</configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup></configuration>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I needed to use it in a project already including a higher version of Newtonsoft.Json than 7

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Saasu.API.Client.IntegrationTests</RootNamespace>
<AssemblyName>Saasu.API.Client.IntegrationTests</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you changing the target framework?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My project was 4.6.1, and I couln't otherwise use the library. Upgrading my framework version led to other issues. I made this change before I intended the pull request.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS. It's not a downgrade. Nuget packages should target the lowest possible framework that supports it, so it can be used as widely as possible. Packages targeted for a lower version framework can be used in a project using a higher version framework, but packages with a higher version framework can't be used in a project with a lower version.

<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<CurrentConfigFileName>app.config</CurrentConfigFileName>
Expand Down Expand Up @@ -60,8 +60,8 @@
<Reference Include="Netaccounts.Ola.RestClient, Version=1.0.5689.19968, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Saasu.API.Dotnet.LegacyRestClient.1.0\lib\Netaccounts.Ola.RestClient.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion Saasu.API.Client.IntegrationTests/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net471" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net471" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you downgrading the target framework?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

<package id="NUnit" version="2.6.4" targetFramework="net471" />
<package id="Saasu.API.Dotnet.LegacyRestClient" version="1.0" targetFramework="net471" />
</packages>
6 changes: 3 additions & 3 deletions Saasu.API.Client/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<Saasu.API.Client.Config>
<setting name="IgnoreSSLErrors" serializeAs="String">
<value>false</value>
<value>true</value>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this value changed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting connection SSL errors, though likely because I can't create an outbound connection. The HTTPClient stops working after a few hours after launch. This wasn't intended as part of the pull request.

</setting>
<setting name="BaseUri" serializeAs="String">
<value>https://api.saasu.com/</value>
Expand Down Expand Up @@ -41,9 +41,9 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

</configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /></startup></configuration>
2 changes: 1 addition & 1 deletion Saasu.API.Client/Config.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 38 additions & 38 deletions Saasu.API.Client/Framework/BaseProxy.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -246,6 +247,14 @@ public virtual ProxyResponse GetResponse(string requestUrl)
return new ProxyResponse(rawResponse, responseMsg.IsSuccessStatusCode, responseMsg.StatusCode, responseMsg.ReasonPhrase);
}

public virtual ProxyResponse<byte[]> GetBinaryResponse(string requestUrl)
{
var responseMsg = GetResponseMessage(requestUrl);
var content = responseMsg.Content.ReadAsByteArrayAsync().Result;
var rawResponse = string.Empty;
return new ProxyResponse<byte[]>(rawResponse, content, responseMsg.IsSuccessStatusCode, responseMsg.StatusCode, responseMsg.ReasonPhrase);
}

public virtual ProxyResponse<T> GetResponse<T>(string requestUri) where T : class
{
return GetResponse<T, T>(requestUri, null);
Expand Down Expand Up @@ -292,57 +301,48 @@ protected virtual System.Net.Http.HttpResponseMessage GetResponseMessage(string
{
return GetResponseMessage<object>(requestUri, null);
}

protected virtual System.Net.Http.HttpResponseMessage GetResponseMessage<T>(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<T>(requestUri, postData, ContentType.AsContentTypeString());
}

MediaTypeFormatter mediaFormatter;
private static Lazy<HttpClient> Client {get;} = new Lazy<HttpClient>(() =>
{
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<T>(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<T>(requestUri, postData, mediaFormatter).Result;
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _bearerToken);
}
else

if (postData != null)
{
responseMsg = client.PostAsync<T>(requestUri, postData, mediaFormatter).Result;
request.Content = new ObjectContent<T>(postData, ContentType == RequestContentType.ApplicationXml
? (MediaTypeFormatter) new XmlMediaTypeFormatter()
: new JsonMediaTypeFormatter());
}

return client.SendAsync(request).Result;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to block the call and it won't be async. These changes will only allow a single http request at a time, where before multiple would have been supported.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think so. HttpClient is intended to be shared, and is reentrant and thread safe. Unless I'm missing something.

See https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/


}

return responseMsg;
}


public T Deserialise<T>(string data) where T : class
{
Expand Down
19 changes: 19 additions & 0 deletions Saasu.API.Client/Proxies/InvoiceProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -110,5 +111,23 @@ public ProxyResponse<InvoiceEmailResult> EmailInvoice(int invoiceId)
return base.GetResponse<InvoiceEmailResult>(uri);
}

public ProxyResponse<byte[]> 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);
}

}
}
2 changes: 1 addition & 1 deletion Saasu.API.Client/Proxies/InvoicesProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ProxyResponse<InvoiceTransactionSummaryResponse> GetInvoices(int? pageNum
{
AppendQueryArg(queryArgs, ApiConstants.FilterTransactionTypeInvoices, transactionType);
}
if (paymentStatus != null && paymentStatus > 0)
if (!string.IsNullOrWhiteSpace(invoiceStatus))
{
AppendQueryArg(queryArgs, ApiConstants.FilterPaymentStatus, paymentStatus.ToString());
}
Expand Down
6 changes: 3 additions & 3 deletions Saasu.API.Client/Saasu.API.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Saasu.API.Client</RootNamespace>
<AssemblyName>Saasu.API.Client</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downgrade

<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
Expand Down Expand Up @@ -53,8 +53,8 @@
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
Expand Down
4 changes: 2 additions & 2 deletions Saasu.API.Client/Saasu.API.Client.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<metadata>
<id>Saasu.API.Dotnet.Sdk</id>
<title>API SDK for the Saasu API</title>
<version>1.1.7</version>
<version>1.1.7.2</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change the nuspec file. We will do this for a release.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was not intended to be a part of the pull request. Because there was no response to our request, we made this change internally so we could push to our private nuget repository without conflicts.

<authors>Saasu</authors>
<description>A client SDK for working with the Saasu API.</description>
<description>A client SDK for working with the Saasu API. Modified for Intellis internal use.</description>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an appropriate description.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. This was not intended to be pulled to the base repo

<summary>A client SDK for working with the Saasu API.</summary>
<language>en-US</language>
<projectUrl>https://github.com/saasu/api-sdk-dotnet</projectUrl>
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Saasu.API.Client/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net471" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net471" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net46" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downgrade.

<package id="OctoPack" version="3.6.3" targetFramework="net471" developmentDependency="true" />
</packages>
3 changes: 3 additions & 0 deletions Saasu.API.Core/Globals/ApiConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down Expand Up @@ -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 + "}";
Expand Down
11 changes: 11 additions & 0 deletions Saasu.API.Core/Models/Invoices/InvoicePdfResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Saasu.API.Core.Models.Invoices
{
public class InvoicePdfResult : BaseResponseModel
{
public int InvoiceId { get; set; }

public byte[] Content { get; set; }


}
}
7 changes: 4 additions & 3 deletions Saasu.API.Core/Saasu.API.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Saasu.API.Core</RootNamespace>
<AssemblyName>Saasu.API.Core</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down Expand Up @@ -53,8 +53,8 @@
<DocumentationFile>bin\Staging\Saasu.API.Core.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
Expand Down Expand Up @@ -106,6 +106,7 @@
<Compile Include="Models\FileIdentity\FileIdentitySummary.cs" />
<Compile Include="Models\FileIdentity\FileSettings.cs" />
<Compile Include="Models\Invoices\EmailInvoice.cs" />
<Compile Include="Models\Invoices\InvoicePdfResult.cs" />
<Compile Include="Models\Invoices\InvoiceEmailResult.cs" />
<Compile Include="Models\Items\BuildItemResult.cs" />
<Compile Include="Models\ItemAdjustments\AdjustmentDetail.cs" />
Expand Down
4 changes: 2 additions & 2 deletions Saasu.API.Core/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /></startup></configuration>
2 changes: 1 addition & 1 deletion Saasu.API.Core/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net471" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net471" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net46" />
</packages>