-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathClient.cs
163 lines (137 loc) · 4.64 KB
/
Client.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// -----------------------------------------------------------------------
// <copyright file="Client.cs" company="YamNet">
// Copyright (c) 2013 YamNet contributors
// </copyright>
// -----------------------------------------------------------------------
namespace YamNet.Client
{
using System;
using System.Net;
/// <summary>
/// The Yammer web client.
/// </summary>
public class Client : IDisposable
{
/// <summary>
/// The default Yammer REST API endpoint.
/// </summary>
private const string DefaultEndpoint = "https://www.yammer.com/api/v1";
/// <summary>
/// Initializes a new instance of the <see cref="Client"/> class.
/// </summary>
/// <param name="token">The access token.</param>
public Client(string token)
{
this.Init(token);
}
/// <summary>
/// Initializes a new instance of the <see cref="Client"/> class.
/// </summary>
/// <param name="token">The access token.</param>
/// <param name="proxy">The proxy.</param>
public Client(string token, IWebProxy proxy)
{
this.Proxy = proxy;
this.Init(token);
}
/// <summary>
/// Gets the group memberships REST API endpoint.
/// </summary>
public GroupClient Groups { get; private set; }
/// <summary>
/// Gets the invitations REST API endpoint.
/// </summary>
public InvitationClient Invitations { get; private set; }
/// <summary>
/// Gets the messages REST API endpoint.
/// </summary>
public MessageClient Messages { get; private set; }
/// <summary>
/// Gets the network REST API endpoint.
/// </summary>
public NetworkClient Networks { get; private set; }
/// <summary>
/// Gets the user's relationship REST API endpoint.
/// </summary>
public RelationshipClient Relationships { get; private set; }
/// <summary>
/// Gets the search REST API endpoint.
/// </summary>
public SearchClient Search { get; private set; }
/// <summary>
/// Gets the message topic REST API endpoint.
/// </summary>
public TopicClient Topics { get; private set; }
/// <summary>
/// Gets the users REST API endpoint.
/// </summary>
public UserClient Users { get; private set; }
/// <summary>
/// Gets or sets the REST API endpoint.
/// </summary>
internal string Endpoint { get; set; }
/// <summary>
/// Gets or sets the bearer token.
/// </summary>
internal string BearerToken { get; set; }
/// <summary>
/// Gets or sets the web proxy.
/// </summary>
internal IWebProxy Proxy { get; set; }
/// <summary>
/// The dispose.
/// </summary>
public void Dispose()
{
if (this.Groups.Client != null)
{
this.Groups.Client.Dispose();
}
if (this.Invitations.Client != null)
{
this.Invitations.Client.Dispose();
}
if (this.Messages.Client != null)
{
this.Messages.Client.Dispose();
}
if (this.Networks.Client != null)
{
this.Networks.Client.Dispose();
}
if (this.Relationships.Client != null)
{
this.Relationships.Client.Dispose();
}
if (this.Search.Client != null)
{
this.Search.Client.Dispose();
}
if (this.Topics.Client != null)
{
this.Topics.Client.Dispose();
}
if (this.Users.Client != null)
{
this.Users.Client.Dispose();
}
}
/// <summary>
/// Initialise the base client.
/// </summary>
/// <param name="token">The access token.</param>
private void Init(string token)
{
this.Endpoint = DefaultEndpoint;
this.BearerToken = token;
this.Groups = new GroupClient(this);
this.Invitations = new InvitationClient(this);
this.Messages = new MessageClient(this);
this.Networks = new NetworkClient(this);
this.Relationships = new RelationshipClient(this);
this.Search = new SearchClient(this);
this.Topics = new TopicClient(this);
this.Users = new UserClient(this);
}
}
}