Skip to content

Commit

Permalink
Merge pull request #21 from dtrenz/develop
Browse files Browse the repository at this point in the history
1.0.1 Release Candidate
  • Loading branch information
dtrenz committed Feb 12, 2016
2 parents f6596e1 + 0bca350 commit 11c2ca1
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
disabled_rules: # rule identifiers to exclude from running
- variable_name
- valid_docs
# Find all the available rules by running:
# swiftlint rules
included: # paths to include during linting. `--path` is ignored if present.
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
All notable changes to this project will be documented in this file.
`LaunchGate` adheres to [Semantic Versioning](http://semver.org/).

## [1.0.1](https://github.com/dtrenz/LaunchGate/releases/tag/1.0.1)
Released on 2016-02-12.

#### Added
- Inline documentation to public API

#### Updated
- NA

#### Fixed
- NA

## [1.0.0](https://github.com/dtrenz/LaunchGate/releases/tag/1.0.0)
Released on 2016-02-12.

Expand Down
55 changes: 54 additions & 1 deletion Source/LaunchGate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,37 @@

import Foundation


/// Custom internal error type
typealias LaunchGateError = protocol<ErrorType, CustomStringConvertible>


public class LaunchGate {

/// Parser to use when parsing the configuration file
public var parser: LaunchGateParser!

/// URI for the configuration file
var configurationFileURL: NSURL!

/// App Store URI ("itms-apps://itunes.apple.com/...") for the current app
var updateURL: NSURL!

/// Manager object for the various alert dialogs
var dialogManager: DialogManager!

// MARK: - Public API

/**
Failable initializer. If either the `configURI` or `appStoreURI` are unable to be
converted into an `NSURL` (i.e. containing illegal URL characters) this initializer
will return `nil`.

- Parameters:
- configURI: URI for the configuration file
- appStoreURI: App Store URI ("itms-apps://itunes.apple.com/...") for the current app

- Returns: A `LaunchGate` instance or `nil`
*/
public init?(configURI: String, appStoreURI: String) {
guard let configURL = NSURL(string: configURI) else { return nil }
guard let appStoreURL = NSURL(string: appStoreURI) else { return nil }
Expand All @@ -31,12 +49,19 @@ public class LaunchGate {
dialogManager = DialogManager()
}

/// Check the configuration file and perform any appropriate action.
public func check() {
performCheck(RemoteFileManager(remoteFileURL: configurationFileURL))
}

// MARK: - Internal API

/**
Check the configuration file and perform any appropriate action, using
the provided `RemoteFileManager`.

- Parameter remoteFileManager: The `RemoteFileManager` to use to fetch the configuration file.
*/
func performCheck(remoteFileManager: RemoteFileManager) {
remoteFileManager.fetchRemoteFile { (jsonData) -> Void in
if let config = self.parser.parse(jsonData) {
Expand All @@ -45,6 +70,13 @@ public class LaunchGate {
}
}

/**
Determine which dialog, if any, to display based on the parsed configuration.

- Parameters:
- config: Configuration parsed from remote configuration file.
- dialogManager: Manager object for the various alert dialogs
*/
func displayDialogIfNecessary(config: LaunchGateConfiguration, dialogManager: DialogManager) {
if let reqUpdate = config.requiredUpdate, appVersion = currentAppVersion() {
if shouldShowRequiredUpdateDialog(reqUpdate, appVersion: appVersion) {
Expand All @@ -61,16 +93,37 @@ public class LaunchGate {
}
}

/**
Determine if an alert dialog should be displayed, based on the configuration.

- Parameter alertConfig: An `AlertConfiguration`, parsed from the configuration file.

- Returns: `true`, if an alert dialog should be displayed; `false`, if not.
*/
func shouldShowAlertDialog(alertConfig: AlertConfiguration) -> Bool {
return alertConfig.blocking || alertConfig.isNotRemembered()
}

/**
Determine if an optional update dialog should be displayed, based on the configuration.

- Parameter updateConfig: An `UpdateConfiguration`, parsed from the configuration file.

- Returns: `true`, if an optional update should be displayed; `false`, if not.
*/
func shouldShowOptionalUpdateDialog(updateConfig: UpdateConfiguration, appVersion: String) -> Bool {
guard updateConfig.isNotRemembered() else { return false }

return appVersion < updateConfig.version
}

/**
Determine if a required update dialog should be displayed, based on the configuration.

- Parameter updateConfig: An `UpdateConfiguration`, parsed from the configuration file.

- Returns: `true`, if a required update dialog should be displayed; `false`, if not.
*/
func shouldShowRequiredUpdateDialog(updateConfig: UpdateConfiguration, appVersion: String) -> Bool {
return appVersion < updateConfig.version
}
Expand Down
6 changes: 6 additions & 0 deletions Source/LaunchGateConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
import Foundation


/// The configuration object that should be created as the result of parsing the remote configuration file.
public struct LaunchGateConfiguration {

/// An `AlertConfiguration`, parsed from the configuration file.
var alert: AlertConfiguration?

/// An optional `UpdateConfiguration`, parsed from the configuration file.
var optionalUpdate: UpdateConfiguration?

/// A required `UpdateConfiguration`, parsed from the configuration file.
var requiredUpdate: UpdateConfiguration?

}
6 changes: 4 additions & 2 deletions Source/LaunchGateParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

import Foundation


/// Protocol to which any configuration parser must conform.
public protocol LaunchGateParser {

/**
Parse the configuration file into a `LaunchGateRemoteConfiguration` object.

- parameter jsonData: The configuration file JSON as NSData.
- Parameter jsonData: The configuration file JSON as NSData.

- returns: The resulting `LaunchGateRemoteConfiguration` object,
- Returns: The resulting `LaunchGateRemoteConfiguration` object,
or `nil` if parsing fails for any reason (i.e. malformed JSON response).
*/
func parse(jsonData: NSData) -> LaunchGateConfiguration?
Expand Down

0 comments on commit 11c2ca1

Please sign in to comment.