Skip to content

Commit 2813416

Browse files
committed
Update constructor for DropboxClient.
1 parent 08bb08d commit 2813416

File tree

11 files changed

+149
-64
lines changed

11 files changed

+149
-64
lines changed

Dropbox.Api.sln

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dropbox.Api.Portable", "Dro
1616
EndProject
1717
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dropbox.Api.Portable40", "Dropbox.Api\Dropbox.Api.Portable40.csproj", "{15223E85-0C1F-4244-A8E6-3F350A40D09F}"
1818
EndProject
19+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dropbox.Api", "Dropbox.Api\Dropbox.Api.csproj", "{68180B54-4724-4CD1-BAA6-EE7BC309797C}"
20+
EndProject
1921
Global
2022
GlobalSection(SharedMSBuildProjectFiles) = preSolution
2123
Examples\UniversalDemo\UniversalDemo\UniversalDemo.Shared\UniversalDemo.Shared.projitems*{51d9899c-31d6-4c22-b894-e9498cb90577}*SharedItemsImports = 4
@@ -117,6 +119,16 @@ Global
117119
{15223E85-0C1F-4244-A8E6-3F350A40D09F}.Release|ARM.ActiveCfg = Release|Any CPU
118120
{15223E85-0C1F-4244-A8E6-3F350A40D09F}.Release|x64.ActiveCfg = Release|Any CPU
119121
{15223E85-0C1F-4244-A8E6-3F350A40D09F}.Release|x86.ActiveCfg = Release|Any CPU
122+
{68180B54-4724-4CD1-BAA6-EE7BC309797C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
123+
{68180B54-4724-4CD1-BAA6-EE7BC309797C}.Debug|Any CPU.Build.0 = Debug|Any CPU
124+
{68180B54-4724-4CD1-BAA6-EE7BC309797C}.Debug|ARM.ActiveCfg = Debug|Any CPU
125+
{68180B54-4724-4CD1-BAA6-EE7BC309797C}.Debug|x64.ActiveCfg = Debug|Any CPU
126+
{68180B54-4724-4CD1-BAA6-EE7BC309797C}.Debug|x86.ActiveCfg = Debug|Any CPU
127+
{68180B54-4724-4CD1-BAA6-EE7BC309797C}.Release|Any CPU.ActiveCfg = Release|Any CPU
128+
{68180B54-4724-4CD1-BAA6-EE7BC309797C}.Release|Any CPU.Build.0 = Release|Any CPU
129+
{68180B54-4724-4CD1-BAA6-EE7BC309797C}.Release|ARM.ActiveCfg = Release|Any CPU
130+
{68180B54-4724-4CD1-BAA6-EE7BC309797C}.Release|x64.ActiveCfg = Release|Any CPU
131+
{68180B54-4724-4CD1-BAA6-EE7BC309797C}.Release|x86.ActiveCfg = Release|Any CPU
120132
EndGlobalSection
121133
GlobalSection(SolutionProperties) = preSolution
122134
HideSolutionNode = FALSE

Dropbox.Api/Dropbox.Api.Portable.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@
4242
<NoWarn>419</NoWarn>
4343
</PropertyGroup>
4444
<ItemGroup>
45-
<Reference Include="System" />
46-
<Reference Include="System.Core" />
47-
<Reference Include="Microsoft.CSharp" />
48-
<Reference Include="System.Net.Http" />
4945
<Reference Include="Newtonsoft.Json">
5046
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\portable-net45+wp80+win8+wpa81+dnxcore50\Newtonsoft.Json.dll</HintPath>
5147
</Reference>
@@ -368,7 +364,6 @@
368364
<Compile Include="Users\UsersRoutes.cs" />
369365
</ItemGroup>
370366
<ItemGroup>
371-
<None Include="app.config" />
372367
<None Include="packages.Dropbox.Api.Portable.config" />
373368
</ItemGroup>
374369
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />

Dropbox.Api/Dropbox.Api.Portable40.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848
<Reference Include="Microsoft.Threading.Tasks.Extensions">
4949
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\portable-net40+sl4+win8+wp71+wpa81\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
5050
</Reference>
51-
<Reference Include="System" />
52-
<Reference Include="System.Core" />
53-
<Reference Include="Microsoft.CSharp" />
5451
<Reference Include="System.IO">
5552
<HintPath>..\packages\Microsoft.Bcl.1.1.10\lib\portable-net40+sl5+win8+wp8+wpa81\System.IO.dll</HintPath>
5653
</Reference>

Dropbox.Api/Dropbox.Api.Doc.csproj renamed to Dropbox.Api/Dropbox.Api.csproj

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,53 @@
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{0E57A534-F4CA-402B-88F4-0B43E55264BA}</ProjectGuid>
7+
<ProjectGuid>{68180B54-4724-4CD1-BAA6-EE7BC309797C}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>Dropbox.Api</RootNamespace>
1111
<AssemblyName>Dropbox.Api</AssemblyName>
1212
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14-
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
15-
<RestorePackages>true</RestorePackages>
1614
</PropertyGroup>
1715
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1816
<DebugSymbols>true</DebugSymbols>
1917
<DebugType>full</DebugType>
2018
<Optimize>false</Optimize>
21-
<OutputPath>docbin\Debug\</OutputPath>
22-
<IntermediateOutputPath>docobj\Debug\</IntermediateOutputPath>
23-
<DefineConstants>TRACE;DEBUG;DOC</DefineConstants>
19+
<OutputPath>bin\Debug\net45</OutputPath>
20+
<IntermediateOutputPath>obj\Debug\net45</IntermediateOutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
2422
<ErrorReport>prompt</ErrorReport>
2523
<WarningLevel>4</WarningLevel>
26-
<DocumentationFile>docbin\Debug\Dropbox.Api.XML</DocumentationFile>
24+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
25+
<DocumentationFile>bin\Debug\net45\Dropbox.Api.XML</DocumentationFile>
26+
<RunCodeAnalysis>true</RunCodeAnalysis>
2727
<NoWarn>419</NoWarn>
2828
</PropertyGroup>
2929
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3030
<DebugType>pdbonly</DebugType>
3131
<Optimize>true</Optimize>
32-
<OutputPath>docbin\Release\</OutputPath>
33-
<IntermediateOutputPath>docobj\Release\</IntermediateOutputPath>
34-
<DefineConstants>TRACE;DOC</DefineConstants>
32+
<OutputPath>bin\Release\net45</OutputPath>
33+
<IntermediateOutputPath>obj\Release\net45</IntermediateOutputPath>
34+
<DefineConstants>TRACE</DefineConstants>
3535
<ErrorReport>prompt</ErrorReport>
3636
<WarningLevel>4</WarningLevel>
37-
<DocumentationFile>docbin\Release\Dropbox.Api.XML</DocumentationFile>
37+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
38+
<DocumentationFile>bin\Release\net45\Dropbox.Api.XML</DocumentationFile>
3839
<NoWarn>419</NoWarn>
3940
</PropertyGroup>
4041
<ItemGroup>
4142
<Reference Include="System" />
4243
<Reference Include="System.Core" />
43-
<Reference Include="System.Net.Http" />
4444
<Reference Include="System.Xml.Linq" />
4545
<Reference Include="System.Data.DataSetExtensions" />
46+
<Reference Include="System.Net.Http" />
4647
<Reference Include="Microsoft.CSharp" />
4748
<Reference Include="System.Data" />
4849
<Reference Include="System.Xml" />
4950
<Reference Include="Newtonsoft.Json">
5051
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
5152
</Reference>
52-
</ItemGroup>
53+
</ItemGroup>
5354
<ItemGroup>
5455
<Compile Include="Babel\Decoder.cs" />
5556
<Compile Include="Babel\Empty.cs" />
@@ -368,13 +369,8 @@
368369
<Compile Include="Users\UsersRoutes.cs" />
369370
</ItemGroup>
370371
<ItemGroup>
371-
<None Include="app.config" />
372372
<None Include="packages.config" />
373373
</ItemGroup>
374-
<ItemGroup>
375-
<None Include="babal_summaries.xml" />
376-
<None Include="namespace_summaries.xml" />
377-
</ItemGroup>
378374
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
379375
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
380376
Other similar extension points exist, see Microsoft.Common.targets.

Dropbox.Api/DropboxClient.common.cs

Lines changed: 113 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,103 @@ namespace Dropbox.Api
1010
using System.Net.Http;
1111

1212
/// <summary>
13-
/// The client which contains endpoints which perform user-level actions.
13+
/// The class which contains all configurations for Dropbox client.
1414
/// </summary>
15-
public sealed partial class DropboxClient : IDisposable
15+
public sealed class DropboxClientConfig
1616
{
1717
/// <summary>
18-
/// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxClient"/> class.
18+
/// Initializes a new instance of the <see cref="DropboxClientConfig"/> class.
19+
/// </summary>
20+
public DropboxClientConfig()
21+
: this(null)
22+
{
23+
}
24+
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="DropboxClientConfig"/> class.
27+
/// </summary>
28+
/// <param name="userAgent">The user agent to use when making requests.</param>
29+
public DropboxClientConfig(string userAgent)
30+
: this(userAgent, 4)
31+
{
32+
}
33+
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="DropboxClientConfig"/> class.
1936
/// </summary>
20-
/// <param name="oauth2AccessToken">The oauth2 access token for making client requests.</param>
21-
/// <param name="maxRetriesOnError">The maximum retries on a 5xx error.</param>
2237
/// <param name="userAgent">The user agent to use when making requests.</param>
23-
/// <param name="httpClient">The custom http client. If not provided, a default
24-
/// http client will be created.</param>
38+
/// <param name="maxRetriesOnError">The max number retries on error.</param>
39+
public DropboxClientConfig(string userAgent, int maxRetriesOnError)
40+
: this(userAgent, maxRetriesOnError, null)
41+
{
42+
}
43+
44+
/// <summary>
45+
/// Initializes a new instance of the <see cref="DropboxClientConfig"/> class.
46+
/// </summary>
47+
/// <param name="userAgent">The user agent to use when making requests.</param>
48+
/// <param name="maxRetriesOnError">The max number retries on error.</param>
49+
/// <param name="httpClient">The custom http client.</param>
50+
internal DropboxClientConfig(string userAgent, int maxRetriesOnError, HttpClient httpClient)
51+
{
52+
this.UserAgent = userAgent;
53+
this.MaxRetriesOnError = maxRetriesOnError;
54+
this.HttpClient = httpClient;
55+
}
56+
57+
/// <summary>
58+
/// Gets or sets the max number retries on error. Default value is 4.
59+
/// </summary>
60+
public int MaxRetriesOnError { get; set; }
61+
62+
/// <summary>
63+
/// Gets or sets the user agent to use when making requests.
64+
/// </summary>
2565
/// <remarks>
26-
/// The <paramref name="userAgent"/> helps Dropbox to identify requests coming from your application.
66+
/// This value helps Dropbox to identify requests coming from your application.
2767
/// We recommend that you use the format <c>"AppName/Version"</c>; if a value is supplied, the string
2868
/// <c>"/OfficialDropboxDotNetV2SDK/__version__"</c> is appended to the user agent.
2969
/// </remarks>
30-
public DropboxClient(
31-
string oauth2AccessToken,
32-
int maxRetriesOnError = 4,
33-
string userAgent = null,
34-
HttpClient httpClient = null)
35-
: this(new DropboxRequestHandlerOptions(oauth2AccessToken, maxRetriesOnError, userAgent, httpClient: httpClient))
70+
public string UserAgent { get; set; }
71+
72+
/// <summary>
73+
/// Gets or sets the custom http client. If not set, a default http client will be created.
74+
/// </summary>
75+
public HttpClient HttpClient { get; set; }
76+
}
77+
78+
/// <summary>
79+
/// The client which contains endpoints which perform user-level actions.
80+
/// </summary>
81+
public sealed partial class DropboxClient : IDisposable
82+
{
83+
/// <summary>
84+
/// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxClient"/> class.
85+
/// </summary>
86+
/// <param name="oauth2AccessToken">The oauth2 access token for making client requests.</param>
87+
public DropboxClient(string oauth2AccessToken)
88+
: this(oauth2AccessToken, new DropboxClientConfig())
89+
{
90+
}
91+
92+
/// <summary>
93+
/// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxClient"/> class.
94+
/// </summary>
95+
/// <param name="oauth2AccessToken">The oauth2 access token for making client requests.</param>
96+
/// <param name="userAgent">The user agent to use when making requests.</param>
97+
[Obsolete("This constructor is deprecated, please use DropboxClientConfig instead.")]
98+
public DropboxClient(string oauth2AccessToken, string userAgent)
99+
: this(oauth2AccessToken, new DropboxClientConfig(userAgent))
100+
{
101+
}
102+
103+
/// <summary>
104+
/// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxClient"/> class.
105+
/// </summary>
106+
/// <param name="oauth2AccessToken">The oauth2 access token for making client requests.</param>
107+
/// <param name="config">The <see cref="DropboxClientConfig"/>.</param>
108+
public DropboxClient(string oauth2AccessToken, DropboxClientConfig config)
109+
: this(new DropboxRequestHandlerOptions(oauth2AccessToken, config.MaxRetriesOnError, config.UserAgent, httpClient: config.HttpClient))
36110
{
37111
if (oauth2AccessToken == null)
38112
{
@@ -72,28 +146,36 @@ public sealed partial class DropboxTeamClient
72146
/// <summary>
73147
/// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxTeamClient"/> class.
74148
/// </summary>
75-
/// <param name="oauth2AccessToken">The team oauth2 access token for making client requests.</param>
76-
/// <param name="maxRetriesOnError">The maximum retries on a 5xx error.</param>
149+
/// <param name="oauth2AccessToken">The oauth2 access token for making client requests.</param>
150+
public DropboxTeamClient(string oauth2AccessToken)
151+
: this(oauth2AccessToken, new DropboxClientConfig())
152+
{
153+
}
154+
155+
/// <summary>
156+
/// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxTeamClient"/> class.
157+
/// </summary>
158+
/// <param name="oauth2AccessToken">The oauth2 access token for making client requests.</param>
77159
/// <param name="userAgent">The user agent to use when making requests.</param>
78-
/// <param name="httpClient">The custom http client. If not provided, a default
79-
/// http client will be created.</param>
80-
/// <remarks>
81-
/// The <paramref name="userAgent"/> helps Dropbox to identify requests coming from your application.
82-
/// We recommend that you use the format <c>"AppName/Version"</c>; if a value is supplied, the string
83-
/// <c>"/OfficialDropboxDotNetV2SDK/__version__"</c> is appended to the user agent.
84-
/// </remarks>
85-
public DropboxTeamClient(
86-
string oauth2AccessToken,
87-
int maxRetriesOnError = 4,
88-
string userAgent = null,
89-
HttpClient httpClient = null)
160+
[Obsolete("This constructor is deprecated, please use DropboxClientConfig instead.")]
161+
public DropboxTeamClient(string oauth2AccessToken, string userAgent)
162+
: this(oauth2AccessToken, new DropboxClientConfig(userAgent))
163+
{
164+
}
165+
166+
/// <summary>
167+
/// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxTeamClient"/> class.
168+
/// </summary>
169+
/// <param name="oauth2AccessToken">The oauth2 access token for making client requests.</param>
170+
/// <param name="config">The <see cref="DropboxClientConfig"/>.</param>
171+
public DropboxTeamClient(string oauth2AccessToken, DropboxClientConfig config)
90172
{
91173
if (oauth2AccessToken == null)
92174
{
93175
throw new ArgumentNullException("oauth2AccessToken");
94176
}
95177

96-
this.options = new DropboxRequestHandlerOptions(oauth2AccessToken, maxRetriesOnError, userAgent, httpClient: httpClient);
178+
this.options = new DropboxRequestHandlerOptions(oauth2AccessToken, config.MaxRetriesOnError, config.UserAgent, httpClient: config.HttpClient);
97179
this.InitializeRoutes(new DropboxRequestHandler(this.options));
98180
}
99181

@@ -171,7 +253,8 @@ public partial class AuthException
171253
/// <param name="message">The message that describes the error.</param>
172254
/// <param name="uri">The request URI</param>
173255
[Obsolete("This constructor will be removed soon.")]
174-
public AuthException(string message, Uri uri = null) : base(null, message)
256+
public AuthException(string message, Uri uri = null)
257+
: base(null, message)
175258
{
176259
this.StatusCode = 401;
177260
this.RequestUri = uri;

Examples/SimpleBlogDemo/Controllers/BlogsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private DropboxClient GetClient(UserProfile user)
8585
return null;
8686
}
8787

88-
return new DropboxClient(user.DropboxAccessToken, userAgent: "SimpleBlogDemo");
88+
return new DropboxClient(user.DropboxAccessToken, new DropboxClientConfig("SimpleBlogDemo"));
8989
}
9090
}
9191
}

Examples/SimpleBlogDemo/Helpers/BlogHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public static async Task<Blog> FromUserAsync(UserProfile user)
174174
return null;
175175
}
176176

177-
using (var client = new DropboxClient(user.DropboxAccessToken, userAgent: "SimpleBlogDemo"))
177+
using (var client = new DropboxClient(user.DropboxAccessToken, new DropboxClientConfig("SimpleBlogDemo")))
178178
{
179179
return new Blog
180180
{

Examples/SimpleBlogDemo/Helpers/ModelHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static DropboxClient GetAuthenticatedClient(this UserProfile user)
3232
return null;
3333
}
3434

35-
return new DropboxClient(user.DropboxAccessToken, userAgent: "SimpleBlogDemo");
35+
return new DropboxClient(user.DropboxAccessToken, new DropboxClientConfig("SimpleBlogDemo"));
3636
}
3737
}
3838
}

Examples/SimpleTest/Program.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ private async Task<int> Run()
5151

5252
try
5353
{
54-
var client = new DropboxClient(accessToken, userAgent: "SimpleTestApp", httpClient: httpClient);
54+
var config = new DropboxClientConfig("SimpleTestApp")
55+
{
56+
HttpClient = httpClient
57+
};
58+
59+
var client = new DropboxClient(accessToken, config);
5560
await RunUserTests(client);
5661

5762
// Tests below are for Dropbox Business endpoints. To run these tests, make sure the ApiKey is for

Examples/UniversalDemo/UniversalDemo/UniversalDemo.Shared/App.xaml.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ protected override void OnWindowCreated(WindowCreatedEventArgs args)
242242
/// </summary>
243243
private void SetNewDropboxClient()
244244
{
245-
this.DropboxClient = new DropboxClient(
246-
oauth2AccessToken: this.AccessToken,
247-
userAgent: "WindowsUniversalAppDemo");
245+
this.DropboxClient = new DropboxClient(this.AccessToken, new DropboxClientConfig("WindowsUniversalAppDemo"));
248246
}
249247

250248
#if WINDOWS_PHONE_APP

0 commit comments

Comments
 (0)