Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64eb96d388 | ||
|
|
de0a0ec296 | ||
|
|
9c7028c01d | ||
|
|
160600c3d8 | ||
|
|
1f6fc0a769 | ||
|
|
f1e0ab2450 | ||
|
|
306056b2f6 | ||
|
|
14bcf19ba8 | ||
|
|
51f464bad0 | ||
|
|
e63d357d36 | ||
|
|
1a4414ad2c | ||
|
|
75288e625a | ||
|
|
f5e33d3a2f | ||
|
|
c6c4b7ebc8 | ||
|
|
b1d4c35f11 | ||
|
|
89e7ce8449 | ||
|
|
ac20e2e1d4 | ||
|
|
c5734a065c |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1,6 @@
|
|||||||
|
# Project specific
|
||||||
|
tests/appsettings.tests.json
|
||||||
|
Novaloop.PaymoApi.sln.DotSettings.user
|
||||||
|
|
||||||
# Created by https://www.gitignore.io/api/dotnetcore,jetbrains+all,visualstudiocode
|
# Created by https://www.gitignore.io/api/dotnetcore,jetbrains+all,visualstudiocode
|
||||||
# Edit at https://www.gitignore.io/?templates=dotnetcore,jetbrains+all,visualstudiocode
|
# Edit at https://www.gitignore.io/?templates=dotnetcore,jetbrains+all,visualstudiocode
|
||||||
@@ -115,3 +118,4 @@ tests/bin
|
|||||||
tests/obj
|
tests/obj
|
||||||
src/obj
|
src/obj
|
||||||
src/bin
|
src/bin
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,32 @@
|
|||||||
|
# You can override the included template(s) by including variable overrides
|
||||||
|
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
|
||||||
|
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
|
||||||
|
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
|
||||||
|
# Note that environment variables can be set in several places
|
||||||
|
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
- publish
|
- publish
|
||||||
|
|
||||||
running tests for tag:
|
running tests for tag:
|
||||||
|
only:
|
||||||
|
- "/^\\d*.\\d*.\\d*$/"
|
||||||
tags:
|
tags:
|
||||||
- shared
|
- shared
|
||||||
image: mcr.microsoft.com/dotnet/core/sdk:3.1
|
image: mcr.microsoft.com/dotnet/core/sdk:3.1
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- dotnet test ./tests
|
- dotnet test ./tests
|
||||||
|
|
||||||
publish to nuget:
|
publish to nuget:
|
||||||
tags:
|
tags:
|
||||||
- shared
|
- shared
|
||||||
only:
|
only:
|
||||||
- /^\d*.\d*.\d*$/ # gets triggered if the commit tag is in the form n.n.n where n is any number
|
- "/^\\d*.\\d*.\\d*$/"
|
||||||
image: mcr.microsoft.com/dotnet/core/sdk:3.1
|
image: mcr.microsoft.com/dotnet/core/sdk:3.1
|
||||||
stage: publish
|
stage: publish
|
||||||
script:
|
script:
|
||||||
- dotnet pack src -o ./packaged
|
- dotnet pack src -o ./packaged
|
||||||
- dotnet nuget push ./packaged/*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json
|
- dotnet nuget push ./packaged/*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json
|
||||||
|
sast:
|
||||||
|
stage: test
|
||||||
|
include:
|
||||||
|
- template: Security/SAST.gitlab-ci.yml
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.26124.0
|
|||||||
MinimumVisualStudioVersion = 15.0.26124.0
|
MinimumVisualStudioVersion = 15.0.26124.0
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Novaloop.PaymoApi", "src\Novaloop.PaymoApi.csproj", "{A9612B7C-67C1-4B6B-8260-167079A31FAF}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Novaloop.PaymoApi", "src\Novaloop.PaymoApi.csproj", "{A9612B7C-67C1-4B6B-8260-167079A31FAF}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Novaloop.PaymoApi.Tests", "tests\Novaloop.PaymoApi.Tests.csproj", "{202BCB4F-78AF-4E9A-B286-C3147374EB53}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Novaloop.PaymoApi.IntegrationTests", "tests\Novaloop.PaymoApi.IntegrationTests.csproj", "{202BCB4F-78AF-4E9A-B286-C3147374EB53}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|||||||
42
src/ClientContacts/IPaymoClientContactsApi.cs
Normal file
42
src/ClientContacts/IPaymoClientContactsApi.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Novaloop.PaymoApi.ClientContacts.Models;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.ClientContacts
|
||||||
|
{
|
||||||
|
public interface IPaymoClientContactsApi
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Receive all existing client contacts
|
||||||
|
/// </summary>
|
||||||
|
Task<IEnumerable<PaymoClientContact>> GetClientContacts();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve an existing client contact by id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="clientContactId">id of the contact</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<PaymoClientContact> GetClientContact(int clientContactId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new client contact
|
||||||
|
/// </summary>
|
||||||
|
Task<PaymoClientContact> CreateClientContact(PaymoClientContact paymoClientContact);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete a client contact
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="clientContactId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task DeleteClientContact(int clientContactId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update an existing client contact
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="clientContact"></param>
|
||||||
|
/// <param name="clientContactId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task UpdateClientContact(ExpandoObject clientContact, int clientContactId);
|
||||||
|
}
|
||||||
|
}
|
||||||
44
src/ClientContacts/Models/PaymoClientContact.cs
Normal file
44
src/ClientContacts/Models/PaymoClientContact.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Novaloop.PaymoApi.Shared;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.ClientContacts.Models
|
||||||
|
{
|
||||||
|
public class PaymoClientContact : PaymoBaseModel
|
||||||
|
{
|
||||||
|
[JsonProperty("client_id")]
|
||||||
|
public int ClientId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("email")]
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("mobile")]
|
||||||
|
public string Mobile { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("phone")]
|
||||||
|
public string Phone { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("fax")]
|
||||||
|
public string Fax { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("skype")]
|
||||||
|
public string Skype { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("notes")]
|
||||||
|
public object Notes { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("image")]
|
||||||
|
public string Image { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("is_main")]
|
||||||
|
public bool IsMain { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("position")]
|
||||||
|
public string Position { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("access")]
|
||||||
|
public bool Access { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/ClientContacts/Models/PaymoClientContactsResponse.cs
Normal file
11
src/ClientContacts/Models/PaymoClientContactsResponse.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.ClientContacts.Models
|
||||||
|
{
|
||||||
|
public class PaymoClientContactsResponse
|
||||||
|
{
|
||||||
|
[JsonProperty("clientcontacts")]
|
||||||
|
public IEnumerable<PaymoClientContact> ClientContacts { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
50
src/ClientContacts/PaymoClientContactsApi.cs
Normal file
50
src/ClientContacts/PaymoClientContactsApi.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Novaloop.PaymoApi.ClientContacts.Models;
|
||||||
|
using Novaloop.PaymoApi.Shared;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.ClientContacts
|
||||||
|
{
|
||||||
|
public class PaymoClientContactsApi : IPaymoClientContactsApi
|
||||||
|
{
|
||||||
|
private readonly IPaymoBaseApi<PaymoClientContactsResponse, PaymoClientContact> _paymoBaseApi;
|
||||||
|
|
||||||
|
public PaymoClientContactsApi(IPaymoBaseApi<PaymoClientContactsResponse, PaymoClientContact> paymoBaseApi)
|
||||||
|
{
|
||||||
|
_paymoBaseApi = paymoBaseApi;
|
||||||
|
_paymoBaseApi.ResourceUri = "clientcontacts";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<IEnumerable<PaymoClientContact>> GetClientContacts()
|
||||||
|
{
|
||||||
|
return (await _paymoBaseApi.GetAll()).ClientContacts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<PaymoClientContact> GetClientContact(int clientContactId)
|
||||||
|
{
|
||||||
|
return (await _paymoBaseApi.Get(clientContactId)).ClientContacts.Single();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<PaymoClientContact> CreateClientContact(PaymoClientContact paymoClientContact)
|
||||||
|
{
|
||||||
|
return (await _paymoBaseApi.Create(paymoClientContact)).ClientContacts.Single();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task DeleteClientContact(int clientContactId)
|
||||||
|
{
|
||||||
|
await _paymoBaseApi.Delete(clientContactId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task UpdateClientContact(ExpandoObject clientContact, int clientContactId)
|
||||||
|
{
|
||||||
|
await _paymoBaseApi.Update(clientContact, clientContactId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
42
src/Clients/IPaymoClientsApi.cs
Normal file
42
src/Clients/IPaymoClientsApi.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Novaloop.PaymoApi.Clients.Models;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Clients
|
||||||
|
{
|
||||||
|
public interface IPaymoClientsApi
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Receive all existing clients
|
||||||
|
/// </summary>
|
||||||
|
Task<IEnumerable<PaymoClient>> GetClients();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve an existing client by id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="clientId">id of the contact</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<PaymoClient> GetClient(int clientId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new client
|
||||||
|
/// </summary>
|
||||||
|
Task<PaymoClient> CreateClient(PaymoClient paymoClient);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete a client
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="clientId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task DeleteClient(int clientId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update an existing client
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="clientId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task UpdateClient(ExpandoObject client, int clientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
52
src/Clients/Models/PaymoClient.cs
Normal file
52
src/Clients/Models/PaymoClient.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Novaloop.PaymoApi.Shared;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Clients.Models
|
||||||
|
{
|
||||||
|
public class PaymoClient : PaymoBaseModel
|
||||||
|
{
|
||||||
|
[JsonProperty("name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("address")]
|
||||||
|
public string Address { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("city")]
|
||||||
|
public string City { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("state")]
|
||||||
|
public string State { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("postal_code")]
|
||||||
|
public string PostalCode { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("country")]
|
||||||
|
public string Country { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("phone")]
|
||||||
|
public string Phone { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("fax")]
|
||||||
|
public string Fax { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("email")]
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("website")]
|
||||||
|
public string Website { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("image")]
|
||||||
|
public string Image { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("fiscal_information")]
|
||||||
|
public string FiscalInformation { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("active")]
|
||||||
|
public bool Active { get; set; } = true;
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"[{Id}] {Name}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/Clients/Models/PaymoClientsResponse.cs
Normal file
11
src/Clients/Models/PaymoClientsResponse.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Clients.Models
|
||||||
|
{
|
||||||
|
public class PaymoClientsResponse
|
||||||
|
{
|
||||||
|
[JsonProperty("clients")]
|
||||||
|
public IEnumerable<PaymoClient> Clients { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
50
src/Clients/PaymoPaymoClientsApi.cs
Normal file
50
src/Clients/PaymoPaymoClientsApi.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Novaloop.PaymoApi.Clients.Models;
|
||||||
|
using Novaloop.PaymoApi.Shared;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Clients
|
||||||
|
{
|
||||||
|
public class PaymoPaymoClientsApi : IPaymoClientsApi
|
||||||
|
{
|
||||||
|
private readonly IPaymoBaseApi<PaymoClientsResponse, PaymoClient> _paymoBaseApi;
|
||||||
|
|
||||||
|
public PaymoPaymoClientsApi(IPaymoBaseApi<PaymoClientsResponse, PaymoClient> paymoBaseApi)
|
||||||
|
{
|
||||||
|
_paymoBaseApi = paymoBaseApi;
|
||||||
|
_paymoBaseApi.ResourceUri = "clients";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<IEnumerable<PaymoClient>> GetClients()
|
||||||
|
{
|
||||||
|
return (await _paymoBaseApi.GetAll()).Clients;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<PaymoClient> GetClient(int clientId)
|
||||||
|
{
|
||||||
|
return (await _paymoBaseApi.Get(clientId)).Clients.Single();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<PaymoClient> CreateClient(PaymoClient paymoClient)
|
||||||
|
{
|
||||||
|
return (await _paymoBaseApi.Create(paymoClient)).Clients.Single();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task DeleteClient(int clientId)
|
||||||
|
{
|
||||||
|
await _paymoBaseApi.Delete(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task UpdateClient(ExpandoObject client, int clientId)
|
||||||
|
{
|
||||||
|
await _paymoBaseApi.Update(client, clientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
using System;
|
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.Models;
|
||||||
|
using Novaloop.PaymoApi.Clients;
|
||||||
|
using Novaloop.PaymoApi.Clients.Models;
|
||||||
using Novaloop.PaymoApi.Shared;
|
using Novaloop.PaymoApi.Shared;
|
||||||
using Novaloop.PaymoApi.Tasks;
|
using Novaloop.PaymoApi.Tasks;
|
||||||
|
using Novaloop.PaymoApi.Tasks.Models;
|
||||||
|
|
||||||
namespace Novaloop.PaymoApi.Extensions
|
namespace Novaloop.PaymoApi.Extensions
|
||||||
{
|
{
|
||||||
@@ -12,8 +17,24 @@ namespace Novaloop.PaymoApi.Extensions
|
|||||||
{
|
{
|
||||||
services.Configure(options);
|
services.Configure(options);
|
||||||
var resolvedOptions = (IOptions<PaymoApiOptions>) services.BuildServiceProvider().GetService(typeof(IOptions<PaymoApiOptions>));
|
var resolvedOptions = (IOptions<PaymoApiOptions>) services.BuildServiceProvider().GetService(typeof(IOptions<PaymoApiOptions>));
|
||||||
services.AddHttpClient<PaymoApiClient>(client => { client.BaseAddress = new Uri(resolvedOptions.Value.BaseUrl); });
|
services.AddHttpClient<PaymoPaymoIApiClient>(client => { client.BaseAddress = new Uri(resolvedOptions.Value.BaseUrl); })
|
||||||
services.AddTransient<IPaymoTasksApiService, PaymoTasksApiService>();
|
.AddHttpMessageHandler(s => s.GetService<PaymoLoggingHandler>());
|
||||||
|
|
||||||
|
// ClientContacts
|
||||||
|
services.AddTransient<IPaymoBaseApi<PaymoClientContactsResponse, PaymoClientContact>, PaymoBaseApi<PaymoClientContactsResponse, PaymoClientContact>>();
|
||||||
|
services.AddTransient<IPaymoClientsApi, PaymoPaymoClientsApi>();
|
||||||
|
|
||||||
|
// Tasks
|
||||||
|
services.AddTransient<IPaymoBaseApi<PaymoTasksResponse, PaymoTask>, PaymoBaseApi<PaymoTasksResponse, PaymoTask>>();
|
||||||
|
services.AddTransient<IPaymoTasksApi, PaymoTasksApi>();
|
||||||
|
|
||||||
|
// Contacts
|
||||||
|
services.AddTransient<IPaymoBaseApi<PaymoClientsResponse, PaymoClient>, PaymoBaseApi<PaymoClientsResponse, PaymoClient>>();
|
||||||
|
services.AddTransient<IPaymoClientContactsApi, PaymoClientContactsApi>();
|
||||||
|
|
||||||
|
// Shared
|
||||||
|
services.AddTransient<PaymoLoggingHandler>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<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>0.1.9</Version>
|
<Version>3.0.0</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>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
|
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
42
src/Shared/IPaymoBaseApi.cs
Normal file
42
src/Shared/IPaymoBaseApi.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Dynamic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Shared
|
||||||
|
{
|
||||||
|
public interface IPaymoBaseApi<TReturnType, TCreatType>
|
||||||
|
{
|
||||||
|
string ResourceUri { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Receive all entities
|
||||||
|
/// </summary>
|
||||||
|
Task<TReturnType> GetAll();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve an existing entity
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entityId">id of the entity</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<TReturnType> Get(int entityId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new entity
|
||||||
|
/// </summary>
|
||||||
|
Task<TReturnType> Create( TCreatType entity);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete an entity
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entityId">id of the entity</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task Delete(int entityId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update an entity
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">entity information to update the entity with</param>
|
||||||
|
/// <param name="id">id of the entity to update</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task Update(ExpandoObject entity, int id);
|
||||||
|
}
|
||||||
|
}
|
||||||
87
src/Shared/PaymoBaseApi.cs
Normal file
87
src/Shared/PaymoBaseApi.cs
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
using System.Dynamic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using Novaloop.PaymoApi.Extensions;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Shared
|
||||||
|
{
|
||||||
|
public class PaymoBaseApi<TReturnType, TCreatType> : IPaymoBaseApi<TReturnType, TCreatType>
|
||||||
|
{
|
||||||
|
public string ResourceUri { get; set; }
|
||||||
|
private readonly PaymoApiOptions _options;
|
||||||
|
private readonly HttpClient _client;
|
||||||
|
|
||||||
|
public PaymoBaseApi(PaymoPaymoIApiClient paymoPaymoIApiClient, IOptions<PaymoApiOptions> options)
|
||||||
|
{
|
||||||
|
_options = options.Value;
|
||||||
|
_client = paymoPaymoIApiClient.Client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Receive all entities
|
||||||
|
/// </summary>
|
||||||
|
public async Task<TReturnType> GetAll()
|
||||||
|
{
|
||||||
|
_client.SetApiKeyHeader(_options.ApiToken);
|
||||||
|
var response = await _client.GetAsync($"api/{ResourceUri}");
|
||||||
|
await response.ThrowExceptionWithDetailsIfUnsuccessful();
|
||||||
|
return await response.Content.ReadAsAsync<TReturnType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve an existing entity
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entityId">id of the entity</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TReturnType> Get(int entityId)
|
||||||
|
{
|
||||||
|
_client.SetApiKeyHeader(_options.ApiToken);
|
||||||
|
var response = await _client.GetAsync($"api/{ResourceUri}/{entityId}");
|
||||||
|
await response.ThrowExceptionWithDetailsIfUnsuccessful();
|
||||||
|
return await response.Content.ReadAsAsync<TReturnType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new entity
|
||||||
|
/// </summary>
|
||||||
|
public async Task<TReturnType> Create(TCreatType entity)
|
||||||
|
{
|
||||||
|
_client.SetApiKeyHeader(_options.ApiToken);
|
||||||
|
var response = await _client.PostAsJsonAsync($"api/{ResourceUri}", entity);
|
||||||
|
await response.ThrowExceptionWithDetailsIfUnsuccessful();
|
||||||
|
return await response.Content.ReadAsAsync<TReturnType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete an entity
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entityId">id of the entity</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task Delete(int entityId)
|
||||||
|
{
|
||||||
|
_client.SetApiKeyHeader(_options.ApiToken);
|
||||||
|
var response = await _client.DeleteAsync($"api/{ResourceUri}/{entityId}");
|
||||||
|
await response.ThrowExceptionWithDetailsIfUnsuccessful();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update an entity
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">entity information to update the entity with</param>
|
||||||
|
/// <param name="id">id of the entity to update</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task Update(ExpandoObject entity, int id)
|
||||||
|
{
|
||||||
|
_client.SetApiKeyHeader(_options.ApiToken);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/Shared/PaymoBaseModel.cs
Normal file
11
src/Shared/PaymoBaseModel.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Shared
|
||||||
|
{
|
||||||
|
public class PaymoBaseModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public DateTime CreatedOn { get; set; }
|
||||||
|
public DateTime UpdatedOn { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Novaloop.PaymoApi.Shared
|
namespace Novaloop.PaymoApi.Shared
|
||||||
{
|
{
|
||||||
public interface IPaymoApiClient
|
public interface PaymoIApiClient
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
45
src/Shared/PaymoLoggingHandler.cs
Normal file
45
src/Shared/PaymoLoggingHandler.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 PaymoLoggingHandler : DelegatingHandler
|
||||||
|
{
|
||||||
|
private readonly ILogger<PaymoLoggingHandler> _logger;
|
||||||
|
|
||||||
|
public PaymoLoggingHandler(ILogger<PaymoLoggingHandler> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PaymoLoggingHandler(HttpMessageHandler innerHandler, ILogger<PaymoLoggingHandler> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,9 @@ using System.Net.Http;
|
|||||||
|
|
||||||
namespace Novaloop.PaymoApi.Shared
|
namespace Novaloop.PaymoApi.Shared
|
||||||
{
|
{
|
||||||
public class PaymoApiClient : IPaymoApiClient
|
public class PaymoPaymoIApiClient : PaymoIApiClient
|
||||||
{
|
{
|
||||||
public PaymoApiClient(HttpClient client)
|
public PaymoPaymoIApiClient(HttpClient client)
|
||||||
{
|
{
|
||||||
Client = client;
|
Client = client;
|
||||||
}
|
}
|
||||||
41
src/Tasks/IPaymoTasksApi.cs
Normal file
41
src/Tasks/IPaymoTasksApi.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Tasks
|
||||||
|
{
|
||||||
|
public interface IPaymoTasksApi
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Receive all existing tasks
|
||||||
|
/// </summary>
|
||||||
|
Task<IEnumerable<Models.PaymoTask>> GetTasks();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve an existing Task by id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="taskId">id of the task</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<Models.PaymoTask> GetTask(int taskId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new Task
|
||||||
|
/// </summary>
|
||||||
|
Task<Models.PaymoTask> CreateTask(Models.PaymoTask paymoTask);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete a task
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="taskId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task DeleteTask(int taskId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update an existing task
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="task"></param>
|
||||||
|
/// <param name="taskId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task UpdateTask(ExpandoObject task, int taskId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using System.Threading.Tasks;
|
|
||||||
using Novaloop.PaymoApi.Tasks.Models;
|
|
||||||
|
|
||||||
namespace Novaloop.PaymoApi.Tasks
|
|
||||||
{
|
|
||||||
public interface IPaymoTasksApiService
|
|
||||||
{
|
|
||||||
Task<GetTasksResponse> GetTasks();
|
|
||||||
Task<GetTasksResponse> GetTask(int taskId);
|
|
||||||
Task<CreateTaskResponse> CreateTask(CreateTaskRequest createTask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Novaloop.PaymoApi.Tasks.Models
|
|
||||||
{
|
|
||||||
public class CreateTaskRequest
|
|
||||||
{
|
|
||||||
[JsonProperty(PropertyName = "name")]
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "description")]
|
|
||||||
public string Description { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "tasklist_id")]
|
|
||||||
public int TasklistId { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "users")]
|
|
||||||
public List<int> Users { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace Novaloop.PaymoApi.Tasks.Models
|
|
||||||
{
|
|
||||||
public class CreateTaskResponse : PaymoTask
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +1,53 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Novaloop.PaymoApi.Shared;
|
||||||
|
|
||||||
namespace Novaloop.PaymoApi.Tasks.Models
|
namespace Novaloop.PaymoApi.Tasks.Models
|
||||||
{
|
{
|
||||||
public class PaymoTask
|
public class PaymoTask : PaymoBaseModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
[JsonProperty("name")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("code")]
|
||||||
public string Code { get; set; }
|
public string Code { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("project_id")]
|
||||||
public int ProjectId { get; set; }
|
public int ProjectId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("tasklist_id")]
|
||||||
public int TasklistId { get; set; }
|
public int TasklistId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("user_id")]
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("complete")]
|
||||||
public bool Complete { get; set; }
|
public bool Complete { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("billable")]
|
||||||
public bool Billable { get; set; }
|
public bool Billable { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("seq")]
|
||||||
public int Seq { get; set; }
|
public int Seq { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("description")]
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("price_per_hour")]
|
||||||
public object PricePerHour { get; set; }
|
public object PricePerHour { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("due_date")]
|
||||||
public object DueDate { get; set; }
|
public object DueDate { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("budget_hours")]
|
||||||
public object BudgetHours { get; set; }
|
public object BudgetHours { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("users")]
|
||||||
public List<int> Users { get; set; }
|
public List<int> Users { get; set; }
|
||||||
public DateTime CreatedOn { get; set; }
|
|
||||||
public DateTime UpdatedOn { get; set; }
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"[{Id}] {Name} ({TasklistId})";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Novaloop.PaymoApi.Tasks.Models
|
namespace Novaloop.PaymoApi.Tasks.Models
|
||||||
{
|
{
|
||||||
public class GetTasksResponse
|
public class PaymoTasksResponse
|
||||||
{
|
{
|
||||||
|
[JsonProperty("tasks")]
|
||||||
public IEnumerable<PaymoTask> Tasks { get; set; }
|
public IEnumerable<PaymoTask> Tasks { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
54
src/Tasks/PaymoTasksApi.cs
Normal file
54
src/Tasks/PaymoTasksApi.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Novaloop.PaymoApi.Shared;
|
||||||
|
using Novaloop.PaymoApi.Tasks.Models;
|
||||||
|
using Task = System.Threading.Tasks.Task;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Tasks
|
||||||
|
{
|
||||||
|
public class PaymoTasksApi : IPaymoTasksApi
|
||||||
|
{
|
||||||
|
private readonly IPaymoBaseApi<PaymoTasksResponse, PaymoTask> _paymoBaseApi;
|
||||||
|
|
||||||
|
public PaymoTasksApi(IPaymoBaseApi<PaymoTasksResponse, PaymoTask> paymoBaseApi)
|
||||||
|
{
|
||||||
|
_paymoBaseApi = paymoBaseApi;
|
||||||
|
_paymoBaseApi.ResourceUri = "tasks";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<IEnumerable<PaymoTask>> GetTasks()
|
||||||
|
{
|
||||||
|
return (await _paymoBaseApi.GetAll()).Tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<PaymoTask> GetTask(int taskId)
|
||||||
|
{
|
||||||
|
return (await _paymoBaseApi.Get(taskId)).Tasks.Single();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<PaymoTask> CreateTask(PaymoTask paymoTask)
|
||||||
|
{
|
||||||
|
return (await _paymoBaseApi.Create(paymoTask)).Tasks.Single();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task DeleteTask(int taskId)
|
||||||
|
{
|
||||||
|
await _paymoBaseApi.Delete(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task UpdateTask(ExpandoObject task, int taskId)
|
||||||
|
{
|
||||||
|
await _paymoBaseApi.Update(task, taskId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using Novaloop.PaymoApi.Extensions;
|
|
||||||
using Novaloop.PaymoApi.Shared;
|
|
||||||
using Novaloop.PaymoApi.Tasks.Models;
|
|
||||||
|
|
||||||
namespace Novaloop.PaymoApi.Tasks
|
|
||||||
{
|
|
||||||
public class PaymoTasksApiService : IPaymoTasksApiService
|
|
||||||
{
|
|
||||||
private readonly PaymoApiOptions _options;
|
|
||||||
private readonly HttpClient _client;
|
|
||||||
|
|
||||||
public PaymoTasksApiService(PaymoApiClient paymoApiClient, IOptions<PaymoApiOptions> options)
|
|
||||||
{
|
|
||||||
_options = options.Value;
|
|
||||||
_client = paymoApiClient.Client;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Receive all existing tasks
|
|
||||||
/// </summary>
|
|
||||||
public async Task<GetTasksResponse> GetTasks()
|
|
||||||
{
|
|
||||||
_client.SetApiKeyHeader(_options.ApiToken);
|
|
||||||
var response = await _client.GetAsync($"api/tasks");
|
|
||||||
await response.ThrowExceptionWithDetailsIfUnsuccessful();
|
|
||||||
return await response.Content.ReadAsAsync<GetTasksResponse>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieve an existing Task by id
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="taskId">id of the task</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<GetTasksResponse> GetTask(int taskId)
|
|
||||||
{
|
|
||||||
_client.SetApiKeyHeader(_options.ApiToken);
|
|
||||||
var response = await _client.GetAsync($"api/tasks/{taskId}");
|
|
||||||
await response.ThrowExceptionWithDetailsIfUnsuccessful();
|
|
||||||
return await response.Content.ReadAsAsync<GetTasksResponse>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new Task
|
|
||||||
/// </summary>
|
|
||||||
public async Task<CreateTaskResponse> CreateTask(CreateTaskRequest createTaskRequest)
|
|
||||||
{
|
|
||||||
_client.SetApiKeyHeader(_options.ApiToken);
|
|
||||||
var response = await _client.PostAsJsonAsync("api/tasks", createTaskRequest);
|
|
||||||
await response.ThrowExceptionWithDetailsIfUnsuccessful();
|
|
||||||
return await response.Content.ReadAsAsync<CreateTaskResponse>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
93
tests/ClientContactsApiTests.cs
Normal file
93
tests/ClientContactsApiTests.cs
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using Novaloop.PaymoApi.ClientContacts;
|
||||||
|
using Novaloop.PaymoApi.ClientContacts.Models;
|
||||||
|
using Novaloop.PaymoApi.Clients;
|
||||||
|
using Novaloop.PaymoApi.Clients.Models;
|
||||||
|
using Novaloop.PaymoApi.Shared;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Tests
|
||||||
|
{
|
||||||
|
[Collection("IntegrationTests")]
|
||||||
|
public class ClientContactsApiTests
|
||||||
|
{
|
||||||
|
private readonly PaymoClientContactsApi _paymoClientContactsApi;
|
||||||
|
private readonly PaymoPaymoClientsApi _paymoPaymoClientsApi;
|
||||||
|
|
||||||
|
private readonly PaymoClientContact _testPaymoClientContact = new PaymoClientContact
|
||||||
|
{
|
||||||
|
Name = "Testclient",
|
||||||
|
Email = "test@client.de"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
public ClientContactsApiTests()
|
||||||
|
{
|
||||||
|
Thread.Sleep(5000);
|
||||||
|
_paymoClientContactsApi = new PaymoClientContactsApi(new PaymoBaseApi<PaymoClientContactsResponse, PaymoClientContact>(DependencyFactory.GeneratePaymoApiClient(), DependencyFactory.GenerateOptions()));
|
||||||
|
_paymoPaymoClientsApi = new PaymoPaymoClientsApi(new PaymoBaseApi<PaymoClientsResponse, PaymoClient>(DependencyFactory.GeneratePaymoApiClient(), DependencyFactory.GenerateOptions()));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void GetClientContacts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var clientContacts = (await _paymoClientContactsApi.GetClientContacts()).ToList();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotEmpty(clientContacts);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void GetClientContact()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var clientContacts = (await _paymoClientContactsApi.GetClientContacts()).ToList();
|
||||||
|
var clientContact = await _paymoClientContactsApi.GetClientContact(clientContacts.First().Id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(clientContact);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void CreateClientContact()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var existingClientContact = (await _paymoPaymoClientsApi.GetClients()).First();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_testPaymoClientContact.ClientId = existingClientContact.Id;
|
||||||
|
var createdClientContact = await _paymoClientContactsApi.CreateClientContact(_testPaymoClientContact);
|
||||||
|
var clientContact = await _paymoClientContactsApi.GetClientContact(createdClientContact.Id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(_testPaymoClientContact.Name, clientContact.Name);
|
||||||
|
Assert.Equal(_testPaymoClientContact.Email, clientContact.Email);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
await _paymoClientContactsApi.DeleteClientContact(createdClientContact.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void DeleteClientContact()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var existingClientContact = (await _paymoPaymoClientsApi.GetClients()).First();
|
||||||
|
_testPaymoClientContact.ClientId = existingClientContact.Id;
|
||||||
|
var createdClientContact = await _paymoClientContactsApi.CreateClientContact(_testPaymoClientContact);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await _paymoClientContactsApi.DeleteClientContact(createdClientContact.Id);
|
||||||
|
var clientContacts = (await _paymoClientContactsApi.GetClientContacts()).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Empty(clientContacts.Where(c => c.Id == createdClientContact.Id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
105
tests/ClientsApiTests.cs
Normal file
105
tests/ClientsApiTests.cs
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
using System.Dynamic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using Novaloop.PaymoApi.Clients;
|
||||||
|
using Novaloop.PaymoApi.Clients.Models;
|
||||||
|
using Novaloop.PaymoApi.Shared;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Tests
|
||||||
|
{
|
||||||
|
[Collection("IntegrationTests")]
|
||||||
|
public class ClientsApiTests
|
||||||
|
{
|
||||||
|
private readonly PaymoPaymoClientsApi _paymoPaymoClientsApi;
|
||||||
|
|
||||||
|
private readonly PaymoClient _testPaymoClient = new PaymoClient
|
||||||
|
{
|
||||||
|
Name = "Testclient",
|
||||||
|
Email = "test@client.de"
|
||||||
|
};
|
||||||
|
|
||||||
|
public ClientsApiTests()
|
||||||
|
{
|
||||||
|
Thread.Sleep(5000);
|
||||||
|
_paymoPaymoClientsApi =
|
||||||
|
new PaymoPaymoClientsApi(new PaymoBaseApi<PaymoClientsResponse, PaymoClient>(DependencyFactory.GeneratePaymoApiClient(),
|
||||||
|
DependencyFactory.GenerateOptions()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void GetClients()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var clients = (await _paymoPaymoClientsApi.GetClients()).ToList();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotEmpty(clients);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void GetClient()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var clients = (await _paymoPaymoClientsApi.GetClients()).ToList();
|
||||||
|
var client = await _paymoPaymoClientsApi.GetClient(clients.First().Id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void CreateClient()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var createdClient = await _paymoPaymoClientsApi.CreateClient(_testPaymoClient);
|
||||||
|
var client = await _paymoPaymoClientsApi.GetClient(createdClient.Id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(_testPaymoClient.Name, client.Name);
|
||||||
|
Assert.Equal(_testPaymoClient.Email, client.Email);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
await _paymoPaymoClientsApi.DeleteClient(createdClient.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void DeleteClient()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var createdClient = await _paymoPaymoClientsApi.CreateClient(_testPaymoClient);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await _paymoPaymoClientsApi.DeleteClient(createdClient.Id);
|
||||||
|
var clients = (await _paymoPaymoClientsApi.GetClients()).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Empty(clients.Where(c => c.Id == createdClient.Id));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void UpdateClient()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var createdClient = await _paymoPaymoClientsApi.CreateClient(_testPaymoClient);
|
||||||
|
dynamic clientUpdateInfo = new ExpandoObject();
|
||||||
|
clientUpdateInfo.Name = "Updated";
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await _paymoPaymoClientsApi.UpdateClient(clientUpdateInfo, createdClient.Id);
|
||||||
|
var updatedClient = await _paymoPaymoClientsApi.GetClient(createdClient.Id);
|
||||||
|
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(clientUpdateInfo.Name, updatedClient.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
tests/DependencyFactory.cs
Normal file
35
tests/DependencyFactory.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Novaloop.PaymoApi.Extensions;
|
||||||
|
using Novaloop.PaymoApi.Shared;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Tests
|
||||||
|
{
|
||||||
|
public static class DependencyFactory
|
||||||
|
{
|
||||||
|
public static PaymoPaymoIApiClient GeneratePaymoApiClient()
|
||||||
|
{
|
||||||
|
return new PaymoPaymoIApiClient(new HttpClient(new PaymoLoggingHandler(new HttpClientHandler(), new NullLogger<PaymoLoggingHandler>())) {BaseAddress = new Uri("https://app.paymoapp.com/")});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IOptions<PaymoApiOptions> GenerateOptions()
|
||||||
|
{
|
||||||
|
var paymoToken = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(AppContext.BaseDirectory)
|
||||||
|
.AddJsonFile("appsettings.tests.json", true, true)
|
||||||
|
.AddEnvironmentVariables()
|
||||||
|
.Build()
|
||||||
|
.GetSection("PaymoApiIntegrationTests:PaymoTestProjectToken").Value;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(paymoToken))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Please set the environment variable 'PAYMOAPIINTEGRATIONTESTS__PAYMOTESTPROJECTTOKEN' with the token of your paymo test-project. Look inside Bitwarden if you work @ Novaloop.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Options.Create(new PaymoApiOptions {ApiToken = paymoToken});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
33
tests/Novaloop.PaymoApi.IntegrationTests.csproj
Normal file
33
tests/Novaloop.PaymoApi.IntegrationTests.csproj
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
|
||||||
|
<RootNamespace>Novaloop.PaymoApi.Tests</RootNamespace>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\src\Novaloop.PaymoApi.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.tests.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.1"/>
|
|
||||||
<PackageReference Include="xunit" Version="2.4.1"/>
|
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
117
tests/TasksApiTests.cs
Normal file
117
tests/TasksApiTests.cs
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
using System.Dynamic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using Novaloop.PaymoApi.Shared;
|
||||||
|
using Novaloop.PaymoApi.Tasks;
|
||||||
|
using Novaloop.PaymoApi.Tasks.Models;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace Novaloop.PaymoApi.Tests
|
||||||
|
{
|
||||||
|
[Collection("IntegrationTests")]
|
||||||
|
public class TasksApiTests
|
||||||
|
{
|
||||||
|
private readonly ITestOutputHelper _testOutputHelper;
|
||||||
|
private readonly PaymoTasksApi _paymoTasksApi;
|
||||||
|
private readonly PaymoTask _testPaymoTask;
|
||||||
|
|
||||||
|
public TasksApiTests(ITestOutputHelper testOutputHelper)
|
||||||
|
{
|
||||||
|
Thread.Sleep(5000);
|
||||||
|
_testOutputHelper = testOutputHelper;
|
||||||
|
_paymoTasksApi =
|
||||||
|
new PaymoTasksApi(new PaymoBaseApi<PaymoTasksResponse, PaymoTask>(DependencyFactory.GeneratePaymoApiClient(),
|
||||||
|
DependencyFactory.GenerateOptions()));
|
||||||
|
|
||||||
|
_testPaymoTask = new PaymoTask
|
||||||
|
{
|
||||||
|
Name = "Testtask",
|
||||||
|
Description = "Just a little task"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void GetTasks()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var tasks = (await _paymoTasksApi.GetTasks()).ToList();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotEmpty(tasks);
|
||||||
|
_testOutputHelper.WriteLine(string.Join(",", tasks));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void GetTask()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var tasks = (await _paymoTasksApi.GetTasks()).ToList();
|
||||||
|
var task = await _paymoTasksApi.GetTask(tasks.First().Id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void CreateTask()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var existingTaskListId = (await _paymoTasksApi.GetTasks()).First().TasklistId;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_testPaymoTask.TasklistId = existingTaskListId;
|
||||||
|
var createdTask = await _paymoTasksApi.CreateTask(_testPaymoTask);
|
||||||
|
var task = await _paymoTasksApi.GetTask(createdTask.Id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(_testPaymoTask.Name, task.Name);
|
||||||
|
Assert.Equal(_testPaymoTask.Description, task.Description);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
await _paymoTasksApi.DeleteTask(createdTask.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void DeleteTask()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var existingTaskListId = (await _paymoTasksApi.GetTasks()).First().TasklistId;
|
||||||
|
_testPaymoTask.TasklistId = existingTaskListId;
|
||||||
|
var createdTask = await _paymoTasksApi.CreateTask(_testPaymoTask);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await _paymoTasksApi.DeleteTask(createdTask.Id);
|
||||||
|
var tasks = (await _paymoTasksApi.GetTasks()).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Empty(tasks.Where(c => c.Id == createdTask.Id));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void UpdateTask()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var existingTaskListId = (await _paymoTasksApi.GetTasks()).First().TasklistId;
|
||||||
|
_testPaymoTask.TasklistId = existingTaskListId;
|
||||||
|
var createdTask = await _paymoTasksApi.CreateTask(_testPaymoTask);
|
||||||
|
dynamic taskUpdateInfo = new ExpandoObject();
|
||||||
|
taskUpdateInfo.Name = "Updated";
|
||||||
|
taskUpdateInfo.TaskListId = _testPaymoTask.TasklistId;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await _paymoTasksApi.UpdateTask(taskUpdateInfo, createdTask.Id);
|
||||||
|
var updatedTask = await _paymoTasksApi.GetTask(createdTask.Id);
|
||||||
|
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(taskUpdateInfo.Name, updatedTask.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Novaloop.PaymoApi.Tests
|
|
||||||
{
|
|
||||||
public class UnitTest1
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void Test1()
|
|
||||||
{
|
|
||||||
Assert.True(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user