Skip to content

Commit 6d4f734

Browse files
author
Qiming Yuan
committed
Refactor project structure and add select admin support.
1 parent c3fa59a commit 6d4f734

14 files changed

+649
-535
lines changed

Dropbox.Api.Tests/DropboxApiTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Dropbox.Api.Tests
99
using System;
1010
using System.Collections.Generic;
1111
using System.IO;
12+
using System.Linq;
1213
using System.Net;
1314
using System.Net.Http;
1415
using System.Text;
@@ -269,6 +270,23 @@ public async Task TestTeamAuthSelectUser()
269270
Assert.AreEqual(account.TeamMemberId, memberId);
270271
}
271272

273+
274+
/// Test team auth select admin.
275+
/// </summary>
276+
/// <returns>The <see cref="Task"/></returns>
277+
[TestMethod]
278+
public async Task TestTeamAuthSelectAdmin()
279+
{
280+
var result = await TeamClient.Team.MembersListAsync();
281+
var adminId = result.Members.Where(m => m.Role.IsTeamAdmin).First().Profile.TeamMemberId;
282+
283+
var userClient = TeamClient.AsAdmin(adminId);
284+
var account = await userClient.Users.GetCurrentAccountAsync();
285+
Assert.AreEqual(account.TeamMemberId, adminId);
286+
287+
// TODO: Add permission specific tests.
288+
}
289+
272290
/// Test app auth.
273291
/// </summary>
274292
/// <returns>The <see cref="Task"/></returns>

Dropbox.Api/Dropbox.Api.Doc.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@
6565
<Compile Include="StructuredException.cs" />
6666
<Compile Include="Stone\Util.cs" />
6767
<Compile Include="DropboxCertHelper.cs" />
68-
<Compile Include="DropboxClient.common.cs" />
68+
<Compile Include="DropboxClient.cs" />
69+
<Compile Include="DropboxClientBase.cs" />
70+
<Compile Include="DropboxAppClient.cs" />
71+
<Compile Include="DropboxTeamClient.cs" />
72+
<Compile Include="DropboxClientConfig.cs" />
73+
<Compile Include="DropboxException.cs" />
6974
<Compile Include="DropboxOauth2Helper.cs" />
7075
<Compile Include="DropboxRequestHandler.cs" />
7176
<Compile Include="AppProperties\AssemblyInfo.cs" />

Dropbox.Api/Dropbox.Api.Portable.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@
6161
<Compile Include="StructuredException.cs" />
6262
<Compile Include="Stone\Util.cs" />
6363
<Compile Include="DropboxCertHelper.cs" />
64-
<Compile Include="DropboxClient.common.cs" />
64+
<Compile Include="DropboxClient.cs" />
65+
<Compile Include="DropboxClientBase.cs" />
66+
<Compile Include="DropboxAppClient.cs" />
67+
<Compile Include="DropboxTeamClient.cs" />
68+
<Compile Include="DropboxClientConfig.cs" />
69+
<Compile Include="DropboxException.cs" />
6570
<Compile Include="DropboxOauth2Helper.cs" />
6671
<Compile Include="DropboxRequestHandler.cs" />
6772
<Compile Include="AppProperties\AssemblyInfo.cs" />

Dropbox.Api/Dropbox.Api.Portable40.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@
8585
<Compile Include="StructuredException.cs" />
8686
<Compile Include="Stone\Util.cs" />
8787
<Compile Include="DropboxCertHelper.cs" />
88-
<Compile Include="DropboxClient.common.cs" />
88+
<Compile Include="DropboxClient.cs" />
89+
<Compile Include="DropboxClientBase.cs" />
90+
<Compile Include="DropboxAppClient.cs" />
91+
<Compile Include="DropboxTeamClient.cs" />
92+
<Compile Include="DropboxClientConfig.cs" />
93+
<Compile Include="DropboxException.cs" />
8994
<Compile Include="DropboxOauth2Helper.cs" />
9095
<Compile Include="DropboxRequestHandler.cs" />
9196
<Compile Include="AppProperties\AssemblyInfo.cs" />

Dropbox.Api/Dropbox.Api.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@
6666
<Compile Include="StructuredException.cs" />
6767
<Compile Include="Stone\Util.cs" />
6868
<Compile Include="DropboxCertHelper.cs" />
69-
<Compile Include="DropboxClient.common.cs" />
69+
<Compile Include="DropboxClient.cs" />
70+
<Compile Include="DropboxClientBase.cs" />
71+
<Compile Include="DropboxAppClient.cs" />
72+
<Compile Include="DropboxTeamClient.cs" />
73+
<Compile Include="DropboxClientConfig.cs" />
74+
<Compile Include="DropboxException.cs" />
7075
<Compile Include="DropboxOauth2Helper.cs" />
7176
<Compile Include="DropboxRequestHandler.cs" />
7277
<Compile Include="AppProperties\AssemblyInfo.cs" />

Dropbox.Api/DropboxAppClient.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//-----------------------------------------------------------------------------
2+
// <copyright file="DropboxAppClient.cs" company="Dropbox Inc">
3+
// Copyright (c) Dropbox Inc. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------------
6+
7+
namespace Dropbox.Api
8+
{
9+
using System;
10+
using System.Text;
11+
12+
/// <summary>
13+
/// The client which contains endpoints which perform app-auth actions.
14+
/// </summary>
15+
public sealed partial class DropboxAppClient : DropboxClientBase
16+
{
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxAppClient"/> class.
19+
/// </summary>
20+
/// <param name="appKey">The Dropbox app key (e.g. consumer key in OAuth).</param>
21+
/// <param name="appSecret">The Dropbox app secret (e.g. consumer secret in OAuth).</param>
22+
public DropboxAppClient(string appKey, string appSecret)
23+
: this(appKey, appSecret, new DropboxClientConfig())
24+
{
25+
}
26+
27+
28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxAppClient"/> class.
30+
/// </summary>
31+
/// <param name="appKey">The Dropbox app key (e.g. consumer key in OAuth).</param>
32+
/// <param name="appSecret">The Dropbox app secret (e.g. consumer secret in OAuth).</param>
33+
/// <param name="config">The <see cref="DropboxClientConfig"/>.</param>
34+
public DropboxAppClient(string appKey, string appSecret, DropboxClientConfig config)
35+
: this(new DropboxRequestHandlerOptions(config, GetBasicAuthHeader(appKey, appSecret)))
36+
{
37+
}
38+
39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxAppClient"/> class.
41+
/// </summary>
42+
/// <param name="options">The request handler options.</param>
43+
private DropboxAppClient(DropboxRequestHandlerOptions options)
44+
: base(new DropboxRequestHandler(options))
45+
{
46+
}
47+
48+
/// <summary>
49+
/// Gets the basic auth header from app key and app secret.
50+
/// </summary>
51+
/// <param name="appKey">The app key.</param>
52+
/// <param name="appSecret">The app secret.</param>
53+
/// <returns>The basic auth header.</returns>
54+
private static string GetBasicAuthHeader(string appKey, string appSecret)
55+
{
56+
if (appKey == null)
57+
{
58+
throw new ArgumentNullException("appKey");
59+
}
60+
61+
if (appSecret == null)
62+
{
63+
throw new ArgumentNullException("appSecret");
64+
}
65+
66+
var rawValue = string.Format("{0}:{1}", appKey, appSecret);
67+
return Convert.ToBase64String(Encoding.UTF8.GetBytes(rawValue));
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)