Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

UserAgent

  • Loading branch information...
commit 88ead4a0a8c49c9259bd2f920a6f682fff66a75e 1 parent 7648949
@timiles timiles authored
View
16 GoCardlessSdk/Api/ApiClient.cs
@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Net;
+using System.Net;
+using System.Net.Mime;
using GoCardlessSdk.Helpers;
using Newtonsoft.Json.Linq;
using RestSharp;
@@ -102,12 +103,13 @@ private static RestRequest GetRestRequest(string resource, Method method, object
return obj.GetType().GetProperties().ToDictionary(p => p.Name, p => p.GetValue(obj, null));
}
- public T Execute<T>(RestRequest request, HttpStatusCode expected = HttpStatusCode.OK) where T : new()
- {
- var client = new RestClient
- {
- BaseUrl = ApiUrl,
- };
+ public T Execute<T>(RestRequest request, HttpStatusCode expected = HttpStatusCode.OK) where T : new()
+ {
+ var client = new RestClient
+ {
+ BaseUrl = ApiUrl,
+ UserAgent = GoCardless.UserAgent
+ };
var serializer = new Newtonsoft.Json.JsonSerializer
{
ContractResolver = new UnderscoreToCamelCasePropertyResolver(),
View
7 GoCardlessSdk/Connect/ConnectClient.cs
@@ -168,9 +168,10 @@ public ConfirmResource ConfirmResource(NameValueCollection requestContent)
});
var client = new RestClient
- {
- BaseUrl = ApiClient.ApiUrl,
- };
+ {
+ BaseUrl = ApiClient.ApiUrl,
+ UserAgent = GoCardless.UserAgent
+ };
var serializer = new JsonSerializer
{
ContractResolver = new UnderscoreToCamelCasePropertyResolver(),
View
28 GoCardlessSdk/GoCardless.cs
@@ -1,5 +1,6 @@
using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
+using System.Reflection;
using GoCardlessSdk.Api;
using GoCardlessSdk.Connect;
using GoCardlessSdk.Helpers;
@@ -54,10 +55,27 @@ public static ConnectClient Connect
public static PartnerClient Partner
{
get { return new PartnerClient(); }
- }
-
-
-
+ }
+
+
+ public static string UserAgent
+ {
+ get { return "gocardless-dotnet/v" + AssemblyVersion; }
+ }
+ public static readonly string AssemblyVersion = GetAssemblyFileVersion();
+ public static string GetAssemblyFileVersion()
+ {
+ Assembly assembly = Assembly.GetAssembly(typeof (GoCardless));
+ var attributes = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)
+ as AssemblyFileVersionAttribute[];
+
+ if (attributes != null && attributes.Length == 1)
+ {
+ return attributes[0].Version;
+ }
+ return "";
+ }
+
private static Func<string> _generateNonce;
internal static Func<string> GenerateNonce
{
View
6 GoCardlessSdk/Partners/PartnerClient.cs
@@ -33,7 +33,11 @@ public MerchantAccessTokenResponse ParseCreateMerchantResponse(string redirectUr
};
var tokenUrl = "oauth/access_token?" + hash.ToQueryString();
- var client = new RestClient(GoCardless.BaseUrl);
+ var client = new RestClient
+ {
+ BaseUrl = GoCardless.BaseUrl,
+ UserAgent = GoCardless.UserAgent
+ };
client.Authenticator = new HttpBasicAuthenticator(GoCardless.AccountDetails.AppId, GoCardless.AccountDetails.AppSecret);
var restRequest = new RestRequest(tokenUrl);
View
4 GoCardlessSdk/Properties/AssemblyInfo.cs
@@ -32,7 +32,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyFileVersion("1.0.*")]
[assembly: InternalsVisibleTo("GoCardlessSdk.Tests")]
Please sign in to comment.
Something went wrong with that request. Please try again.