Add PromiseKit dependency

- Added PromiseKit dependency
This commit is contained in:
2018-11-15 22:08:00 -04:00
parent 2689d86c18
commit be7b6b5881
541 changed files with 46282 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
*.xcodeproj/**/xcuserdata/
*.xcscmblueprint
/Carthage
/.build
.DS_Store

View File

@@ -0,0 +1,42 @@
language: objective-c
os: osx
matrix:
include:
# - {osx_image: xcode8.3, env: 'PLAT=macOS SWFT=3.1 DST="arch=x86_64"'}
# - {osx_image: xcode8.3, env: 'PLAT=iOS SWFT=3.1 DST="OS=10.3.1,name=iPhone SE"'}
# - {osx_image: xcode8.3, env: 'PLAT=tvOS SWFT=3.1 DST="OS=10.2,name=Apple TV 1080p"'}
# - {osx_image: xcode8.3, env: 'PLAT=watchOS SWFT=3.1 DST="OS=3.2,name=Apple Watch - 38mm"'}
- {osx_image: xcode9.2, env: 'PLAT=macOS SWFT=3.2 DST="arch=x86_64"'}
- {osx_image: xcode9.2, env: 'PLAT=iOS SWFT=3.2 DST="OS=11.2,name=iPhone SE"'}
- {osx_image: xcode9.2, env: 'PLAT=tvOS SWFT=3.2 DST="OS=11.2,name=Apple TV"'}
- {osx_image: xcode9.2, env: 'PLAT=watchOS SWFT=3.2 DST="OS=4.2,name=Apple Watch - 38mm"'}
- {osx_image: xcode9.4, env: 'PLAT=macOS SWFT=3.3 DST="arch=x86_64"'}
- {osx_image: xcode9.4, env: 'PLAT=iOS SWFT=3.3 DST="OS=11.4,name=iPhone 5s"'}
- {osx_image: xcode9.4, env: 'PLAT=tvOS SWFT=3.3 DST="OS=11.4,name=Apple TV"'}
- {osx_image: xcode9.4, env: 'PLAT=watchOS SWFT=3.3 DST="OS=4.3,name=Apple Watch - 38mm"'}
- {osx_image: xcode9.2, env: 'PLAT=macOS SWFT=4.0 DST="arch=x86_64"'}
- {osx_image: xcode9.2, env: 'PLAT=iOS SWFT=4.0 DST="OS=11.2,name=iPhone SE"'}
- {osx_image: xcode9.2, env: 'PLAT=tvOS SWFT=4.0 DST="OS=11.2,name=Apple TV"'}
- {osx_image: xcode9.2, env: 'PLAT=watchOS SWFT=4.0 DST="OS=4.2,name=Apple Watch - 38mm"'}
- {osx_image: xcode9.4, env: 'PLAT=macOS SWFT=4.1 DST="arch=x86_64" TEST=1'}
- {osx_image: xcode9.4, env: 'PLAT=iOS SWFT=4.1 DST="OS=11.4,name=iPhone 5s" TEST=1'}
- {osx_image: xcode9.4, env: 'PLAT=tvOS SWFT=4.1 DST="OS=11.4,name=Apple TV" TEST=1'}
- {osx_image: xcode9.4, env: 'PLAT=watchOS SWFT=4.1 DST="OS=4.3,name=Apple Watch - 38mm"'}
cache:
directories:
- Carthage
before_install:
- carthage bootstrap --cache-builds --no-use-binaries --platform $PLAT --verbose
install:
- xcodebuild -scheme PMKOMGHTTPURLRQ -target PMKOMGHTTPURLRQ -quiet -destination "$DST" SWIFT_VERSION=$SWFT SWIFT_TREAT_WARNINGS_AS_ERRORS=YES build
- if [[ $TEST == "1" ]]; then
xcodebuild -scheme PMKOMGHTTPURLRQ -target PMKOMGTests -quiet -destination "$DST" build;
fi
script:
- if [[ $TEST == "1" ]]; then
xcodebuild -scheme PMKOMGHTTPURLRQ -quiet -destination "$DST" test;
fi

View File

@@ -0,0 +1,3 @@
github "mxcl/PromiseKit" ~> 6.3
github "mxcl/OMGHTTPURLRQ" ~> 3.2
github "PromiseKit/Foundation" ~> 3.1

View File

@@ -0,0 +1 @@
github "AliSoftware/OHHTTPStubs" ~> 6.0

View File

@@ -0,0 +1,4 @@
github "AliSoftware/OHHTTPStubs" "6.1.0"
github "PromiseKit/Foundation" "3.1.0"
github "mxcl/OMGHTTPURLRQ" "3.2.5"
github "mxcl/PromiseKit" "6.3.3"

View File

@@ -0,0 +1,7 @@
// Created by Kevin Ballard on 12/14/15.
// Copyright © 2015 Postmates. All rights reserved.
FRAMEWORK_SEARCH_PATHS[sdk=macosx*] = $(SRCROOT)/Carthage/Build/Mac/ $(inherited)
FRAMEWORK_SEARCH_PATHS[sdk=iphone*] = $(SRCROOT)/Carthage/Build/iOS/ $(inherited)
FRAMEWORK_SEARCH_PATHS[sdk=watch*] = $(SRCROOT)/Carthage/Build/watchOS/ $(inherited)
FRAMEWORK_SEARCH_PATHS[sdk=appletv*] = $(SRCROOT)/Carthage/Build/tvOS/ $(inherited)

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@@ -0,0 +1,466 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
6331B3FC1D657CB700544154 /* PMKOMGHTTPURLRQ.h in Headers */ = {isa = PBXBuildFile; fileRef = 6331B3F91D657CB700544154 /* PMKOMGHTTPURLRQ.h */; settings = {ATTRIBUTES = (Public, ); }; };
6331B3FF1D657DA400544154 /* NSURLSession+OMG+AnyPromise.m in Sources */ = {isa = PBXBuildFile; fileRef = 6331B3FD1D657DA400544154 /* NSURLSession+OMG+AnyPromise.m */; };
6331B4001D657DA400544154 /* NSURLSession+OMG+Promise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6331B3FE1D657DA400544154 /* NSURLSession+OMG+Promise.swift */; };
6342D1B51D68E7BB005D7062 /* TestNSURLSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 6331B4011D657DDB00544154 /* TestNSURLSession.m */; };
63C700081D5C021F003BAE60 /* TestNSURLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63C700021D5C021F003BAE60 /* TestNSURLSession.swift */; };
63C7FFF71D5C020D003BAE60 /* PMKOMGHTTPURLRQ.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63C7FFA71D5BEE09003BAE60 /* PMKOMGHTTPURLRQ.framework */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
63C7FFF81D5C020D003BAE60 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 63C7FF9E1D5BEE09003BAE60 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 63C7FFA61D5BEE09003BAE60;
remoteInfo = PMKFoundation;
};
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
6331B3F91D657CB700544154 /* PMKOMGHTTPURLRQ.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PMKOMGHTTPURLRQ.h; path = Sources/PMKOMGHTTPURLRQ.h; sourceTree = SOURCE_ROOT; };
6331B3FD1D657DA400544154 /* NSURLSession+OMG+AnyPromise.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSURLSession+OMG+AnyPromise.m"; path = "Sources/NSURLSession+OMG+AnyPromise.m"; sourceTree = SOURCE_ROOT; };
6331B3FE1D657DA400544154 /* NSURLSession+OMG+Promise.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSURLSession+OMG+Promise.swift"; path = "Sources/NSURLSession+OMG+Promise.swift"; sourceTree = SOURCE_ROOT; };
6331B4011D657DDB00544154 /* TestNSURLSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TestNSURLSession.m; path = Tests/TestNSURLSession.m; sourceTree = SOURCE_ROOT; };
63C700021D5C021F003BAE60 /* TestNSURLSession.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestNSURLSession.swift; path = Tests/TestNSURLSession.swift; sourceTree = SOURCE_ROOT; };
63C700091D5C0253003BAE60 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
63C7FFA71D5BEE09003BAE60 /* PMKOMGHTTPURLRQ.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PMKOMGHTTPURLRQ.framework; sourceTree = BUILT_PRODUCTS_DIR; };
63C7FFF21D5C020D003BAE60 /* PMKOMGTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PMKOMGTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
63CCF8121D5C0C4E00503216 /* Cartfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Cartfile; sourceTree = "<group>"; };
63CCF8131D5C0C4E00503216 /* Cartfile.private */ = {isa = PBXFileReference; lastKnownFileType = text; path = Cartfile.private; sourceTree = "<group>"; };
63CCF8171D5C11B500503216 /* Carthage.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Carthage.xcconfig; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
63C7FFA31D5BEE09003BAE60 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
63C7FFEF1D5C020D003BAE60 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
63C7FFF71D5C020D003BAE60 /* PMKOMGHTTPURLRQ.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
63C7FF9D1D5BEE09003BAE60 = {
isa = PBXGroup;
children = (
63C700091D5C0253003BAE60 /* Info.plist */,
63CCF8121D5C0C4E00503216 /* Cartfile */,
63CCF8131D5C0C4E00503216 /* Cartfile.private */,
63CCF8171D5C11B500503216 /* Carthage.xcconfig */,
63C7FFA91D5BEE09003BAE60 /* Sources */,
63C7FFF31D5C020D003BAE60 /* Tests */,
63C7FFA81D5BEE09003BAE60 /* Products */,
);
sourceTree = "<group>";
};
63C7FFA81D5BEE09003BAE60 /* Products */ = {
isa = PBXGroup;
children = (
63C7FFA71D5BEE09003BAE60 /* PMKOMGHTTPURLRQ.framework */,
63C7FFF21D5C020D003BAE60 /* PMKOMGTests.xctest */,
);
name = Products;
sourceTree = "<group>";
};
63C7FFA91D5BEE09003BAE60 /* Sources */ = {
isa = PBXGroup;
children = (
6331B3F91D657CB700544154 /* PMKOMGHTTPURLRQ.h */,
6331B3FD1D657DA400544154 /* NSURLSession+OMG+AnyPromise.m */,
6331B3FE1D657DA400544154 /* NSURLSession+OMG+Promise.swift */,
);
path = Sources;
sourceTree = SOURCE_ROOT;
};
63C7FFF31D5C020D003BAE60 /* Tests */ = {
isa = PBXGroup;
children = (
63C700021D5C021F003BAE60 /* TestNSURLSession.swift */,
6331B4011D657DDB00544154 /* TestNSURLSession.m */,
);
path = Tests;
sourceTree = SOURCE_ROOT;
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
63C7FFA41D5BEE09003BAE60 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
6331B3FC1D657CB700544154 /* PMKOMGHTTPURLRQ.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */
63C7FFA61D5BEE09003BAE60 /* PMKOMGHTTPURLRQ */ = {
isa = PBXNativeTarget;
buildConfigurationList = 63C7FFAF1D5BEE09003BAE60 /* Build configuration list for PBXNativeTarget "PMKOMGHTTPURLRQ" */;
buildPhases = (
63C7FFA21D5BEE09003BAE60 /* Sources */,
63C7FFA31D5BEE09003BAE60 /* Frameworks */,
63C7FFA41D5BEE09003BAE60 /* Headers */,
);
buildRules = (
);
dependencies = (
);
name = PMKOMGHTTPURLRQ;
productName = "PMK+UIKit";
productReference = 63C7FFA71D5BEE09003BAE60 /* PMKOMGHTTPURLRQ.framework */;
productType = "com.apple.product-type.framework";
};
63C7FFF11D5C020D003BAE60 /* PMKOMGTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 63C7FFFA1D5C020D003BAE60 /* Build configuration list for PBXNativeTarget "PMKOMGTests" */;
buildPhases = (
63C7FFEE1D5C020D003BAE60 /* Sources */,
63C7FFEF1D5C020D003BAE60 /* Frameworks */,
639447051D5D011300DDAE3C /* Embed Carthage Frameworks */,
);
buildRules = (
);
dependencies = (
63C7FFF91D5C020D003BAE60 /* PBXTargetDependency */,
);
name = PMKOMGTests;
productName = PMKTests/NS;
productReference = 63C7FFF21D5C020D003BAE60 /* PMKOMGTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
63C7FF9E1D5BEE09003BAE60 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0800;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = "Max Howell";
TargetAttributes = {
63C7FFA61D5BEE09003BAE60 = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
63C7FFF11D5C020D003BAE60 = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = 63C7FFA11D5BEE09003BAE60 /* Build configuration list for PBXProject "PMKOMGHTTPURLRQ" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 63C7FF9D1D5BEE09003BAE60;
productRefGroup = 63C7FFA81D5BEE09003BAE60 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
63C7FFA61D5BEE09003BAE60 /* PMKOMGHTTPURLRQ */,
63C7FFF11D5C020D003BAE60 /* PMKOMGTests */,
);
};
/* End PBXProject section */
/* Begin PBXShellScriptBuildPhase section */
639447051D5D011300DDAE3C /* Embed Carthage Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
PromiseKit,
OMGHTTPURLRQ,
OHHTTPStubs,
PMKFoundation,
);
name = "Embed Carthage Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "case \"$PLATFORM_NAME\" in\nmacosx) plat=Mac;;\niphone*) plat=iOS;;\nwatch*) plat=watchOS;;\nappletv*) plat=tvOS;;\n*) echo \"error: Unknown PLATFORM_NAME: $PLATFORM_NAME\"; exit 1;;\nesac\nfor (( n = 0; n < SCRIPT_INPUT_FILE_COUNT; n++ )); do\nVAR=SCRIPT_INPUT_FILE_$n\nframework=$(basename \"${!VAR}\")\nexport SCRIPT_INPUT_FILE_$n=\"$SRCROOT\"/Carthage/Build/$plat/\"$framework\".framework\ndone\n\n/usr/local/bin/carthage copy-frameworks || exit\n\nfor (( n = 0; n < SCRIPT_INPUT_FILE_COUNT; n++ )); do\nVAR=SCRIPT_INPUT_FILE_$n\nsource=${!VAR}.dSYM\ndest=${BUILT_PRODUCTS_DIR}/$(basename \"$source\")\nditto \"$source\" \"$dest\" || exit\ndone";
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
63C7FFA21D5BEE09003BAE60 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6331B3FF1D657DA400544154 /* NSURLSession+OMG+AnyPromise.m in Sources */,
6331B4001D657DA400544154 /* NSURLSession+OMG+Promise.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
63C7FFEE1D5C020D003BAE60 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
63C700081D5C021F003BAE60 /* TestNSURLSession.swift in Sources */,
6342D1B51D68E7BB005D7062 /* TestNSURLSession.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
63C7FFF91D5C020D003BAE60 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 63C7FFA61D5BEE09003BAE60 /* PMKOMGHTTPURLRQ */;
targetProxy = 63C7FFF81D5C020D003BAE60 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
63C7FFAD1D5BEE09003BAE60 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 63CCF8171D5C11B500503216 /* Carthage.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.promisekit.OMGHTTPURLRQ;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos watchsimulator watchos macosx appletvsimulator appletvos";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
name = Debug;
};
63C7FFAE1D5BEE09003BAE60 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 63CCF8171D5C11B500503216 /* Carthage.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = org.promisekit.OMGHTTPURLRQ;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos watchsimulator watchos macosx appletvsimulator appletvos";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
name = Release;
};
63C7FFB01D5BEE09003BAE60 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_MODULE_NAME = "${TARGET_NAME}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
63C7FFB11D5BEE09003BAE60 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_MODULE_NAME = "${TARGET_NAME}";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
63C7FFFB1D5C020D003BAE60 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
GCC_WARN_INHIBIT_ALL_WARNINGS = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SUPPRESS_WARNINGS = YES;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
63C7FFFC1D5C020D003BAE60 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
GCC_WARN_INHIBIT_ALL_WARNINGS = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SUPPRESS_WARNINGS = YES;
SWIFT_VERSION = 4.0;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
63C7FFA11D5BEE09003BAE60 /* Build configuration list for PBXProject "PMKOMGHTTPURLRQ" */ = {
isa = XCConfigurationList;
buildConfigurations = (
63C7FFAD1D5BEE09003BAE60 /* Debug */,
63C7FFAE1D5BEE09003BAE60 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
63C7FFAF1D5BEE09003BAE60 /* Build configuration list for PBXNativeTarget "PMKOMGHTTPURLRQ" */ = {
isa = XCConfigurationList;
buildConfigurations = (
63C7FFB01D5BEE09003BAE60 /* Debug */,
63C7FFB11D5BEE09003BAE60 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
63C7FFFA1D5C020D003BAE60 /* Build configuration list for PBXNativeTarget "PMKOMGTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
63C7FFFB1D5C020D003BAE60 /* Debug */,
63C7FFFC1D5C020D003BAE60 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 63C7FF9E1D5BEE09003BAE60 /* Project object */;
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:/Users/mxcl/Desktop/PMK+UIKit/PMKFoundation.xcodeproj">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
<false/>
</dict>
</plist>

View File

@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "NO">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "NO"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "63C7FFA61D5BEE09003BAE60"
BuildableName = "PMKOMGHTTPURLRQ.framework"
BlueprintName = "PMKOMGHTTPURLRQ"
ReferencedContainer = "container:PMKOMGHTTPURLRQ.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "63C7FFF11D5C020D003BAE60"
BuildableName = "PMKOMGTests.xctest"
BlueprintName = "PMKOMGTests"
ReferencedContainer = "container:PMKOMGHTTPURLRQ.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "NSURLSessionTests/test1">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "63C7FFA61D5BEE09003BAE60"
BuildableName = "PMKOMGHTTPURLRQ.framework"
BlueprintName = "PMKOMGHTTPURLRQ"
ReferencedContainer = "container:PMKOMGHTTPURLRQ.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "63C7FFA61D5BEE09003BAE60"
BuildableName = "PMKOMGHTTPURLRQ.framework"
BlueprintName = "PMKOMGHTTPURLRQ"
ReferencedContainer = "container:PMKOMGHTTPURLRQ.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "63C7FFA61D5BEE09003BAE60"
BuildableName = "PMKOMGHTTPURLRQ.framework"
BlueprintName = "PMKOMGHTTPURLRQ"
ReferencedContainer = "container:PMKOMGHTTPURLRQ.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,65 @@
# DEPRECATED
Use PMKFoundation or PMKAlamofire, the promises provided by this repository are minimal
and add little value over just using OMG by itself and passing its URLRequests to
URLSession manually.
# PromiseKit OMGHTTPURLRQ Extensions ![Build Status]
This project provides convenience methods on NSURLSession using [OMGHTTPURLRQ].
## Usage
```swift
URLSession.shared.POST(url, formData: params).then { data -> Void in
// by default you just get the raw `Data`
}
URLSession.shared.GET(url).asDictionary().then { json -> Void in
// call `asDictionary()` to have the result decoded
// as JSON with the result being an `NSDictionary`
// the promise is rejected if the JSON can not be
// decoded or the resulting object is not a dictionary
}
URLSession.shared.PUT(url, json: params).asArray().then { json -> Void in
// json: NSArray
}
URLSession.shared.DELETE(url).asString().then { string -> Void in
// string: String
}
```
## CocoaPods
```ruby
pod "PromiseKit/OMGHTTPURLRQ", "~> 6.0"
```
The extensions are built into `PromiseKit.framework` thus nothing else is needed.
## Carthage
```ruby
github "PromiseKit/OMGHTTPURLRQ-" ~> 3.0
```
The extensions are built into their own framework:
```swift
// swift
import PromiseKit
import OMGHTTPURLRQ
import PMKOMGHTTPURLRQ
```
```objc
// objc
@import PromiseKit;
@import OMGHTTPURLRQ;
@import PMKOMGHTTPURLRQ;
```
[Build Status]: https://travis-ci.org/PromiseKit/OMGHTTPURLRQ.svg?branch=master

View File

@@ -0,0 +1,100 @@
#import <Foundation/NSJSONSerialization.h>
#import <OMGHTTPURLRQ/OMGHTTPURLRQ.h>
#import <Foundation/NSURLResponse.h>
#import <CoreFoundation/CFString.h>
#import <Foundation/NSOperation.h>
#import <Foundation/NSURLError.h>
#import <CoreFoundation/CFURL.h>
#import <Foundation/NSThread.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSError.h>
#import <Foundation/NSURL.h>
#import "PMKOMGHTTPURLRQ.h"
#if !COCOAPODS
#import <PMKFoundation/NSURLSession+AnyPromise.h>
#else
#import "NSURLSession+AnyPromise.h"
#endif
static id PMKURLRequestFromURLFormat(NSError **err, id urlFormat, ...);
static id go(NSURLSession *, NSMutableURLRequest *);
@implementation NSURLSession (PMKOMG)
- (AnyPromise *)GET:(id)urlFormat, ... {
id err;
id rq = PMKURLRequestFromURLFormat(&err, urlFormat);
if (err) return [AnyPromise promiseWithValue:err];
return go(self, rq);
}
- (AnyPromise *)GET:(NSString *)url query:(NSDictionary *)params {
id err;
id rq = [OMGHTTPURLRQ GET:url:params error:&err];
if (err) return [AnyPromise promiseWithValue:err];
return go(self, rq);
}
- (AnyPromise *)POST:(NSString *)url formURLEncodedParameters:(NSDictionary *)params {
id err;
id rq = [OMGHTTPURLRQ POST:url:params error:&err];
if (err) return [AnyPromise promiseWithValue:err];
return go(self, rq);
}
- (AnyPromise *)POST:(NSString *)urlString JSON:(NSDictionary *)params {
id err;
id rq = [OMGHTTPURLRQ POST:urlString JSON:params error:&err];
if (err) return [AnyPromise promiseWithValue:err];
return go(self, rq);
}
- (AnyPromise *)PUT:(NSString *)url formURLEncodedParameters:(NSDictionary *)params {
id err;
id rq = [OMGHTTPURLRQ PUT:url:params error:&err];
if (err) return [AnyPromise promiseWithValue:err];
return go(self, rq);
}
- (AnyPromise *)DELETE:(NSString *)url formURLEncodedParameters:(NSDictionary *)params {
id err;
id rq = [OMGHTTPURLRQ DELETE:url :params error:&err];
if (err) return [AnyPromise promiseWithValue:err];
return go(self, rq);
}
- (AnyPromise *)PATCH:(NSString *)url JSON:(NSDictionary *)params {
id err;
id rq = [OMGHTTPURLRQ PATCH:url JSON:params error:&err];
if (err) return [AnyPromise promiseWithValue:err];
return go(self, rq);
}
@end
static id PMKURLRequestFromURLFormat(NSError **err, id urlFormat, ...) {
if ([urlFormat isKindOfClass:[NSString class]]) {
va_list arguments;
va_start(arguments, urlFormat);
urlFormat = [[NSString alloc] initWithFormat:urlFormat arguments:arguments];
va_end(arguments);
} else if ([urlFormat isKindOfClass:[NSURL class]]) {
NSMutableURLRequest *rq = [[NSMutableURLRequest alloc] initWithURL:urlFormat];
[rq setValue:OMGUserAgent() forHTTPHeaderField:@"User-Agent"];
return rq;
} else {
urlFormat = [urlFormat description];
}
return [OMGHTTPURLRQ GET:urlFormat:nil error:err];
}
static id go(NSURLSession *session, NSMutableURLRequest *rq) {
if ([rq valueForHTTPHeaderField:@"User-Agent"] == nil) {
[rq setValue:OMGUserAgent() forHTTPHeaderField:@"User-Agent"];
}
return [session promiseDataTaskWithRequest:rq];
}

View File

@@ -0,0 +1,170 @@
import OMGHTTPURLRQ
import Foundation
#if !PMKCocoaPods
import PMKFoundation
import PromiseKit
#endif
/**
To import the `OMGHTTPURLRQ` category:
use_frameworks!
pod "PromiseKit/OMGHTTPURLRQ"
And then in your sources:
import PromiseKit
We provide convenience categories for the `URLSession.shared`, or
an instance method `promise`. If you need more complicated behavior
we recommend wrapping that usage in a `Promise` initializer.
*/
extension URLSession {
/**
Makes a **GET** request to the provided URL.
let p = URLSession.shared.GET("http://example.com", query: ["foo": "bar"])
p.then { data -> Void in
//
}
p.asImage().then { image -> Void in
//
}
p.asDictionary().then { json -> Void in
//
}
- Parameter url: The URL to request.
- Parameter query: The parameters to be encoded as the query string for the GET request.
- Returns: A promise that represents the GET request.
*/
public func GET(_ url: String, query: [String: Any]? = nil) -> Promise<(data: Data, response: URLResponse)> {
return start(try OMGHTTPURLRQ.get(url, query) as URLRequest)
}
/**
Makes a POST request to the provided URL passing form URL encoded
parameters.
Form URL-encoding is the standard way to POST on the Internet, so
probably this is what you want. If it doesnt work, try the `+POST:JSON`
variant.
let url = "http://jsonplaceholder.typicode.com/posts"
let params = ["title": "foo", "body": "bar", "userId": 1]
URLSession.shared.POST(url, formData: params).asDictionary().then { json -> Void in
//
}
- Parameter url: The URL to request.
- Parameter formData: The parameters to be form URL-encoded and passed as the POST body.
- Returns: A promise that represents the POST request.
*/
public func POST(_ url: String, formData: [String: Any]? = nil) -> Promise<(data: Data, response: URLResponse)> {
return start(try OMGHTTPURLRQ.post(url, formData) as URLRequest)
}
/**
Makes a POST request to the provided URL passing multipart form-data.
let formData = OMGMultipartFormData()
let imgData = Data(contentsOfFile: "image.png")
formData.addFile(imgdata, parameterName: "file1", filename: "myimage1.png", contentType: "image/png")
URLSession.shared.POST(url, multipartFormData: formData).then { data in
//
}
- Parameter url: The URL to request.
- Parameter multipartFormData: The parameters to be multipart form-data encoded and passed as the POST body.
- Returns: A promise that represents the POST request.
- SeeAlso: [https://github.com/mxcl/OMGHTTPURLRQ](OMGHTTPURLRQ)
*/
public func POST(_ url: String, multipartFormData: OMGMultipartFormData) -> Promise<(data: Data, response: URLResponse)> {
return start(try OMGHTTPURLRQ.post(url, multipartFormData) as URLRequest)
}
/**
Makes a POST request to the provided URL passing JSON encoded
parameters.
Most web servers nowadays support POST with either JSON or form
URL-encoding. If in doubt try form URL-encoded parameters first.
let url = "http://jsonplaceholder.typicode.com/posts"
let params = ["title": "foo", "body": "bar", "userId": 1]
URLSession.shared.POST(url, json: params).asDictionary().then { json -> Void in
//
}
- Parameter url: The URL to request.
- Parameter json: The parameters to be JSON-encoded and passed as the POST body.
- Returns: A promise that represents the POST request.
*/
public func POST(_ url: String, json: [String: Any]? = nil) -> Promise<(data: Data, response: URLResponse)> {
return start(try OMGHTTPURLRQ.post(url, json: json) as URLRequest)
}
/**
Makes a PUT request to the provided URL passing JSON encoded parameters.
let url = "http://jsonplaceholder.typicode.com/posts"
let params = ["title": "foo", "body": "bar", "userId": 1]
URLSession.shared.PUT(url, json: params).asDictionary().then { json -> Void in
//
}
- Parameter url: The URL to request.
- Parameter json: The parameters to be JSON-encoded and passed as the PUT body.
- Returns: A promise that represents the PUT request.
*/
public func PUT(_ url: String, json: [String: Any]? = nil) -> Promise<(data: Data, response: URLResponse)> {
return start(try OMGHTTPURLRQ.put(url, json: json) as URLRequest)
}
/**
Makes a DELETE request to the provided URL passing form URL-encoded
parameters.
let url = "http://jsonplaceholder.typicode.com/posts/1"
URLSession.shared.DELETE(url).then.asDictionary() { json -> Void in
//
}
- Parameter url: The URL to request.
- Returns: A promise that represents the PUT request.
*/
public func DELETE(_ url: String) -> Promise<(data: Data, response: URLResponse)> {
return start(try OMGHTTPURLRQ.delete(url, nil) as URLRequest)
}
/**
Makes a PATCH request to the provided URL passing the provided JSON parameters.
let url = "http://jsonplaceholder.typicode.com/posts/1"
let params = ["foo": "bar"]
NSURLConnection.PATCH(url, json: params).asDictionary().then { json -> Void in
//
}
- Parameter url: The URL to request.
- Parameter json: The JSON parameters to encode as the PATCH body.
- Returns: A promise that represents the PUT request.
*/
public func PATCH(_ url: String, json: [String: Any]? = nil) -> Promise<(data: Data, response: URLResponse)> {
return start(try OMGHTTPURLRQ.patch(url, json: json) as URLRequest)
}
private func start(_ body: @autoclosure () throws -> URLRequest) -> Promise<(data: Data, response: URLResponse)> {
do {
var request = try body()
if request.value(forHTTPHeaderField: "User-Agent") == nil {
request.setValue(OMGUserAgent(), forHTTPHeaderField: "User-Agent")
}
return dataTask(.promise, with: request)
} catch {
return Promise(error: error)
}
}
}

View File

@@ -0,0 +1,200 @@
#import <Foundation/Foundation.h>
#import <PromiseKit/AnyPromise.h>
/**
To import the `NSURLSession` category:
use_frameworks!
pod "PromiseKit/Foundation"
Or `NSURLSession` is one of the categories imported by the umbrella pod:
use_frameworks!
pod "PromiseKit"
And then in your sources:
#import <PromiseKit/PromiseKit.h>
PromiseKit automatically deserializes the raw HTTP data response into the
appropriate rich data type based on the mime type the server provides.
Thus if the response is JSON you will get the deserialized JSON response.
PromiseKit supports decoding into strings, JSON and UIImages.
However if your server does not provide a rich content-type, you will
just get `NSData`. This is rare, but a good example we came across was
downloading files from Dropbox.
PromiseKit goes to quite some lengths to provide good `NSError` objects
for error conditions at all stages of the HTTP to rich-data type
pipeline. We provide the following additional `userInfo` keys as
appropriate:
- `PMKURLErrorFailingDataKey`
- `PMKURLErrorFailingStringKey`
- `PMKURLErrorFailingURLResponseKey`
PromiseKit uses [OMGHTTPURLRQ](https://github.com/mxcl/OMGHTTPURLRQ) to
make its HTTP requests. PromiseKit only provides a convenience layer
above OMGHTTPURLRQ, thus if you need more power (eg. a multipartFormData
POST), use OMGHTTPURLRQ to generate the `NSURLRequest` and then pass
that request to `+promise:`.
@see https://github.com/mxcl/OMGHTTPURLRQ
*/
@interface NSURLSession (PMKOMG)
/**
Makes a GET request to the provided URL.
[NSURLSession GET:@"http://placekitten.com/320/320"].then(^(UIImage *img){
// PromiseKit decodes the image (if its an image)
});
@param urlStringFormatOrURL The `NSURL` or string format to request.
@return A promise that fulfills with three parameters:
1) The deserialized data response.
2) The `NSHTTPURLResponse`.
3) The raw `NSData` response.
*/
- (AnyPromise *)GET:(id)urlStringFormatOrURL, ... NS_REFINED_FOR_SWIFT;
/**
Makes a GET request with the provided query parameters.
id url = @"http://jsonplaceholder.typicode.com/comments";
id params = @{@"postId": @1};
[NSURLSession GET:url query:params].then(^(NSDictionary *jsonResponse){
// PromiseKit decodes the JSON dictionary (if its JSON)
});
@param urlString The `NSURL` or URL string format to request.
@param parameters The parameters to be encoded as the query string for the GET request.
@return A promise that fulfills with three parameters:
1) The deserialized data response.
2) The `NSHTTPURLResponse`.
3) The raw `NSData` response.
*/
- (AnyPromise *)GET:(NSString *)urlString query:(NSDictionary *)parameters NS_REFINED_FOR_SWIFT;
/**
Makes a POST request to the provided URL passing form URL encoded
parameters.
Form URL-encoding is the standard way to POST on the Internet, so
probably this is what you want. If it doesnt work, try the `+POST:JSON`
variant.
id url = @"http://jsonplaceholder.typicode.com/posts";
id params = @{@"title": @"foo", @"body": @"bar", @"userId": @1};
[NSURLSession POST:url formURLEncodedParameters:params].then(^(NSDictionary *jsonResponse){
// PromiseKit decodes the JSON dictionary (if its JSON)
});
@param urlString The URL to request.
@param parameters The parameters to be form URL-encoded and passed as the POST body.
@return A promise that fulfills with three parameters:
1) The deserialized data response.
2) The `NSHTTPURLResponse`.
3) The raw `NSData` response.
*/
- (AnyPromise *)POST:(NSString *)urlString formURLEncodedParameters:(NSDictionary *)parameters NS_REFINED_FOR_SWIFT;
/**
Makes a POST request to the provided URL passing JSON encoded parameters.
Most web servers nowadays support POST with either JSON or form
URL-encoding. If in doubt try form URL-encoded parameters first.
id url = @"http://jsonplaceholder.typicode.com/posts";
id params = @{@"title": @"foo", @"body": @"bar", @"userId": @1};
[NSURLSession POST:url JSON:params].then(^(NSDictionary *jsonResponse){
// PromiseKit decodes the JSON dictionary (if its JSON)
});
@param urlString The URL to request.
@param JSONParameters The parameters to be JSON encoded and passed as the POST body.
@return A promise that fulfills with three parameters:
1) The deserialized data response.
2) The `NSHTTPURLResponse`.
3) The raw `NSData` response.
*/
- (AnyPromise *)POST:(NSString *)urlString JSON:(NSDictionary *)JSONParameters NS_REFINED_FOR_SWIFT;
/**
Makes a PUT request to the provided URL passing form URL-encoded
parameters.
id url = @"http://jsonplaceholder.typicode.com/posts/1";
id params = @{@"id": @1, @"title": @"foo", @"body": @"bar", @"userId": @1};
[NSURLSession PUT:url formURLEncodedParameters:params].then(^(NSDictionary *jsonResponse){
// PromiseKit decodes the JSON dictionary (if its JSON)
});
@param urlString The URL to request.
@param parameters The parameters to be form URL-encoded and passed as the HTTP body.
@return A promise that fulfills with three parameters:
1) The deserialized data response.
2) The `NSHTTPURLResponse`.
3) The raw `NSData` response.
*/
- (AnyPromise *)PUT:(NSString *)urlString formURLEncodedParameters:(NSDictionary *)parameters NS_REFINED_FOR_SWIFT;
/**
Makes a DELETE request to the provided URL passing form URL-encoded
parameters.
id url = @"http://jsonplaceholder.typicode.com/posts/1";
id params = nil;
[NSURLSession DELETE:url formURLEncodedParameters:params].then(^(NSDictionary *jsonResponse){
// PromiseKit decodes the JSON dictionary (if its JSON)
});
@param urlString The URL to request.
@param parameters The parameters to be form URL-encoded and passed as the HTTP body.
@return A promise that fulfills with three parameters:
1) The deserialized data response.
2) The `NSHTTPURLResponse`.
3) The raw `NSData` response.
*/
- (AnyPromise *)DELETE:(NSString *)urlString formURLEncodedParameters:(NSDictionary *)parameters NS_REFINED_FOR_SWIFT;
/**
Makes a PATCH request to the provided URL passing the provided JSON parameters.
id url = @"http://jsonplaceholder.typicode.com/posts/1";
id params = nil;
[NSURLSession PATCH:url JSON:params].then(^(NSDictionary *jsonResponse){
// PromiseKit decodes the JSON dictionary (if its JSON)
});
@param urlString The URL to request.
@param JSONParameters The JSON parameters.
@return A promise that fulfills with three parameters:
1) The deserialized data response.
2) The `NSHTTPURLResponse`.
3) The raw `NSData` response.
*/
- (AnyPromise *)PATCH:(NSString *)urlString JSON:(NSDictionary *)JSONParameters NS_REFINED_FOR_SWIFT;
@end

View File

@@ -0,0 +1,48 @@
@import PMKOMGHTTPURLRQ;
@import PMKFoundation;
@import OHHTTPStubs;
@import PromiseKit;
@import XCTest;
@implementation NSURLSessionTests: XCTestCase
- (void)tearDown {
[OHHTTPStubs removeAllStubs];
}
- (void)test1 {
id stubData = [NSData dataWithBytes:"[a: 3]" length:1];
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *rq){
return [rq.URL.host isEqualToString:@"example.com"];
} withStubResponse:^(NSURLRequest *request){
return [OHHTTPStubsResponse responseWithData:stubData statusCode:200 headers:@{@"Content-Type": @"application/json"}];
}];
id ex = [self expectationWithDescription:@""];
[[NSURLSession sharedSession] GET:[NSURL URLWithString:@"http://example.com"]].catch(^(NSError *err){
XCTAssertEqualObjects(err.domain, NSCocoaErrorDomain); //TODO this is why we should replace this domain
XCTAssertEqual(err.code, 3840);
XCTAssertEqualObjects(err.userInfo[PMKURLErrorFailingDataKey], stubData);
XCTAssertNotNil(err.userInfo[PMKURLErrorFailingURLResponseKey]);
[ex fulfill];
});
[self waitForExpectationsWithTimeout:1 handler:nil];
}
- (void)test2 {
id ex = [self expectationWithDescription:@""];
[[NSURLSession sharedSession] GET:nil].catch(^(NSError *err){
XCTAssertEqualObjects(err.domain, NSURLErrorDomain);
XCTAssertEqual(err.code, NSURLErrorUnsupportedURL);
[ex fulfill];
});
[self waitForExpectationsWithTimeout:1 handler:nil];
}
@end

View File

@@ -0,0 +1,74 @@
import PMKOMGHTTPURLRQ
import OHHTTPStubs
import PromiseKit
import XCTest
class NSURLSessionTests: XCTestCase {
func test1() {
let json: NSDictionary = ["key1": "value1", "key2": ["value2A", "value2B"]]
OHHTTPStubs.stubRequests(passingTest: { $0.url!.host == "example.com" }) { _ in
return OHHTTPStubsResponse(jsonObject: json, statusCode: 200, headers: nil)
}
let ex = expectation(description: "")
URLSession.shared.GET("http://example.com").compactMap {
try JSONSerialization.jsonObject(with: $0.data)
}.done {
XCTAssertEqual(json, $0 as? NSDictionary)
ex.fulfill()
}
waitForExpectations(timeout: 1)
}
func test2() {
// test that Promise<Data> chains thens
// this test because I dont trust the Swift compiler
let dummy = ("fred" as NSString).data(using: String.Encoding.utf8.rawValue)!
OHHTTPStubs.stubRequests(passingTest: { $0.url!.host == "example.com" }) { _ in
return OHHTTPStubsResponse(data: dummy, statusCode: 200, headers: [:])
}
let ex = expectation(description: "")
after(seconds: 0.1).then {
URLSession.shared.GET("http://example.com")
}.done {
XCTAssertEqual($0.data, dummy)
ex.fulfill()
}
waitForExpectations(timeout: 1)
}
func testSyntax() {
let json: NSDictionary = ["key1": "value1", "key2": ["value2A", "value2B"]]
OHHTTPStubs.stubRequests(passingTest: {
$0.url!.host == "example.com"
}, withStubResponse: { _ in
OHHTTPStubsResponse(jsonObject: json, statusCode: 200, headers: nil)
})
let p = URLSession.shared.GET("http://example.com", query: [
"1": 1,
"2": 2
])
let ex = expectation(description: "")
p.compactMap {
try JSONSerialization.jsonObject(with: $0.data)
}.done {
XCTAssertEqual(json, $0 as? NSDictionary)
ex.fulfill()
}
waitForExpectations(timeout: 1)
}
override func tearDown() {
OHHTTPStubs.removeAllStubs()
}
}