Skip to content

Commit

Permalink
Merge pull request #24 from gocardless/template-changes
Browse files Browse the repository at this point in the history
Release 2.16.0
  • Loading branch information
Simon Grimshaw authored Sep 6, 2019
2 parents c54c35e + cb4532b commit 03ebb63
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 42 deletions.
4 changes: 2 additions & 2 deletions GoCardless/GoCardless.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<PackageId>GoCardless</PackageId>
<PackageVersion>2.15.0</PackageVersion>
<PackageVersion>2.16.0</PackageVersion>
<Authors>GoCardless Ltd</Authors>
<Description>Client for the GoCardless API - a powerful, simple solution for the collection of recurring bank-to-bank payments</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
Expand All @@ -11,7 +11,7 @@
<Copyright>GoCardless Ltd</Copyright>
<PackageTags>gocardless payments rest api direct debit</PackageTags>
<PackageLicenseUrl>https://github.com/gocardless/gocardless-dotnet/blob/master/LICENSE.txt</PackageLicenseUrl>
<PackageReleaseNotes>https://github.com/gocardless/gocardless-dotnet/releases/tag/v2.15.0</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/gocardless/gocardless-dotnet/releases/tag/v2.16.0</PackageReleaseNotes>
<TargetFrameworks>netstandard1.6;netstandard2.0;net452</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
74 changes: 35 additions & 39 deletions GoCardless/GoCardlessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ private async Task<T> ExecuteAsyncInner<T>(string method, string path, List<KeyV
{
var json = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
var result = JsonConvert.DeserializeObject<T>(json, new JsonSerializerSettings());

if (result == null)
{
result = (T)Activator.CreateInstance(typeof(T));
}

result.ResponseMessage = responseMessage;
return result;
}
Expand Down Expand Up @@ -203,64 +209,54 @@ private async Task<T> ExecuteAsyncInner<T>(string method, string path, List<KeyV

private HttpRequestMessage BuildHttpRequestMessage<T>(string method, string path, List<KeyValuePair<string, object>> urlParams, object requestParams, string payloadKey, RequestSettings requestSettings) where T : ApiResponse
{
//insert url arguments into template
foreach (var arg in urlParams)
{
//insert url arguments into template
foreach (var arg in urlParams)
{
path = path.Replace(":" + arg.Key, Helpers.Stringify(arg.Value));
}
path = path.Replace(":" + arg.Key, Helpers.Stringify(arg.Value));
}
{
//add querystring for GET requests

if (method == "GET")
//add querystring for GET requests
if (method == "GET")
{
var requestArguments = Helpers.ExtractQueryStringValuesFromObject(requestParams);
if (requestArguments.Count > 0)
{
var requestArguments = Helpers.ExtractQueryStringValuesFromObject(requestParams);
if (requestArguments.Count > 0)
{
var queryString = String.Join("&", requestArguments.Select(Helpers.QueryStringArgument));
path += "?" + queryString;
}
var queryString = String.Join("&", requestArguments.Select(Helpers.QueryStringArgument));
path += "?" + queryString;
}
}


var httpMethod = new HttpMethod(method);

var requestMessage = new HttpRequestMessage(httpMethod, new Uri(_baseUrl, path));
requestMessage.Headers.Add("User-Agent", "gocardless-dotnet/2.15.0");
requestMessage.Headers.Add("User-Agent", "gocardless-dotnet/2.16.0");
requestMessage.Headers.Add("GoCardless-Version", "2015-07-06");
requestMessage.Headers.Add("GoCardless-Client-Version", "2.15.0");
requestMessage.Headers.Add("GoCardless-Client-Version", "2.16.0");
requestMessage.Headers.Add("GoCardless-Client-Library", "gocardless-dotnet");
requestMessage.Headers.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _accessToken);

//add request body for non-GETs
if (method != "GET" && requestParams != null && !String.IsNullOrWhiteSpace(payloadKey))
{
//add request body for non-GETs
if (method != "GET")
var settings = new Newtonsoft.Json.JsonSerializerSettings
{
if (requestParams != null)
{
var settings = new Newtonsoft.Json.JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
var serializer = JsonSerializer.Create(settings);
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
var serializer = JsonSerializer.Create(settings);

StringBuilder sb = new StringBuilder();
using (var sw = new StringWriter(sb))
{
var jo = new JObject();
using (var jsonTextWriter = new LinuxLineEndingJsonTextWriter(sw))
{
serializer.Serialize(jsonTextWriter, requestParams);
jo[payloadKey] = JToken.Parse(sb.ToString());
}
requestMessage.Content = new StringContent(jo.ToString(Formatting.Indented), Encoding.UTF8,
"application/json");
}
StringBuilder sb = new StringBuilder();
using (var sw = new StringWriter(sb))
{
var jo = new JObject();
using (var jsonTextWriter = new LinuxLineEndingJsonTextWriter(sw))
{
serializer.Serialize(jsonTextWriter, requestParams);
jo[payloadKey] = JToken.Parse(sb.ToString());
}
requestMessage.Content = new StringContent(jo.ToString(Formatting.Indented), Encoding.UTF8,
"application/json");
}
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For full details of the GoCardless API, see the [API docs](https://developer.goc

To install `GoCardless`, run the following command in the [Package Manager Console](https://docs.microsoft.com/en-us/nuget/tools/package-manager-console)

`Install-Package GoCardless -Version 2.15.0`
`Install-Package GoCardless -Version 2.16.0`


## Usage
Expand Down

0 comments on commit 03ebb63

Please sign in to comment.