Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

MLIBZ-2343: adding Options for Client #264

Merged
merged 3 commits into from Feb 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 36 additions & 3 deletions Kinvey/Kinvey/Client.swift
Expand Up @@ -90,6 +90,7 @@ open class Client: Credential {
open var cachePolicy: NSURLRequest.CachePolicy = .useProtocolCachePolicy

/// Timeout interval for this client instance.
@available(*, deprecated: 3.12.2, message: "Please use `options` instead")
open var timeoutInterval: TimeInterval = 60

/**
Expand Down Expand Up @@ -142,9 +143,27 @@ open class Client: Credential {
}

/// Constructor that already initialize the client. The `initialize` method is called automatically.
public convenience init(appKey: String, appSecret: String, accessGroup: String? = nil, apiHostName: URL = Client.defaultApiHostName, authHostName: URL = Client.defaultAuthHostName) {
public convenience init<U: User>(
appKey: String,
appSecret: String,
accessGroup: String? = nil,
apiHostName: URL = Client.defaultApiHostName,
authHostName: URL = Client.defaultAuthHostName,
schema: Schema? = nil,
options: Options? = nil,
completionHandler: ((Result<U?, Swift.Error>) -> Void)? = nil
) {
self.init()
initialize(appKey: appKey, appSecret: appSecret, accessGroup: accessGroup, apiHostName: apiHostName, authHostName: authHostName) { activerUser, error in
initialize(
appKey: appKey,
appSecret: appSecret,
accessGroup: accessGroup,
apiHostName: apiHostName,
authHostName: authHostName,
schema: schema,
options: options
) { (result: Result<U?, Swift.Error>) in
completionHandler?(result)
}
}

Expand Down Expand Up @@ -238,10 +257,24 @@ open class Client: Credential {
}

/// Initialize a `Client` instance with all the needed parameters.
open func initialize<U: User>(appKey: String, appSecret: String, accessGroup: String? = nil, apiHostName: URL = Client.defaultApiHostName, authHostName: URL = Client.defaultAuthHostName, encryptionKey: Data? = nil, schema: Schema? = nil, completionHandler: @escaping (Result<U?, Swift.Error>) -> Void) {
open func initialize<U: User>(
appKey: String,
appSecret: String,
accessGroup: String? = nil,
apiHostName: URL = Client.defaultApiHostName,
authHostName: URL = Client.defaultAuthHostName,
encryptionKey: Data? = nil,
schema: Schema? = nil,
options: Options? = nil,
completionHandler: @escaping (Result<U?, Swift.Error>) -> Void
) {
validateInitialize(appKey: appKey, appSecret: appSecret)
self.encryptionKey = encryptionKey
self.schemaVersion = schema?.version ?? 0
self.options = options
if let timeout = options?.timeout {
Copy link
Contributor

Choose a reason for hiding this comment

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

If options.timeout is our preferred way to set global timeouts, let's deprecate Client.timeoutInterval.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, let me do this

self.timeoutInterval = timeout
}

Migration.performMigration(persistenceId: appKey, encryptionKey: encryptionKey, schemaVersion: schemaVersion, migrationHandler: schema?.migrationHandler)

Expand Down