Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14bcf19ba8 | ||
|
|
51f464bad0 | ||
|
|
e63d357d36 | ||
|
|
1a4414ad2c | ||
|
|
75288e625a | ||
|
|
f5e33d3a2f |
@@ -3,6 +3,8 @@ stages:
|
|||||||
- publish
|
- publish
|
||||||
|
|
||||||
running tests for tag:
|
running tests for tag:
|
||||||
|
only:
|
||||||
|
- /^\d*.\d*.\d*$/ # gets triggered if the commit tag is in the form n.n.n where n is any number
|
||||||
tags:
|
tags:
|
||||||
- shared
|
- shared
|
||||||
image: mcr.microsoft.com/dotnet/core/sdk:3.1
|
image: mcr.microsoft.com/dotnet/core/sdk:3.1
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Novaloop.PaymoApi.ClientContacts.Models;
|
using Novaloop.PaymoApi.ClientContacts.Models;
|
||||||
@@ -8,9 +9,9 @@ namespace Novaloop.PaymoApi.ClientContacts
|
|||||||
{
|
{
|
||||||
public class ClientContactsApi : IClientContactsApi
|
public class ClientContactsApi : IClientContactsApi
|
||||||
{
|
{
|
||||||
private readonly IBaseApi<GetClientContactsResponse, ClientContact> _baseApi;
|
private readonly IBaseApi<ClientContactsResponse, ClientContact> _baseApi;
|
||||||
|
|
||||||
public ClientContactsApi(IBaseApi<GetClientContactsResponse, ClientContact> baseApi)
|
public ClientContactsApi(IBaseApi<ClientContactsResponse, ClientContact> baseApi)
|
||||||
{
|
{
|
||||||
_baseApi = baseApi;
|
_baseApi = baseApi;
|
||||||
_baseApi.ResourceUri = "clientcontacts";
|
_baseApi.ResourceUri = "clientcontacts";
|
||||||
@@ -41,7 +42,7 @@ namespace Novaloop.PaymoApi.ClientContacts
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task UpdateClientContact(ClientContact clientContact, int clientContactId)
|
public async Task UpdateClientContact(ExpandoObject clientContact, int clientContactId)
|
||||||
{
|
{
|
||||||
await _baseApi.Update(clientContact, clientContactId);
|
await _baseApi.Update(clientContact, clientContactId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Novaloop.PaymoApi.ClientContacts.Models;
|
using Novaloop.PaymoApi.ClientContacts.Models;
|
||||||
|
|
||||||
@@ -36,6 +37,6 @@ namespace Novaloop.PaymoApi.ClientContacts
|
|||||||
/// <param name="clientContact"></param>
|
/// <param name="clientContact"></param>
|
||||||
/// <param name="clientContactId"></param>
|
/// <param name="clientContactId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task UpdateClientContact(ClientContact clientContact, int clientContactId);
|
Task UpdateClientContact(ExpandoObject clientContact, int clientContactId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ using Newtonsoft.Json;
|
|||||||
|
|
||||||
namespace Novaloop.PaymoApi.ClientContacts.Models
|
namespace Novaloop.PaymoApi.ClientContacts.Models
|
||||||
{
|
{
|
||||||
public class GetClientContactsResponse
|
public class ClientContactsResponse
|
||||||
{
|
{
|
||||||
[JsonProperty("clientcontacts")]
|
[JsonProperty("clientcontacts")]
|
||||||
public IEnumerable<ClientContact> ClientContacts { get; set; }
|
public IEnumerable<ClientContact> ClientContacts { get; set; }
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Novaloop.PaymoApi.Clients.Models;
|
using Novaloop.PaymoApi.Clients.Models;
|
||||||
@@ -41,7 +42,7 @@ namespace Novaloop.PaymoApi.Clients
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task UpdateClient(Client client, int clientId)
|
public async Task UpdateClient(ExpandoObject client, int clientId)
|
||||||
{
|
{
|
||||||
await _baseApi.Update(client, clientId);
|
await _baseApi.Update(client, clientId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Novaloop.PaymoApi.Clients.Models;
|
using Novaloop.PaymoApi.Clients.Models;
|
||||||
|
|
||||||
@@ -36,6 +37,6 @@ namespace Novaloop.PaymoApi.Clients
|
|||||||
/// <param name="client"></param>
|
/// <param name="client"></param>
|
||||||
/// <param name="clientId"></param>
|
/// <param name="clientId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task UpdateClient(Client client, int clientId);
|
Task UpdateClient(ExpandoObject client, int clientId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ using System;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Novaloop.PaymoApi.ClientContacts;
|
using Novaloop.PaymoApi.ClientContacts;
|
||||||
|
using Novaloop.PaymoApi.ClientContacts.Models;
|
||||||
using Novaloop.PaymoApi.Clients;
|
using Novaloop.PaymoApi.Clients;
|
||||||
using Novaloop.PaymoApi.Clients.Models;
|
using Novaloop.PaymoApi.Clients.Models;
|
||||||
using Novaloop.PaymoApi.Shared;
|
using Novaloop.PaymoApi.Shared;
|
||||||
@@ -16,19 +17,23 @@ namespace Novaloop.PaymoApi.Extensions
|
|||||||
{
|
{
|
||||||
services.Configure(options);
|
services.Configure(options);
|
||||||
var resolvedOptions = (IOptions<ApiOptions>) services.BuildServiceProvider().GetService(typeof(IOptions<ApiOptions>));
|
var resolvedOptions = (IOptions<ApiOptions>) services.BuildServiceProvider().GetService(typeof(IOptions<ApiOptions>));
|
||||||
services.AddHttpClient<ApiClient>(client => { client.BaseAddress = new Uri(resolvedOptions.Value.BaseUrl); });
|
services.AddHttpClient<ApiClient>(client => { client.BaseAddress = new Uri(resolvedOptions.Value.BaseUrl); })
|
||||||
|
.AddHttpMessageHandler(s => s.GetService<LoggingHandler>());
|
||||||
|
|
||||||
// Clients
|
// ClientContacts
|
||||||
services.AddTransient<IBaseApi<ClientsResponse, Client>, BaseApi<ClientsResponse, Client>>();
|
services.AddTransient<IBaseApi<ClientContactsResponse, ClientContact>, BaseApi<ClientContactsResponse, ClientContact>>();
|
||||||
services.AddTransient<IClientsApi, ClientsApi>();
|
services.AddTransient<IClientsApi, ClientsApi>();
|
||||||
|
|
||||||
// Tasks
|
// Tasks
|
||||||
services.AddTransient<ITasksApi, TasksApi>();
|
|
||||||
services.AddTransient<IBaseApi<TasksResponse, Task>, BaseApi<TasksResponse, Task>>();
|
services.AddTransient<IBaseApi<TasksResponse, Task>, BaseApi<TasksResponse, Task>>();
|
||||||
|
services.AddTransient<ITasksApi, TasksApi>();
|
||||||
|
|
||||||
// Contacts
|
// Contacts
|
||||||
services.AddTransient<IClientContactsApi, ClientContactsApi>();
|
|
||||||
services.AddTransient<IBaseApi<ClientsResponse, Client>, BaseApi<ClientsResponse, Client>>();
|
services.AddTransient<IBaseApi<ClientsResponse, Client>, BaseApi<ClientsResponse, Client>>();
|
||||||
|
services.AddTransient<IClientContactsApi, ClientContactsApi>();
|
||||||
|
|
||||||
|
// Shared
|
||||||
|
services.AddTransient<LoggingHandler>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<PackageId>Novaloop.PaymoApi</PackageId>
|
<PackageId>Novaloop.PaymoApi</PackageId>
|
||||||
<title>Access your paymo instance for asp.net core</title>
|
<title>Access your paymo instance for asp.net core</title>
|
||||||
<PackageTags>api;paymo;asp.net core;</PackageTags>
|
<PackageTags>api;paymo;asp.net core;</PackageTags>
|
||||||
<Version>1.1.2</Version>
|
<Version>1.1.5</Version>
|
||||||
<Authors>Matthias Langhard</Authors>
|
<Authors>Matthias Langhard</Authors>
|
||||||
<Company>Novaloop AG</Company>
|
<Company>Novaloop AG</Company>
|
||||||
<PackageProjectUrl>https://gitlab.com/novaloop-oss/novaloop.paymoapi</PackageProjectUrl>
|
<PackageProjectUrl>https://gitlab.com/novaloop-oss/novaloop.paymoapi</PackageProjectUrl>
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
|
using System.Dynamic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
using Novaloop.PaymoApi.Extensions;
|
using Novaloop.PaymoApi.Extensions;
|
||||||
|
|
||||||
namespace Novaloop.PaymoApi.Shared
|
namespace Novaloop.PaymoApi.Shared
|
||||||
@@ -70,10 +74,13 @@ namespace Novaloop.PaymoApi.Shared
|
|||||||
/// <param name="entity">entity information to update the entity with</param>
|
/// <param name="entity">entity information to update the entity with</param>
|
||||||
/// <param name="id">id of the entity to update</param>
|
/// <param name="id">id of the entity to update</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task Update(TCreatType entity, int id)
|
public async Task Update(ExpandoObject entity, int id)
|
||||||
{
|
{
|
||||||
_client.SetApiKeyHeader(_options.ApiToken);
|
_client.SetApiKeyHeader(_options.ApiToken);
|
||||||
var response = await _client.PutAsJsonAsync($"api/{ResourceUri}/{id}", entity);
|
var serializerSettings = new JsonSerializerSettings {ContractResolver = new CamelCasePropertyNamesContractResolver()};
|
||||||
|
var body = JsonConvert.SerializeObject(entity, serializerSettings);
|
||||||
|
var stringContent = new StringContent(body, Encoding.UTF8, "application/json");
|
||||||
|
var response = await _client.PutAsync($"api/{ResourceUri}/{id}", stringContent);
|
||||||
await response.ThrowExceptionWithDetailsIfUnsuccessful();
|
await response.ThrowExceptionWithDetailsIfUnsuccessful();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Dynamic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Novaloop.PaymoApi.Shared
|
namespace Novaloop.PaymoApi.Shared
|
||||||
@@ -36,6 +37,6 @@ namespace Novaloop.PaymoApi.Shared
|
|||||||
/// <param name="entity">entity information to update the entity with</param>
|
/// <param name="entity">entity information to update the entity with</param>
|
||||||
/// <param name="id">id of the entity to update</param>
|
/// <param name="id">id of the entity to update</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task Update( TCreatType entity, int id);
|
Task Update(ExpandoObject entity, int id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
45
src/Shared/LoggingHandler.cs
Normal file
45
src/Shared/LoggingHandler.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Shared
|
||||||
|
{
|
||||||
|
public class LoggingHandler : DelegatingHandler
|
||||||
|
{
|
||||||
|
private readonly ILogger<LoggingHandler> _logger;
|
||||||
|
|
||||||
|
public LoggingHandler(ILogger<LoggingHandler> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoggingHandler(HttpMessageHandler innerHandler, ILogger<LoggingHandler> logger)
|
||||||
|
: base(innerHandler)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
_logger.LogDebug($"Request:\n{request}");
|
||||||
|
if (request.Content != null)
|
||||||
|
{
|
||||||
|
var body = await request.Content.ReadAsStringAsync();
|
||||||
|
_logger.LogDebug(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = await base.SendAsync(request, cancellationToken);
|
||||||
|
|
||||||
|
_logger.LogDebug($"Response:\n{response}");
|
||||||
|
if (response.Content != null)
|
||||||
|
{
|
||||||
|
var body = await response.Content.ReadAsStringAsync();
|
||||||
|
_logger.LogDebug(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Novaloop.PaymoApi.Tasks
|
namespace Novaloop.PaymoApi.Tasks
|
||||||
@@ -35,6 +36,6 @@ namespace Novaloop.PaymoApi.Tasks
|
|||||||
/// <param name="task"></param>
|
/// <param name="task"></param>
|
||||||
/// <param name="taskId"></param>
|
/// <param name="taskId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task UpdateTask(Novaloop.PaymoApi.Tasks.Models.Task task, int taskId);
|
Task UpdateTask(ExpandoObject task, int taskId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Novaloop.PaymoApi.Shared;
|
using Novaloop.PaymoApi.Shared;
|
||||||
@@ -45,7 +46,7 @@ namespace Novaloop.PaymoApi.Tasks
|
|||||||
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task UpdateTask(Novaloop.PaymoApi.Tasks.Models.Task task, int taskId)
|
public async Task UpdateTask(ExpandoObject task, int taskId)
|
||||||
{
|
{
|
||||||
await _baseApi.Update(task, taskId);
|
await _baseApi.Update(task, taskId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace Novaloop.PaymoApi.Tests
|
|||||||
|
|
||||||
public ClientContactsApiTests()
|
public ClientContactsApiTests()
|
||||||
{
|
{
|
||||||
_clientContactsApi = new ClientContactsApi(new BaseApi<GetClientContactsResponse, ClientContact>(DependencyFactory.GeneratePaymoApiClient(), DependencyFactory.GenerateOptions()));
|
_clientContactsApi = new ClientContactsApi(new BaseApi<ClientContactsResponse, ClientContact>(DependencyFactory.GeneratePaymoApiClient(), DependencyFactory.GenerateOptions()));
|
||||||
_clientsApi = new ClientsApi(new BaseApi<ClientsResponse, Client>(DependencyFactory.GeneratePaymoApiClient(), DependencyFactory.GenerateOptions()));
|
_clientsApi = new ClientsApi(new BaseApi<ClientsResponse, Client>(DependencyFactory.GeneratePaymoApiClient(), DependencyFactory.GenerateOptions()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Dynamic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Novaloop.PaymoApi.Clients;
|
using Novaloop.PaymoApi.Clients;
|
||||||
using Novaloop.PaymoApi.Clients.Models;
|
using Novaloop.PaymoApi.Clients.Models;
|
||||||
@@ -84,7 +85,8 @@ namespace Novaloop.PaymoApi.Tests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var createdClient = await _clientsApi.CreateClient(_testClient);
|
var createdClient = await _clientsApi.CreateClient(_testClient);
|
||||||
var clientUpdateInfo = new Client {Name = "Updated"};
|
dynamic clientUpdateInfo = new ExpandoObject();
|
||||||
|
clientUpdateInfo.Name = "Updated";
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await _clientsApi.UpdateClient(clientUpdateInfo, createdClient.Id);
|
await _clientsApi.UpdateClient(clientUpdateInfo, createdClient.Id);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Novaloop.PaymoApi.Extensions;
|
using Novaloop.PaymoApi.Extensions;
|
||||||
using Novaloop.PaymoApi.Shared;
|
using Novaloop.PaymoApi.Shared;
|
||||||
@@ -11,7 +12,7 @@ namespace Novaloop.PaymoApi.Tests
|
|||||||
{
|
{
|
||||||
public static ApiClient GeneratePaymoApiClient()
|
public static ApiClient GeneratePaymoApiClient()
|
||||||
{
|
{
|
||||||
return new ApiClient(new HttpClient {BaseAddress = new Uri("https://app.paymoapp.com/")});
|
return new ApiClient(new HttpClient(new LoggingHandler(new HttpClientHandler(), new NullLogger<LoggingHandler>())) {BaseAddress = new Uri("https://app.paymoapp.com/")});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IOptions<ApiOptions> GenerateOptions()
|
public static IOptions<ApiOptions> GenerateOptions()
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Dynamic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Novaloop.PaymoApi.Shared;
|
using Novaloop.PaymoApi.Shared;
|
||||||
using Novaloop.PaymoApi.Tasks;
|
using Novaloop.PaymoApi.Tasks;
|
||||||
@@ -95,7 +96,9 @@ namespace Novaloop.PaymoApi.Tests
|
|||||||
var existingTaskListId = (await _tasksApi.GetTasks()).First().TasklistId;
|
var existingTaskListId = (await _tasksApi.GetTasks()).First().TasklistId;
|
||||||
_testTask.TasklistId = existingTaskListId;
|
_testTask.TasklistId = existingTaskListId;
|
||||||
var createdTask = await _tasksApi.CreateTask(_testTask);
|
var createdTask = await _tasksApi.CreateTask(_testTask);
|
||||||
var taskUpdateInfo = new Task {Name = "Updated", TasklistId = _testTask.TasklistId};
|
dynamic taskUpdateInfo = new ExpandoObject();
|
||||||
|
taskUpdateInfo.Name = "Updated";
|
||||||
|
taskUpdateInfo.TaskListId = _testTask.TasklistId;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await _tasksApi.UpdateTask(taskUpdateInfo, createdTask.Id);
|
await _tasksApi.UpdateTask(taskUpdateInfo, createdTask.Id);
|
||||||
|
|||||||
Reference in New Issue
Block a user