Skip to content

Commit f38f9b0

Browse files
authored
Merge pull request #90 from tranpl/1.1.0
1.1.0
2 parents a61bb09 + d62d219 commit f38f9b0

25 files changed

+1758
-959
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: csharp
22
mono: none
3-
dotnet: 2.1.810
3+
dotnet: 5.0.2
44
script:
55
- dotnet restore
66
- dotnet build ./RedcapApi/

README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ __Prerequisites__
1313
5. Build the solution, then run the tests
1414

1515
__API METHODS SUPPORTED (Not all listed)__
16+
* ExportLoggingAsync
17+
* ExportDagsAsync
18+
* ImportDagsAsync
19+
* DeleteDagsAsync
1620
* ExportArmsAsync
1721
* ImportArmsAsync
1822
* DeleteArmsAsync
@@ -54,7 +58,7 @@ namespace RedcapApiDemo
5458
Console.WriteLine("Redcap Api Demo Started!");
5559
// Use your own API Token here...
5660
var apiToken = "3D57A7FA57C8A43F6C8803A84BB3957B";
57-
var redcap_api = new RedcapApi("http://localhost/redcap/api/");
61+
var redcap_api = new RedcapApi("https://localhost/redcap/api/");
5862

5963
Console.WriteLine("Exporting all records from project.");
6064
var result = redcap_api.ExportRecordsAsync(apiToken).Result;
@@ -73,21 +77,21 @@ __Install directly in Package Manager Console or Command Line Interface__
7377
```C#
7478
Package Manager
7579

76-
Install-Package RedcapAPI -Version 1.0.9
80+
Install-Package RedcapAPI -Version 1.1.0
7781

7882
```
7983

8084
```C#
8185
.NET CLI
8286

83-
dotnet add package RedcapAPI --version 1.0.9
87+
dotnet add package RedcapAPI --version 1.1.0
8488

8589
```
8690

8791
```C#
8892
Paket CLI
8993

90-
paket add RedcapAPI --version 1.0.9
94+
paket add RedcapAPI --version 1.1.0
9195

9296
```
9397

RedcapApi/Api/Redcap.cs

+324-14
Large diffs are not rendered by default.

RedcapApi/Broker/ApiBroker.cs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Runtime.CompilerServices;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
using RestSharp;
8+
9+
using Serilog;
10+
11+
namespace Redcap.Broker
12+
{
13+
public partial class ApiBroker: IApiBroker
14+
{
15+
protected readonly HttpClient httpClient;
16+
protected readonly IRestClient restClient;
17+
public ApiBroker(HttpClient httpClient, IRestClient restClient)
18+
{
19+
this.httpClient = httpClient;
20+
this.restClient = restClient;
21+
}
22+
public void LogException(Exception ex,
23+
[CallerMemberName] string method = null,
24+
[CallerFilePath] string filePath = null,
25+
[CallerLineNumber] int lineNumber = 0)
26+
{
27+
var errorMessage = $"Message: {ex.Message}. Method: {method} File: {filePath} LineNumber: {lineNumber}";
28+
Log.Error($"Message: {ex.Message}. Method: {method} File: {filePath} LineNumber: {lineNumber}");
29+
throw new Exception(errorMessage);
30+
}
31+
public async Task<T> PostAsync<T>(IRestRequest request, CancellationToken cancellationToken = default)
32+
{
33+
var response = await restClient.PostAsync<T>(request, cancellationToken);
34+
35+
return response;
36+
}
37+
public async Task<T> ExecuteAsync<T>(RestRequest request) where T : new()
38+
{
39+
var response = await restClient.ExecuteAsync<T>(request);
40+
if(response.ErrorException != null)
41+
{
42+
LogException(response.ErrorException);
43+
}
44+
return response.Data;
45+
}
46+
}
47+
}

RedcapApi/Broker/IApiBroker.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Runtime.CompilerServices;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
6+
using RestSharp;
7+
8+
namespace Redcap.Broker
9+
{
10+
public interface IApiBroker
11+
{
12+
Task<T> ExecuteAsync<T>(RestRequest request) where T : new();
13+
void LogException(Exception ex, [CallerMemberName] string method = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber = 0);
14+
Task<T> PostAsync<T>(IRestRequest request, CancellationToken cancellationToken = default);
15+
}
16+
}

RedcapApi/Interfaces/IRedcap.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1484,5 +1484,11 @@ public interface IRedcap
14841484
/// <param name="dateFormat">MDY, DMY, YMD [default] - the format of values being imported for dates or datetime fields (understood with M representing 'month', D as 'day', and Y as 'year') - NOTE: The default format is Y-M-D (with dashes), while MDY and DMY values should always be formatted as M/D/Y or D/M/Y (with slashes), respectively.</param>
14851485
/// <returns>Returns the content with format specified.</returns>
14861486
Task<string> SaveRecordsAsync(List<string> data, ReturnContent returnContent, OverwriteBehavior overwriteBehavior, ReturnFormat? inputFormat, RedcapDataType? redcapDataType, OnErrorFormat? returnFormat, string dateFormat = "MDY");
1487+
Task<string> ExportLoggingAsync(string token, Content content, ReturnFormat format = ReturnFormat.json, LogType logType = LogType.All, string user = null, string record = null, string dag = null, string beginTime = null, string endTime = null, OnErrorFormat onErrorFormat = OnErrorFormat.json);
1488+
Task<string> ExportDagsAsync(string token, Content content, ReturnFormat format = ReturnFormat.json, OnErrorFormat onErrorFormat = OnErrorFormat.json);
1489+
Task<string> ImportDagsAsync<T>(string token, Content content, RedcapAction action, ReturnFormat format, List<T> data, OnErrorFormat onErrorFormat = OnErrorFormat.json);
1490+
Task<string> DeleteDagsAsync(string token, Content content, RedcapAction action, string[] dags);
1491+
Task<string> ExportUserDagAssignmentAsync(string token, Content content, ReturnFormat format = ReturnFormat.json, OnErrorFormat onErrorFormat = OnErrorFormat.json);
1492+
Task<string> ImportUserDagAssignmentAsync<T>(string token, Content content, RedcapAction action, ReturnFormat format, List<T> data, OnErrorFormat onErrorFormat = OnErrorFormat.json);
14871493
}
14881494
}

RedcapApi/Models/Action.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Redcap.Models
88
{
99
/// <summary>
10-
/// API Action
10+
/// API Action => Export, Import, Delete
1111
/// </summary>
1212
public enum RedcapAction
1313
{

RedcapApi/Models/Content.cs

+15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ namespace Redcap.Models
88
/// </summary>
99
public enum Content
1010
{
11+
/// <summary>
12+
/// Log
13+
/// </summary>
14+
[Display(Name ="log")]
15+
Log,
16+
/// <summary>
17+
/// User-Mapping
18+
/// </summary>
19+
[Display(Name = "userDagMapping")]
20+
UserDagMapping,
21+
/// <summary>
22+
/// Dag Content
23+
/// </summary>
24+
[Display(Name = "dag")]
25+
Dag,
1126
/// <summary>
1227
/// Arm Content
1328
/// </summary>

RedcapApi/Models/Demographic.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Redcap.Models
4+
{
5+
/// <summary>
6+
/// Simplified demographics instrument that we can test with.
7+
/// </summary>
8+
public class Demographic
9+
{
10+
/// <summary>
11+
///
12+
/// </summary>
13+
[JsonRequired]
14+
[JsonProperty("record_id")]
15+
public string RecordId { get; set; }
16+
17+
/// <summary>
18+
///
19+
/// </summary>
20+
[JsonProperty("first_name")]
21+
public string FirstName { get; set; }
22+
23+
/// <summary>
24+
///
25+
/// </summary>
26+
[JsonProperty("last_name")]
27+
public string LastName { get; set; }
28+
}
29+
}

RedcapApi/Models/LogType.cs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace Redcap.Models
4+
{
5+
/// <summary>
6+
/// Logging type
7+
/// </summary>
8+
public enum LogType
9+
{
10+
/// <summary>
11+
/// Data Export
12+
/// </summary>
13+
[Display(Name = "export")]
14+
Export,
15+
16+
/// <summary>
17+
/// Manage/Design
18+
/// </summary>
19+
[Display(Name = "manage")]
20+
Manage,
21+
22+
/// <summary>
23+
/// User or role created-updated-deleted
24+
/// </summary>
25+
[Display(Name = "user")]
26+
User,
27+
28+
/// <summary>
29+
/// Record created-updated-deleted
30+
/// </summary>
31+
[Display(Name = "record")]
32+
Record,
33+
34+
/// <summary>
35+
/// Record created (only)
36+
/// </summary>
37+
[Display(Name = "record_add")]
38+
RecordAdd,
39+
40+
/// <summary>
41+
/// Record updated (only)
42+
/// </summary>
43+
[Display(Name = "record_edit")]
44+
RecordEdit,
45+
46+
/// <summary>
47+
/// Record deleted (only)
48+
/// </summary>
49+
[Display(Name = "record_delete")]
50+
RecordDelete,
51+
52+
/// <summary>
53+
/// Record locking and e-signatures
54+
/// </summary>
55+
[Display(Name ="lock_record")]
56+
LockRecord,
57+
/// <summary>
58+
/// Page views
59+
/// </summary>
60+
///
61+
[Display(Name = "page_view")]
62+
PageView,
63+
/// <summary>
64+
/// All event types (excluding page views)
65+
/// </summary>
66+
[Display(Name = "")]
67+
All
68+
}
69+
}

RedcapApi/Models/RedcapDag.cs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
using Newtonsoft.Json;
6+
7+
namespace Redcap.Models
8+
{
9+
/// <summary>
10+
/// Data Access Group
11+
/// Example:
12+
/// [{"data_access_group_name":"CA Site","unique_group_name":"ca_site"}
13+
/// {"data_access_group_name":"FL Site","unique_group_name":"fl_site"},
14+
/// { "data_access_group_name":"New Site","unique_group_name":""}]
15+
/// </summary>
16+
public class RedcapDag
17+
{
18+
/// <summary>
19+
/// group name
20+
/// </summary>
21+
///
22+
[JsonProperty("data_access_group_name")]
23+
public string GroupName { get; set; }
24+
/// <summary>
25+
/// auto-generated unique group name
26+
/// </summary>
27+
///
28+
[JsonProperty("unique_group_name")]
29+
30+
public string UniqueGroupName { get; set; }
31+
}
32+
}

RedcapApi/Redcap.csproj

+23-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>netstandard2.1</TargetFramework>
55
<Authors>Michael Tran</Authors>
66
<Company>Virginia Commonwealth University</Company>
77
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
@@ -10,51 +10,57 @@
1010
<Description>This library allows applications on the .NET platform to make http calls to REDCap instances.</Description>
1111
<Product>Redcap Api Library</Product>
1212
<PackageId>RedcapAPI</PackageId>
13-
<Version>1.0.9</Version>
14-
<AssemblyVersion>1.0.9.0</AssemblyVersion>
13+
<Version>1.1.0</Version>
14+
<AssemblyVersion>1.1.0.0</AssemblyVersion>
1515
<PackageTags>redcap api library vcu</PackageTags>
16-
<PackageReleaseNotes>- add improvements to 'ImportRecordsAsync'
17-
Add ability to declare csv delimiter to match REDCap's API paramters
18-
- minor update documentation
19-
- Minor version bump
20-
</PackageReleaseNotes>
16+
<PackageReleaseNotes>New APIs have been added!
17+
-ExportLoggingAsync
18+
-ExportDagsAsync
19+
-ImportDagsAsync
20+
-DeleteDagsAsync
21+
-ExportUserDagAssignmentAsync
22+
-ImportUserDagAssignmentAsync
23+
-Added models to support new APIs
24+
Minor bugs fixes to existing APIs regarding optional parameters.</PackageReleaseNotes>
2125
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
2226
<ApplicationIcon />
2327
<OutputType>Library</OutputType>
2428
<StartupObject />
2529
<NeutralLanguage>en</NeutralLanguage>
26-
<FileVersion>1.0.9.0</FileVersion>
30+
<FileVersion>1.1.0.0</FileVersion>
2731
<license>https://github.com/cctrbic/redcap-api/blob/master/LICENSE.md</license>
2832
<Copyright>https://github.com/cctrbic/redcap-api/blob/master/LICENSE.md</Copyright>
2933
<icon>https://vortex.cctr.vcu.edu/images/ram_crest_160.png</icon>
3034
<PackageLicenseExpression>MIT</PackageLicenseExpression>
31-
<PackageIcon>ram_crest_160.png</PackageIcon>
35+
<PackageIcon>vcu.png</PackageIcon>
3236
</PropertyGroup>
3337
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
3438
<Optimize>false</Optimize>
35-
<DocumentationFile>bin\Debug\netcoreapp2.0\Redcap.xml</DocumentationFile>
39+
<DocumentationFile></DocumentationFile>
3640
<DebugType>portable</DebugType>
3741
<DebugSymbols>true</DebugSymbols>
3842
<PlatformTarget>AnyCPU</PlatformTarget>
3943
</PropertyGroup>
4044
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
41-
<DocumentationFile>D:\Github\redcap-api\RedcapApi\Redcap.xml</DocumentationFile>
45+
<DocumentationFile></DocumentationFile>
4246
</PropertyGroup>
4347
<ItemGroup>
4448
<Compile Remove="bin\**" />
4549
<EmbeddedResource Remove="bin\**" />
4650
<None Remove="bin\**" />
47-
<None Include="..\ram_crest_160.png">
51+
<None Include="..\vcu.png">
4852
<Pack>True</Pack>
4953
<PackagePath></PackagePath>
5054
</None>
5155
</ItemGroup>
5256
<ItemGroup>
53-
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
54-
<PackageReference Include="Serilog" Version="2.7.1" />
55-
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
57+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
58+
<PackageReference Include="RestSharp" Version="106.11.7" />
59+
<PackageReference Include="Serilog" Version="2.10.0" />
60+
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
61+
<PackageReference Include="System.Text.Json" Version="5.0.1" />
5662
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
57-
<PackageReference Include="xunit.extensibility.core" Version="2.4.0" />
63+
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
5864
<Content Include="Models\RedcapMetaData.cs" />
5965
<Content Include="Models\RecordStatus.cs" />
6066
</ItemGroup>

0 commit comments

Comments
 (0)