Skip to content

Commit

Permalink
Merge pull request #2 from auth0/swift-2.0
Browse files Browse the repository at this point in the history
Swift 2.0 and Xcode 7 support
  • Loading branch information
hzalaz committed Sep 17, 2015
2 parents a35f4aa + abb1af6 commit 3b1be46
Show file tree
Hide file tree
Showing 116 changed files with 1,960 additions and 995 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
reference: http://www.objc.io/issue-6/travis-ci.html
language: objective-c
osx_image: xcode6.4
osx_image: xcode7
env:
global:
- LC_CTYPE=en_US.UTF-8
- LANG=en_US.UTF-8
matrix:
- DESTINATION="OS=8.3,name=iPhone 6" SCHEME="Auth0-iOS" SDK=iphonesimulator8.4
- DESTINATION="OS=8.4,name=iPhone 6 Plus" SCHEME="Auth0-iOS" SDK=iphonesimulator8.4
- DESTINATION="arch=x86_64" SCHEME="Auth0-OSX" SDK=macosx10.10
- DESTINATION="OS=9.0,name=iPhone 6" SCHEME="Auth0-iOS" SDK=iphonesimulator
- DESTINATION="OS=8.3,name=iPhone 6" SCHEME="Auth0-iOS" SDK=iphonesimulator
- DESTINATION="OS=8.4,name=iPhone 6 Plus" SCHEME="Auth0-iOS" SDK=iphonesimulator
- DESTINATION="arch=x86_64" SCHEME="Auth0-OSX" SDK=macosx
cache:
- bundler
before_install:
Expand Down
13 changes: 12 additions & 1 deletion Auth0.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@
5F0068B31B3B3EFF0048928E /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0640;
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = Auth0;
TargetAttributes = {
5F0068BB1B3B3EFF0048928E = {
Expand Down Expand Up @@ -551,6 +553,7 @@
CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -634,6 +637,7 @@
INFOPLIST_FILE = Auth0/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.auth0.Auth0;
PRODUCT_NAME = Auth0;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -656,6 +660,7 @@
INFOPLIST_FILE = Auth0/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.auth0.Auth0;
PRODUCT_NAME = Auth0;
SKIP_INSTALL = YES;
};
Expand All @@ -676,6 +681,7 @@
);
INFOPLIST_FILE = Auth0Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.auth0.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Auth0Tests/Auth0-iOSTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -693,6 +699,7 @@
);
INFOPLIST_FILE = Auth0Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.auth0.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Auth0Tests/Auth0-iOSTests-Bridging-Header.h";
};
Expand Down Expand Up @@ -721,6 +728,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = com.auth0.Auth0;
PRODUCT_NAME = Auth0;
SDKROOT = macosx;
SKIP_INSTALL = YES;
Expand All @@ -746,6 +754,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = com.auth0.Auth0;
PRODUCT_NAME = Auth0;
SDKROOT = macosx;
SKIP_INSTALL = YES;
Expand All @@ -770,6 +779,7 @@
INFOPLIST_FILE = Auth0Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = "com.auth0.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "Auth0Tests/Auth0-OSXTests-Bridging-Header.h";
Expand All @@ -790,6 +800,7 @@
INFOPLIST_FILE = Auth0Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = "com.auth0.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "Auth0Tests/Auth0-OSXTests-Bridging-Header.h";
Expand Down
13 changes: 8 additions & 5 deletions Auth0.xcodeproj/xcshareddata/xcschemes/Auth0-OSX.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0640"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:Auth0.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand All @@ -85,10 +88,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
13 changes: 8 additions & 5 deletions Auth0.xcodeproj/xcshareddata/xcschemes/Auth0-iOS.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0640"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:Auth0.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand All @@ -85,10 +88,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
8 changes: 4 additions & 4 deletions Auth0/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public struct API {
/**
Creates a new API object for a given Auth0 subdomain

:param: domain of an Auth0 account
- parameter domain: of an Auth0 account

:returns: a new instance
- returns: a new instance
*/
public init(domain: String) {
self.domainUrl = (domain.hasPrefix("http") ? NSURL(string: domain) : NSURL(string: "https://".stringByAppendingString(domain)))!
Expand All @@ -48,9 +48,9 @@ public struct API {
/**
Initialize API v2 /users endpoint with a valid JWT

:param: token a valid jwt of API v2 or an `id_token` of a user
- parameter token: a valid jwt of API v2 or an `id_token` of a user

:returns: users api helper
- returns: users api helper
*/
public func users(token: String) -> Users {
return Users(api: self, token: token)
Expand Down
28 changes: 17 additions & 11 deletions Auth0/APIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,38 @@ public struct APIRequest<T> {
/**
Register a new callback for the request's JSON response

:param: callback to be called when a response is received or an error occurs. It can yield the error that caused the request to fail or server's JSON response if it's successful
- parameter callback: to be called when a response is received or an error occurs. It can yield the error that caused the request to fail or server's JSON response if it's successful
*/
public func responseJSON(callback: (error: NSError?, payload:T?) -> ()) {
switch(request, error) {
case let (.None, .Some(error)):
callback(error: error, payload: nil)
case let (.Some(request), .None):
request.responseJSON { _, resp, payload, err in
switch (resp, payload, err) {
case (_, nil, let error):
request
.validate(statusCode: 200..<300)
.responseJSON { request, response, result in
switch (response, result) {
case (_, .Failure(nil, let error as NSError)):
callback(error: error, payload: nil)
case (let response, _, nil) where response != nil && 200...299 ~= response!.statusCode:
case (_, .Success(let payload)):
if let responseObject = self.builder?(payload: payload) {
callback(error: nil, payload: responseObject)
} else {
callback(error: errorWithCode(.InvalidPayload, userInfo: [NSLocalizedDescriptionKey: "Failed to obtain JSON from \(payload)"]), payload: nil)
}
case (let response, _, nil) where response != nil && 400...599 ~= response!.statusCode && payload != nil:
let info = [
NSLocalizedDescriptionKey: "Request to \(request.request.URL) failed with status code \(response?.statusCode)",
APIRequestErrorErrorKey: payload!,
APIRequestErrorStatusCodeKey: response!.statusCode
case (let response, .Failure(let payload, _)) where payload != nil && response != nil:
let statusCode = response!.statusCode
let message = "Request to \(request?.URL) failed with status code \(statusCode)"
var info: [String: AnyObject] = [
NSLocalizedDescriptionKey: message,
APIRequestErrorStatusCodeKey: statusCode
]
if let error = try? NSJSONSerialization.JSONObjectWithData(payload!, options: NSJSONReadingOptions()) {
info[APIRequestErrorErrorKey] = error
}
callback(error: errorWithCode(.Failed, userInfo: info), payload: nil)
default:
callback(error: errorWithCode(.Failed, userInfo: [NSLocalizedDescriptionKey: "Request to \(request.request.URL) failed"]), payload: nil)
callback(error: errorWithCode(.Failed, userInfo: [NSLocalizedDescriptionKey: "Request to \(request?.URL) failed"]), payload: nil)
}
}
default:
Expand Down
14 changes: 7 additions & 7 deletions Auth0/Auth0.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public struct Auth0 {
Creates a new Auth0 object.
It retrieves your Auth0 account domain from `Info.plist` file entry with key `Auth0Domain`

:returns: a new instance
- returns: a new instance
*/
public init() {
let info = NSBundle.mainBundle().infoDictionary
Expand All @@ -49,9 +49,9 @@ public struct Auth0 {
Creates a new Auth0 object with an account Auth0 domain.
The domain can be a full web url, e.g.: `https://samples.auth0.com`, or just the domain name, e.g. `samples.auth0.com`

:param: domain of your Auth0 account
- parameter domain: of your Auth0 account

:returns: a new instance
- returns: a new instance
*/
public init(domain: String) {
self.api = API(domain: domain)
Expand All @@ -60,9 +60,9 @@ public struct Auth0 {
/**
Initialize API v2 /users endpoint with a valid JWT

:param: token a valid jwt of API v2 or an `id_token` of a user
- parameter token: a valid jwt of API v2 or an `id_token` of a user

:returns: users api helper
- returns: users api helper
*/
public func users(token: String) -> Users {
return api.users(token)
Expand All @@ -71,9 +71,9 @@ public struct Auth0 {
/**
Initialize API v2 /users endpoint with a valid JWT from shared Auth0 configuration

:param: token a valid jwt of API v2 or an `id_token` of a user
- parameter token: a valid jwt of API v2 or an `id_token` of a user

:returns: users api helper
- returns: users api helper
*/
public static func users(token: String) -> Users {
return Auth0.sharedInstance.api.users(token)
Expand Down
Loading

0 comments on commit 3b1be46

Please sign in to comment.