Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add better, more flexible APIs for SDK initialization. #79

Merged
merged 1 commit into from
Dec 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Parse/Internal/Command/ParseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ public ParseCommand(string relativeUri,
Method = method;
Data = stream;

// TODO (richardross): Inject configuration instead of using shared static here.
Headers = new List<KeyValuePair<string, string>> {
new KeyValuePair<string, string>("X-Parse-Application-Id", ParseClient.ApplicationId),
new KeyValuePair<string, string>("X-Parse-Application-Id", ParseClient.CurrentConfiguration.ApplicationId),
new KeyValuePair<string, string>("X-Parse-Windows-Key", ParseClient.CurrentConfiguration.WindowsKey),
new KeyValuePair<string, string>("X-Parse-Client-Version", ParseClient.VersionString),
new KeyValuePair<string, string>("X-Parse-Installation-Id", ParseClient.InstallationId.ToString())
};
Expand All @@ -71,10 +73,12 @@ public ParseCommand(string relativeUri,
if (!string.IsNullOrEmpty(ParseClient.PlatformHooks.OSVersion)) {
Headers.Add(new KeyValuePair<string, string>("X-Parse-OS-Version", ParseClient.PlatformHooks.OSVersion));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was here for a reason, IIRC for Cloud Code stuff. Have you verified that IntegrationTest still run?

}
// TODO (richardross): I hate the idea of having this super tightly coupled static variable in here.
// Lets eventually get rid of it.
if (!string.IsNullOrEmpty(ParseClient.MasterKey)) {
Headers.Add(new KeyValuePair<string, string>("X-Parse-Master-Key", ParseClient.MasterKey));
} else {
Headers.Add(new KeyValuePair<string, string>("X-Parse-Windows-Key", ParseClient.WindowsKey));
Headers.Add(new KeyValuePair<string, string>("X-Parse-Windows-Key", ParseClient.CurrentConfiguration.WindowsKey));
}
if (!string.IsNullOrEmpty(sessionToken)) {
Headers.Add(new KeyValuePair<string, string>("X-Parse-Session-Token", sessionToken));
Expand Down
38 changes: 34 additions & 4 deletions Parse/Public/ParseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ public static partial class ParseClient {
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'f'Z'",
};

/// <summary>
/// Represents the configuration of the Parse SDK.
/// </summary>
public struct Configuration {
/// <summary>
/// The Parse.com application ID of your app.
/// </summary>
public String ApplicationId { get; set; }

/// <summary>
/// The Parse.com .NET key for your app.
/// </summary>
public String WindowsKey { get; set; }
}

private static readonly object mutex = new object();
private static readonly string[] assemblyNames = {
Expand Down Expand Up @@ -60,10 +74,12 @@ private static Type GetParseType(string name) {
private static readonly IParseCommandRunner commandRunner;
internal static IParseCommandRunner ParseCommandRunner { get { return commandRunner; } }

/// <summary>
/// The current configuration that parse has been initialized with.
/// </summary>
public static Configuration CurrentConfiguration { get; internal set; }
internal static Uri HostName { get; set; }
internal static string MasterKey { get; set; }
internal static string ApplicationId { get; set; }
internal static string WindowsKey { get; set; }

internal static Version Version {
get {
Expand All @@ -90,10 +106,24 @@ internal static string VersionString {
/// <param name="dotnetKey">The .NET API Key provided in the Parse dashboard.
/// </param>
public static void Initialize(string applicationId, string dotnetKey) {
Initialize(new Configuration {
ApplicationId = applicationId,
WindowsKey = dotnetKey
});
}

/// <summary>
/// Authenticates this client as belonging to your application. This must be
/// called before your application can use the Parse library. The recommended
/// way is to put a call to <c>ParseFramework.Initialize</c> in your
/// Application startup.
/// </summary>
/// <param name="configuration">The configuration to initialze Parse with.
/// </param>
public static void Initialize(Configuration configuration) {
lock (mutex) {
HostName = HostName ?? new Uri("https://api.parse.com/1/");
ApplicationId = applicationId;
WindowsKey = dotnetKey;
CurrentConfiguration = configuration;

ParseObject.RegisterSubclass<ParseUser>();
ParseObject.RegisterSubclass<ParseInstallation>();
Expand Down