Skip to content

Commit c39e232

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 325a5ad commit c39e232

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
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

+37-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ namespace Parse {
1818
/// configuration for the Parse library.
1919
/// </summary>
2020
public static partial class ParseClient {
21+
/// <summary>
22+
/// Represents the configuration of the Parse SDK.
23+
/// </summary>
24+
public struct Configuration {
25+
/// <summary>
26+
/// The Parse.com application ID of your app.
27+
/// </summary>
28+
public String ApplicationId { get; set; }
29+
30+
/// <summary>
31+
/// The Parse.com .NET key for your app.
32+
/// </summary>
33+
public String WindowsKey { get; set; }
34+
}
35+
2136
internal const string DateFormatString = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'";
2237

2338
private static readonly object mutex = new object();
@@ -49,12 +64,13 @@ private static Type GetParseType(string name) {
4964
internal static IPlatformHooks PlatformHooks { get { return platformHooks; } }
5065

5166
private static readonly IParseCommandRunner commandRunner;
52-
internal static IParseCommandRunner ParseCommandRunner { get { return commandRunner; } }
53-
67+
internal static IParseCommandRunner ParseCommandRunner { get { return commandRunner; } }
68+
69+
/// <summary>
70+
/// The current configuration that parse has been initialized with.
71+
/// </summary>
72+
public static Configuration CurrentConfiguration { get; internal set; }
5473
internal static Uri HostName { get; set; }
55-
internal static string MasterKey { get; set; }
56-
internal static string ApplicationId { get; set; }
57-
internal static string WindowsKey { get; set; }
5874

5975
internal static Version Version {
6076
get {
@@ -81,10 +97,24 @@ internal static string VersionString {
8197
/// <param name="dotnetKey">The .NET API Key provided in the Parse dashboard.
8298
/// </param>
8399
public static void Initialize(string applicationId, string dotnetKey) {
100+
Initialize(new Configuration {
101+
ApplicationId = applicationId,
102+
WindowsKey = dotnetKey
103+
});
104+
}
105+
106+
/// <summary>
107+
/// Authenticates this client as belonging to your application. This must be
108+
/// called before your application can use the Parse library. The recommended
109+
/// way is to put a call to <c>ParseFramework.Initialize</c> in your
110+
/// Application startup.
111+
/// </summary>
112+
/// <param name="configuration">The configuration to initialze Parse with.
113+
/// </param>
114+
public static void Initialize(Configuration configuration) {
84115
lock (mutex) {
85116
HostName = HostName ?? new Uri("https://api.parse.com/1/");
86-
ApplicationId = applicationId;
87-
WindowsKey = dotnetKey;
117+
CurrentConfiguration = configuration;
88118

89119
ParseObject.RegisterSubclass<ParseUser>();
90120
ParseObject.RegisterSubclass<ParseInstallation>();

0 commit comments

Comments
 (0)