-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathSignNowContext.cs
More file actions
99 lines (85 loc) · 3.87 KB
/
Copy pathSignNowContext.cs
File metadata and controls
99 lines (85 loc) · 3.87 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using SignNow.Net.Internal.Constants;
using SignNow.Net.Interfaces;
using SignNow.Net.Model;
using SignNow.Net.Service;
using System;
using System.Net.Http;
namespace SignNow.Net
{
/// <summary>
/// Service container with all signNow services
/// </summary>
public class SignNowContext : WebClientBase, ISignNowContext
{
/// <inheritdoc cref="IOAuth2Service"/>
public OAuth2Service OAuth { get; protected set; }
/// <inheritdoc cref="IUserService"/>
public IUserService Users { get; protected set; }
/// <inheritdoc cref="ISignInvite"/>
public ISignInvite Invites { get; protected set; }
/// <inheritdoc cref="IDocumentService"/>
public IDocumentService Documents { get; protected set; }
/// <inheritdoc cref="IFolderService"/>
public IFolderService Folders { get; protected set; }
/// <inheritdoc cref="IEventSubscriptionService"/>
public IEventSubscriptionService Events { get; protected set; }
/// <inheritdoc cref="IDocumentGroup"/>
public IDocumentGroup DocumentGroup { get; protected set; }
/// <inheritdoc cref="IDocumentGroupInvite"/>
public IDocumentGroupInvite GroupInvites { get; protected set; }
/// <summary>
/// Create all the services using single instance of <see cref="ISignNowClient"/> and other dependencies.
/// </summary>
/// <param name="token">User Access token</param>
public SignNowContext(Token token) : this(ApiUrl.ApiBaseUrl, token)
{
}
/// <inheritdoc cref="SignNowContext(Token)"/>
/// <summary>Create all the services with user provided Http Client</summary>
/// <param name="baseApiUrl">Base signNow api URL</param>
/// <param name="client">User provided Http Client</param>
public SignNowContext(Uri baseApiUrl, Token token, HttpClient client)
: this(baseApiUrl, token, new SignNowClient(client))
{
}
/// <inheritdoc cref="SignNowContext(Token)"/>
/// <param name="baseApiUrl">Base signNow api URL</param>
/// <param name="signNowClient">signNow HTTP Client</param>
public SignNowContext(Uri baseApiUrl, Token token, ISignNowClient signNowClient = null)
: base(baseApiUrl, token, signNowClient)
{
OAuth = new OAuth2Service(ApiBaseUrl, "", "", SignNowClient);
Users = new UserService(ApiBaseUrl, Token, SignNowClient);
Invites = (ISignInvite) Users;
Documents = new DocumentService(ApiBaseUrl, Token, SignNowClient);
Folders = new FolderService(ApiBaseUrl, Token, SignNowClient);
Events = new EventSubscriptionService(ApiBaseUrl, Token, SignNowClient);
DocumentGroup = new DocumentGroupService(ApiBaseUrl, Token, SignNowClient);
GroupInvites = (IDocumentGroupInvite) DocumentGroup;
}
/// <summary>
/// Setup application client ID/Secret for authorization.
/// </summary>
/// <param name="clientId">Application client ID</param>
/// <param name="clientSecret">Application client Secret</param>
public void SetAppCredentials(string clientId, string clientSecret)
{
OAuth.ClientId = clientId;
OAuth.ClientSecret = clientSecret;
}
public Token GetAccessToken(string login, string password, Scope scope)
{
Token = OAuth.GetTokenAsync(login, password, scope).Result;
SyncTokens();
return Token;
}
private void SyncTokens()
{
((UserService)Users).Token = Token;
((DocumentService)Documents).Token = Token;
((FolderService)Folders).Token = Token;
((EventSubscriptionService)Events).Token = Token;
((DocumentGroupService)DocumentGroup).Token = Token;
}
}
}