Skip to content

Commit 955ac70

Browse files
petelopeznull511
authored andcommitted
Client interface (#17)
* Add interface to allow mocking the client * Allow JenkinsClient to take a Context in ctor Add ApiToken to context
1 parent 5330fa3 commit 955ac70

3 files changed

Lines changed: 80 additions & 2 deletions

File tree

Jenkins.Net/IJenkinsClient.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
using JenkinsNET.Models;
4+
5+
namespace JenkinsNET
6+
{
7+
/// <summary>
8+
/// Methods for interacting with Jenkins API.
9+
/// </summary>
10+
public interface IJenkinsClient
11+
{
12+
/// <summary>
13+
/// Group of methods for interacting with Jenkins Jobs.
14+
/// </summary>
15+
JenkinsClientJobs Jobs {get;}
16+
17+
/// <summary>
18+
/// Group of methods for interacting with Jenkins Builds.
19+
/// </summary>
20+
JenkinsClientBuilds Builds {get;}
21+
22+
/// <summary>
23+
/// Group of methods for interacting with the Jenkins Job-Queue.
24+
/// </summary>
25+
JenkinsClientQueue Queue {get;}
26+
27+
/// <summary>
28+
/// Group of methods for interacting with Jenkins Artifacts.
29+
/// </summary>
30+
JenkinsClientArtifacts Artifacts {get;}
31+
32+
/// <summary>
33+
/// Updates the security Crumb attached to this client.
34+
/// </summary>
35+
/// <exception cref="JenkinsNetException"></exception>
36+
void UpdateSecurityCrumb();
37+
38+
39+
/// <summary>
40+
/// Updates the security Crumb attached to this client asynchronously.
41+
/// </summary>
42+
/// <param name="token">An optional token for aborting the request.</param>
43+
/// <exception cref="JenkinsNetException"></exception>
44+
Task UpdateSecurityCrumbAsync(CancellationToken token = default(CancellationToken));
45+
46+
/// <summary>
47+
/// Gets the root description of the Jenkins node.
48+
/// </summary>
49+
/// <exception cref="JenkinsNetException"></exception>
50+
Jenkins Get();
51+
52+
53+
/// <summary>
54+
/// Gets the root description of the Jenkins node asynchronously.
55+
/// </summary>
56+
/// <param name="token">An optional token for aborting the request.</param>
57+
/// <exception cref="JenkinsNetException"></exception>
58+
Task<Jenkins> GetAsync(CancellationToken token = default(CancellationToken));
59+
}
60+
}

Jenkins.Net/IJenkinsContext.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using JenkinsNET.Models;
1+
using System;
2+
using JenkinsNET.Models;
23

34
namespace JenkinsNET
45
{
@@ -21,8 +22,14 @@ public interface IJenkinsContext
2122
/// <summary>
2223
/// [optional] Jenkins Password.
2324
/// </summary>
25+
[Obsolete("This property will be removed in future versions; please use 'JenkinsContext.ApiToken' instead.")]
2426
string Password {get;}
2527

28+
/// <summary>
29+
/// [optional] Jenkins ApiToken for the <see cref="UserName"/>.
30+
/// </summary>
31+
string ApiToken {get; set;}
32+
2633
/// <summary>
2734
/// [optional] Jenkins CSRF Crumb.
2835
/// </summary>

Jenkins.Net/JenkinsClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace JenkinsNET
1010
/// <summary>
1111
/// HTTP-Client for interacting with Jenkins API.
1212
/// </summary>
13-
public class JenkinsClient : IJenkinsContext
13+
public class JenkinsClient : IJenkinsContext, IJenkinsClient
1414
{
1515
/// <summary>
1616
/// The address of the Jenkins instance.
@@ -82,6 +82,17 @@ public JenkinsClient(string baseUrl) : this()
8282
this.BaseUrl = baseUrl;
8383
}
8484

85+
/// <summary>
86+
/// Creates a new Jenkins Client using the provided <see cref="IJenkinsContext"/>.
87+
/// </summary>
88+
public JenkinsClient(IJenkinsContext context) : this(context.BaseUrl)
89+
{
90+
this.UserName = context.UserName;
91+
this.ApiToken = context.ApiToken;
92+
this.Password = context.Password;
93+
this.Crumb = context.Crumb;
94+
}
95+
8596
/// <summary>
8697
/// Updates the security Crumb attached to this client.
8798
/// </summary>

0 commit comments

Comments
 (0)