Skip to content

Commit

Permalink
Merge pull request #11 from gettyimages/get-current-user-info
Browse files Browse the repository at this point in the history
add get current user's info
  • Loading branch information
cleankode authored Feb 28, 2019
2 parents ebb14ac + 8b03add commit 0a63c74
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
12 changes: 11 additions & 1 deletion GettyImages.Api/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Net.Http;
using System.Threading.Tasks;
using GettyImages.Api.Download;
using GettyImages.Api.Orders;
using GettyImages.Api.Search;

namespace GettyImages.Api
Expand Down Expand Up @@ -585,5 +584,16 @@ public AssetLicensing.AcquireExtendedLicense AcquireExtendedLicense()
{
return AssetLicensing.AcquireExtendedLicense.GetInstance(_credentials, _baseUrl, _customHandler);
}

/// <summary>
/// Returns information about the current user
/// </summary>
/// <returns>
/// The <see cref="Api.Customers.Customers" />.
/// </returns>
public Customers.Customers Customers()
{
return Api.Customers.Customers.GetInstance(_credentials, _baseUrl, _customHandler);
}
}
}
36 changes: 36 additions & 0 deletions GettyImages.Api/Customers/Customers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Net.Http;
using System.Threading.Tasks;

namespace GettyImages.Api.Customers
{
public class Customers : ApiRequest
{
protected const string V3CustomersPath = "/customers/current";

public Customers(Credentials credentials, string baseUrl, DelegatingHandler customHandler) : base(customHandler)
{
Credentials = credentials;
BaseUrl = baseUrl;
}

internal static Customers GetInstance(Credentials credentials, string baseUrl, DelegatingHandler customHandler)
{
return new Customers(credentials, baseUrl, customHandler);
}

public override async Task<dynamic> ExecuteAsync()
{
Method = "GET";
Path = V3CustomersPath;

return await base.ExecuteAsync();
}

public Customers WithAcceptLanguage(string value)
{
AddHeaderParameter(Constants.AcceptLanguage, value);

return this;
}
}
}
22 changes: 22 additions & 0 deletions UnitTests/Customers/CustomersTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using FluentAssertions;
using GettyImages.Api;
using Xunit;

namespace UnitTests.Customers
{
public class CustomersTests
{
[Fact]
public void GetCustomerInfoBasic()
{
var testHandler = TestUtil.CreateTestHandler();

var response = ApiClient.GetApiClientWithResourceOwnerCredentials("apiKey", "apiSecret", "userName", "userPassword", testHandler)
.Customers()
.ExecuteAsync()
.Result;

testHandler.Request.RequestUri.AbsoluteUri.Should().Contain("/customers/current");
}
}
}

0 comments on commit 0a63c74

Please sign in to comment.