Skip to content

Commit f11d216

Browse files
Add better, more flexible APIs for SDK initialization.
This PR hopes to unify some of these initialization settings int o a single 'configuration' class that can be easily used to intialize parse in a much cleaner way, especially as we add even more initialization options. Depends on #77.
1 parent df7d27a commit f11d216

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

Parse/Internal/Command/ParseCommand.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public ParseCommand(string relativeUri,
5151
Data = stream;
5252

5353
Headers = new List<KeyValuePair<string, string>> {
54-
new KeyValuePair<string, string>("X-Parse-Application-Id", ParseClient.ApplicationId),
54+
new KeyValuePair<string, string>("X-Parse-Application-Id", ParseClient.CurrentConfiguration.ApplicationId),
55+
new KeyValuePair<string, string>("X-Parse-Windows-Key", ParseClient.CurrentConfiguration.WindowsKey),
5556
new KeyValuePair<string, string>("X-Parse-Client-Version", ParseClient.VersionString),
5657
new KeyValuePair<string, string>("X-Parse-Installation-Id", ParseClient.InstallationId.ToString())
5758
};
@@ -71,11 +72,6 @@ public ParseCommand(string relativeUri,
7172
if (!string.IsNullOrEmpty(ParseClient.PlatformHooks.OSVersion)) {
7273
Headers.Add(new KeyValuePair<string, string>("X-Parse-OS-Version", ParseClient.PlatformHooks.OSVersion));
7374
}
74-
if (!string.IsNullOrEmpty(ParseClient.MasterKey)) {
75-
Headers.Add(new KeyValuePair<string, string>("X-Parse-Master-Key", ParseClient.MasterKey));
76-
} else {
77-
Headers.Add(new KeyValuePair<string, string>("X-Parse-Windows-Key", ParseClient.WindowsKey));
78-
}
7975
if (!string.IsNullOrEmpty(sessionToken)) {
8076
Headers.Add(new KeyValuePair<string, string>("X-Parse-Session-Token", sessionToken));
8177
}

Parse/ParseClient.cs

+34-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ public static partial class ParseClient {
2828
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'f'Z'",
2929
};
3030

31+
/// <summary>
32+
/// Represents the configuration of the Parse SDK.
33+
/// </summary>
34+
public struct Configuration {
35+
/// <summary>
36+
/// The Parse.com application ID of your app.
37+
/// </summary>
38+
public String ApplicationId { get; set; }
39+
40+
/// <summary>
41+
/// The Parse.com .NET key for your app.
42+
/// </summary>
43+
public String WindowsKey { get; set; }
44+
}
3145

3246
private static readonly object mutex = new object();
3347
private static readonly string[] assemblyNames = {
@@ -60,10 +74,11 @@ private static Type GetParseType(string name) {
6074
private static readonly IParseCommandRunner commandRunner;
6175
internal static IParseCommandRunner ParseCommandRunner { get { return commandRunner; } }
6276

77+
/// <summary>
78+
/// The current configuration that parse has been initialized with.
79+
/// </summary>
80+
public static Configuration CurrentConfiguration { get; internal set; }
6381
internal static Uri HostName { get; set; }
64-
internal static string MasterKey { get; set; }
65-
internal static string ApplicationId { get; set; }
66-
internal static string WindowsKey { get; set; }
6782

6883
internal static Version Version {
6984
get {
@@ -90,10 +105,24 @@ internal static string VersionString {
90105
/// <param name="dotnetKey">The .NET API Key provided in the Parse dashboard.
91106
/// </param>
92107
public static void Initialize(string applicationId, string dotnetKey) {
108+
Initialize(new Configuration {
109+
ApplicationId = applicationId,
110+
WindowsKey = dotnetKey
111+
});
112+
}
113+
114+
/// <summary>
115+
/// Authenticates this client as belonging to your application. This must be
116+
/// called before your application can use the Parse library. The recommended
117+
/// way is to put a call to <c>ParseFramework.Initialize</c> in your
118+
/// Application startup.
119+
/// </summary>
120+
/// <param name="configuration">The configuration to initialze Parse with.
121+
/// </param>
122+
public static void Initialize(Configuration configuration) {
93123
lock (mutex) {
94124
HostName = HostName ?? new Uri("https://api.parse.com/1/");
95-
ApplicationId = applicationId;
96-
WindowsKey = dotnetKey;
125+
CurrentConfiguration = configuration;
97126

98127
ParseObject.RegisterSubclass<ParseUser>();
99128
ParseObject.RegisterSubclass<ParseInstallation>();

0 commit comments

Comments
 (0)