/
CredentialsValidator.cs
43 lines (40 loc) · 1.51 KB
/
CredentialsValidator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Net;
using Apidaze.SDK.Base;
using RestSharp;
namespace Apidaze.SDK.Validate
{
/// <summary>
/// Class CredentialsValidator.
/// Implements the <see cref="Apidaze.SDK.Base.BaseApiClient" />
/// Implements the <see cref="Apidaze.SDK.Validates.ICredentialsValidator" />
/// </summary>
/// <seealso cref="Apidaze.SDK.Base.BaseApiClient" />
/// <seealso cref="Apidaze.SDK.Validates.ICredentialsValidator" />
public class CredentialsValidator : BaseApiClient, ICredentialsValidator
{
/// <summary>
/// Initializes a new instance of the <see cref="CredentialsValidator" /> class.
/// </summary>
/// <param name="client">The client.</param>
/// <param name="credentials">The credentials.</param>
public CredentialsValidator(IRestClient client, Credentials credentials) : base(client, credentials)
{
}
/// <summary>
/// Gets the resource.
/// </summary>
/// <value>The resource.</value>
protected override string Resource => "/validates";
/// <summary>
/// Validates the credentials.
/// </summary>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
public bool ValidateCredentials()
{
var restRequest = AuthenticateRequest();
var response = Client.Execute(restRequest);
EnsureSuccessResponse(response);
return response.StatusCode != HttpStatusCode.Unauthorized;
}
}
}