Skip to content

Commit

Permalink
- added gitignore
Browse files Browse the repository at this point in the history
- created Alamofire Request extension
- added some tests
- added iOS and OS X targets
  • Loading branch information
tristanhimmelman committed Apr 30, 2015
1 parent 2aadaa5 commit 0f74776
Show file tree
Hide file tree
Showing 15 changed files with 1,271 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ DerivedData
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Checkouts

Carthage/Build
18 changes: 18 additions & 0 deletions AlamofireObjectMapper.podspec
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
691 changes: 691 additions & 0 deletions AlamofireObjectMapper.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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>
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 AlamofireObjectMapper.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions AlamofireObjectMapper/AlamofireObjectMapper.h
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>


70 changes: 70 additions & 0 deletions AlamofireObjectMapper/AlmofireObjectMapper.swift
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)
}
}
}

}
}
26 changes: 26 additions & 0 deletions AlamofireObjectMapper/Info.plist
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>
Loading

0 comments on commit 0f74776

Please sign in to comment.