Skip to content

Commit 2352884

Browse files
author
Jani Giannoudis
committed
refactored invoke webhook method to the base runtime/function
updated version to 0.5.0-230719-5
1 parent 939a14b commit 2352884

13 files changed

+52
-187
lines changed

Client.Scripting/Function/CaseFunction.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,4 @@ public T GetCaseAttribute<T>(string attributeName, T defaultValue = default)
4343
var value = Runtime.GetCaseAttribute(attributeName);
4444
return value == null ? defaultValue : (T)Convert.ChangeType(value, typeof(T));
4545
}
46-
47-
#region Webhooks
48-
49-
/// <summary>Invoke case webhook</summary>
50-
/// <param name="requestOperation">The request operation</param>
51-
/// <param name="requestMessage">The webhook request message</param>
52-
/// <returns>The webhook response object</returns>
53-
public T InvokeWebhook<T>(string requestOperation, object requestMessage = null)
54-
{
55-
if (string.IsNullOrWhiteSpace(requestOperation))
56-
{
57-
throw new ArgumentException(nameof(requestOperation));
58-
}
59-
60-
// webhook request
61-
var jsonRequest = requestMessage != null ? JsonSerializer.Serialize(requestMessage) : null;
62-
var jsonResponse = Runtime.InvokeWebhook(requestOperation, jsonRequest);
63-
if (string.IsNullOrWhiteSpace(jsonResponse))
64-
{
65-
return default;
66-
}
67-
var response = JsonSerializer.Deserialize<T>(jsonResponse);
68-
return response;
69-
}
70-
71-
#endregion
72-
7346
}

Client.Scripting/Function/CaseRelationFunction.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -570,30 +570,4 @@ public void CopyValue(string sourceFieldName, string targetFieldName) =>
570570

571571
#endregion
572572

573-
#region Webhooks
574-
575-
/// <summary>Invoke case webhook</summary>
576-
/// <param name="requestOperation">The request operation</param>
577-
/// <param name="requestMessage">The webhook request message</param>
578-
/// <returns>The webhook response object</returns>
579-
public T InvokeWebhook<T>(string requestOperation, object requestMessage = null)
580-
{
581-
if (string.IsNullOrWhiteSpace(requestOperation))
582-
{
583-
throw new ArgumentException("Invalid webhook request operation", nameof(requestOperation));
584-
}
585-
586-
// webhook request
587-
var jsonRequest = requestMessage != null ? JsonSerializer.Serialize(requestMessage) : null;
588-
var jsonResponse = Runtime.InvokeWebhook(requestOperation, jsonRequest);
589-
if (string.IsNullOrWhiteSpace(jsonResponse))
590-
{
591-
return default;
592-
}
593-
var response = JsonSerializer.Deserialize<T>(jsonResponse);
594-
return response;
595-
}
596-
597-
#endregion
598-
599573
}

Client.Scripting/Function/Function.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Runtime.CompilerServices;
6+
using System.Text.Json;
67

78
namespace PayrollEngine.Client.Scripting.Function;
89

@@ -173,6 +174,32 @@ public void AddTask(string name, string instruction, DateTime scheduleDate, stri
173174

174175
#endregion
175176

177+
#region Webhooks
178+
179+
/// <summary>Invoke report webhook</summary>
180+
/// <param name="requestOperation">The request operation</param>
181+
/// <param name="requestMessage">The webhook request message</param>
182+
/// <returns>The webhook response object</returns>
183+
public T InvokeWebhook<T>(string requestOperation, object requestMessage = null)
184+
{
185+
if (string.IsNullOrWhiteSpace(requestOperation))
186+
{
187+
throw new ArgumentException(nameof(requestOperation));
188+
}
189+
190+
// webhook request
191+
var jsonRequest = requestMessage != null ? JsonSerializer.Serialize(requestMessage) : null;
192+
var jsonResponse = Runtime.InvokeWebhook(requestOperation, jsonRequest);
193+
if (string.IsNullOrWhiteSpace(jsonResponse))
194+
{
195+
return default;
196+
}
197+
var response = JsonSerializer.Deserialize<T>(jsonResponse);
198+
return response;
199+
}
200+
201+
#endregion
202+
176203
#region Scripting Development
177204

178205
/// <summary>The name of the source file (scripting development)</summary>

Client.Scripting/Function/PayrunFunction.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -296,30 +296,4 @@ public IList<CollectorCustomResult> GetConsolidatedCollectorCustomResults(Collec
296296

297297
#endregion
298298

299-
#region Webhooks
300-
301-
/// <summary>Invoke payrun webhook</summary>
302-
/// <param name="requestOperation">The request operation</param>
303-
/// <param name="requestMessage">The webhook request message</param>
304-
/// <returns>The webhook response object</returns>
305-
public T InvokeWebhook<T>(string requestOperation, object requestMessage = null)
306-
{
307-
if (string.IsNullOrWhiteSpace(requestOperation))
308-
{
309-
throw new ArgumentException(nameof(requestOperation));
310-
}
311-
312-
// webhook request
313-
var jsonRequest = requestMessage != null ? JsonSerializer.Serialize(requestMessage) : null;
314-
var jsonResponse = Runtime.InvokeWebhook(requestOperation, jsonRequest);
315-
if (string.IsNullOrWhiteSpace(jsonResponse))
316-
{
317-
return default;
318-
}
319-
var response = JsonSerializer.Deserialize<T>(jsonResponse);
320-
return response;
321-
}
322-
323-
#endregion
324-
325299
}

Client.Scripting/Function/ReportFunction.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -879,30 +879,4 @@ private static DataRow GetCaseFieldRow(DataTable caseFields, CaseValueColumn col
879879

880880
#endregion
881881

882-
#region Webhooks
883-
884-
/// <summary>Invoke report webhook</summary>
885-
/// <param name="requestOperation">The request operation</param>
886-
/// <param name="requestMessage">The webhook request message</param>
887-
/// <returns>The webhook response object</returns>
888-
public T InvokeWebhook<T>(string requestOperation, object requestMessage = null)
889-
{
890-
if (string.IsNullOrWhiteSpace(requestOperation))
891-
{
892-
throw new ArgumentException(nameof(requestOperation));
893-
}
894-
895-
// webhook request
896-
var jsonRequest = requestMessage != null ? JsonSerializer.Serialize(requestMessage) : null;
897-
var jsonResponse = Runtime.InvokeWebhook(requestOperation, jsonRequest);
898-
if (string.IsNullOrWhiteSpace(jsonResponse))
899-
{
900-
return default;
901-
}
902-
var response = JsonSerializer.Deserialize<T>(jsonResponse);
903-
return response;
904-
}
905-
906-
#endregion
907-
908882
}

Client.Scripting/PayrollEngine.Client.Scripting.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175

176176
<ItemGroup>
177177
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
178-
<PackageReference Include="PayrollEngine.Client.Core" Version="0.5.0-230719-4" />
178+
<PackageReference Include="PayrollEngine.Client.Core" Version="0.5.0-230719-5" />
179179
</ItemGroup>
180180

181181
<!-- include xml documention files and json schemas to the nuget package -->

Client.Scripting/PayrollEngine.Client.Scripting.xml

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,12 +3758,6 @@
37583758
<member name="M:PayrollEngine.Client.Scripting.Function.CaseFunction.GetCaseAttribute``1(System.String,``0)">
37593759
<summary>Get case attribute typed value</summary>
37603760
</member>
3761-
<member name="M:PayrollEngine.Client.Scripting.Function.CaseFunction.InvokeWebhook``1(System.String,System.Object)">
3762-
<summary>Invoke case webhook</summary>
3763-
<param name="requestOperation">The request operation</param>
3764-
<param name="requestMessage">The webhook request message</param>
3765-
<returns>The webhook response object</returns>
3766-
</member>
37673761
<member name="T:PayrollEngine.Client.Scripting.Function.CaseInputActions">
37683762
<summary>Extension methods for case input actions</summary>
37693763
</member>
@@ -4659,12 +4653,6 @@
46594653
<member name="M:PayrollEngine.Client.Scripting.Function.CaseRelationFunction.CopyValue(System.String,System.String)">
46604654
<summary>Copy the case value from source to target</summary>
46614655
</member>
4662-
<member name="M:PayrollEngine.Client.Scripting.Function.CaseRelationFunction.InvokeWebhook``1(System.String,System.Object)">
4663-
<summary>Invoke case webhook</summary>
4664-
<param name="requestOperation">The request operation</param>
4665-
<param name="requestMessage">The webhook request message</param>
4666-
<returns>The webhook response object</returns>
4667-
</member>
46684656
<member name="T:PayrollEngine.Client.Scripting.Function.CaseRelationValidateActions">
46694657
<summary>Extension methods for the case change actions</summary>
46704658
</member>
@@ -5454,6 +5442,12 @@
54545442
<param name="category">The task category</param>
54555443
<param name="attributes">The task attributes</param>
54565444
</member>
5445+
<member name="M:PayrollEngine.Client.Scripting.Function.Function.InvokeWebhook``1(System.String,System.Object)">
5446+
<summary>Invoke report webhook</summary>
5447+
<param name="requestOperation">The request operation</param>
5448+
<param name="requestMessage">The webhook request message</param>
5449+
<returns>The webhook response object</returns>
5450+
</member>
54575451
<member name="P:PayrollEngine.Client.Scripting.Function.Function.SourceFileName">
54585452
<summary>The name of the source file (scripting development)</summary>
54595453
<value>The name of the source file</value>
@@ -6261,12 +6255,6 @@
62616255
<param name="query">The result query</param>
62626256
<returns>Consolidated employee collector custom results</returns>
62636257
</member>
6264-
<member name="M:PayrollEngine.Client.Scripting.Function.PayrunFunction.InvokeWebhook``1(System.String,System.Object)">
6265-
<summary>Invoke payrun webhook</summary>
6266-
<param name="requestOperation">The request operation</param>
6267-
<param name="requestMessage">The webhook request message</param>
6268-
<returns>The webhook response object</returns>
6269-
</member>
62706258
<member name="T:PayrollEngine.Client.Scripting.Function.PayrunStartFunction">
62716259
<summary>Payrun start function</summary>
62726260
</member>
@@ -6783,12 +6771,6 @@
67836771
<param name="parameterName">The parameter name</param>
67846772
<returns>The object id, null for unknown payrun</returns>
67856773
</member>
6786-
<member name="M:PayrollEngine.Client.Scripting.Function.ReportFunction.InvokeWebhook``1(System.String,System.Object)">
6787-
<summary>Invoke report webhook</summary>
6788-
<param name="requestOperation">The request operation</param>
6789-
<param name="requestMessage">The webhook request message</param>
6790-
<returns>The webhook response object</returns>
6791-
</member>
67926774
<member name="T:PayrollEngine.Client.Scripting.Function.ReportStartFunction">
67936775
<summary>Report start function</summary>
67946776
</member>
@@ -8803,12 +8785,6 @@
88038785
<param name="sourceFieldName">The name of the source case field</param>
88048786
<param name="targetFieldName">The name of the target case field</param>
88058787
</member>
8806-
<member name="M:PayrollEngine.Client.Scripting.Runtime.ICaseRelationRuntime.InvokeWebhook(System.String,System.String)">
8807-
<summary>Invoke case relation webhook and receive the response JSON data</summary>
8808-
<param name="requestOperation">The request operation</param>
8809-
<param name="requestMessage">The JSON request message</param>
8810-
<returns>The webhook response object as JSON</returns>
8811-
</member>
88128788
<member name="T:PayrollEngine.Client.Scripting.Runtime.ICaseRelationValidateRuntime">
88138789
<summary>Runtime for the case relation validate function <see cref="T:PayrollEngine.Client.Scripting.Function.CaseRelationValidateFunction"/></summary>
88148790
</member>
@@ -8843,12 +8819,6 @@
88438819
<param name="attributeName">Name of the attribute</param>
88448820
<returns>The case attribute value</returns>
88458821
</member>
8846-
<member name="M:PayrollEngine.Client.Scripting.Runtime.ICaseRuntime.InvokeWebhook(System.String,System.String)">
8847-
<summary>Invoke case webhook and receive the response JSON data</summary>
8848-
<param name="requestOperation">The request operation</param>
8849-
<param name="requestMessage">The JSON request message</param>
8850-
<returns>The webhook response object as JSON</returns>
8851-
</member>
88528822
<member name="T:PayrollEngine.Client.Scripting.Runtime.ICaseValidateRuntime">
88538823
<summary>Runtime for the case validate function <see cref="T:PayrollEngine.Client.Scripting.Function.CaseFunction"/></summary>
88548824
</member>
@@ -9286,12 +9256,6 @@
92869256
<param name="tags">The result tags</param>
92879257
<returns>The consolidated collector custom results</returns>
92889258
</member>
9289-
<member name="M:PayrollEngine.Client.Scripting.Runtime.IPayrunRuntime.InvokeWebhook(System.String,System.String)">
9290-
<summary>Invoke payrun webhook and receive the response JSON data</summary>
9291-
<param name="requestOperation">The request operation</param>
9292-
<param name="requestMessage">The JSON request message</param>
9293-
<returns>The webhook response object as JSON</returns>
9294-
</member>
92959259
<member name="T:PayrollEngine.Client.Scripting.Runtime.IPayrunStartRuntime">
92969260
<summary>Runtime for the payrun employee available function <see cref="T:PayrollEngine.Client.Scripting.Function.PayrunStartFunction"/></summary>
92979261
</member>
@@ -9480,12 +9444,6 @@
94809444
<param name="key">The log key</param>
94819445
<param name="reportDate">The report date (default: now)</param>
94829446
</member>
9483-
<member name="M:PayrollEngine.Client.Scripting.Runtime.IReportRuntime.InvokeWebhook(System.String,System.String)">
9484-
<summary>Invoke report webhook and receive the response JSON data</summary>
9485-
<param name="requestOperation">The request operation</param>
9486-
<param name="requestMessage">The JSON request message</param>
9487-
<returns>The webhook response object as JSON</returns>
9488-
</member>
94899447
<member name="T:PayrollEngine.Client.Scripting.Runtime.IReportStartRuntime">
94909448
<summary>Runtime for the report start function <see cref="T:PayrollEngine.Client.Scripting.Function.ReportStartFunction"/></summary>
94919449
</member>
@@ -9551,6 +9509,12 @@
95519509
<param name="category">The task category</param>
95529510
<param name="attributes">The task attributes</param>
95539511
</member>
9512+
<member name="M:PayrollEngine.Client.Scripting.Runtime.IRuntime.InvokeWebhook(System.String,System.String)">
9513+
<summary>Invoke case relation webhook and receive the response JSON data</summary>
9514+
<param name="requestOperation">The request operation</param>
9515+
<param name="requestMessage">The JSON request message</param>
9516+
<returns>The webhook response object as JSON</returns>
9517+
</member>
95549518
<member name="T:PayrollEngine.Client.Scripting.Runtime.IWageTypeResultRuntime">
95559519
<summary>Runtime for the wage type result function <see cref="T:PayrollEngine.Client.Scripting.Function.WageTypeResultFunction"/></summary>
95569520
</member>

Client.Scripting/Runtime/ICaseRelationRuntime.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,4 @@ public interface ICaseRelationRuntime : IPayrollRuntime
249249

250250
#endregion
251251

252-
#region Webhook
253-
254-
/// <summary>Invoke case relation webhook and receive the response JSON data</summary>
255-
/// <param name="requestOperation">The request operation</param>
256-
/// <param name="requestMessage">The JSON request message</param>
257-
/// <returns>The webhook response object as JSON</returns>
258-
string InvokeWebhook(string requestOperation, string requestMessage = null);
259-
260-
#endregion
261-
262252
}

Client.Scripting/Runtime/ICaseRuntime.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,4 @@ public interface ICaseRuntime : IPayrollRuntime
1414
/// <param name="attributeName">Name of the attribute</param>
1515
/// <returns>The case attribute value</returns>
1616
object GetCaseAttribute(string attributeName);
17-
18-
/// <summary>Invoke case webhook and receive the response JSON data</summary>
19-
/// <param name="requestOperation">The request operation</param>
20-
/// <param name="requestMessage">The JSON request message</param>
21-
/// <returns>The webhook response object as JSON</returns>
22-
string InvokeWebhook(string requestOperation, string requestMessage = null);
2317
}

Client.Scripting/Runtime/IPayrunRuntime.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,4 @@ IList<Tuple<string, string, Tuple<DateTime, DateTime>, decimal, List<string>, Di
192192

193193
#endregion
194194

195-
#region Webhook
196-
197-
/// <summary>Invoke payrun webhook and receive the response JSON data</summary>
198-
/// <param name="requestOperation">The request operation</param>
199-
/// <param name="requestMessage">The JSON request message</param>
200-
/// <returns>The webhook response object as JSON</returns>
201-
string InvokeWebhook(string requestOperation, string requestMessage = null);
202-
203-
#endregion
204-
205195
}

0 commit comments

Comments
 (0)