-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- created Alamofire Request extension - added some tests - added iOS and OS X targets
- Loading branch information
1 parent
2aadaa5
commit 0f74776
Showing
15 changed files
with
1,271 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Pod::Spec.new do |s| | ||
|
||
s.name = "AlamofireObjectMapper" | ||
s.version = "0.1" | ||
s.license = { :type => "MIT", :file => "LICENSE" } | ||
s.summary = "An extension to Alamofire which converts responses into objects using ObjectMapper" | ||
s.homepage = "https://github.com/tristanhimmelman/AlamofireObjectMapper" | ||
s.author = { "Tristan Himmelman" => "[email protected]" } | ||
s.source = { :git => 'https://github.com/tristanhimmelman/AlamofireObjectMapper.git', :tag => s.version.to_s } | ||
|
||
s.ios.deployment_target = '8.0' | ||
s.osx.deployment_target = '10.9' | ||
s.requires_arc = 'true' | ||
s.source_files = 'AlamofireObjectMapper/**/*.swift' | ||
s.dependency 'Alamofire', '~> 1.2' | ||
s.dependency 'ObjectMapper', '~> 0.10' | ||
|
||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
AlamofireObjectMapper.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
110 changes: 110 additions & 0 deletions
110
AlamofireObjectMapper.xcodeproj/xcshareddata/xcschemes/AlamofireObjectMapper OSX.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "0630" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6AB2A0841AF27DF1001EBB20" | ||
BuildableName = "AlamofireObjectMapper.framework" | ||
BlueprintName = "AlamofireObjectMapper OSX" | ||
ReferencedContainer = "container:AlamofireObjectMapper.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "NO" | ||
buildForArchiving = "NO" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6AB2A08E1AF27DF1001EBB20" | ||
BuildableName = "AlamofireObjectMapperTests OSX.xctest" | ||
BlueprintName = "AlamofireObjectMapperTests OSX" | ||
ReferencedContainer = "container:AlamofireObjectMapper.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
buildConfiguration = "Debug"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6AB2A08E1AF27DF1001EBB20" | ||
BuildableName = "AlamofireObjectMapperTests OSX.xctest" | ||
BlueprintName = "AlamofireObjectMapperTests OSX" | ||
ReferencedContainer = "container:AlamofireObjectMapper.xcodeproj"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6AB2A0841AF27DF1001EBB20" | ||
BuildableName = "AlamofireObjectMapper.framework" | ||
BlueprintName = "AlamofireObjectMapper OSX" | ||
ReferencedContainer = "container:AlamofireObjectMapper.xcodeproj"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</TestAction> | ||
<LaunchAction | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
buildConfiguration = "Debug" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
allowLocationSimulation = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6AB2A0841AF27DF1001EBB20" | ||
BuildableName = "AlamofireObjectMapper.framework" | ||
BlueprintName = "AlamofireObjectMapper OSX" | ||
ReferencedContainer = "container:AlamofireObjectMapper.xcodeproj"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
<AdditionalOptions> | ||
</AdditionalOptions> | ||
</LaunchAction> | ||
<ProfileAction | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
buildConfiguration = "Release" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6AB2A0841AF27DF1001EBB20" | ||
BuildableName = "AlamofireObjectMapper.framework" | ||
BlueprintName = "AlamofireObjectMapper OSX" | ||
ReferencedContainer = "container:AlamofireObjectMapper.xcodeproj"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
96 changes: 96 additions & 0 deletions
96
AlamofireObjectMapper.xcodeproj/xcshareddata/xcschemes/AlamofireObjectMapper iOS.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "0630" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6AB2A0101AF26C36001EBB20" | ||
BuildableName = "AlamofireObjectMapper.framework" | ||
BlueprintName = "AlamofireObjectMapper iOS" | ||
ReferencedContainer = "container:AlamofireObjectMapper.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
buildConfiguration = "Debug"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6AB2A01B1AF26C36001EBB20" | ||
BuildableName = "AlamofireObjectMapperTests iOS.xctest" | ||
BlueprintName = "AlamofireObjectMapperTests iOS" | ||
ReferencedContainer = "container:AlamofireObjectMapper.xcodeproj"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6AB2A0101AF26C36001EBB20" | ||
BuildableName = "AlamofireObjectMapper.framework" | ||
BlueprintName = "AlamofireObjectMapper iOS" | ||
ReferencedContainer = "container:AlamofireObjectMapper.xcodeproj"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</TestAction> | ||
<LaunchAction | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
buildConfiguration = "Debug" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
allowLocationSimulation = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6AB2A0101AF26C36001EBB20" | ||
BuildableName = "AlamofireObjectMapper.framework" | ||
BlueprintName = "AlamofireObjectMapper iOS" | ||
ReferencedContainer = "container:AlamofireObjectMapper.xcodeproj"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
<AdditionalOptions> | ||
</AdditionalOptions> | ||
</LaunchAction> | ||
<ProfileAction | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
buildConfiguration = "Release" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "6AB2A0101AF26C36001EBB20" | ||
BuildableName = "AlamofireObjectMapper.framework" | ||
BlueprintName = "AlamofireObjectMapper iOS" | ||
ReferencedContainer = "container:AlamofireObjectMapper.xcodeproj"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
13 changes: 13 additions & 0 deletions
13
AlamofireObjectMapper.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// AlamofireObjectMapper.h | ||
// AlamofireObjectMapper | ||
// | ||
// Created by Tristan Himmelman on 2015-04-30. | ||
// Copyright (c) 2015 Tristan Himmelman. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
//! Project version number for AlamofireObjectMapper. | ||
FOUNDATION_EXPORT double AlamofireObjectMapperVersionNumber; | ||
|
||
//! Project version string for AlamofireObjectMapper. | ||
FOUNDATION_EXPORT const unsigned char AlamofireObjectMapperVersionString[]; | ||
|
||
// In this header, you should import all the public headers of your framework using statements like #import <AlamofireObjectMapper/PublicHeader.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// Request.swift | ||
// AlamofireObjectMapper | ||
// | ||
// Created by Tristan Himmelman on 2015-04-30. | ||
// Copyright (c) 2015 Tristan Himmelman. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
import ObjectMapper | ||
|
||
extension Request { | ||
|
||
/** | ||
Adds a handler to be called once the request has finished. | ||
|
||
:param: completionHandler A closure to be executed once the request has finished and the data has been mapped to a swift Object. The closure takes 2 arguments: the response object (of type Mappable) and any error produced while making the request | ||
|
||
:returns: The request. | ||
*/ | ||
public func responseObject<T: Mappable>(completionHandler: (T?, NSError?) -> Void) -> Self { | ||
return response(queue: nil, serializer: Request.JSONResponseSerializer(options: NSJSONReadingOptions.AllowFragments)) { (request, response, object, error) -> Void in | ||
|
||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { | ||
|
||
let parsedObject = Mapper<T>().map(object) | ||
|
||
dispatch_async(dispatch_get_main_queue()) { | ||
completionHandler(parsedObject, error) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
Adds a handler to be called once the request has finished. | ||
|
||
:param: completionHandler A closure to be executed once the request has finished and the data has been mapped to a swift Object. The closure takes 5 arguments: the URL request, the URL response, the response object (of type Mappable), the raw response data, and any error produced making the request. | ||
|
||
:returns: The request. | ||
*/ | ||
public func responseObject<T: Mappable>(completionHandler: (NSURLRequest, NSHTTPURLResponse?, T?, AnyObject?, NSError?) -> Void) -> Self { | ||
return responseObject(nil, completionHandler: completionHandler) | ||
} | ||
|
||
/** | ||
Adds a handler to be called once the request has finished. | ||
|
||
:param: queue The queue on which the completion handler is dispatched. | ||
:param: completionHandler A closure to be executed once the request has finished and the data has been mapped to a swift Object. The closure takes 5 arguments: the URL request, the URL response, the response object (of type Mappable), the raw response data, and any error produced making the request. | ||
|
||
:returns: The request. | ||
*/ | ||
public func responseObject<T: Mappable>(queue: dispatch_queue_t?, completionHandler: (NSURLRequest, NSHTTPURLResponse?, T?, AnyObject?, NSError?) -> Void) -> Self { | ||
|
||
return response(queue: queue, serializer: Request.JSONResponseSerializer(options: NSJSONReadingOptions.AllowFragments)) { (request, response, data, error) -> Void in | ||
|
||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { | ||
|
||
let parsedObject = Mapper<T>().map(data) | ||
|
||
dispatch_async(queue ?? dispatch_get_main_queue()) { | ||
completionHandler(self.request, self.response, parsedObject, data, error) | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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>com.tristanhimmelman.$(PRODUCT_NAME:rfc1034identifier)</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>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>$(CURRENT_PROJECT_VERSION)</string> | ||
<key>NSPrincipalClass</key> | ||
<string></string> | ||
</dict> | ||
</plist> |
Oops, something went wrong.