From c103a46f7baa54b23faf21f458090c6f5a59f4f8 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Wed, 7 Sep 2016 16:08:30 +0200 Subject: [PATCH 01/92] Adds basic API for mutipartUpload --- .../contents.xcworkspacedata | 3 + DBNetworkStack/NetworkService.swift | 23 +-- DBNetworkStack/ResourceServiceProviding.swift | 28 ++- Experiments.playground/Contents.swift | 56 ++++++ .../MultipartFormDataRepresenting.swift | 190 ++++++++++++++++++ Experiments.playground/contents.xcplayground | 4 + 6 files changed, 278 insertions(+), 26 deletions(-) create mode 100644 Experiments.playground/Contents.swift create mode 100644 Experiments.playground/Sources/MultipartFormDataRepresenting.swift create mode 100644 Experiments.playground/contents.xcplayground diff --git a/DBNetworkStack.xcworkspace/contents.xcworkspacedata b/DBNetworkStack.xcworkspace/contents.xcworkspacedata index 8165c55..609fe15 100644 --- a/DBNetworkStack.xcworkspace/contents.xcworkspacedata +++ b/DBNetworkStack.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,9 @@ + + diff --git a/DBNetworkStack/NetworkService.swift b/DBNetworkStack/NetworkService.swift index 19ad4b1..dbf8a64 100644 --- a/DBNetworkStack/NetworkService.swift +++ b/DBNetworkStack/NetworkService.swift @@ -64,25 +64,4 @@ public final class NetworkService: NetworkServiceProviding { public func baseURL(fromRessource ressource: T) -> NSURL? { return endPoints[ressource.request.baseURLKey.name] } - - //MARK: Private - - public func process(response response: NSHTTPURLResponse?, ressource: T, data: NSData?, error: NSError?) throws -> T.Model { - if let error = error { - throw NSError.errorWithUnderlyingError(error, code: .HTTPError) - } - if let statusCode = response?.statusCode, responseError = NSError.backendError(statusCode, data: data) { - throw responseError - } - guard let data = data else { - throw NSError(code: .BackendError) - } - do { - return try ressource.parse(data: data) - } catch let error as CustomStringConvertible { - throw NSError(code: .SerializationError, userInfo: ["key": String(error)]) - } - } - - -} +} \ No newline at end of file diff --git a/DBNetworkStack/ResourceServiceProviding.swift b/DBNetworkStack/ResourceServiceProviding.swift index 9dacf50..ef567b7 100644 --- a/DBNetworkStack/ResourceServiceProviding.swift +++ b/DBNetworkStack/ResourceServiceProviding.swift @@ -28,7 +28,7 @@ import Foundation /** `NetworkServiceProviding` provides access to remote ressources. */ -public protocol NetworkServiceProviding { +public protocol NetworkServiceProviding: NetworkResponseProcessing { /** Fetches a ressource asynchrony from remote location @@ -41,7 +41,27 @@ public protocol NetworkServiceProviding { func fetch(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> ()) -> NetworkTask func baseURL(fromRessource ressource: T) -> NSURL? - - func process(response response: NSHTTPURLResponse?, ressource: T, data: NSData?, error: NSError?) throws -> T.Model - +} + +public protocol NetworkResponseProcessing { + func process(response response: NSHTTPURLResponse?, ressource: T, data: NSData?, error: NSError?) throws -> T.Model +} + +extension NetworkResponseProcessing { + public func process(response response: NSHTTPURLResponse?, ressource: T, data: NSData?, error: NSError?) throws -> T.Model { + if let error = error { + throw NSError.errorWithUnderlyingError(error, code: .HTTPError) + } + if let statusCode = response?.statusCode, responseError = NSError.backendError(statusCode, data: data) { + throw responseError + } + guard let data = data else { + throw NSError(code: .BackendError) + } + do { + return try ressource.parse(data: data) + } catch let error as CustomStringConvertible { + throw NSError(code: .SerializationError, userInfo: ["key": String(error)]) + } + } } \ No newline at end of file diff --git a/Experiments.playground/Contents.swift b/Experiments.playground/Contents.swift new file mode 100644 index 0000000..f565807 --- /dev/null +++ b/Experiments.playground/Contents.swift @@ -0,0 +1,56 @@ +//: Playground - noun: a place where people can play + +import UIKit +import DBNetworkStack +import XCPlayground + +XCPlaygroundPage.currentPage.needsIndefiniteExecution = true + +protocol MultiparRessource: RessourceModeling { + var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void { get } + var encodingMemoryThreshold: UInt64 { get } +} + + + +protocol UploadAccessProviding { + func upload( + request: NetworkRequestRepresening, relativeToBaseURL: NSURL, + multipartFormData: (MultipartFormDataRepresenting) -> (), + encodingMemoryThreshold: UInt64, + callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> NetworkTask + +} + +protocol MultiUploadPoviderServiceProviding { + func upload(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> ()) -> NetworkTask +} + +class MultiUploadPoviderService: MultiUploadPoviderServiceProviding, NetworkResponseProcessing { + let uploadAccess: UploadAccessProviding + + init(uploadAccess: UploadAccessProviding) { + self.uploadAccess = uploadAccess + } + + func upload(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> ()) -> NetworkTask { + //TODO: Build baseURL + let baseURL = NSURL() + return uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, encodingMemoryThreshold: ressource.encodingMemoryThreshold, callback: { data, response, error in + do { + let parsed = try self.process(response: response, ressource: ressource, data: data, error: error) + dispatch_async(dispatch_get_main_queue()) { + onCompletion(parsed) + } + } catch let error as NSError { + dispatch_async(dispatch_get_main_queue()) { + return onError(error) + } + } + }) + } +} + + + + diff --git a/Experiments.playground/Sources/MultipartFormDataRepresenting.swift b/Experiments.playground/Sources/MultipartFormDataRepresenting.swift new file mode 100644 index 0000000..14f3443 --- /dev/null +++ b/Experiments.playground/Sources/MultipartFormDataRepresenting.swift @@ -0,0 +1,190 @@ +// +// MultipartFormData.swift +// +// Copyright (c) 2014-2016 Alamofire Software Foundation (http://alamofire.org/) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +import Foundation + +public protocol MultipartFormDataRepresenting: class { + + // MARK: - Properties + + /// The `Content-Type` header value containing the boundary used to generate the `multipart/form-data`. + var contentType: String { get } + + /// The content length of all body parts used to generate the `multipart/form-data` not including the boundaries. + var contentLength: UInt64 { get } + + /// The boundary used to separate the body parts in the encoded form data. + var boundary: String { get } + + // MARK: - Body Parts + + /** + Creates a body part from the data and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - `Content-Disposition: form-data; name=#{name}` (HTTP Header) + - Encoded data + - Multipart form boundary + + - parameter data: The data to encode into the multipart form data. + - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header. + */ + func appendBodyPart(data data: NSData, name: String) + + /** + Creates a body part from the data and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - `Content-Disposition: form-data; name=#{name}` (HTTP Header) + - `Content-Type: #{generated mimeType}` (HTTP Header) + - Encoded data + - Multipart form boundary + + - parameter data: The data to encode into the multipart form data. + - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header. + - parameter mimeType: The MIME type to associate with the data content type in the `Content-Type` HTTP header. + */ + func appendBodyPart(data data: NSData, name: String, mimeType: String) + + /** + Creates a body part from the data and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - `Content-Disposition: form-data; name=#{name}; filename=#{filename}` (HTTP Header) + - `Content-Type: #{mimeType}` (HTTP Header) + - Encoded file data + - Multipart form boundary + + - parameter data: The data to encode into the multipart form data. + - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header. + - parameter fileName: The filename to associate with the data in the `Content-Disposition` HTTP header. + - parameter mimeType: The MIME type to associate with the data in the `Content-Type` HTTP header. + */ + func appendBodyPart(data data: NSData, name: String, fileName: String, mimeType: String) + + /** + Creates a body part from the file and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - `Content-Disposition: form-data; name=#{name}; filename=#{generated filename}` (HTTP Header) + - `Content-Type: #{generated mimeType}` (HTTP Header) + - Encoded file data + - Multipart form boundary + + The filename in the `Content-Disposition` HTTP header is generated from the last path component of the + `fileURL`. The `Content-Type` HTTP header MIME type is generated by mapping the `fileURL` extension to the + system associated MIME type. + + - parameter fileURL: The URL of the file whose content will be encoded into the multipart form data. + - parameter name: The name to associate with the file content in the `Content-Disposition` HTTP header. + */ + func appendBodyPart(fileURL fileURL: NSURL, name: String) + + /** + Creates a body part from the file and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - Content-Disposition: form-data; name=#{name}; filename=#{filename} (HTTP Header) + - Content-Type: #{mimeType} (HTTP Header) + - Encoded file data + - Multipart form boundary + + - parameter fileURL: The URL of the file whose content will be encoded into the multipart form data. + - parameter name: The name to associate with the file content in the `Content-Disposition` HTTP header. + - parameter fileName: The filename to associate with the file content in the `Content-Disposition` HTTP header. + - parameter mimeType: The MIME type to associate with the file content in the `Content-Type` HTTP header. + */ + func appendBodyPart(fileURL fileURL: NSURL, name: String, fileName: String, mimeType: String) + + /** + Creates a body part from the stream and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - `Content-Disposition: form-data; name=#{name}; filename=#{filename}` (HTTP Header) + - `Content-Type: #{mimeType}` (HTTP Header) + - Encoded stream data + - Multipart form boundary + + - parameter stream: The input stream to encode in the multipart form data. + - parameter length: The content length of the stream. + - parameter name: The name to associate with the stream content in the `Content-Disposition` HTTP header. + - parameter fileName: The filename to associate with the stream content in the `Content-Disposition` HTTP header. + - parameter mimeType: The MIME type to associate with the stream content in the `Content-Type` HTTP header. + */ + func appendBodyPart( + stream stream: NSInputStream, + length: UInt64, + name: String, + fileName: String, + mimeType: String) + + /** + Creates a body part with the headers, stream and length and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - HTTP headers + - Encoded stream data + - Multipart form boundary + + - parameter stream: The input stream to encode in the multipart form data. + - parameter length: The content length of the stream. + - parameter headers: The HTTP headers for the body part. + */ + func appendBodyPart(stream stream: NSInputStream, length: UInt64, headers: [String: String]) + + // MARK: - Data Encoding + + /** + Encodes all the appended body parts into a single `NSData` object. + + It is important to note that this method will load all the appended body parts into memory all at the same + time. This method should only be used when the encoded data will have a small memory footprint. For large data + cases, please use the `writeEncodedDataToDisk(fileURL:completionHandler:)` method. + + - throws: An `NSError` if encoding encounters an error. + + - returns: The encoded `NSData` if encoding is successful. + */ + func encode() throws -> NSData + + /** + Writes the appended body parts into the given file URL. + + This process is facilitated by reading and writing with input and output streams, respectively. Thus, + this approach is very memory efficient and should be used for large body part data. + + - parameter fileURL: The file URL to write the multipart form data into. + + - throws: An `NSError` if encoding encounters an error. + */ + func writeEncodedDataToDisk(fileURL: NSURL) throws + + +} diff --git a/Experiments.playground/contents.xcplayground b/Experiments.playground/contents.xcplayground new file mode 100644 index 0000000..5da2641 --- /dev/null +++ b/Experiments.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From 1b62d09d9caf8663f6c3bb7ba8e87991d1fd4b89 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Thu, 8 Sep 2016 07:29:15 +0200 Subject: [PATCH 02/92] Alamofire Multipart example implementation --- Experiments.playground/Contents.swift | 118 ++++++++++++++++---------- 1 file changed, 71 insertions(+), 47 deletions(-) diff --git a/Experiments.playground/Contents.swift b/Experiments.playground/Contents.swift index f565807..3381c59 100644 --- a/Experiments.playground/Contents.swift +++ b/Experiments.playground/Contents.swift @@ -3,53 +3,77 @@ import UIKit import DBNetworkStack import XCPlayground - -XCPlaygroundPage.currentPage.needsIndefiniteExecution = true - -protocol MultiparRessource: RessourceModeling { - var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void { get } - var encodingMemoryThreshold: UInt64 { get } -} - - - -protocol UploadAccessProviding { - func upload( - request: NetworkRequestRepresening, relativeToBaseURL: NSURL, - multipartFormData: (MultipartFormDataRepresenting) -> (), - encodingMemoryThreshold: UInt64, - callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> NetworkTask - -} - -protocol MultiUploadPoviderServiceProviding { - func upload(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> ()) -> NetworkTask -} - -class MultiUploadPoviderService: MultiUploadPoviderServiceProviding, NetworkResponseProcessing { - let uploadAccess: UploadAccessProviding - - init(uploadAccess: UploadAccessProviding) { - self.uploadAccess = uploadAccess - } - - func upload(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> ()) -> NetworkTask { - //TODO: Build baseURL - let baseURL = NSURL() - return uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, encodingMemoryThreshold: ressource.encodingMemoryThreshold, callback: { data, response, error in - do { - let parsed = try self.process(response: response, ressource: ressource, data: data, error: error) - dispatch_async(dispatch_get_main_queue()) { - onCompletion(parsed) - } - } catch let error as NSError { - dispatch_async(dispatch_get_main_queue()) { - return onError(error) - } - } - }) - } -} +//import Alamofire +// +//XCPlaygroundPage.currentPage.needsIndefiniteExecution = true +// +//protocol MultiparRessource: RessourceModeling { +// var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void { get } +// var encodingMemoryThreshold: UInt64 { get } +//} +// +//extension Alamofire.MultipartFormData: MultipartFormDataRepresenting {} +//extension Alamofire.Request: NetworkTask {} +// +//class AlamofireUploadAccess: UploadAccessProviding { +// func upload(request: NetworkRequestRepresening, relativeToBaseURL: NSURL, multipartFormData: (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: (NetworkTask) -> ()) { +// Alamofire.upload( +// .POST, +// NSURL(string: request.path, relativeToURL: relativeToBaseURL)!, +// multipartFormData: multipartFormData, +// encodingCompletion: { encodingResult in +// switch encodingResult { +// case .Success(let upload, _, _): +// onNetworkTaskCreation(upload) +// upload.response(completionHandler: { request, response, data, error in +// callback(data, response, error) +// }) +// case .Failure(let encodingError): +// //TODO ErrorHandling +// callback(nil, nil, NSError(code: .BadRequest, userInfo: ["err": ""])) +// } +// }) +// } +//} +// +// +// +//protocol UploadAccessProviding { +// func upload( +// request: NetworkRequestRepresening, relativeToBaseURL: NSURL, +// multipartFormData: (MultipartFormDataRepresenting) -> (), +// encodingMemoryThreshold: UInt64, +// callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: (NetworkTask) -> ()) +//} +// +//protocol MultiUploadPoviderServiceProviding { +// func upload(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> (), onNetworkTaskCreation: (NetworkTask) -> ()) +//} +// +//class MultiPartUploadPoviderService: MultiUploadPoviderServiceProviding, NetworkResponseProcessing { +// let uploadAccess: UploadAccessProviding +// +// init(uploadAccess: UploadAccessProviding) { +// self.uploadAccess = uploadAccess +// } +// +// func upload(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> (), onNetworkTaskCreation: (NetworkTask) -> ()) { +// //TODO: Build baseURL +// let baseURL = NSURL() +// uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, encodingMemoryThreshold: ressource.encodingMemoryThreshold, callback: { data, response, error in +// do { +// let parsed = try self.process(response: response, ressource: ressource, data: data, error: error) +// dispatch_async(dispatch_get_main_queue()) { +// onCompletion(parsed) +// } +// } catch let error as NSError { +// dispatch_async(dispatch_get_main_queue()) { +// return onError(error) +// } +// } +// }, onNetworkTaskCreation: onNetworkTaskCreation) +// } +//} From c298bb007974243d3850acb8055f083e2c685ff5 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 20 Sep 2016 14:04:22 +0200 Subject: [PATCH 03/92] Naming --- DBNetworkStack.xcodeproj/project.pbxproj | 8 ++++---- ...rviceProviding.swift => NetworkServiceProviding.swift} | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) rename DBNetworkStack/{ResourceServiceProviding.swift => NetworkServiceProviding.swift} (98%) diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index 3958761..88700dc 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -16,7 +16,7 @@ C60BE6661D6B2BF3006B0364 /* DBNetworkStack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C60BE65B1D6B2BF3006B0364 /* DBNetworkStack.framework */; }; C60BE68B1D6B2C46006B0364 /* NetworkRequestRepresening.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67B1D6B2C46006B0364 /* NetworkRequestRepresening.swift */; }; C60BE68C1D6B2C46006B0364 /* RessourceModeling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67C1D6B2C46006B0364 /* RessourceModeling.swift */; }; - C60BE68D1D6B2C46006B0364 /* ResourceServiceProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67D1D6B2C46006B0364 /* ResourceServiceProviding.swift */; }; + C60BE68D1D6B2C46006B0364 /* NetworkServiceProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67D1D6B2C46006B0364 /* NetworkServiceProviding.swift */; }; C60BE68E1D6B2C46006B0364 /* JSONRessourceModeling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67E1D6B2C46006B0364 /* JSONRessourceModeling.swift */; }; C60BE68F1D6B2C46006B0364 /* HTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67F1D6B2C46006B0364 /* HTTPMethod.swift */; }; C60BE6901D6B2C46006B0364 /* Ressource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6801D6B2C46006B0364 /* Ressource.swift */; }; @@ -67,7 +67,7 @@ C60BE66C1D6B2BF3006B0364 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; C60BE67B1D6B2C46006B0364 /* NetworkRequestRepresening.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkRequestRepresening.swift; sourceTree = ""; }; C60BE67C1D6B2C46006B0364 /* RessourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RessourceModeling.swift; sourceTree = ""; }; - C60BE67D1D6B2C46006B0364 /* ResourceServiceProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResourceServiceProviding.swift; sourceTree = ""; }; + C60BE67D1D6B2C46006B0364 /* NetworkServiceProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkServiceProviding.swift; sourceTree = ""; }; C60BE67E1D6B2C46006B0364 /* JSONRessourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONRessourceModeling.swift; sourceTree = ""; }; C60BE67F1D6B2C46006B0364 /* HTTPMethod.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPMethod.swift; sourceTree = ""; }; C60BE6801D6B2C46006B0364 /* Ressource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Ressource.swift; sourceTree = ""; }; @@ -185,7 +185,7 @@ children = ( C60BE67B1D6B2C46006B0364 /* NetworkRequestRepresening.swift */, C60BE67C1D6B2C46006B0364 /* RessourceModeling.swift */, - C60BE67D1D6B2C46006B0364 /* ResourceServiceProviding.swift */, + C60BE67D1D6B2C46006B0364 /* NetworkServiceProviding.swift */, C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */, C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */, C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */, @@ -345,7 +345,7 @@ C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */, C60BE6AD1D6B3E81006B0364 /* NetworkTask.swift in Sources */, C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */, - C60BE68D1D6B2C46006B0364 /* ResourceServiceProviding.swift in Sources */, + C60BE68D1D6B2C46006B0364 /* NetworkServiceProviding.swift in Sources */, C6455A041D78BA48008A8C85 /* ExperimentResponseParsing.swift in Sources */, C60BE68B1D6B2C46006B0364 /* NetworkRequestRepresening.swift in Sources */, C60BE6AF1D6C24E6006B0364 /* Error.swift in Sources */, diff --git a/DBNetworkStack/ResourceServiceProviding.swift b/DBNetworkStack/NetworkServiceProviding.swift similarity index 98% rename from DBNetworkStack/ResourceServiceProviding.swift rename to DBNetworkStack/NetworkServiceProviding.swift index fe50626..8cf5a2c 100644 --- a/DBNetworkStack/ResourceServiceProviding.swift +++ b/DBNetworkStack/NetworkServiceProviding.swift @@ -1,5 +1,5 @@ // -// ResourceServiceProviding.swift +// NetworkServiceProviding.swift // DBNetworkStack // // Legal Notice! DB Systel GmbH proprietary License! From 0aaa8512bcfd7417d37bcbbee597c235907f44ad Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Thu, 29 Sep 2016 11:38:43 +0200 Subject: [PATCH 04/92] Added protocol for providers of a base url --- DBNetworkStack.xcodeproj/project.pbxproj | 4 +++ DBNetworkStack/BaseURLProviding.swift | 37 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 DBNetworkStack/BaseURLProviding.swift diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index 6b0c291..4fb85d6 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */; }; C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */; }; C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425091D76F79F00FD3B38 /* NetworkService.swift */; }; C604250E1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C604250D1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift */; }; @@ -52,6 +53,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLProviding.swift; sourceTree = ""; }; C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60425091D76F79F00FD3B38 /* NetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C604250D1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AlamofireNetworkAccessTest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -180,6 +182,7 @@ C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */, C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */, C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */, + 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */, ); name = protocol; sourceTree = ""; @@ -351,6 +354,7 @@ C6F235D31D7DA71F00E628D8 /* AlamofireNetworkAccess.swift in Sources */, C60BE68F1D6B2C46006B0364 /* HTTPMethod.swift in Sources */, C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */, + 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */, C60BE6AD1D6B3E81006B0364 /* NetworkTask.swift in Sources */, C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */, C60BE68D1D6B2C46006B0364 /* NetworkServiceProviding.swift in Sources */, diff --git a/DBNetworkStack/BaseURLProviding.swift b/DBNetworkStack/BaseURLProviding.swift new file mode 100644 index 0000000..5725d09 --- /dev/null +++ b/DBNetworkStack/BaseURLProviding.swift @@ -0,0 +1,37 @@ +// +// BaseURLProviding.swift +// DBNetworkStack +// +// Created by Christian Himmelsbach on 29.09.16. +// Copyright © 2016 DBSystel. All rights reserved. +// + +import Foundation + +internal protocol BaseURLProviding { + + var endPoints: [String:NSURL] {get} + /** + Provides an baseURL for a given ressource. + + To be more flexible, a request does only contain a path and not a full URL. + Mapping has to be done in the service to get an registerd baseURL for the request. + + - parameter ressource: The ressource you want to get a baseURL for. + + - return matching baseURL to the given ressource + */ + func baseURL(with ressource: T) -> NSURL +} + +extension BaseURLProviding { + + func baseURL(with ressource: T) -> NSURL { + + guard let baseURL = endPoints[ressource.request.baseURLKey.name] else { + fatalError("Missing baseurl for key: \(ressource.request.baseURLKey.name)") + } + + return baseURL + } +} \ No newline at end of file From 708237a564a4cf1a353cb364d937fff033f80fab Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Thu, 29 Sep 2016 11:41:58 +0200 Subject: [PATCH 05/92] Common types are now bundled in one file --- DBNetworkStack.xcodeproj/project.pbxproj | 8 ++++---- ...NetworkStackError.swift => DBNetworkStackTypes.swift} | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) rename DBNetworkStack/{DBNetworkStackError.swift => DBNetworkStackTypes.swift} (85%) diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index 4fb85d6..88137e6 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 7C40B9F81D9D034200620563 /* DBNetworkStackTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */; }; 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */; }; C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */; }; C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425091D76F79F00FD3B38 /* NetworkService.swift */; }; @@ -28,7 +29,6 @@ C60BE6A21D6B3807006B0364 /* NetworkRequestMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE69F1D6B3807006B0364 /* NetworkRequestMock.swift */; }; C60BE6A31D6B3807006B0364 /* NetworkServiceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */; }; C60BE6AD1D6B3E81006B0364 /* NetworkTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */; }; - C60BE6AF1D6C24E6006B0364 /* DBNetworkStackError.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6AE1D6C24E6006B0364 /* DBNetworkStackError.swift */; }; C65F087B1D757A3C00239CC1 /* JSONMappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C65F087A1D757A3C00239CC1 /* JSONMappable.swift */; }; C65F08821D75AC8D00239CC1 /* BaseURLKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */; }; C6816E211D87C51C003B699A /* URLSessionNetworkAccessTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6816E201D87C51C003B699A /* URLSessionNetworkAccessTest.swift */; }; @@ -53,6 +53,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = DBNetworkStackTypes.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLProviding.swift; sourceTree = ""; }; C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60425091D76F79F00FD3B38 /* NetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -78,7 +79,6 @@ C60BE69F1D6B3807006B0364 /* NetworkRequestMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkRequestMock.swift; sourceTree = ""; }; C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkServiceTest.swift; sourceTree = ""; }; C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkTask.swift; sourceTree = ""; }; - C60BE6AE1D6C24E6006B0364 /* DBNetworkStackError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DBNetworkStackError.swift; sourceTree = ""; }; C65F087A1D757A3C00239CC1 /* JSONMappable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONMappable.swift; sourceTree = ""; }; C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLKey.swift; sourceTree = ""; }; C6816E201D87C51C003B699A /* URLSessionNetworkAccessTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLSessionNetworkAccessTest.swift; sourceTree = ""; }; @@ -147,7 +147,7 @@ C60BE6841D6B2C46006B0364 /* AlamofireNetworkAccess.swift */, C6F235D41D7DA75000E628D8 /* URLSessionNetworkAccess.swift */, C60425091D76F79F00FD3B38 /* NetworkService.swift */, - C60BE6AE1D6C24E6006B0364 /* DBNetworkStackError.swift */, + 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */, C60BE65E1D6B2BF3006B0364 /* DBNetworkStack.h */, C60BE6601D6B2BF3006B0364 /* Info.plist */, ); @@ -360,7 +360,7 @@ C60BE68D1D6B2C46006B0364 /* NetworkServiceProviding.swift in Sources */, C6455A041D78BA48008A8C85 /* ExperimentResponseParsing.swift in Sources */, C60BE68B1D6B2C46006B0364 /* NetworkRequestRepresening.swift in Sources */, - C60BE6AF1D6C24E6006B0364 /* DBNetworkStackError.swift in Sources */, + 7C40B9F81D9D034200620563 /* DBNetworkStackTypes.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/DBNetworkStack/DBNetworkStackError.swift b/DBNetworkStack/DBNetworkStackTypes.swift similarity index 85% rename from DBNetworkStack/DBNetworkStackError.swift rename to DBNetworkStack/DBNetworkStackTypes.swift index 37d72bb..cb62025 100644 --- a/DBNetworkStack/DBNetworkStackError.swift +++ b/DBNetworkStack/DBNetworkStackTypes.swift @@ -1,5 +1,5 @@ // -// Error.swift +// DBNetworkStackTypes.swift // DBNetworkStack // // Legal Notice! DB Systel GmbH proprietary License! @@ -25,6 +25,11 @@ import Foundation +public typealias DBNetworkTaskCreationCompletionBlock = (NetworkTask) -> () +// TODO: Use typealiases for functions with generic types +//typealias NetworkRequestCompletionBlock = (T.Model) -> () +public typealias DBNetworkRequestErrorBlock = (DBNetworkStackError) -> () + /** `DBNetworkStackError` provides a collection of error types which can occur during execution. */ @@ -53,4 +58,4 @@ public enum DBNetworkStackError: ErrorType { return nil } } -} +} \ No newline at end of file From 4d2349a9afbaa82b7d800b706d698a77975474cf Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Thu, 29 Sep 2016 12:17:33 +0200 Subject: [PATCH 06/92] Added model for multipart formdata --- DBNetworkStack.xcodeproj/project.pbxproj | 13 ++ .../MultipartFormDataRepresenting.swift | 190 ++++++++++++++++++ .../MultipartFormDataRessource.swift | 36 ++++ .../MultipartFormDataRessourceModelling.swift | 34 ++++ 4 files changed, 273 insertions(+) create mode 100644 DBNetworkStack/MultipartFormDataRepresenting.swift create mode 100644 DBNetworkStack/MultipartFormDataRessource.swift create mode 100644 DBNetworkStack/MultipartFormDataRessourceModelling.swift diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index 88137e6..40a995a 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 7C40B9E51D9AA38600620563 /* MultipartFormDataRepresenting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */; }; + 7C40B9E91D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */; }; + 7C40B9EB1D9AA4DE00620563 /* MultipartFormDataRessource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataRessource.swift */; }; 7C40B9F81D9D034200620563 /* DBNetworkStackTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */; }; 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */; }; C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */; }; @@ -53,6 +56,9 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultipartFormDataRepresenting.swift; sourceTree = ""; }; + 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataRessourceModelling.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataRessource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataRessource.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = DBNetworkStackTypes.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLProviding.swift; sourceTree = ""; }; C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -143,6 +149,7 @@ C60BE6A81D6B399A006B0364 /* protocol */, C60BE67F1D6B2C46006B0364 /* HTTPMethod.swift */, C60BE6801D6B2C46006B0364 /* Ressource.swift */, + 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataRessource.swift */, C60BE6831D6B2C46006B0364 /* NetworkRequest.swift */, C60BE6841D6B2C46006B0364 /* AlamofireNetworkAccess.swift */, C6F235D41D7DA75000E628D8 /* URLSessionNetworkAccess.swift */, @@ -182,6 +189,9 @@ C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */, C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */, C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */, + 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */, + 7C40B9E61D9AA48200620563 /* MultipartUploadServiceProviding.swift */, + 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */, 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */, ); name = protocol; @@ -344,7 +354,9 @@ files = ( C60BE6931D6B2C46006B0364 /* NetworkRequest.swift in Sources */, C60BE6911D6B2C46006B0364 /* JSONRessource.swift in Sources */, + 7C40B9EB1D9AA4DE00620563 /* MultipartFormDataRessource.swift in Sources */, C60BE6901D6B2C46006B0364 /* Ressource.swift in Sources */, + 7C40B9E91D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift in Sources */, C60BE6921D6B2C46006B0364 /* JSONArrayRessource.swift in Sources */, C65F08821D75AC8D00239CC1 /* BaseURLKey.swift in Sources */, C65F087B1D757A3C00239CC1 /* JSONMappable.swift in Sources */, @@ -354,6 +366,7 @@ C6F235D31D7DA71F00E628D8 /* AlamofireNetworkAccess.swift in Sources */, C60BE68F1D6B2C46006B0364 /* HTTPMethod.swift in Sources */, C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */, + 7C40B9E51D9AA38600620563 /* MultipartFormDataRepresenting.swift in Sources */, 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */, C60BE6AD1D6B3E81006B0364 /* NetworkTask.swift in Sources */, C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */, diff --git a/DBNetworkStack/MultipartFormDataRepresenting.swift b/DBNetworkStack/MultipartFormDataRepresenting.swift new file mode 100644 index 0000000..8105619 --- /dev/null +++ b/DBNetworkStack/MultipartFormDataRepresenting.swift @@ -0,0 +1,190 @@ +// +// MultipartFormDataRepresenting.swift +// +// Copyright (c) 2014-2016 Alamofire Software Foundation (http://alamofire.org/) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +import Foundation + +public protocol MultipartFormDataRepresenting: class { + + // MARK: - Properties + + /// The `Content-Type` header value containing the boundary used to generate the `multipart/form-data`. + var contentType: String { get } + + /// The content length of all body parts used to generate the `multipart/form-data` not including the boundaries. + var contentLength: UInt64 { get } + + /// The boundary used to separate the body parts in the encoded form data. + var boundary: String { get } + + // MARK: - Body Parts + + /** + Creates a body part from the data and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - `Content-Disposition: form-data; name=#{name}` (HTTP Header) + - Encoded data + - Multipart form boundary + + - parameter data: The data to encode into the multipart form data. + - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header. + */ + func appendBodyPart(data data: NSData, name: String) + + /** + Creates a body part from the data and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - `Content-Disposition: form-data; name=#{name}` (HTTP Header) + - `Content-Type: #{generated mimeType}` (HTTP Header) + - Encoded data + - Multipart form boundary + + - parameter data: The data to encode into the multipart form data. + - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header. + - parameter mimeType: The MIME type to associate with the data content type in the `Content-Type` HTTP header. + */ + func appendBodyPart(data data: NSData, name: String, mimeType: String) + + /** + Creates a body part from the data and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - `Content-Disposition: form-data; name=#{name}; filename=#{filename}` (HTTP Header) + - `Content-Type: #{mimeType}` (HTTP Header) + - Encoded file data + - Multipart form boundary + + - parameter data: The data to encode into the multipart form data. + - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header. + - parameter fileName: The filename to associate with the data in the `Content-Disposition` HTTP header. + - parameter mimeType: The MIME type to associate with the data in the `Content-Type` HTTP header. + */ + func appendBodyPart(data data: NSData, name: String, fileName: String, mimeType: String) + + /** + Creates a body part from the file and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - `Content-Disposition: form-data; name=#{name}; filename=#{generated filename}` (HTTP Header) + - `Content-Type: #{generated mimeType}` (HTTP Header) + - Encoded file data + - Multipart form boundary + + The filename in the `Content-Disposition` HTTP header is generated from the last path component of the + `fileURL`. The `Content-Type` HTTP header MIME type is generated by mapping the `fileURL` extension to the + system associated MIME type. + + - parameter fileURL: The URL of the file whose content will be encoded into the multipart form data. + - parameter name: The name to associate with the file content in the `Content-Disposition` HTTP header. + */ + func appendBodyPart(fileURL fileURL: NSURL, name: String) + + /** + Creates a body part from the file and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - Content-Disposition: form-data; name=#{name}; filename=#{filename} (HTTP Header) + - Content-Type: #{mimeType} (HTTP Header) + - Encoded file data + - Multipart form boundary + + - parameter fileURL: The URL of the file whose content will be encoded into the multipart form data. + - parameter name: The name to associate with the file content in the `Content-Disposition` HTTP header. + - parameter fileName: The filename to associate with the file content in the `Content-Disposition` HTTP header. + - parameter mimeType: The MIME type to associate with the file content in the `Content-Type` HTTP header. + */ + func appendBodyPart(fileURL fileURL: NSURL, name: String, fileName: String, mimeType: String) + + /** + Creates a body part from the stream and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - `Content-Disposition: form-data; name=#{name}; filename=#{filename}` (HTTP Header) + - `Content-Type: #{mimeType}` (HTTP Header) + - Encoded stream data + - Multipart form boundary + + - parameter stream: The input stream to encode in the multipart form data. + - parameter length: The content length of the stream. + - parameter name: The name to associate with the stream content in the `Content-Disposition` HTTP header. + - parameter fileName: The filename to associate with the stream content in the `Content-Disposition` HTTP header. + - parameter mimeType: The MIME type to associate with the stream content in the `Content-Type` HTTP header. + */ + func appendBodyPart( + stream stream: NSInputStream, + length: UInt64, + name: String, + fileName: String, + mimeType: String) + + /** + Creates a body part with the headers, stream and length and appends it to the multipart form data object. + + The body part data will be encoded using the following format: + + - HTTP headers + - Encoded stream data + - Multipart form boundary + + - parameter stream: The input stream to encode in the multipart form data. + - parameter length: The content length of the stream. + - parameter headers: The HTTP headers for the body part. + */ + func appendBodyPart(stream stream: NSInputStream, length: UInt64, headers: [String: String]) + + // MARK: - Data Encoding + + /** + Encodes all the appended body parts into a single `NSData` object. + + It is important to note that this method will load all the appended body parts into memory all at the same + time. This method should only be used when the encoded data will have a small memory footprint. For large data + cases, please use the `writeEncodedDataToDisk(fileURL:completionHandler:)` method. + + - throws: An `NSError` if encoding encounters an error. + + - returns: The encoded `NSData` if encoding is successful. + */ + func encode() throws -> NSData + + /** + Writes the appended body parts into the given file URL. + + This process is facilitated by reading and writing with input and output streams, respectively. Thus, + this approach is very memory efficient and should be used for large body part data. + + - parameter fileURL: The file URL to write the multipart form data into. + + - throws: An `NSError` if encoding encounters an error. + */ + func writeEncodedDataToDisk(fileURL: NSURL) throws + + +} diff --git a/DBNetworkStack/MultipartFormDataRessource.swift b/DBNetworkStack/MultipartFormDataRessource.swift new file mode 100644 index 0000000..dd719dc --- /dev/null +++ b/DBNetworkStack/MultipartFormDataRessource.swift @@ -0,0 +1,36 @@ +// +// MultipartFormDataRessource.swift +// DBNetworkStack +// +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// +// Created by Christian Himmelsbach on 27.09.16. +// +// +// DBNetworkStack +// + +import Foundation + +struct MultipartFormDataRessource: MultipartFormDataRessourceModelling { + var request: NetworkRequestRepresening + var parse: (data: NSData) throws -> Model + var encodingMemoryThreshold: UInt64 + var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void +} diff --git a/DBNetworkStack/MultipartFormDataRessourceModelling.swift b/DBNetworkStack/MultipartFormDataRessourceModelling.swift new file mode 100644 index 0000000..642c4cf --- /dev/null +++ b/DBNetworkStack/MultipartFormDataRessourceModelling.swift @@ -0,0 +1,34 @@ +// +// MultipartFormDataRessourceModelling.swift +// DBNetworkStack +// +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// +// Created by Christian Himmelsbach on 27.09.16. +// +// +// DBNetworkStack +// + +import Foundation + +public protocol MultipartFormDataRessourceModelling: RessourceModeling { + var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void { get } + var encodingMemoryThreshold: UInt64 { get } +} From 6802b26e281caaaf390ecc8482c1089d171bc330 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Thu, 29 Sep 2016 12:19:48 +0200 Subject: [PATCH 07/92] Added multipart access and service protocols + updated NetworkService implementation to conform to BaseURLProviding --- DBNetworkStack.xcodeproj/project.pbxproj | 12 ++- DBNetworkStack/BaseURLProviding.swift | 22 +++++- DBNetworkStack/MultipartUploadService.swift | 77 +++++++++++++++++++ .../MultipartUploadServiceProviding.swift | 54 +++++++++++++ DBNetworkStack/NetworkService.swift | 22 +----- DBNetworkStack/UploadAccessProviding.swift | 53 +++++++++++++ 6 files changed, 219 insertions(+), 21 deletions(-) create mode 100644 DBNetworkStack/MultipartUploadService.swift create mode 100644 DBNetworkStack/MultipartUploadServiceProviding.swift create mode 100644 DBNetworkStack/UploadAccessProviding.swift diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index 40a995a..a0e70da 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -7,9 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + 7C40B9E31D9A9A7000620563 /* UploadAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E21D9A9A7000620563 /* UploadAccessProviding.swift */; }; 7C40B9E51D9AA38600620563 /* MultipartFormDataRepresenting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */; }; + 7C40B9E71D9AA48200620563 /* MultipartUploadServiceProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E61D9AA48200620563 /* MultipartUploadServiceProviding.swift */; }; 7C40B9E91D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */; }; 7C40B9EB1D9AA4DE00620563 /* MultipartFormDataRessource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataRessource.swift */; }; + 7C40B9F61D9D028000620563 /* MultipartUploadService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F51D9D028000620563 /* MultipartUploadService.swift */; }; 7C40B9F81D9D034200620563 /* DBNetworkStackTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */; }; 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */; }; C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */; }; @@ -56,9 +59,12 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 7C40B9E21D9A9A7000620563 /* UploadAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = UploadAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultipartFormDataRepresenting.swift; sourceTree = ""; }; + 7C40B9E61D9AA48200620563 /* MultipartUploadServiceProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartUploadServiceProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataRessourceModelling.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataRessource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataRessource.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + 7C40B9F51D9D028000620563 /* MultipartUploadService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartUploadService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = DBNetworkStackTypes.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLProviding.swift; sourceTree = ""; }; C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -154,6 +160,7 @@ C60BE6841D6B2C46006B0364 /* AlamofireNetworkAccess.swift */, C6F235D41D7DA75000E628D8 /* URLSessionNetworkAccess.swift */, C60425091D76F79F00FD3B38 /* NetworkService.swift */, + 7C40B9F51D9D028000620563 /* MultipartUploadService.swift */, 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */, C60BE65E1D6B2BF3006B0364 /* DBNetworkStack.h */, C60BE6601D6B2BF3006B0364 /* Info.plist */, @@ -189,6 +196,7 @@ C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */, C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */, C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */, + 7C40B9E21D9A9A7000620563 /* UploadAccessProviding.swift */, 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */, 7C40B9E61D9AA48200620563 /* MultipartUploadServiceProviding.swift */, 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */, @@ -357,8 +365,10 @@ 7C40B9EB1D9AA4DE00620563 /* MultipartFormDataRessource.swift in Sources */, C60BE6901D6B2C46006B0364 /* Ressource.swift in Sources */, 7C40B9E91D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift in Sources */, + 7C40B9E31D9A9A7000620563 /* UploadAccessProviding.swift in Sources */, C60BE6921D6B2C46006B0364 /* JSONArrayRessource.swift in Sources */, C65F08821D75AC8D00239CC1 /* BaseURLKey.swift in Sources */, + 7C40B9F61D9D028000620563 /* MultipartUploadService.swift in Sources */, C65F087B1D757A3C00239CC1 /* JSONMappable.swift in Sources */, C60BE68E1D6B2C46006B0364 /* JSONRessourceModeling.swift in Sources */, C6F235D51D7DA75000E628D8 /* URLSessionNetworkAccess.swift in Sources */, @@ -368,10 +378,10 @@ C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */, 7C40B9E51D9AA38600620563 /* MultipartFormDataRepresenting.swift in Sources */, 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */, + 7C40B9E71D9AA48200620563 /* MultipartUploadServiceProviding.swift in Sources */, C60BE6AD1D6B3E81006B0364 /* NetworkTask.swift in Sources */, C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */, C60BE68D1D6B2C46006B0364 /* NetworkServiceProviding.swift in Sources */, - C6455A041D78BA48008A8C85 /* ExperimentResponseParsing.swift in Sources */, C60BE68B1D6B2C46006B0364 /* NetworkRequestRepresening.swift in Sources */, 7C40B9F81D9D034200620563 /* DBNetworkStackTypes.swift in Sources */, ); diff --git a/DBNetworkStack/BaseURLProviding.swift b/DBNetworkStack/BaseURLProviding.swift index 5725d09..232f60f 100644 --- a/DBNetworkStack/BaseURLProviding.swift +++ b/DBNetworkStack/BaseURLProviding.swift @@ -2,8 +2,28 @@ // BaseURLProviding.swift // DBNetworkStack // +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// // Created by Christian Himmelsbach on 29.09.16. -// Copyright © 2016 DBSystel. All rights reserved. +// +// +// DBNetworkStack // import Foundation diff --git a/DBNetworkStack/MultipartUploadService.swift b/DBNetworkStack/MultipartUploadService.swift new file mode 100644 index 0000000..a8f8e5c --- /dev/null +++ b/DBNetworkStack/MultipartUploadService.swift @@ -0,0 +1,77 @@ +// +// MultipartUploadService.swift +// DBNetworkStack +// +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// +// Created by Christian Himmelsbach on 29.09.16. +// +// +// DBNetworkStack +// + +import Foundation + +public final class MultipartUploadService: MultipartUploadServiceProviding, NetworkResponseProcessing, BaseURLProviding { + + private let uploadAccess: UploadAccessProviding + let endPoints: Dictionary + + /** + Creates an `MultipartUploadService` instance with a given uploadAccess and a map of endPoints + + - parameter uploadAccess: provides basic access to the network. + - parameter endPoints: map of baseURLKey -> baseURLs + */ + public init(uploadAccess: UploadAccessProviding, endPoints: Dictionary) { + self.uploadAccess = uploadAccess + self.endPoints = endPoints + } + + + public func upload(ressource: T, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil) { + + let baseURL = self.baseURL(with: ressource) + uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, encodingMemoryThreshold: ressource.encodingMemoryThreshold, callback: { data, response, error in + + do { + let parsed = try self.process( + response: response, + ressource: ressource, + data: data, + error: error + ) + dispatch_async(dispatch_get_main_queue()) { + onCompletion(parsed) + } + } catch let error as DBNetworkStackError { + dispatch_async(dispatch_get_main_queue()) { + return onError(error) + } + } catch { + + } + + }, onNetworkTaskCreation: { task in + dispatch_async(dispatch_get_main_queue(), { + onNetworkTaskCreation?(task) + }) + }) + } +} diff --git a/DBNetworkStack/MultipartUploadServiceProviding.swift b/DBNetworkStack/MultipartUploadServiceProviding.swift new file mode 100644 index 0000000..ad4c7ce --- /dev/null +++ b/DBNetworkStack/MultipartUploadServiceProviding.swift @@ -0,0 +1,54 @@ +// +// MultipartUploadPoviderServiceProviding.swift +// DBNetworkStack +// +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// +// Created by Christian Himmelsbach on 27.09.16. +// +// +// DBNetworkStack +// + +import Foundation + +public protocol MultipartUploadServiceProviding { + func upload( + ressource: T, + onCompletion: (T.Model) -> (), + onError: DBNetworkRequestErrorBlock, + onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? + ) +} + +extension MultipartUploadServiceProviding { + func upload( + ressource: T, + onCompletion: (T.Model) -> (), + onError: DBNetworkRequestErrorBlock, + onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil + ) { + upload( + ressource, + onCompletion: onCompletion, + onError: onError, + onNetworkTaskCreation: onNetworkTaskCreation + ) + } +} diff --git a/DBNetworkStack/NetworkService.swift b/DBNetworkStack/NetworkService.swift index eeab0f2..bd0c1d7 100644 --- a/DBNetworkStack/NetworkService.swift +++ b/DBNetworkStack/NetworkService.swift @@ -29,7 +29,7 @@ import Foundation /** `NetworkService` handles network request for ressources by using `Alamofire` as the network layer. */ -public final class NetworkService: NetworkServiceProviding { +public final class NetworkService: NetworkServiceProviding, BaseURLProviding { let networkAccess: NetworkAccessProviding let endPoints: Dictionary @@ -45,9 +45,8 @@ public final class NetworkService: NetworkServiceProviding { } public func request(ressource: T, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> ()) -> NetworkTask { - guard let baseURL = baseURL(with: ressource) else { - fatalError("Missing baseurl for key: \(ressource.request.baseURLKey.name)") - } + + let baseURL = self.baseURL(with: ressource) let reuqest = ressource.request.urlRequest(with: baseURL) let dataTask = networkAccess.load(request: reuqest, callback: { data, response, error in do { @@ -68,19 +67,4 @@ public final class NetworkService: NetworkServiceProviding { return dataTask } - /** - Provides an baseURL for a given ressource. - - To be more flexible, a request does only contain a path and not a full URL. - Mapping has to be done in the service to get an registerd baseURL for the request. - - - parameter ressource: The ressource you want to get a baseURL for. - - - return matching baseURL to the given ressource - */ - private func baseURL(with ressource: T) -> NSURL? { - return endPoints[ressource.request.baseURLKey.name] - } - - } diff --git a/DBNetworkStack/UploadAccessProviding.swift b/DBNetworkStack/UploadAccessProviding.swift new file mode 100644 index 0000000..134036f --- /dev/null +++ b/DBNetworkStack/UploadAccessProviding.swift @@ -0,0 +1,53 @@ +// +// UploadAccessProviding.swift +// DBNetworkStack +// +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// +// Created by Christian Himmelsbach on 27.09.16. +// +// +// DBNetworkStack +// + +import Foundation + +public protocol UploadAccessProviding { + func upload( + request: NetworkRequestRepresening, + relativeToBaseURL baseURL: NSURL, + multipartFormData: (MultipartFormDataRepresenting) -> (), + encodingMemoryThreshold: UInt64, + callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), + onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? + ) +} + +extension UploadAccessProviding { + func upload( + request: NetworkRequestRepresening, + relativeToBaseURL baseURL: NSURL, + multipartFormData: (MultipartFormDataRepresenting) -> (), + encodingMemoryThreshold: UInt64, + callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), + onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil + ) { + upload(request,relativeToBaseURL: baseURL, multipartFormData: multipartFormData, encodingMemoryThreshold: encodingMemoryThreshold, callback: callback, onNetworkTaskCreation: onNetworkTaskCreation) + } +} \ No newline at end of file From 4cdb301982e45b79242f99d6dd8287c704edff53 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Thu, 29 Sep 2016 17:31:05 +0200 Subject: [PATCH 08/92] Naming --- DBNetworkStack.xcodeproj/project.pbxproj | 24 +++++++++---------- ...tipartFormDataUploadAccessProviding.swift} | 6 ++--- ...t => MultipartFormDataUploadService.swift} | 18 +++++++------- ...ipartFormDataUploadServiceProviding.swift} | 4 ++-- 4 files changed, 27 insertions(+), 25 deletions(-) rename DBNetworkStack/{UploadAccessProviding.swift => MultipartFormDataUploadAccessProviding.swift} (92%) rename DBNetworkStack/{MultipartUploadService.swift => MultipartFormDataUploadService.swift} (77%) rename DBNetworkStack/{MultipartUploadServiceProviding.swift => MultipartFormDataUploadServiceProviding.swift} (94%) diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index a0e70da..57d1a78 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -7,12 +7,12 @@ objects = { /* Begin PBXBuildFile section */ - 7C40B9E31D9A9A7000620563 /* UploadAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E21D9A9A7000620563 /* UploadAccessProviding.swift */; }; + 7C40B9E31D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E21D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift */; }; 7C40B9E51D9AA38600620563 /* MultipartFormDataRepresenting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */; }; - 7C40B9E71D9AA48200620563 /* MultipartUploadServiceProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E61D9AA48200620563 /* MultipartUploadServiceProviding.swift */; }; + 7C40B9E71D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E61D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift */; }; 7C40B9E91D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */; }; 7C40B9EB1D9AA4DE00620563 /* MultipartFormDataRessource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataRessource.swift */; }; - 7C40B9F61D9D028000620563 /* MultipartUploadService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F51D9D028000620563 /* MultipartUploadService.swift */; }; + 7C40B9F61D9D028000620563 /* MultipartFormDataUploadService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F51D9D028000620563 /* MultipartFormDataUploadService.swift */; }; 7C40B9F81D9D034200620563 /* DBNetworkStackTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */; }; 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */; }; C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */; }; @@ -59,12 +59,12 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 7C40B9E21D9A9A7000620563 /* UploadAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = UploadAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + 7C40B9E21D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultipartFormDataRepresenting.swift; sourceTree = ""; }; - 7C40B9E61D9AA48200620563 /* MultipartUploadServiceProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartUploadServiceProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + 7C40B9E61D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadServiceProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataRessourceModelling.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataRessource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataRessource.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - 7C40B9F51D9D028000620563 /* MultipartUploadService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartUploadService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + 7C40B9F51D9D028000620563 /* MultipartFormDataUploadService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = DBNetworkStackTypes.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLProviding.swift; sourceTree = ""; }; C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -160,7 +160,7 @@ C60BE6841D6B2C46006B0364 /* AlamofireNetworkAccess.swift */, C6F235D41D7DA75000E628D8 /* URLSessionNetworkAccess.swift */, C60425091D76F79F00FD3B38 /* NetworkService.swift */, - 7C40B9F51D9D028000620563 /* MultipartUploadService.swift */, + 7C40B9F51D9D028000620563 /* MultipartFormDataUploadService.swift */, 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */, C60BE65E1D6B2BF3006B0364 /* DBNetworkStack.h */, C60BE6601D6B2BF3006B0364 /* Info.plist */, @@ -196,9 +196,9 @@ C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */, C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */, C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */, - 7C40B9E21D9A9A7000620563 /* UploadAccessProviding.swift */, + 7C40B9E21D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift */, 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */, - 7C40B9E61D9AA48200620563 /* MultipartUploadServiceProviding.swift */, + 7C40B9E61D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift */, 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */, 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */, ); @@ -365,10 +365,10 @@ 7C40B9EB1D9AA4DE00620563 /* MultipartFormDataRessource.swift in Sources */, C60BE6901D6B2C46006B0364 /* Ressource.swift in Sources */, 7C40B9E91D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift in Sources */, - 7C40B9E31D9A9A7000620563 /* UploadAccessProviding.swift in Sources */, + 7C40B9E31D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift in Sources */, C60BE6921D6B2C46006B0364 /* JSONArrayRessource.swift in Sources */, C65F08821D75AC8D00239CC1 /* BaseURLKey.swift in Sources */, - 7C40B9F61D9D028000620563 /* MultipartUploadService.swift in Sources */, + 7C40B9F61D9D028000620563 /* MultipartFormDataUploadService.swift in Sources */, C65F087B1D757A3C00239CC1 /* JSONMappable.swift in Sources */, C60BE68E1D6B2C46006B0364 /* JSONRessourceModeling.swift in Sources */, C6F235D51D7DA75000E628D8 /* URLSessionNetworkAccess.swift in Sources */, @@ -378,7 +378,7 @@ C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */, 7C40B9E51D9AA38600620563 /* MultipartFormDataRepresenting.swift in Sources */, 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */, - 7C40B9E71D9AA48200620563 /* MultipartUploadServiceProviding.swift in Sources */, + 7C40B9E71D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift in Sources */, C60BE6AD1D6B3E81006B0364 /* NetworkTask.swift in Sources */, C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */, C60BE68D1D6B2C46006B0364 /* NetworkServiceProviding.swift in Sources */, diff --git a/DBNetworkStack/UploadAccessProviding.swift b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift similarity index 92% rename from DBNetworkStack/UploadAccessProviding.swift rename to DBNetworkStack/MultipartFormDataUploadAccessProviding.swift index 134036f..7f3a167 100644 --- a/DBNetworkStack/UploadAccessProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift @@ -1,5 +1,5 @@ // -// UploadAccessProviding.swift +// MultipartFormDataUploadAccessProviding.swift // DBNetworkStack // // Legal Notice! DB Systel GmbH proprietary License! @@ -28,7 +28,7 @@ import Foundation -public protocol UploadAccessProviding { +public protocol MultipartFormDataUploadAccessProviding { func upload( request: NetworkRequestRepresening, relativeToBaseURL baseURL: NSURL, @@ -39,7 +39,7 @@ public protocol UploadAccessProviding { ) } -extension UploadAccessProviding { +extension MultipartFormDataUploadAccessProviding { func upload( request: NetworkRequestRepresening, relativeToBaseURL baseURL: NSURL, diff --git a/DBNetworkStack/MultipartUploadService.swift b/DBNetworkStack/MultipartFormDataUploadService.swift similarity index 77% rename from DBNetworkStack/MultipartUploadService.swift rename to DBNetworkStack/MultipartFormDataUploadService.swift index a8f8e5c..89e170c 100644 --- a/DBNetworkStack/MultipartUploadService.swift +++ b/DBNetworkStack/MultipartFormDataUploadService.swift @@ -1,5 +1,5 @@ // -// MultipartUploadService.swift +// MultipartFormDataUploadService.swift // DBNetworkStack // // Legal Notice! DB Systel GmbH proprietary License! @@ -28,18 +28,18 @@ import Foundation -public final class MultipartUploadService: MultipartUploadServiceProviding, NetworkResponseProcessing, BaseURLProviding { +public final class MultipartFormDataUploadService: MultipartFormDataUploadServiceProviding, NetworkResponseProcessing, BaseURLProviding { - private let uploadAccess: UploadAccessProviding + private let uploadAccess: MultipartFormDataUploadAccessProviding let endPoints: Dictionary /** - Creates an `MultipartUploadService` instance with a given uploadAccess and a map of endPoints + Creates an `MultipartFormDataUploadService` instance with a given uploadAccess and a map of endPoints - parameter uploadAccess: provides basic access to the network. - parameter endPoints: map of baseURLKey -> baseURLs */ - public init(uploadAccess: UploadAccessProviding, endPoints: Dictionary) { + public init(uploadAccess: MultipartFormDataUploadAccessProviding, endPoints: Dictionary) { self.uploadAccess = uploadAccess self.endPoints = endPoints } @@ -60,12 +60,14 @@ public final class MultipartUploadService: MultipartUploadServiceProviding, Netw dispatch_async(dispatch_get_main_queue()) { onCompletion(parsed) } - } catch let error as DBNetworkStackError { + } catch let parsingError as DBNetworkStackError { dispatch_async(dispatch_get_main_queue()) { - return onError(error) + return onError(parsingError) } } catch { - + dispatch_async(dispatch_get_main_queue()) { + return onError(.UnknownError) + } } }, onNetworkTaskCreation: { task in diff --git a/DBNetworkStack/MultipartUploadServiceProviding.swift b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift similarity index 94% rename from DBNetworkStack/MultipartUploadServiceProviding.swift rename to DBNetworkStack/MultipartFormDataUploadServiceProviding.swift index ad4c7ce..220a1b9 100644 --- a/DBNetworkStack/MultipartUploadServiceProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift @@ -28,7 +28,7 @@ import Foundation -public protocol MultipartUploadServiceProviding { +public protocol MultipartFormDataUploadServiceProviding { func upload( ressource: T, onCompletion: (T.Model) -> (), @@ -37,7 +37,7 @@ public protocol MultipartUploadServiceProviding { ) } -extension MultipartUploadServiceProviding { +extension MultipartFormDataUploadServiceProviding { func upload( ressource: T, onCompletion: (T.Model) -> (), From ed9bc4959cd6aca730ff0bdf1ad91fb1e9f6bce2 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 4 Oct 2016 12:46:12 +0200 Subject: [PATCH 09/92] Refactoring --- DBNetworkStack.xcodeproj/project.pbxproj | 4 +++ DBNetworkStackTests/NetworkServiceMock.swift | 19 ------------- DBNetworkStackTests/NetworkTaskMock.swift | 29 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 DBNetworkStackTests/NetworkTaskMock.swift diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index 57d1a78..3f99925 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 7C40B9F61D9D028000620563 /* MultipartFormDataUploadService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F51D9D028000620563 /* MultipartFormDataUploadService.swift */; }; 7C40B9F81D9D034200620563 /* DBNetworkStackTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */; }; 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */; }; + 7C40B9FE1D9D66A600620563 /* NetworkTaskMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */; }; C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */; }; C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425091D76F79F00FD3B38 /* NetworkService.swift */; }; C604250E1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C604250D1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift */; }; @@ -67,6 +68,7 @@ 7C40B9F51D9D028000620563 /* MultipartFormDataUploadService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = DBNetworkStackTypes.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLProviding.swift; sourceTree = ""; }; + 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkTaskMock.swift; sourceTree = ""; }; C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60425091D76F79F00FD3B38 /* NetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C604250D1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AlamofireNetworkAccessTest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -222,6 +224,7 @@ C60BE69E1D6B3807006B0364 /* AlamofireMock.swift */, C60BE69F1D6B3807006B0364 /* NetworkRequestMock.swift */, C6A5DED51D760E5000BC38B1 /* NetworkServiceMock.swift */, + 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */, ); name = Mocks; sourceTree = ""; @@ -392,6 +395,7 @@ buildActionMask = 2147483647; files = ( C6C86F531D910CE500D6E59E /* NetworkRequestTest.swift in Sources */, + 7C40B9FE1D9D66A600620563 /* NetworkTaskMock.swift in Sources */, C699E0771D917501006FE7C6 /* DBNetworkStackErrorTest.swift in Sources */, C6A5DED61D760E5000BC38B1 /* NetworkServiceMock.swift in Sources */, C60425131D7803CA00FD3B38 /* RessourceTest.swift in Sources */, diff --git a/DBNetworkStackTests/NetworkServiceMock.swift b/DBNetworkStackTests/NetworkServiceMock.swift index 4c6d279..4a6e47a 100644 --- a/DBNetworkStackTests/NetworkServiceMock.swift +++ b/DBNetworkStackTests/NetworkServiceMock.swift @@ -26,25 +26,6 @@ import Foundation import DBNetworkStack -class NetworkTaskMock: NetworkTask { - var isCanceld = false - func cancel() { - isCanceld = true - } - - func resume() { - - } - - func suspend() { - - } - - var progress: NSProgress { - return NSProgress() - } -} - class NetworkAccessMock: NetworkAccessProviding { private(set) var data: NSData? private(set) var response: NSHTTPURLResponse? diff --git a/DBNetworkStackTests/NetworkTaskMock.swift b/DBNetworkStackTests/NetworkTaskMock.swift new file mode 100644 index 0000000..9b871f9 --- /dev/null +++ b/DBNetworkStackTests/NetworkTaskMock.swift @@ -0,0 +1,29 @@ +// +// NetworkTaskMock.swift +// DBNetworkStack +// +// Created by Christian Himmelsbach on 29.09.16. +// Copyright © 2016 DBSystel. All rights reserved. +// + +import Foundation +import DBNetworkStack + +class NetworkTaskMock: NetworkTask { + var isCanceld = false + func cancel() { + isCanceld = true + } + + func resume() { + + } + + func suspend() { + + } + + var progress: NSProgress { + return NSProgress() + } +} From 173d45cd1210826a95f1dd58551bf4efd0e67160 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 4 Oct 2016 13:03:01 +0200 Subject: [PATCH 10/92] Updates gitignore --- .gitignore | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 052a62a..cab8c69 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,65 @@ -Carthage/* +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xcuserstate + +## Obj-C/Swift specific +*.hmap +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +.build/ + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# Pods/ + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output \ No newline at end of file From 73a955f9fe962a27aab65f664a6e331c4cafc8dc Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 4 Oct 2016 13:04:54 +0200 Subject: [PATCH 11/92] Added mock for upload access implementation --- DBNetworkStack.xcodeproj/project.pbxproj | 4 ++++ .../UploadAccessServiceMock.swift | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 DBNetworkStackTests/UploadAccessServiceMock.swift diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index 3f99925..c65222c 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 7C40B9F61D9D028000620563 /* MultipartFormDataUploadService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F51D9D028000620563 /* MultipartFormDataUploadService.swift */; }; 7C40B9F81D9D034200620563 /* DBNetworkStackTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */; }; 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */; }; + 7C40B9FC1D9D661B00620563 /* UploadAccessServiceMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9FB1D9D661B00620563 /* UploadAccessServiceMock.swift */; }; 7C40B9FE1D9D66A600620563 /* NetworkTaskMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */; }; C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */; }; C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425091D76F79F00FD3B38 /* NetworkService.swift */; }; @@ -68,6 +69,7 @@ 7C40B9F51D9D028000620563 /* MultipartFormDataUploadService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = DBNetworkStackTypes.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLProviding.swift; sourceTree = ""; }; + 7C40B9FB1D9D661B00620563 /* UploadAccessServiceMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = UploadAccessServiceMock.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkTaskMock.swift; sourceTree = ""; }; C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60425091D76F79F00FD3B38 /* NetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -224,6 +226,7 @@ C60BE69E1D6B3807006B0364 /* AlamofireMock.swift */, C60BE69F1D6B3807006B0364 /* NetworkRequestMock.swift */, C6A5DED51D760E5000BC38B1 /* NetworkServiceMock.swift */, + 7C40B9FB1D9D661B00620563 /* UploadAccessServiceMock.swift */, 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */, ); name = Mocks; @@ -407,6 +410,7 @@ C68CC28F1D8BED570019D940 /* BaseURLKeyTest.swift in Sources */, C60BE6A21D6B3807006B0364 /* NetworkRequestMock.swift in Sources */, C604250E1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift in Sources */, + 7C40B9FC1D9D661B00620563 /* UploadAccessServiceMock.swift in Sources */, C6A5DED41D760CC900BC38B1 /* JSONRessourceTest.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/DBNetworkStackTests/UploadAccessServiceMock.swift b/DBNetworkStackTests/UploadAccessServiceMock.swift new file mode 100644 index 0000000..f797346 --- /dev/null +++ b/DBNetworkStackTests/UploadAccessServiceMock.swift @@ -0,0 +1,24 @@ +// +// UploadAccessServiceMock.swift +// DBNetworkStack +// +// Created by Christian Himmelsbach on 29.09.16. +// Copyright © 2016 DBSystel. All rights reserved. +// + +import Foundation +import DBNetworkStack + +struct UploadAccessServiceMock: MultipartFormDataUploadAccessProviding { + func upload(request: NetworkRequestRepresening, relativeToBaseURL: NSURL, multipartFormData: (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock?) { + + dispatch_async(dispatch_get_main_queue()) { + onNetworkTaskCreation?(NetworkTaskMock()) + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(2.0)*Int64(NSEC_PER_SEC)), dispatch_get_main_queue(), { + callback(NSData(),nil,nil) + }) + } + + } +} \ No newline at end of file From 8c543455b490e568dfe165cf3a5a2dc3b577e489 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 4 Oct 2016 13:05:36 +0200 Subject: [PATCH 12/92] Updated source headers --- DBNetworkStack/DBNetworkStack.h | 19 ++++++++++++++++++- .../DBNetworkStackErrorTest.swift | 19 ++++++++++++++++++- DBNetworkStackTests/NetworkRequestTest.swift | 19 ++++++++++++++++++- DBNetworkStackTests/NetworkTaskMock.swift | 19 ++++++++++++++++++- .../UploadAccessServiceMock.swift | 19 ++++++++++++++++++- 5 files changed, 90 insertions(+), 5 deletions(-) diff --git a/DBNetworkStack/DBNetworkStack.h b/DBNetworkStack/DBNetworkStack.h index 1bba1c0..3d49ec5 100644 --- a/DBNetworkStack/DBNetworkStack.h +++ b/DBNetworkStack/DBNetworkStack.h @@ -2,8 +2,25 @@ // DBNetworkStack.h // DBNetworkStack // +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// // Created by Lukas Schmidt on 22.08.16. -// Copyright © 2016 DBSystel. All rights reserved. // #import diff --git a/DBNetworkStackTests/DBNetworkStackErrorTest.swift b/DBNetworkStackTests/DBNetworkStackErrorTest.swift index 6416e14..aaa230d 100644 --- a/DBNetworkStackTests/DBNetworkStackErrorTest.swift +++ b/DBNetworkStackTests/DBNetworkStackErrorTest.swift @@ -2,8 +2,25 @@ // DBNetworkStackErrorTest.swift // DBNetworkStack // +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// // Created by Lukas Schmidt on 20.09.16. -// Copyright © 2016 DBSystel. All rights reserved. // import XCTest diff --git a/DBNetworkStackTests/NetworkRequestTest.swift b/DBNetworkStackTests/NetworkRequestTest.swift index cb0fe5e..7f409cc 100644 --- a/DBNetworkStackTests/NetworkRequestTest.swift +++ b/DBNetworkStackTests/NetworkRequestTest.swift @@ -2,8 +2,25 @@ // NetworkRequestTest.swift // DBNetworkStack // +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// // Created by Lukas Schmidt on 20.09.16. -// Copyright © 2016 DBSystel. All rights reserved. // import XCTest diff --git a/DBNetworkStackTests/NetworkTaskMock.swift b/DBNetworkStackTests/NetworkTaskMock.swift index 9b871f9..53a2591 100644 --- a/DBNetworkStackTests/NetworkTaskMock.swift +++ b/DBNetworkStackTests/NetworkTaskMock.swift @@ -2,8 +2,25 @@ // NetworkTaskMock.swift // DBNetworkStack // +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// // Created by Christian Himmelsbach on 29.09.16. -// Copyright © 2016 DBSystel. All rights reserved. // import Foundation diff --git a/DBNetworkStackTests/UploadAccessServiceMock.swift b/DBNetworkStackTests/UploadAccessServiceMock.swift index f797346..67c7f2c 100644 --- a/DBNetworkStackTests/UploadAccessServiceMock.swift +++ b/DBNetworkStackTests/UploadAccessServiceMock.swift @@ -2,8 +2,25 @@ // UploadAccessServiceMock.swift // DBNetworkStack // +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// // Created by Christian Himmelsbach on 29.09.16. -// Copyright © 2016 DBSystel. All rights reserved. // import Foundation From e55c51f298fafd0ec72da3127c7a3a4f983afea7 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 4 Oct 2016 13:27:21 +0200 Subject: [PATCH 13/92] Create README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..7183c35 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# DBNetworkStack + +[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) + + +DBNetworkStack is a network abstraction for fetching request and mapping them to model objects. It is build completely on protocols so every layer can be exchanged and is well testable. The idea behind comes from this [article](https://talk.objc.io/episodes/S01E01-networking) From 62b9efd0c3c9f5db7c91c39d7d9b22abddb25d24 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 4 Oct 2016 13:35:20 +0200 Subject: [PATCH 14/92] Added test class for multipart formdata tests --- DBNetworkStack.xcodeproj/project.pbxproj | 6 +- .../MultipartFormDataRessource.swift | 17 +- .../MultipartFormDataUploadServiceTests.swift | 52 +++++ Experiments.playground/Contents.swift | 139 +++++++------ .../MultipartFormDataRepresenting.swift | 190 ------------------ 5 files changed, 151 insertions(+), 253 deletions(-) create mode 100644 DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift delete mode 100644 Experiments.playground/Sources/MultipartFormDataRepresenting.swift diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index c65222c..4963298 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */; }; 7C40B9FC1D9D661B00620563 /* UploadAccessServiceMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9FB1D9D661B00620563 /* UploadAccessServiceMock.swift */; }; 7C40B9FE1D9D66A600620563 /* NetworkTaskMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */; }; + 7C40BA001D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9FF1D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift */; }; C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */; }; C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425091D76F79F00FD3B38 /* NetworkService.swift */; }; C604250E1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C604250D1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift */; }; @@ -71,6 +72,7 @@ 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLProviding.swift; sourceTree = ""; }; 7C40B9FB1D9D661B00620563 /* UploadAccessServiceMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = UploadAccessServiceMock.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkTaskMock.swift; sourceTree = ""; }; + 7C40B9FF1D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadServiceTests.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60425091D76F79F00FD3B38 /* NetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C604250D1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AlamofireNetworkAccessTest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -187,6 +189,7 @@ C60BE66C1D6B2BF3006B0364 /* Info.plist */, C68CC28E1D8BED570019D940 /* BaseURLKeyTest.swift */, C699E0761D917501006FE7C6 /* DBNetworkStackErrorTest.swift */, + 7C40B9FF1D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift */, ); path = DBNetworkStackTests; sourceTree = ""; @@ -201,8 +204,8 @@ C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */, C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */, 7C40B9E21D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift */, - 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */, 7C40B9E61D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift */, + 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */, 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */, 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */, ); @@ -402,6 +405,7 @@ C699E0771D917501006FE7C6 /* DBNetworkStackErrorTest.swift in Sources */, C6A5DED61D760E5000BC38B1 /* NetworkServiceMock.swift in Sources */, C60425131D7803CA00FD3B38 /* RessourceTest.swift in Sources */, + 7C40BA001D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift in Sources */, C60BE6A11D6B3807006B0364 /* AlamofireMock.swift in Sources */, C6A5DEDA1D76A06000BC38B1 /* TrainModel.swift in Sources */, C6816E211D87C51C003B699A /* URLSessionNetworkAccessTest.swift in Sources */, diff --git a/DBNetworkStack/MultipartFormDataRessource.swift b/DBNetworkStack/MultipartFormDataRessource.swift index dd719dc..ee4d55c 100644 --- a/DBNetworkStack/MultipartFormDataRessource.swift +++ b/DBNetworkStack/MultipartFormDataRessource.swift @@ -28,9 +28,16 @@ import Foundation -struct MultipartFormDataRessource: MultipartFormDataRessourceModelling { - var request: NetworkRequestRepresening - var parse: (data: NSData) throws -> Model - var encodingMemoryThreshold: UInt64 - var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void +public struct MultipartFormDataRessource: MultipartFormDataRessourceModelling { + public var request: NetworkRequestRepresening + public var parse: (data: NSData) throws -> Model + public var encodingMemoryThreshold: UInt64 + public var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void + + public init(request: NetworkRequestRepresening, parse: (data: NSData) throws -> Model, encodingMemoryThreshold: UInt64, encodeInMultipartFormData: MultipartFormDataRepresenting -> Void) { + self.request = request + self.parse = parse + self.encodingMemoryThreshold = encodingMemoryThreshold + self.encodeInMultipartFormData = encodeInMultipartFormData + } } diff --git a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift new file mode 100644 index 0000000..83bea3e --- /dev/null +++ b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift @@ -0,0 +1,52 @@ +// +// MultipartFormDataUploadServiceTests.swift +// DBNetworkStack +// +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// +// Created by Christian Himmelsbach on 29.09.16. +// + +import XCTest +@testable import DBNetworkStack + +class MultipartFormDataUploadServiceTests: XCTestCase { + + var networkAccess = UploadAccessServiceMock() +// var service: MultipartFormDataUploadServiceProviding + + override func setUp() { + super.setUp() +// service = MultipartFormDataUploadService( +// uploadAccess: networkAccess, +// endPoints: <#T##Dictionary#> +// ) + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testUpload() { + + } + +} diff --git a/Experiments.playground/Contents.swift b/Experiments.playground/Contents.swift index 3381c59..917a0b8 100644 --- a/Experiments.playground/Contents.swift +++ b/Experiments.playground/Contents.swift @@ -4,18 +4,90 @@ import UIKit import DBNetworkStack import XCPlayground //import Alamofire -// -//XCPlaygroundPage.currentPage.needsIndefiniteExecution = true -// -//protocol MultiparRessource: RessourceModeling { -// var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void { get } -// var encodingMemoryThreshold: UInt64 { get } -//} -// + +XCPlaygroundPage.currentPage.needsIndefiniteExecution = true + +struct Formular { + let text: String + let image: UIImage +} + +struct Report { + init(data: NSData) throws { + + } +} + +// Mock + +struct MyNetworkTask: NetworkTask { + func cancel() { + + } + func resume() { + + } + func suspend() { + + } + + var progress = NSProgress() +} +struct UploadAccessMock: MultipartFormDataUploadAccessProviding { + func upload(request: NetworkRequestRepresening, relativeToBaseURL: NSURL, multipartFormData: (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock?) { + + dispatch_async(dispatch_get_main_queue()) { + onNetworkTaskCreation?(MyNetworkTask()) + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(2.0)*Int64(NSEC_PER_SEC)), dispatch_get_main_queue(), { + callback(NSData(),nil,nil) + }) + } + + } +} + +enum APIs: String, BaseURLKey { + case BFA + + var name: String { + return rawValue + } + var url: NSURL { + return NSURL(string: "https://dbbfa.herokuapp.com/")! + } +} + +let formular = Formular(text: "hallo", image: UIImage()) +let ressource = MultipartFormDataRessource( + request: NetworkRequest(path: "", baseURLKey: APIs.BFA), + parse: { try Report(data: $0) }, + encodingMemoryThreshold: 1000, + encodeInMultipartFormData: {multipartFormData in + multipartFormData.appendBodyPart(data: formular.text.dataUsingEncoding(NSUTF8StringEncoding)!, name: "text") + multipartFormData.appendBodyPart(data: UIImagePNGRepresentation(formular.image)!, name: "image") +}) +let baseURL = APIs.BFA +let service = MultipartFormDataUploadService( + uploadAccess: UploadAccessMock(), + endPoints: [baseURL.name:baseURL.url] +) + +service.upload(ressource, onCompletion: { report in + print("Nicey") +}, onError: { error in + print("Error: \(error)") +}, onNetworkTaskCreation: { task in + print("Task created") + +}) + + +// Alamofire Implmentation //extension Alamofire.MultipartFormData: MultipartFormDataRepresenting {} //extension Alamofire.Request: NetworkTask {} // -//class AlamofireUploadAccess: UploadAccessProviding { +//class AlamofireUploadAccess: MultipartFormDataUploadAccessProviding { // func upload(request: NetworkRequestRepresening, relativeToBaseURL: NSURL, multipartFormData: (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: (NetworkTask) -> ()) { // Alamofire.upload( // .POST, @@ -30,51 +102,4 @@ import XCPlayground // }) // case .Failure(let encodingError): // //TODO ErrorHandling -// callback(nil, nil, NSError(code: .BadRequest, userInfo: ["err": ""])) -// } -// }) -// } -//} -// -// -// -//protocol UploadAccessProviding { -// func upload( -// request: NetworkRequestRepresening, relativeToBaseURL: NSURL, -// multipartFormData: (MultipartFormDataRepresenting) -> (), -// encodingMemoryThreshold: UInt64, -// callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: (NetworkTask) -> ()) -//} -// -//protocol MultiUploadPoviderServiceProviding { -// func upload(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> (), onNetworkTaskCreation: (NetworkTask) -> ()) -//} -// -//class MultiPartUploadPoviderService: MultiUploadPoviderServiceProviding, NetworkResponseProcessing { -// let uploadAccess: UploadAccessProviding -// -// init(uploadAccess: UploadAccessProviding) { -// self.uploadAccess = uploadAccess -// } -// -// func upload(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> (), onNetworkTaskCreation: (NetworkTask) -> ()) { -// //TODO: Build baseURL -// let baseURL = NSURL() -// uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, encodingMemoryThreshold: ressource.encodingMemoryThreshold, callback: { data, response, error in -// do { -// let parsed = try self.process(response: response, ressource: ressource, data: data, error: error) -// dispatch_async(dispatch_get_main_queue()) { -// onCompletion(parsed) -// } -// } catch let error as NSError { -// dispatch_async(dispatch_get_main_queue()) { -// return onError(error) -// } -// } -// }, onNetworkTaskCreation: onNetworkTaskCreation) -// } -//} - - - - +// callback(nil, nil, NSError(code: .BadRequest, diff --git a/Experiments.playground/Sources/MultipartFormDataRepresenting.swift b/Experiments.playground/Sources/MultipartFormDataRepresenting.swift deleted file mode 100644 index 14f3443..0000000 --- a/Experiments.playground/Sources/MultipartFormDataRepresenting.swift +++ /dev/null @@ -1,190 +0,0 @@ -// -// MultipartFormData.swift -// -// Copyright (c) 2014-2016 Alamofire Software Foundation (http://alamofire.org/) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -import Foundation - -public protocol MultipartFormDataRepresenting: class { - - // MARK: - Properties - - /// The `Content-Type` header value containing the boundary used to generate the `multipart/form-data`. - var contentType: String { get } - - /// The content length of all body parts used to generate the `multipart/form-data` not including the boundaries. - var contentLength: UInt64 { get } - - /// The boundary used to separate the body parts in the encoded form data. - var boundary: String { get } - - // MARK: - Body Parts - - /** - Creates a body part from the data and appends it to the multipart form data object. - - The body part data will be encoded using the following format: - - - `Content-Disposition: form-data; name=#{name}` (HTTP Header) - - Encoded data - - Multipart form boundary - - - parameter data: The data to encode into the multipart form data. - - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header. - */ - func appendBodyPart(data data: NSData, name: String) - - /** - Creates a body part from the data and appends it to the multipart form data object. - - The body part data will be encoded using the following format: - - - `Content-Disposition: form-data; name=#{name}` (HTTP Header) - - `Content-Type: #{generated mimeType}` (HTTP Header) - - Encoded data - - Multipart form boundary - - - parameter data: The data to encode into the multipart form data. - - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header. - - parameter mimeType: The MIME type to associate with the data content type in the `Content-Type` HTTP header. - */ - func appendBodyPart(data data: NSData, name: String, mimeType: String) - - /** - Creates a body part from the data and appends it to the multipart form data object. - - The body part data will be encoded using the following format: - - - `Content-Disposition: form-data; name=#{name}; filename=#{filename}` (HTTP Header) - - `Content-Type: #{mimeType}` (HTTP Header) - - Encoded file data - - Multipart form boundary - - - parameter data: The data to encode into the multipart form data. - - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header. - - parameter fileName: The filename to associate with the data in the `Content-Disposition` HTTP header. - - parameter mimeType: The MIME type to associate with the data in the `Content-Type` HTTP header. - */ - func appendBodyPart(data data: NSData, name: String, fileName: String, mimeType: String) - - /** - Creates a body part from the file and appends it to the multipart form data object. - - The body part data will be encoded using the following format: - - - `Content-Disposition: form-data; name=#{name}; filename=#{generated filename}` (HTTP Header) - - `Content-Type: #{generated mimeType}` (HTTP Header) - - Encoded file data - - Multipart form boundary - - The filename in the `Content-Disposition` HTTP header is generated from the last path component of the - `fileURL`. The `Content-Type` HTTP header MIME type is generated by mapping the `fileURL` extension to the - system associated MIME type. - - - parameter fileURL: The URL of the file whose content will be encoded into the multipart form data. - - parameter name: The name to associate with the file content in the `Content-Disposition` HTTP header. - */ - func appendBodyPart(fileURL fileURL: NSURL, name: String) - - /** - Creates a body part from the file and appends it to the multipart form data object. - - The body part data will be encoded using the following format: - - - Content-Disposition: form-data; name=#{name}; filename=#{filename} (HTTP Header) - - Content-Type: #{mimeType} (HTTP Header) - - Encoded file data - - Multipart form boundary - - - parameter fileURL: The URL of the file whose content will be encoded into the multipart form data. - - parameter name: The name to associate with the file content in the `Content-Disposition` HTTP header. - - parameter fileName: The filename to associate with the file content in the `Content-Disposition` HTTP header. - - parameter mimeType: The MIME type to associate with the file content in the `Content-Type` HTTP header. - */ - func appendBodyPart(fileURL fileURL: NSURL, name: String, fileName: String, mimeType: String) - - /** - Creates a body part from the stream and appends it to the multipart form data object. - - The body part data will be encoded using the following format: - - - `Content-Disposition: form-data; name=#{name}; filename=#{filename}` (HTTP Header) - - `Content-Type: #{mimeType}` (HTTP Header) - - Encoded stream data - - Multipart form boundary - - - parameter stream: The input stream to encode in the multipart form data. - - parameter length: The content length of the stream. - - parameter name: The name to associate with the stream content in the `Content-Disposition` HTTP header. - - parameter fileName: The filename to associate with the stream content in the `Content-Disposition` HTTP header. - - parameter mimeType: The MIME type to associate with the stream content in the `Content-Type` HTTP header. - */ - func appendBodyPart( - stream stream: NSInputStream, - length: UInt64, - name: String, - fileName: String, - mimeType: String) - - /** - Creates a body part with the headers, stream and length and appends it to the multipart form data object. - - The body part data will be encoded using the following format: - - - HTTP headers - - Encoded stream data - - Multipart form boundary - - - parameter stream: The input stream to encode in the multipart form data. - - parameter length: The content length of the stream. - - parameter headers: The HTTP headers for the body part. - */ - func appendBodyPart(stream stream: NSInputStream, length: UInt64, headers: [String: String]) - - // MARK: - Data Encoding - - /** - Encodes all the appended body parts into a single `NSData` object. - - It is important to note that this method will load all the appended body parts into memory all at the same - time. This method should only be used when the encoded data will have a small memory footprint. For large data - cases, please use the `writeEncodedDataToDisk(fileURL:completionHandler:)` method. - - - throws: An `NSError` if encoding encounters an error. - - - returns: The encoded `NSData` if encoding is successful. - */ - func encode() throws -> NSData - - /** - Writes the appended body parts into the given file URL. - - This process is facilitated by reading and writing with input and output streams, respectively. Thus, - this approach is very memory efficient and should be used for large body part data. - - - parameter fileURL: The file URL to write the multipart form data into. - - - throws: An `NSError` if encoding encounters an error. - */ - func writeEncodedDataToDisk(fileURL: NSURL) throws - - -} From 1bcd51a60b027adf691c6918d8de4ed62f793c37 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 11 Oct 2016 07:22:05 +0200 Subject: [PATCH 15/92] Multipart test --- DBNetworkStack.xcodeproj/project.pbxproj | 8 ++- .../MultipartFormDataUploadService.swift | 21 +------- DBNetworkStack/NetworkService.swift | 15 +----- DBNetworkStack/NetworkServiceProviding.swift | 25 +++++++++ .../MulitpartFormDataRepresentingMock.swift | 51 +++++++++++++++++++ .../MultipartFormDataUploadServiceTests.swift | 38 +++++++++----- .../UploadAccessServiceMock.swift | 21 ++++++-- 7 files changed, 128 insertions(+), 51 deletions(-) create mode 100644 DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index b3f8c53..62ccabe 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -46,6 +46,7 @@ C6A5DED41D760CC900BC38B1 /* JSONRessourceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A5DED31D760CC900BC38B1 /* JSONRessourceTest.swift */; }; C6A5DED61D760E5000BC38B1 /* NetworkServiceMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A5DED51D760E5000BC38B1 /* NetworkServiceMock.swift */; }; C6A5DEDA1D76A06000BC38B1 /* TrainModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A5DED91D76A06000BC38B1 /* TrainModel.swift */; }; + C6AB45D91DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6AB45D81DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift */; }; C6C86F531D910CE500D6E59E /* NetworkRequestTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6C86F521D910CE500D6E59E /* NetworkRequestTest.swift */; }; C6F235D31D7DA71F00E628D8 /* AlamofireNetworkAccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6841D6B2C46006B0364 /* AlamofireNetworkAccess.swift */; }; C6F235D51D7DA75000E628D8 /* URLSessionNetworkAccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6F235D41D7DA75000E628D8 /* URLSessionNetworkAccess.swift */; }; @@ -82,7 +83,7 @@ C60BE65E1D6B2BF3006B0364 /* DBNetworkStack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DBNetworkStack.h; sourceTree = ""; }; C60BE6601D6B2BF3006B0364 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; C60BE6651D6B2BF3006B0364 /* DBNetworkStackTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DBNetworkStackTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - C60BE66C1D6B2BF3006B0364 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + C60BE66C1D6B2BF3006B0364 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = DBNetworkStackTests/Info.plist; sourceTree = ""; }; C60BE67B1D6B2C46006B0364 /* NetworkRequestRepresening.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkRequestRepresening.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60BE67C1D6B2C46006B0364 /* RessourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RessourceModeling.swift; sourceTree = ""; }; C60BE67D1D6B2C46006B0364 /* NetworkServiceProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkServiceProviding.swift; sourceTree = ""; }; @@ -105,6 +106,7 @@ C6A5DED31D760CC900BC38B1 /* JSONRessourceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONRessourceTest.swift; sourceTree = ""; }; C6A5DED51D760E5000BC38B1 /* NetworkServiceMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkServiceMock.swift; sourceTree = ""; }; C6A5DED91D76A06000BC38B1 /* TrainModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrainModel.swift; sourceTree = ""; }; + C6AB45D81DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MulitpartFormDataRepresentingMock.swift; sourceTree = ""; }; C6C86F521D910CE500D6E59E /* NetworkRequestTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkRequestTest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C6F235D41D7DA75000E628D8 /* URLSessionNetworkAccess.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLSessionNetworkAccess.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -141,6 +143,7 @@ children = ( C60BE65D1D6B2BF3006B0364 /* DBNetworkStack */, C60BE6691D6B2BF3006B0364 /* DBNetworkStackTests */, + C60BE66C1D6B2BF3006B0364 /* Info.plist */, C60BE65C1D6B2BF3006B0364 /* Products */, ); sourceTree = ""; @@ -186,7 +189,6 @@ C60425121D7803CA00FD3B38 /* RessourceTest.swift */, C6816E201D87C51C003B699A /* URLSessionNetworkAccessTest.swift */, C6C86F521D910CE500D6E59E /* NetworkRequestTest.swift */, - C60BE66C1D6B2BF3006B0364 /* Info.plist */, C68CC28E1D8BED570019D940 /* BaseURLKeyTest.swift */, C699E0761D917501006FE7C6 /* DBNetworkStackErrorTest.swift */, 7C40B9FF1D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift */, @@ -231,6 +233,7 @@ C6A5DED51D760E5000BC38B1 /* NetworkServiceMock.swift */, 7C40B9FB1D9D661B00620563 /* UploadAccessServiceMock.swift */, 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */, + C6AB45D81DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift */, ); name = Mocks; sourceTree = ""; @@ -414,6 +417,7 @@ C68CC28F1D8BED570019D940 /* BaseURLKeyTest.swift in Sources */, C60BE6A21D6B3807006B0364 /* NetworkRequestMock.swift in Sources */, C604250E1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift in Sources */, + C6AB45D91DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift in Sources */, 7C40B9FC1D9D661B00620563 /* UploadAccessServiceMock.swift in Sources */, C6A5DED41D760CC900BC38B1 /* JSONRessourceTest.swift in Sources */, ); diff --git a/DBNetworkStack/MultipartFormDataUploadService.swift b/DBNetworkStack/MultipartFormDataUploadService.swift index 89e170c..3af5d68 100644 --- a/DBNetworkStack/MultipartFormDataUploadService.swift +++ b/DBNetworkStack/MultipartFormDataUploadService.swift @@ -49,26 +49,7 @@ public final class MultipartFormDataUploadService: MultipartFormDataUploadServic let baseURL = self.baseURL(with: ressource) uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, encodingMemoryThreshold: ressource.encodingMemoryThreshold, callback: { data, response, error in - - do { - let parsed = try self.process( - response: response, - ressource: ressource, - data: data, - error: error - ) - dispatch_async(dispatch_get_main_queue()) { - onCompletion(parsed) - } - } catch let parsingError as DBNetworkStackError { - dispatch_async(dispatch_get_main_queue()) { - return onError(parsingError) - } - } catch { - dispatch_async(dispatch_get_main_queue()) { - return onError(.UnknownError) - } - } + self.processAsync(response: response, ressource: ressource, data: data, error: error, onCompletion: onCompletion, onError: onError) }, onNetworkTaskCreation: { task in dispatch_async(dispatch_get_main_queue(), { diff --git a/DBNetworkStack/NetworkService.swift b/DBNetworkStack/NetworkService.swift index bd0c1d7..0772b77 100644 --- a/DBNetworkStack/NetworkService.swift +++ b/DBNetworkStack/NetworkService.swift @@ -49,20 +49,7 @@ public final class NetworkService: NetworkServiceProviding, BaseURLProviding { let baseURL = self.baseURL(with: ressource) let reuqest = ressource.request.urlRequest(with: baseURL) let dataTask = networkAccess.load(request: reuqest, callback: { data, response, error in - do { - let parsed = try self.process(response: response, ressource: ressource, data: data, error: error) - dispatch_async(dispatch_get_main_queue()) { - onCompletion(parsed) - } - } catch let parsingError as DBNetworkStackError { - dispatch_async(dispatch_get_main_queue()) { - return onError(parsingError) - } - } catch { - dispatch_async(dispatch_get_main_queue()) { - return onError(.UnknownError) - } - } + self.processAsync(response: response, ressource: ressource, data: data, error: error, onCompletion: onCompletion, onError: onError) }) return dataTask } diff --git a/DBNetworkStack/NetworkServiceProviding.swift b/DBNetworkStack/NetworkServiceProviding.swift index 4290ff0..1619481 100644 --- a/DBNetworkStack/NetworkServiceProviding.swift +++ b/DBNetworkStack/NetworkServiceProviding.swift @@ -77,3 +77,28 @@ extension NetworkResponseProcessing { } } } + +extension NetworkResponseProcessing { + func processAsync(response response: NSHTTPURLResponse?, ressource: T, data: NSData?, error: NSError?, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> ()) { + do { + let parsed = try self.process( + response: response, + ressource: ressource, + data: data, + error: error + ) + dispatch_async(dispatch_get_main_queue()) { + onCompletion(parsed) + } + } catch let parsingError as DBNetworkStackError { + dispatch_async(dispatch_get_main_queue()) { + return onError(parsingError) + } + } catch { + dispatch_async(dispatch_get_main_queue()) { + return onError(.UnknownError) + } + } + } + +} diff --git a/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift b/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift new file mode 100644 index 0000000..09f6bc5 --- /dev/null +++ b/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift @@ -0,0 +1,51 @@ +// +// MulitpartFormDataRepresentingMock.swift +// DBNetworkStack +// +// Created by Lukas Schmidt on 04.10.16. +// Copyright © 2016 DBSystel. All rights reserved. +// + +import Foundation +import DBNetworkStack + +public class MulitpartFormDataRepresentingMock: MultipartFormDataRepresenting { + public var contentType: String = "multipart/form-data" + public var contentLength: UInt64 = 128 + public var boundary: String = "" + + public func appendBodyPart(data data: NSData, name: String) { + + } + + public func appendBodyPart(data data: NSData, name: String, mimeType: String) { + + } + + public func appendBodyPart(fileURL fileURL: NSURL, name: String, fileName: String, mimeType: String) { + + } + + public func appendBodyPart(fileURL fileURL: NSURL, name: String) { + + } + + public func appendBodyPart(data data: NSData, name: String, fileName: String, mimeType: String) { + } + + public func appendBodyPart(stream stream: NSInputStream, length: UInt64, headers: [String : String]) { + + } + + public func appendBodyPart(stream stream: NSInputStream, length: UInt64, name: String, fileName: String, mimeType: String) { + + } + + public func encode() throws -> NSData { + return NSData() + } + + public func writeEncodedDataToDisk(fileURL: NSURL) throws { + + } +} diff --git a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift index 83bea3e..5406e53 100644 --- a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift +++ b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift @@ -29,24 +29,38 @@ import XCTest class MultipartFormDataUploadServiceTests: XCTestCase { var networkAccess = UploadAccessServiceMock() -// var service: MultipartFormDataUploadServiceProviding + var service: MultipartFormDataUploadServiceProviding! override func setUp() { super.setUp() -// service = MultipartFormDataUploadService( -// uploadAccess: networkAccess, -// endPoints: <#T##Dictionary#> -// ) - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() + service = MultipartFormDataUploadService( + uploadAccess: networkAccess, + endPoints: [ TestEndPoints.EndPoint.name: NSURL()] + ) } func testUpload() { - + //Given + let request = NetworkRequest(path: "/train", baseURLKey: TestEndPoints.EndPoint) + let ressource = MultipartFormDataRessource(request: request, parse: { $0 }, + encodingMemoryThreshold: 200, encodeInMultipartFormData: { + formdata in + }) + networkAccess.changeMock(data: Train.validJSONData, response: nil, error: nil) + var didCreateTask = false + //When + let expection = expectationWithDescription("loadValidRequest") + service.upload(ressource, onCompletion: { data in + XCTAssertEqual(Train.validJSONData, data) + XCTAssert(didCreateTask) + expection.fulfill() + }, onError: { err in + print(err) + XCTFail() + }, onNetworkTaskCreation: { task in + didCreateTask = true + }) + waitForExpectationsWithTimeout(5, handler: nil) } } diff --git a/DBNetworkStackTests/UploadAccessServiceMock.swift b/DBNetworkStackTests/UploadAccessServiceMock.swift index 67c7f2c..c16d1a6 100644 --- a/DBNetworkStackTests/UploadAccessServiceMock.swift +++ b/DBNetworkStackTests/UploadAccessServiceMock.swift @@ -26,16 +26,31 @@ import Foundation import DBNetworkStack -struct UploadAccessServiceMock: MultipartFormDataUploadAccessProviding { +class UploadAccessServiceMock: MultipartFormDataUploadAccessProviding { + + var uploadData: NSData? + + private var reponseData: NSData? + private var responseError: NSError? + private var response: NSHTTPURLResponse? + private var multipartFormData: ((MultipartFormDataRepresenting) -> ())? + func upload(request: NetworkRequestRepresening, relativeToBaseURL: NSURL, multipartFormData: (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock?) { dispatch_async(dispatch_get_main_queue()) { + multipartFormData(MulitpartFormDataRepresentingMock()) onNetworkTaskCreation?(NetworkTaskMock()) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(2.0)*Int64(NSEC_PER_SEC)), dispatch_get_main_queue(), { - callback(NSData(),nil,nil) + callback(self.reponseData, self.response, self.responseError) }) } } -} \ No newline at end of file + + func changeMock(data data: NSData?, response: NSHTTPURLResponse?, error: NSError?) { + self.reponseData = data + self.response = response + self.responseError = error + } +} From 4863b9e2ead0515ed2c180d8a8a3b591905b43c2 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 11 Oct 2016 07:48:18 +0200 Subject: [PATCH 16/92] Cleans listing issues --- .swiftlint.yml | 2 +- DBNetworkStack.xcodeproj/project.pbxproj | 16 ---- DBNetworkStack/AlamofireNetworkAccess.swift | 73 ------------------- DBNetworkStack/BaseURLProviding.swift | 3 +- DBNetworkStack/DBNetworkStackTypes.swift | 5 +- .../MultipartFormDataRepresenting.swift | 1 - .../MultipartFormDataRessource.swift | 3 +- ...ltipartFormDataUploadAccessProviding.swift | 6 +- .../MultipartFormDataUploadService.swift | 9 ++- DBNetworkStack/NetworkService.swift | 6 +- DBNetworkStack/NetworkServiceProviding.swift | 3 +- DBNetworkStack/Ressource.swift | 1 - DBNetworkStackTests/AlamofireMock.swift | 49 ------------- .../AlamofireNetworkAccessTest.swift | 63 ---------------- DBNetworkStackTests/JSONRessourceTest.swift | 7 +- DBNetworkStackTests/NetworkRequestMock.swift | 50 ------------- DBNetworkStackTests/NetworkServiceTest.swift | 6 -- DBNetworkStackTests/RessourceTest.swift | 2 - DBNetworkStackTests/TrainModel.swift | 2 +- .../UploadAccessServiceMock.swift | 4 +- Experiments.playground/Contents.swift | 22 ------ 21 files changed, 27 insertions(+), 306 deletions(-) delete mode 100644 DBNetworkStack/AlamofireNetworkAccess.swift delete mode 100644 DBNetworkStackTests/AlamofireMock.swift delete mode 100644 DBNetworkStackTests/AlamofireNetworkAccessTest.swift delete mode 100644 DBNetworkStackTests/NetworkRequestMock.swift diff --git a/.swiftlint.yml b/.swiftlint.yml index 4ce6ee0..7d5153f 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -14,7 +14,7 @@ excluded: # paths to ignore during linting. Takes precedence over `included`. force_cast: warning # implicitly force_try: severity: warning # explicitly -line_length: 140 +line_length: 160 function_parameter_count: warning: 10 error: 15 diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index 62ccabe..1afba68 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -20,7 +20,6 @@ 7C40BA001D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9FF1D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift */; }; C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */; }; C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425091D76F79F00FD3B38 /* NetworkService.swift */; }; - C604250E1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C604250D1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift */; }; C60425101D78002400FD3B38 /* JSONArrayRessourceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C604250F1D78002400FD3B38 /* JSONArrayRessourceTest.swift */; }; C60425131D7803CA00FD3B38 /* RessourceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425121D7803CA00FD3B38 /* RessourceTest.swift */; }; C60BE65F1D6B2BF3006B0364 /* DBNetworkStack.h in Headers */ = {isa = PBXBuildFile; fileRef = C60BE65E1D6B2BF3006B0364 /* DBNetworkStack.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -34,8 +33,6 @@ C60BE6911D6B2C46006B0364 /* JSONRessource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6811D6B2C46006B0364 /* JSONRessource.swift */; }; C60BE6921D6B2C46006B0364 /* JSONArrayRessource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6821D6B2C46006B0364 /* JSONArrayRessource.swift */; }; C60BE6931D6B2C46006B0364 /* NetworkRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6831D6B2C46006B0364 /* NetworkRequest.swift */; }; - C60BE6A11D6B3807006B0364 /* AlamofireMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE69E1D6B3807006B0364 /* AlamofireMock.swift */; }; - C60BE6A21D6B3807006B0364 /* NetworkRequestMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE69F1D6B3807006B0364 /* NetworkRequestMock.swift */; }; C60BE6A31D6B3807006B0364 /* NetworkServiceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */; }; C60BE6AD1D6B3E81006B0364 /* NetworkTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */; }; C65F087B1D757A3C00239CC1 /* JSONMappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C65F087A1D757A3C00239CC1 /* JSONMappable.swift */; }; @@ -48,7 +45,6 @@ C6A5DEDA1D76A06000BC38B1 /* TrainModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A5DED91D76A06000BC38B1 /* TrainModel.swift */; }; C6AB45D91DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6AB45D81DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift */; }; C6C86F531D910CE500D6E59E /* NetworkRequestTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6C86F521D910CE500D6E59E /* NetworkRequestTest.swift */; }; - C6F235D31D7DA71F00E628D8 /* AlamofireNetworkAccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6841D6B2C46006B0364 /* AlamofireNetworkAccess.swift */; }; C6F235D51D7DA75000E628D8 /* URLSessionNetworkAccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6F235D41D7DA75000E628D8 /* URLSessionNetworkAccess.swift */; }; /* End PBXBuildFile section */ @@ -76,7 +72,6 @@ 7C40B9FF1D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadServiceTests.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60425091D76F79F00FD3B38 /* NetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - C604250D1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AlamofireNetworkAccessTest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C604250F1D78002400FD3B38 /* JSONArrayRessourceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONArrayRessourceTest.swift; sourceTree = ""; }; C60425121D7803CA00FD3B38 /* RessourceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RessourceTest.swift; sourceTree = ""; }; C60BE65B1D6B2BF3006B0364 /* DBNetworkStack.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DBNetworkStack.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -93,9 +88,6 @@ C60BE6811D6B2C46006B0364 /* JSONRessource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONRessource.swift; sourceTree = ""; }; C60BE6821D6B2C46006B0364 /* JSONArrayRessource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONArrayRessource.swift; sourceTree = ""; }; C60BE6831D6B2C46006B0364 /* NetworkRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkRequest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - C60BE6841D6B2C46006B0364 /* AlamofireNetworkAccess.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AlamofireNetworkAccess.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - C60BE69E1D6B3807006B0364 /* AlamofireMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AlamofireMock.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - C60BE69F1D6B3807006B0364 /* NetworkRequestMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkRequestMock.swift; sourceTree = ""; }; C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkServiceTest.swift; sourceTree = ""; }; C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkTask.swift; sourceTree = ""; }; C65F087A1D757A3C00239CC1 /* JSONMappable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONMappable.swift; sourceTree = ""; }; @@ -166,7 +158,6 @@ C60BE6801D6B2C46006B0364 /* Ressource.swift */, 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataRessource.swift */, C60BE6831D6B2C46006B0364 /* NetworkRequest.swift */, - C60BE6841D6B2C46006B0364 /* AlamofireNetworkAccess.swift */, C6F235D41D7DA75000E628D8 /* URLSessionNetworkAccess.swift */, C60425091D76F79F00FD3B38 /* NetworkService.swift */, 7C40B9F51D9D028000620563 /* MultipartFormDataUploadService.swift */, @@ -183,7 +174,6 @@ C6A5DED81D76A05300BC38B1 /* Helpers */, C6A5DED21D760C9E00BC38B1 /* Mocks */, C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */, - C604250D1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift */, C6A5DED31D760CC900BC38B1 /* JSONRessourceTest.swift */, C604250F1D78002400FD3B38 /* JSONArrayRessourceTest.swift */, C60425121D7803CA00FD3B38 /* RessourceTest.swift */, @@ -228,8 +218,6 @@ C6A5DED21D760C9E00BC38B1 /* Mocks */ = { isa = PBXGroup; children = ( - C60BE69E1D6B3807006B0364 /* AlamofireMock.swift */, - C60BE69F1D6B3807006B0364 /* NetworkRequestMock.swift */, C6A5DED51D760E5000BC38B1 /* NetworkServiceMock.swift */, 7C40B9FB1D9D661B00620563 /* UploadAccessServiceMock.swift */, 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */, @@ -385,7 +373,6 @@ C60BE68E1D6B2C46006B0364 /* JSONRessourceModeling.swift in Sources */, C6F235D51D7DA75000E628D8 /* URLSessionNetworkAccess.swift in Sources */, C60BE68C1D6B2C46006B0364 /* RessourceModeling.swift in Sources */, - C6F235D31D7DA71F00E628D8 /* AlamofireNetworkAccess.swift in Sources */, C60BE68F1D6B2C46006B0364 /* HTTPMethod.swift in Sources */, C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */, 7C40B9E51D9AA38600620563 /* MultipartFormDataRepresenting.swift in Sources */, @@ -409,14 +396,11 @@ C6A5DED61D760E5000BC38B1 /* NetworkServiceMock.swift in Sources */, C60425131D7803CA00FD3B38 /* RessourceTest.swift in Sources */, 7C40BA001D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift in Sources */, - C60BE6A11D6B3807006B0364 /* AlamofireMock.swift in Sources */, C6A5DEDA1D76A06000BC38B1 /* TrainModel.swift in Sources */, C6816E211D87C51C003B699A /* URLSessionNetworkAccessTest.swift in Sources */, C60425101D78002400FD3B38 /* JSONArrayRessourceTest.swift in Sources */, C60BE6A31D6B3807006B0364 /* NetworkServiceTest.swift in Sources */, C68CC28F1D8BED570019D940 /* BaseURLKeyTest.swift in Sources */, - C60BE6A21D6B3807006B0364 /* NetworkRequestMock.swift in Sources */, - C604250E1D76FF0300FD3B38 /* AlamofireNetworkAccessTest.swift in Sources */, C6AB45D91DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift in Sources */, 7C40B9FC1D9D661B00620563 /* UploadAccessServiceMock.swift in Sources */, C6A5DED41D760CC900BC38B1 /* JSONRessourceTest.swift in Sources */, diff --git a/DBNetworkStack/AlamofireNetworkAccess.swift b/DBNetworkStack/AlamofireNetworkAccess.swift deleted file mode 100644 index 487c751..0000000 --- a/DBNetworkStack/AlamofireNetworkAccess.swift +++ /dev/null @@ -1,73 +0,0 @@ -// -// NetworkService.swift -// DBNetworkStack -// -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. -// -// Created by Lukas Schmidt on 21.07.16. -// - -import Foundation -//import Alamofire -// -//public struct AlamofireNetworkAccess: NetworkAccessProviding { -// public typealias RequestMethod = (method: Alamofire.Method, URLString: URLStringConvertible, parameters: [String : AnyObject]?, encoding: Alamofire.ParameterEncoding, headers: [String : String]?) -> NetworkRequestModeling -// private let requestFunction: RequestMethod -// -// /** -// Creates an `AlamofireNetworkService` instance with an underlying Alamofire implementation -// -// - parameter requestFunction: A function of type `RequestMethod` similar to `Alamofire.Request` which can fetch data. -// */ -// public init(requestFunction: RequestMethod = Alamofire.request, endPoints: Dictionary) { -// self.requestFunction = requestFunction -// } -// -// public func load(request request: NetworkRequestRepresening, relativeToBaseURL baseURL: NSURL, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> CancelableRequest { -// guard let absoluteURL = NSURL(string: request.path, relativeToURL: baseURL) else { -// fatalError("Error createing absolute URL from path: \(request.path), with baseURL: \(baseURL)") -// } -// -// let request = requestFunction(method: request.HTTPMethod.alamofireMethod, -// URLString: absoluteURL, -// parameters: request.parameter, -// encoding: Alamofire.ParameterEncoding.URL, -// headers: request.allHTTPHeaderFields) -// request.response(queue: nil) { _, response, data, error in -// callback(data, response, error) -// } -// -// return request -// } -//} -// -//extension DBNetworkStack.HTTPMethod { -// var alamofireMethod: Alamofire.Method { -// return Alamofire.Method(rawValue: self.rawValue)! -// } -//} -// -// -///** -// Abstracts Alamofire.Request to make it testable -//*/ -//public protocol NetworkRequestModeling: CancelableRequest { -// func response(queue queue: dispatch_queue_t?, completionHandler: (NSURLRequest?, NSHTTPURLResponse?, NSData?, NSError?) -> Void) -> Self -//} -//extension Alamofire.Request: NetworkRequestModeling { } diff --git a/DBNetworkStack/BaseURLProviding.swift b/DBNetworkStack/BaseURLProviding.swift index 232f60f..8af8fda 100644 --- a/DBNetworkStack/BaseURLProviding.swift +++ b/DBNetworkStack/BaseURLProviding.swift @@ -54,4 +54,5 @@ extension BaseURLProviding { return baseURL } -} \ No newline at end of file + +} diff --git a/DBNetworkStack/DBNetworkStackTypes.swift b/DBNetworkStack/DBNetworkStackTypes.swift index cb62025..3ffe29a 100644 --- a/DBNetworkStack/DBNetworkStackTypes.swift +++ b/DBNetworkStack/DBNetworkStackTypes.swift @@ -26,7 +26,7 @@ import Foundation public typealias DBNetworkTaskCreationCompletionBlock = (NetworkTask) -> () -// TODO: Use typealiases for functions with generic types +// TODO: Use typealiases for functions with generic types in Swift 3.x //typealias NetworkRequestCompletionBlock = (T.Model) -> () public typealias DBNetworkRequestErrorBlock = (DBNetworkStackError) -> () @@ -58,4 +58,5 @@ public enum DBNetworkStackError: ErrorType { return nil } } -} \ No newline at end of file + +} diff --git a/DBNetworkStack/MultipartFormDataRepresenting.swift b/DBNetworkStack/MultipartFormDataRepresenting.swift index 8105619..3b95706 100644 --- a/DBNetworkStack/MultipartFormDataRepresenting.swift +++ b/DBNetworkStack/MultipartFormDataRepresenting.swift @@ -186,5 +186,4 @@ public protocol MultipartFormDataRepresenting: class { */ func writeEncodedDataToDisk(fileURL: NSURL) throws - } diff --git a/DBNetworkStack/MultipartFormDataRessource.swift b/DBNetworkStack/MultipartFormDataRessource.swift index ee4d55c..4dd7d17 100644 --- a/DBNetworkStack/MultipartFormDataRessource.swift +++ b/DBNetworkStack/MultipartFormDataRessource.swift @@ -34,7 +34,8 @@ public struct MultipartFormDataRessource: MultipartFormDataRessourceModel public var encodingMemoryThreshold: UInt64 public var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void - public init(request: NetworkRequestRepresening, parse: (data: NSData) throws -> Model, encodingMemoryThreshold: UInt64, encodeInMultipartFormData: MultipartFormDataRepresenting -> Void) { + public init(request: NetworkRequestRepresening, parse: (data: NSData) throws -> Model, + encodingMemoryThreshold: UInt64, encodeInMultipartFormData: MultipartFormDataRepresenting -> Void) { self.request = request self.parse = parse self.encodingMemoryThreshold = encodingMemoryThreshold diff --git a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift index 7f3a167..a7e802c 100644 --- a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift @@ -48,6 +48,8 @@ extension MultipartFormDataUploadAccessProviding { callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil ) { - upload(request,relativeToBaseURL: baseURL, multipartFormData: multipartFormData, encodingMemoryThreshold: encodingMemoryThreshold, callback: callback, onNetworkTaskCreation: onNetworkTaskCreation) + upload(request, relativeToBaseURL: baseURL, multipartFormData: multipartFormData, encodingMemoryThreshold: encodingMemoryThreshold, + callback: callback, onNetworkTaskCreation: onNetworkTaskCreation) } -} \ No newline at end of file + +} diff --git a/DBNetworkStack/MultipartFormDataUploadService.swift b/DBNetworkStack/MultipartFormDataUploadService.swift index 3af5d68..ba73536 100644 --- a/DBNetworkStack/MultipartFormDataUploadService.swift +++ b/DBNetworkStack/MultipartFormDataUploadService.swift @@ -44,12 +44,13 @@ public final class MultipartFormDataUploadService: MultipartFormDataUploadServic self.endPoints = endPoints } - - public func upload(ressource: T, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil) { + public func upload(ressource: T, onCompletion: (T.Model) -> (), + onError: (DBNetworkStackError) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil) { let baseURL = self.baseURL(with: ressource) - uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, encodingMemoryThreshold: ressource.encodingMemoryThreshold, callback: { data, response, error in - self.processAsync(response: response, ressource: ressource, data: data, error: error, onCompletion: onCompletion, onError: onError) + uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, + encodingMemoryThreshold: ressource.encodingMemoryThreshold, callback: { data, response, error in + self.processAsyncResponse(response: response, ressource: ressource, data: data, error: error, onCompletion: onCompletion, onError: onError) }, onNetworkTaskCreation: { task in dispatch_async(dispatch_get_main_queue(), { diff --git a/DBNetworkStack/NetworkService.swift b/DBNetworkStack/NetworkService.swift index 0772b77..c147312 100644 --- a/DBNetworkStack/NetworkService.swift +++ b/DBNetworkStack/NetworkService.swift @@ -25,9 +25,8 @@ import Foundation - /** - `NetworkService` handles network request for ressources by using `Alamofire` as the network layer. + `NetworkService` handles network request for ressources by using a given NetworkAccessProviding */ public final class NetworkService: NetworkServiceProviding, BaseURLProviding { let networkAccess: NetworkAccessProviding @@ -45,11 +44,10 @@ public final class NetworkService: NetworkServiceProviding, BaseURLProviding { } public func request(ressource: T, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> ()) -> NetworkTask { - let baseURL = self.baseURL(with: ressource) let reuqest = ressource.request.urlRequest(with: baseURL) let dataTask = networkAccess.load(request: reuqest, callback: { data, response, error in - self.processAsync(response: response, ressource: ressource, data: data, error: error, onCompletion: onCompletion, onError: onError) + self.processAsyncResponse(response: response, ressource: ressource, data: data, error: error, onCompletion: onCompletion, onError: onError) }) return dataTask } diff --git a/DBNetworkStack/NetworkServiceProviding.swift b/DBNetworkStack/NetworkServiceProviding.swift index 1619481..22597e8 100644 --- a/DBNetworkStack/NetworkServiceProviding.swift +++ b/DBNetworkStack/NetworkServiceProviding.swift @@ -79,7 +79,8 @@ extension NetworkResponseProcessing { } extension NetworkResponseProcessing { - func processAsync(response response: NSHTTPURLResponse?, ressource: T, data: NSData?, error: NSError?, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> ()) { + func processAsyncResponse(response response: NSHTTPURLResponse?, ressource: T, data: NSData?, + error: NSError?, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> ()) { do { let parsed = try self.process( response: response, diff --git a/DBNetworkStack/Ressource.swift b/DBNetworkStack/Ressource.swift index 599df75..1e5aaab 100644 --- a/DBNetworkStack/Ressource.swift +++ b/DBNetworkStack/Ressource.swift @@ -25,7 +25,6 @@ import Foundation - public struct Ressource: RessourceModeling { public let request: NetworkRequestRepresening public let parse: (data: NSData) throws -> Model diff --git a/DBNetworkStackTests/AlamofireMock.swift b/DBNetworkStackTests/AlamofireMock.swift deleted file mode 100644 index c072348..0000000 --- a/DBNetworkStackTests/AlamofireMock.swift +++ /dev/null @@ -1,49 +0,0 @@ -// -// AlamofireMock.swift -// DBNetworkStack -// -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. -// -// Created by Lukas Schmidt on 26.07.16. -// - -import Foundation -//import Alamofire -//@testable import DBNetworkStack -// -//class AlamofireMock { -// var method: Alamofire.Method? -// var URLString: URLStringConvertible? -// var parameter: [String : AnyObject]? -// var encoding: Alamofire.ParameterEncoding? -// var headers: [String : String]? -// -// var returnedRequest: NetworkRequestModeling? -// -// -// func request(method method: Alamofire.Method, URLString: URLStringConvertible, parameters: [String : AnyObject]? , encoding: Alamofire.ParameterEncoding, headers: [String : String]?) -> NetworkRequestModeling { -// self.method = method -// self.URLString = URLString -// self.parameter = parameters -// self.encoding = encoding -// self.headers = headers -// -// return returnedRequest ?? NetworkRequestMock() -// } -//} \ No newline at end of file diff --git a/DBNetworkStackTests/AlamofireNetworkAccessTest.swift b/DBNetworkStackTests/AlamofireNetworkAccessTest.swift deleted file mode 100644 index 3b3e6f0..0000000 --- a/DBNetworkStackTests/AlamofireNetworkAccessTest.swift +++ /dev/null @@ -1,63 +0,0 @@ -// -// AlamofireNetworkAccessTest.swift -// DBNetworkStack -// -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. -// -// Created by Lukas Schmidt on 31.08.16. -// - -import XCTest -@testable import DBNetworkStack - - -//class AlamofireNetworkAccessTest: XCTestCase { -// -// var alamofireMock = AlamofireMock() -// var networkAccess: AlamofireNetworkAccessProvider! -// -// override func setUp() { -// networkAccess = AlamofireNetworkAccessProvider(requestFunction: alamofireMock.request, endPoints: [TestEndPoints.EndPoint.name: NSURL()]) -// } -// -// func testValidRequest() { -// //Given -// let parameter: [String: AnyObject] = ["id": 1, "name": "ICE"] -// let headers = ["testHeaderField": "testHeaderValue"] -// let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.EndPoint, HTTPMethod: .GET, parameter: parameter, allHTTPHeaderField: headers) -// let baseURL = NSURL(string: "https://bahn.de")! -// -// //When -// networkAccess.load(request: request, relativeToBaseURL: baseURL, callback: { _, _, _ in -// -// }) -// -// //Then -// XCTAssertEqual(alamofireMock.URLString?.URLString, "https://bahn.de/train") -// XCTAssertEqual(alamofireMock.method, HTTPMethod.GET.alamofireMethod) -// //XCTAssertEqual(alamofireMock.parameters, url.URLString) -// -// //XCTAssert(alamofireMock.encoding! == Alamofire.ParameterEncoding.URL) -// XCTAssertEqual(alamofireMock.headers!, headers) -// XCTAssertEqual(alamofireMock.parameter?.count, 2) -// XCTAssertEqual(alamofireMock.parameter?["id"] as? Int, 1) -// XCTAssertEqual(alamofireMock.parameter?["name"] as? String, "ICE") -// -// } -//} \ No newline at end of file diff --git a/DBNetworkStackTests/JSONRessourceTest.swift b/DBNetworkStackTests/JSONRessourceTest.swift index a7584b8..164d202 100644 --- a/DBNetworkStackTests/JSONRessourceTest.swift +++ b/DBNetworkStackTests/JSONRessourceTest.swift @@ -33,12 +33,11 @@ class JSONRessourceTest: XCTestCase { let ressource = JSONRessource(request: request) //When - let fetchedTrain = try! ressource.parse(data: Train.validJSONData) + let fetchedTrain = try? ressource.parse(data: Train.validJSONData) - //Then XCTAssertNotNil(fetchedTrain) - XCTAssertEqual(fetchedTrain.name, "ICE") + XCTAssertEqual(fetchedTrain?.name, "ICE") } func testRessourceWithInvalidData() { @@ -55,5 +54,3 @@ class JSONRessourceTest: XCTestCase { } } - - diff --git a/DBNetworkStackTests/NetworkRequestMock.swift b/DBNetworkStackTests/NetworkRequestMock.swift deleted file mode 100644 index 559b4d3..0000000 --- a/DBNetworkStackTests/NetworkRequestMock.swift +++ /dev/null @@ -1,50 +0,0 @@ -// -// NetworkRequestMock.swift -// DBNetworkStack -// -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. -// -// Created by Lukas Schmidt on 26.07.16. -// - -import Foundation -@testable import DBNetworkStack - -//class NetworkRequestMock: NetworkRequestModeling { -// let data: NSData? -// let error: NSError? -// -// init(data: NSData?, error: NSError? = nil) { -// self.data = data -// self.error = error -// } -// -// convenience init() { -// self.init(data: nil, error: nil) -// } -// -// func response(queue queue: dispatch_queue_t?, completionHandler: (NSURLRequest?, NSHTTPURLResponse?, NSData?, NSError?) -> Void) -> Self { -// completionHandler(nil, nil, data, error) -// return self -// } -// -// func cancel() { -// -// } -//} \ No newline at end of file diff --git a/DBNetworkStackTests/NetworkServiceTest.swift b/DBNetworkStackTests/NetworkServiceTest.swift index 975c88e..5422be3 100644 --- a/DBNetworkStackTests/NetworkServiceTest.swift +++ b/DBNetworkStackTests/NetworkServiceTest.swift @@ -73,7 +73,6 @@ class NetworkServiceTest: XCTestCase { let ressource = JSONRessource(request: request) networkAccess.changeMock(data: nil, response: nil, error: nil) - //When let expection = expectationWithDescription("testNoData") networkService.request(ressource, onCompletion: { fetchedTrain in @@ -98,7 +97,6 @@ class NetworkServiceTest: XCTestCase { let ressource = JSONRessource(request: request) networkAccess.changeMock(data: Train.invalidJSONData, response: nil, error: nil) - //When let expection = expectationWithDescription("testInvalidData") networkService.request(ressource, onCompletion: { fetchedTrain in @@ -146,7 +144,6 @@ class NetworkServiceTest: XCTestCase { let ressource = JSONRessource(request: request) networkAccess.changeMock(data: nil, response: nil, error: error) - //When let expection = expectationWithDescription("testOnError") networkService.request(ressource, onCompletion: { fetchedTrain in @@ -161,7 +158,6 @@ class NetworkServiceTest: XCTestCase { } }) - waitForExpectationsWithTimeout(1, handler: nil) } @@ -172,7 +168,6 @@ class NetworkServiceTest: XCTestCase { let response = NSHTTPURLResponse(URL: NSURL(), statusCode: 401, HTTPVersion: nil, headerFields: nil) networkAccess.changeMock(data: nil, response: response, error: nil) - //When let expection = expectationWithDescription("testOnError") networkService.request(ressource, onCompletion: { fetchedTrain in @@ -187,7 +182,6 @@ class NetworkServiceTest: XCTestCase { } }) - waitForExpectationsWithTimeout(1, handler: nil) } } diff --git a/DBNetworkStackTests/RessourceTest.swift b/DBNetworkStackTests/RessourceTest.swift index e705f0b..80008ab 100644 --- a/DBNetworkStackTests/RessourceTest.swift +++ b/DBNetworkStackTests/RessourceTest.swift @@ -28,7 +28,6 @@ import XCTest class RessourceTest: XCTestCase { - func testRessource() { //Given let validData = "ICE".dataUsingEncoding(NSUTF8StringEncoding)! @@ -38,7 +37,6 @@ class RessourceTest: XCTestCase { //When let name = try? ressource.parse(data: validData) - //Then XCTAssertNotNil(name) XCTAssertEqual(name!!, "ICE") diff --git a/DBNetworkStackTests/TrainModel.swift b/DBNetworkStackTests/TrainModel.swift index 399e67c..18bcb4b 100644 --- a/DBNetworkStackTests/TrainModel.swift +++ b/DBNetworkStackTests/TrainModel.swift @@ -34,7 +34,7 @@ extension Train: JSONMappable { init(object: Dictionary) throws { if let name = object["name"] as? String { self.name = name - }else { + } else { throw NSError(domain: "", code: 0, userInfo: nil) } } diff --git a/DBNetworkStackTests/UploadAccessServiceMock.swift b/DBNetworkStackTests/UploadAccessServiceMock.swift index c16d1a6..19d3a1f 100644 --- a/DBNetworkStackTests/UploadAccessServiceMock.swift +++ b/DBNetworkStackTests/UploadAccessServiceMock.swift @@ -35,7 +35,9 @@ class UploadAccessServiceMock: MultipartFormDataUploadAccessProviding { private var response: NSHTTPURLResponse? private var multipartFormData: ((MultipartFormDataRepresenting) -> ())? - func upload(request: NetworkRequestRepresening, relativeToBaseURL: NSURL, multipartFormData: (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock?) { + func upload(request: NetworkRequestRepresening, relativeToBaseURL: NSURL, multipartFormData: (MultipartFormDataRepresenting) -> (), + encodingMemoryThreshold: UInt64, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), + onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock?) { dispatch_async(dispatch_get_main_queue()) { multipartFormData(MulitpartFormDataRepresentingMock()) diff --git a/Experiments.playground/Contents.swift b/Experiments.playground/Contents.swift index 6fd80e2..f40485c 100644 --- a/Experiments.playground/Contents.swift +++ b/Experiments.playground/Contents.swift @@ -81,25 +81,3 @@ service.upload(ressource, onCompletion: { report in print("Task created") }) - - -// Alamofire Implmentation -//extension Alamofire.MultipartFormData: MultipartFormDataRepresenting {} -//extension Alamofire.Request: NetworkTask {} -// -//class AlamofireUploadAccess: MultipartFormDataUploadAccessProviding { -// func upload(request: NetworkRequestRepresening, relativeToBaseURL: NSURL, multipartFormData: (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: (NetworkTask) -> ()) { -// Alamofire.upload( -// .POST, -// NSURL(string: request.path, relativeToURL: relativeToBaseURL)!, -// multipartFormData: multipartFormData, -// encodingCompletion: { encodingResult in -// switch encodingResult { -// case .Success(let upload, _, _): -// onNetworkTaskCreation(upload) -// upload.response(completionHandler: { request, response, data, error in -// callback(data, response, error) -// }) -// case .Failure(let encodingError): -// //TODO ErrorHandling -// callback(nil, nil, NSError(code: .BadRequest, From ef7aa8d6634f5f41be841579296db4320b860e1c Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 11 Oct 2016 08:06:34 +0200 Subject: [PATCH 17/92] Introduces new ArrayRessourceModeling for a generic abstraction of all resources which provide structured data in an array --- DBNetworkStack.xcodeproj/project.pbxproj | 6 +++- DBNetworkStack/ArrayRessourceModeling.swift | 31 +++++++++++++++++++++ DBNetworkStack/JSONArrayRessource.swift | 3 +- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 DBNetworkStack/ArrayRessourceModeling.swift diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index 1afba68..87b35f3 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -35,6 +35,7 @@ C60BE6931D6B2C46006B0364 /* NetworkRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6831D6B2C46006B0364 /* NetworkRequest.swift */; }; C60BE6A31D6B3807006B0364 /* NetworkServiceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */; }; C60BE6AD1D6B3E81006B0364 /* NetworkTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */; }; + C61348B91DACB4F2000F0583 /* ArrayRessourceModeling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C61348B81DACB4F2000F0583 /* ArrayRessourceModeling.swift */; }; C65F087B1D757A3C00239CC1 /* JSONMappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C65F087A1D757A3C00239CC1 /* JSONMappable.swift */; }; C65F08821D75AC8D00239CC1 /* BaseURLKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */; }; C6816E211D87C51C003B699A /* URLSessionNetworkAccessTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6816E201D87C51C003B699A /* URLSessionNetworkAccessTest.swift */; }; @@ -90,6 +91,7 @@ C60BE6831D6B2C46006B0364 /* NetworkRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkRequest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkServiceTest.swift; sourceTree = ""; }; C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkTask.swift; sourceTree = ""; }; + C61348B81DACB4F2000F0583 /* ArrayRessourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayRessourceModeling.swift; sourceTree = ""; }; C65F087A1D757A3C00239CC1 /* JSONMappable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONMappable.swift; sourceTree = ""; }; C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLKey.swift; sourceTree = ""; }; C6816E201D87C51C003B699A /* URLSessionNetworkAccessTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLSessionNetworkAccessTest.swift; sourceTree = ""; }; @@ -189,8 +191,9 @@ C60BE6A81D6B399A006B0364 /* protocol */ = { isa = PBXGroup; children = ( - C60BE67B1D6B2C46006B0364 /* NetworkRequestRepresening.swift */, C60BE67C1D6B2C46006B0364 /* RessourceModeling.swift */, + C61348B81DACB4F2000F0583 /* ArrayRessourceModeling.swift */, + C60BE67B1D6B2C46006B0364 /* NetworkRequestRepresening.swift */, C60BE67D1D6B2C46006B0364 /* NetworkServiceProviding.swift */, C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */, C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */, @@ -360,6 +363,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C61348B91DACB4F2000F0583 /* ArrayRessourceModeling.swift in Sources */, C60BE6931D6B2C46006B0364 /* NetworkRequest.swift in Sources */, C60BE6911D6B2C46006B0364 /* JSONRessource.swift in Sources */, 7C40B9EB1D9AA4DE00620563 /* MultipartFormDataRessource.swift in Sources */, diff --git a/DBNetworkStack/ArrayRessourceModeling.swift b/DBNetworkStack/ArrayRessourceModeling.swift new file mode 100644 index 0000000..c81b8cf --- /dev/null +++ b/DBNetworkStack/ArrayRessourceModeling.swift @@ -0,0 +1,31 @@ +// +// ArrayRessourceModeling.swift +// DBNetworkStack +// +// Legal Notice! DB Systel GmbH proprietary License! +// +// Copyright (C) 2015 DB Systel GmbH +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// This code is protected by copyright law and is the exclusive property of +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ + +// Consent to use ("licence") shall be granted solely on the basis of a +// written licence agreement signed by the customer and DB Systel GmbH. Any +// other use, in particular copying, redistribution, publication or +// modification of this code without written permission of DB Systel GmbH is +// expressly prohibited. + +// In the event of any permitted copying, redistribution or publication of +// this code, no changes in or deletion of author attribution, trademark +// legend or copyright notice shall be made. +// +// Created by Lukas Schmidt on 11.10.16. +// + +import Foundation + +protocol ArrayRessourceModeling: RessourceModeling { + associatedtype Element + associatedtype Model = Array +} diff --git a/DBNetworkStack/JSONArrayRessource.swift b/DBNetworkStack/JSONArrayRessource.swift index 5e5ee92..c515027 100644 --- a/DBNetworkStack/JSONArrayRessource.swift +++ b/DBNetworkStack/JSONArrayRessource.swift @@ -32,7 +32,8 @@ import Foundation See `RessourceModeling` for more details. */ -public struct JSONArrayRessource: JSONRessourceModeling { +public struct JSONArrayRessource: JSONRessourceModeling, ArrayRessourceModeling { + public typealias Element = Element_ public let request: NetworkRequestRepresening public var parse: (data: NSData) throws -> Array { return parseFunction From 57b5378e113f2ca4bbff49080753ce0f1ccfcfc0 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 11 Oct 2016 08:12:26 +0200 Subject: [PATCH 18/92] Removes whitespace --- DBNetworkStackTests/NetworkServiceTest.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/DBNetworkStackTests/NetworkServiceTest.swift b/DBNetworkStackTests/NetworkServiceTest.swift index 5422be3..f6bdebe 100644 --- a/DBNetworkStackTests/NetworkServiceTest.swift +++ b/DBNetworkStackTests/NetworkServiceTest.swift @@ -136,7 +136,6 @@ class NetworkServiceTest: XCTestCase { waitForExpectationsWithTimeout(1, handler: nil) } - func testOnError() { //Given let error = NSError(domain: "", code: 0, userInfo: nil) From d0a83f68dde5dfd999b121154e47320b7e55d331 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 11 Oct 2016 08:16:55 +0200 Subject: [PATCH 19/92] Changes license texts to MIT --- DBNetworkStack/ArrayRessourceModeling.swift | 36 +++++++++--------- DBNetworkStack/BaseURLKey.swift | 36 +++++++++--------- DBNetworkStack/BaseURLProviding.swift | 38 +++++++++---------- DBNetworkStack/DBNetworkStack.h | 36 +++++++++--------- DBNetworkStack/DBNetworkStackTypes.swift | 36 +++++++++--------- DBNetworkStack/HTTPMethod.swift | 36 +++++++++--------- DBNetworkStack/JSONArrayRessource.swift | 36 +++++++++--------- DBNetworkStack/JSONMappable.swift | 36 +++++++++--------- DBNetworkStack/JSONRessource.swift | 36 +++++++++--------- DBNetworkStack/JSONRessourceModeling.swift | 36 +++++++++--------- .../MultipartFormDataRessource.swift | 38 +++++++++---------- .../MultipartFormDataRessourceModelling.swift | 38 +++++++++---------- ...ltipartFormDataUploadAccessProviding.swift | 38 +++++++++---------- .../MultipartFormDataUploadService.swift | 38 +++++++++---------- ...tipartFormDataUploadServiceProviding.swift | 38 +++++++++---------- DBNetworkStack/NetworkAccessProviding.swift | 36 +++++++++--------- DBNetworkStack/NetworkRequest.swift | 36 +++++++++--------- .../NetworkRequestRepresening.swift | 36 +++++++++--------- DBNetworkStack/NetworkService.swift | 36 +++++++++--------- DBNetworkStack/NetworkServiceProviding.swift | 36 +++++++++--------- DBNetworkStack/NetworkTask.swift | 36 +++++++++--------- DBNetworkStack/Ressource.swift | 36 +++++++++--------- DBNetworkStack/RessourceModeling.swift | 36 +++++++++--------- DBNetworkStack/URLSessionNetworkAccess.swift | 36 +++++++++--------- DBNetworkStackTests/BaseURLKeyTest.swift | 36 +++++++++--------- .../DBNetworkStackErrorTest.swift | 36 +++++++++--------- .../JSONArrayRessourceTest.swift | 36 +++++++++--------- DBNetworkStackTests/JSONRessourceTest.swift | 36 +++++++++--------- .../MultipartFormDataUploadServiceTests.swift | 36 +++++++++--------- DBNetworkStackTests/NetworkRequestTest.swift | 36 +++++++++--------- DBNetworkStackTests/NetworkServiceMock.swift | 36 +++++++++--------- DBNetworkStackTests/NetworkServiceTest.swift | 36 +++++++++--------- DBNetworkStackTests/NetworkTaskMock.swift | 36 +++++++++--------- DBNetworkStackTests/RessourceTest.swift | 36 +++++++++--------- DBNetworkStackTests/TrainModel.swift | 36 +++++++++--------- .../URLSessionNetworkAccessTest.swift | 36 +++++++++--------- .../UploadAccessServiceMock.swift | 36 +++++++++--------- 37 files changed, 703 insertions(+), 641 deletions(-) diff --git a/DBNetworkStack/ArrayRessourceModeling.swift b/DBNetworkStack/ArrayRessourceModeling.swift index c81b8cf..b42df42 100644 --- a/DBNetworkStack/ArrayRessourceModeling.swift +++ b/DBNetworkStack/ArrayRessourceModeling.swift @@ -1,24 +1,26 @@ // // ArrayRessourceModeling.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 11.10.16. // diff --git a/DBNetworkStack/BaseURLKey.swift b/DBNetworkStack/BaseURLKey.swift index c31185a..391ba44 100644 --- a/DBNetworkStack/BaseURLKey.swift +++ b/DBNetworkStack/BaseURLKey.swift @@ -1,24 +1,26 @@ // // BaseURLKey.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 30.08.16. // diff --git a/DBNetworkStack/BaseURLProviding.swift b/DBNetworkStack/BaseURLProviding.swift index 8af8fda..3c0162e 100644 --- a/DBNetworkStack/BaseURLProviding.swift +++ b/DBNetworkStack/BaseURLProviding.swift @@ -1,31 +1,31 @@ // // BaseURLProviding.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. // -// Created by Christian Himmelsbach on 29.09.16. +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // -// DBNetworkStack +// Created by Christian Himmelsbach on 29.09.16. // + import Foundation internal protocol BaseURLProviding { diff --git a/DBNetworkStack/DBNetworkStack.h b/DBNetworkStack/DBNetworkStack.h index 3d49ec5..50e5848 100644 --- a/DBNetworkStack/DBNetworkStack.h +++ b/DBNetworkStack/DBNetworkStack.h @@ -1,24 +1,26 @@ // // DBNetworkStack.h -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 22.08.16. // diff --git a/DBNetworkStack/DBNetworkStackTypes.swift b/DBNetworkStack/DBNetworkStackTypes.swift index 3ffe29a..b25d029 100644 --- a/DBNetworkStack/DBNetworkStackTypes.swift +++ b/DBNetworkStack/DBNetworkStackTypes.swift @@ -1,24 +1,26 @@ // // DBNetworkStackTypes.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 23.08.16. // diff --git a/DBNetworkStack/HTTPMethod.swift b/DBNetworkStack/HTTPMethod.swift index 7c0d81a..2e22cf0 100644 --- a/DBNetworkStack/HTTPMethod.swift +++ b/DBNetworkStack/HTTPMethod.swift @@ -1,24 +1,26 @@ // // HTTPMethod.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 21.07.16. // diff --git a/DBNetworkStack/JSONArrayRessource.swift b/DBNetworkStack/JSONArrayRessource.swift index c515027..be5fbb6 100644 --- a/DBNetworkStack/JSONArrayRessource.swift +++ b/DBNetworkStack/JSONArrayRessource.swift @@ -1,24 +1,26 @@ // // JSONListRessource.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 27.07.16. // diff --git a/DBNetworkStack/JSONMappable.swift b/DBNetworkStack/JSONMappable.swift index a4dccfe..bf69a9c 100644 --- a/DBNetworkStack/JSONMappable.swift +++ b/DBNetworkStack/JSONMappable.swift @@ -1,24 +1,26 @@ // // JSONMappable.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 30.08.16. // diff --git a/DBNetworkStack/JSONRessource.swift b/DBNetworkStack/JSONRessource.swift index 64d40d5..a6be76e 100644 --- a/DBNetworkStack/JSONRessource.swift +++ b/DBNetworkStack/JSONRessource.swift @@ -1,24 +1,26 @@ // // JSONRessource.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 22.07.16. // diff --git a/DBNetworkStack/JSONRessourceModeling.swift b/DBNetworkStack/JSONRessourceModeling.swift index 598c86f..5d8a0e3 100644 --- a/DBNetworkStack/JSONRessourceModeling.swift +++ b/DBNetworkStack/JSONRessourceModeling.swift @@ -1,24 +1,26 @@ // // JSONRessourceModeling.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 27.07.16. // diff --git a/DBNetworkStack/MultipartFormDataRessource.swift b/DBNetworkStack/MultipartFormDataRessource.swift index 4dd7d17..a4cdf09 100644 --- a/DBNetworkStack/MultipartFormDataRessource.swift +++ b/DBNetworkStack/MultipartFormDataRessource.swift @@ -1,31 +1,31 @@ // // MultipartFormDataRessource.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. // -// Created by Christian Himmelsbach on 27.09.16. +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // -// DBNetworkStack +// Created by Christian Himmelsbach on 27.09.16. // + import Foundation public struct MultipartFormDataRessource: MultipartFormDataRessourceModelling { diff --git a/DBNetworkStack/MultipartFormDataRessourceModelling.swift b/DBNetworkStack/MultipartFormDataRessourceModelling.swift index 642c4cf..d216cb7 100644 --- a/DBNetworkStack/MultipartFormDataRessourceModelling.swift +++ b/DBNetworkStack/MultipartFormDataRessourceModelling.swift @@ -1,31 +1,31 @@ // // MultipartFormDataRessourceModelling.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. // -// Created by Christian Himmelsbach on 27.09.16. +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // -// DBNetworkStack +// Created by Christian Himmelsbach on 27.09.16. // + import Foundation public protocol MultipartFormDataRessourceModelling: RessourceModeling { diff --git a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift index a7e802c..5744e10 100644 --- a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift @@ -1,31 +1,31 @@ // // MultipartFormDataUploadAccessProviding.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. // -// Created by Christian Himmelsbach on 27.09.16. +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // -// DBNetworkStack +// Created by Christian Himmelsbach on 27.09.16. // + import Foundation public protocol MultipartFormDataUploadAccessProviding { diff --git a/DBNetworkStack/MultipartFormDataUploadService.swift b/DBNetworkStack/MultipartFormDataUploadService.swift index ba73536..6c79d56 100644 --- a/DBNetworkStack/MultipartFormDataUploadService.swift +++ b/DBNetworkStack/MultipartFormDataUploadService.swift @@ -1,31 +1,31 @@ // // MultipartFormDataUploadService.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. // -// Created by Christian Himmelsbach on 29.09.16. +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // -// DBNetworkStack +// Created by Christian Himmelsbach on 29.09.16. // + import Foundation public final class MultipartFormDataUploadService: MultipartFormDataUploadServiceProviding, NetworkResponseProcessing, BaseURLProviding { diff --git a/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift index 220a1b9..7557aeb 100644 --- a/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift @@ -1,31 +1,31 @@ // // MultipartUploadPoviderServiceProviding.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. // -// Created by Christian Himmelsbach on 27.09.16. +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // -// DBNetworkStack +// Created by Christian Himmelsbach on 27.09.16. // + import Foundation public protocol MultipartFormDataUploadServiceProviding { diff --git a/DBNetworkStack/NetworkAccessProviding.swift b/DBNetworkStack/NetworkAccessProviding.swift index 587aabe..121d3d6 100644 --- a/DBNetworkStack/NetworkAccessProviding.swift +++ b/DBNetworkStack/NetworkAccessProviding.swift @@ -1,24 +1,26 @@ // // NetworkAccessProviding.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 31.08.16. // diff --git a/DBNetworkStack/NetworkRequest.swift b/DBNetworkStack/NetworkRequest.swift index 5a7af3f..622fa09 100644 --- a/DBNetworkStack/NetworkRequest.swift +++ b/DBNetworkStack/NetworkRequest.swift @@ -1,24 +1,26 @@ // // NetworkRequest.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 21.07.16. // diff --git a/DBNetworkStack/NetworkRequestRepresening.swift b/DBNetworkStack/NetworkRequestRepresening.swift index 8963a59..bcd42d0 100644 --- a/DBNetworkStack/NetworkRequestRepresening.swift +++ b/DBNetworkStack/NetworkRequestRepresening.swift @@ -1,24 +1,26 @@ // // NetworkResourceRepresening.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 21.07.16. // diff --git a/DBNetworkStack/NetworkService.swift b/DBNetworkStack/NetworkService.swift index c147312..62b904d 100644 --- a/DBNetworkStack/NetworkService.swift +++ b/DBNetworkStack/NetworkService.swift @@ -1,24 +1,26 @@ // // NetworkService.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 31.08.16. // diff --git a/DBNetworkStack/NetworkServiceProviding.swift b/DBNetworkStack/NetworkServiceProviding.swift index 22597e8..c7bb8cc 100644 --- a/DBNetworkStack/NetworkServiceProviding.swift +++ b/DBNetworkStack/NetworkServiceProviding.swift @@ -1,24 +1,26 @@ // // NetworkServiceProviding.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 21.07.16. // diff --git a/DBNetworkStack/NetworkTask.swift b/DBNetworkStack/NetworkTask.swift index d9f4640..9b1b45a 100644 --- a/DBNetworkStack/NetworkTask.swift +++ b/DBNetworkStack/NetworkTask.swift @@ -1,24 +1,26 @@ // // CancelableRequest.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 22.08.16. // diff --git a/DBNetworkStack/Ressource.swift b/DBNetworkStack/Ressource.swift index 1e5aaab..cc79f9a 100644 --- a/DBNetworkStack/Ressource.swift +++ b/DBNetworkStack/Ressource.swift @@ -1,24 +1,26 @@ // // Ressource.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 21.07.16. // diff --git a/DBNetworkStack/RessourceModeling.swift b/DBNetworkStack/RessourceModeling.swift index 2252c58..7f908c9 100644 --- a/DBNetworkStack/RessourceModeling.swift +++ b/DBNetworkStack/RessourceModeling.swift @@ -1,24 +1,26 @@ // // RessourceModeling.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 21.07.16. // diff --git a/DBNetworkStack/URLSessionNetworkAccess.swift b/DBNetworkStack/URLSessionNetworkAccess.swift index 7b37445..57c2383 100644 --- a/DBNetworkStack/URLSessionNetworkAccess.swift +++ b/DBNetworkStack/URLSessionNetworkAccess.swift @@ -1,24 +1,26 @@ // // URLSessionNetworkAccess.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 05.09.16. // diff --git a/DBNetworkStackTests/BaseURLKeyTest.swift b/DBNetworkStackTests/BaseURLKeyTest.swift index eb9c2fa..5d1a345 100644 --- a/DBNetworkStackTests/BaseURLKeyTest.swift +++ b/DBNetworkStackTests/BaseURLKeyTest.swift @@ -1,24 +1,26 @@ // // BaseURLKeyTest.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 16.09.16. // diff --git a/DBNetworkStackTests/DBNetworkStackErrorTest.swift b/DBNetworkStackTests/DBNetworkStackErrorTest.swift index aaa230d..d817d74 100644 --- a/DBNetworkStackTests/DBNetworkStackErrorTest.swift +++ b/DBNetworkStackTests/DBNetworkStackErrorTest.swift @@ -1,24 +1,26 @@ // // DBNetworkStackErrorTest.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 20.09.16. // diff --git a/DBNetworkStackTests/JSONArrayRessourceTest.swift b/DBNetworkStackTests/JSONArrayRessourceTest.swift index 0809f00..c1b7f69 100644 --- a/DBNetworkStackTests/JSONArrayRessourceTest.swift +++ b/DBNetworkStackTests/JSONArrayRessourceTest.swift @@ -1,24 +1,26 @@ // // JSONArrayRessourceTest.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 01.09.16. // diff --git a/DBNetworkStackTests/JSONRessourceTest.swift b/DBNetworkStackTests/JSONRessourceTest.swift index 164d202..706865d 100644 --- a/DBNetworkStackTests/JSONRessourceTest.swift +++ b/DBNetworkStackTests/JSONRessourceTest.swift @@ -1,24 +1,26 @@ // // JSONRessourceTest.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 30.08.16. // diff --git a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift index 5406e53..2deb75e 100644 --- a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift +++ b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift @@ -1,24 +1,26 @@ // // MultipartFormDataUploadServiceTests.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Christian Himmelsbach on 29.09.16. // diff --git a/DBNetworkStackTests/NetworkRequestTest.swift b/DBNetworkStackTests/NetworkRequestTest.swift index 7f409cc..e348a0e 100644 --- a/DBNetworkStackTests/NetworkRequestTest.swift +++ b/DBNetworkStackTests/NetworkRequestTest.swift @@ -1,24 +1,26 @@ // // NetworkRequestTest.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 20.09.16. // diff --git a/DBNetworkStackTests/NetworkServiceMock.swift b/DBNetworkStackTests/NetworkServiceMock.swift index 4a6e47a..95dafbd 100644 --- a/DBNetworkStackTests/NetworkServiceMock.swift +++ b/DBNetworkStackTests/NetworkServiceMock.swift @@ -1,24 +1,26 @@ // // NetworkServiceMock.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 30.08.16. // diff --git a/DBNetworkStackTests/NetworkServiceTest.swift b/DBNetworkStackTests/NetworkServiceTest.swift index f6bdebe..91a23c1 100644 --- a/DBNetworkStackTests/NetworkServiceTest.swift +++ b/DBNetworkStackTests/NetworkServiceTest.swift @@ -1,24 +1,26 @@ // // NetworkServiceTest.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 26.07.16. // diff --git a/DBNetworkStackTests/NetworkTaskMock.swift b/DBNetworkStackTests/NetworkTaskMock.swift index 53a2591..cca136e 100644 --- a/DBNetworkStackTests/NetworkTaskMock.swift +++ b/DBNetworkStackTests/NetworkTaskMock.swift @@ -1,24 +1,26 @@ // // NetworkTaskMock.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Christian Himmelsbach on 29.09.16. // diff --git a/DBNetworkStackTests/RessourceTest.swift b/DBNetworkStackTests/RessourceTest.swift index 80008ab..afd4469 100644 --- a/DBNetworkStackTests/RessourceTest.swift +++ b/DBNetworkStackTests/RessourceTest.swift @@ -1,24 +1,26 @@ // // RessourceTest.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 01.09.16. // diff --git a/DBNetworkStackTests/TrainModel.swift b/DBNetworkStackTests/TrainModel.swift index 18bcb4b..fa84049 100644 --- a/DBNetworkStackTests/TrainModel.swift +++ b/DBNetworkStackTests/TrainModel.swift @@ -1,24 +1,26 @@ // // TrainModel.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 31.08.16. // diff --git a/DBNetworkStackTests/URLSessionNetworkAccessTest.swift b/DBNetworkStackTests/URLSessionNetworkAccessTest.swift index 67e46fd..82c3fea 100644 --- a/DBNetworkStackTests/URLSessionNetworkAccessTest.swift +++ b/DBNetworkStackTests/URLSessionNetworkAccessTest.swift @@ -1,24 +1,26 @@ // // URLSessionNetworkAccessTest.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Lukas Schmidt on 13.09.16. // diff --git a/DBNetworkStackTests/UploadAccessServiceMock.swift b/DBNetworkStackTests/UploadAccessServiceMock.swift index 19d3a1f..5163986 100644 --- a/DBNetworkStackTests/UploadAccessServiceMock.swift +++ b/DBNetworkStackTests/UploadAccessServiceMock.swift @@ -1,24 +1,26 @@ // // UploadAccessServiceMock.swift -// DBNetworkStack // -// Legal Notice! DB Systel GmbH proprietary License! -// -// Copyright (C) 2015 DB Systel GmbH -// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// This code is protected by copyright law and is the exclusive property of +// Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ - -// Consent to use ("licence") shall be granted solely on the basis of a -// written licence agreement signed by the customer and DB Systel GmbH. Any -// other use, in particular copying, redistribution, publication or -// modification of this code without written permission of DB Systel GmbH is -// expressly prohibited. - -// In the event of any permitted copying, redistribution or publication of -// this code, no changes in or deletion of author attribution, trademark -// legend or copyright notice shall be made. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. // // Created by Christian Himmelsbach on 29.09.16. // From e8c9cddb0f52ec32e8e9808c713b80610912f10e Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 11 Oct 2016 08:19:49 +0200 Subject: [PATCH 20/92] Removes old playgrounds --- .../contents.xcworkspacedata | 6 -- Demo.playground/Contents.swift | 56 ------------- Demo.playground/contents.xcplayground | 4 - Demo.playground/timeline.xctimeline | 6 -- Experiments.playground/Contents.swift | 83 ------------------- Experiments.playground/contents.xcplayground | 4 - 6 files changed, 159 deletions(-) delete mode 100644 Demo.playground/Contents.swift delete mode 100644 Demo.playground/contents.xcplayground delete mode 100644 Demo.playground/timeline.xctimeline delete mode 100644 Experiments.playground/Contents.swift delete mode 100644 Experiments.playground/contents.xcplayground diff --git a/DBNetworkStack.xcworkspace/contents.xcworkspacedata b/DBNetworkStack.xcworkspace/contents.xcworkspacedata index 609fe15..4db1d7c 100644 --- a/DBNetworkStack.xcworkspace/contents.xcworkspacedata +++ b/DBNetworkStack.xcworkspace/contents.xcworkspacedata @@ -1,12 +1,6 @@ - - - - diff --git a/Demo.playground/Contents.swift b/Demo.playground/Contents.swift deleted file mode 100644 index 2dd6344..0000000 --- a/Demo.playground/Contents.swift +++ /dev/null @@ -1,56 +0,0 @@ -//: Playground - noun: a place where people can play - -import UIKit -@testable import DBNetworkStack -import XCPlayground - -XCPlaygroundPage.currentPage.needsIndefiniteExecution = true - -public struct Station { - public let id: String - public let name: String -} - -extension Station: JSONMappable { - public init(object: [String: AnyObject]) throws { - id = object["id"] as! String - name = object["name"] as! String - } -} - -enum BaseURLs: String, BaseURLKey { - case BFA - case BahnDE - - var name: String { - return rawValue - } - - var URL: NSURL { - switch self { - case BFA: - return NSURL(string: "https://dbbfa.herokuapp.com/")! - case .BahnDE: - return NSURL(string: "https://www.bahn.de")! - } - } -} - -let baseURL = BaseURLs.BFA -let urlSessionNetworkAccess = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration()) -let service = NetworkService(networkAccess: urlSessionNetworkAccess, endPoints: [baseURL.name: baseURL.URL]) - -let searchTerm = "Frankfurt" - -let path = ("/v1/station/search") -let request = NetworkRequest(path: path, baseURLKey: baseURL, parameter: ["term": searchTerm]) -request.absoluteURLWith(baseURL.url).absoluteString -let ressource = JSONArrayRessource(request: request) - -let task = service.fetch(ressource, onCompletion: { station in - print(station) - }, onError: { error in - print(error) -}) - -print(task.progress) diff --git a/Demo.playground/contents.xcplayground b/Demo.playground/contents.xcplayground deleted file mode 100644 index 5da2641..0000000 --- a/Demo.playground/contents.xcplayground +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Demo.playground/timeline.xctimeline b/Demo.playground/timeline.xctimeline deleted file mode 100644 index bf468af..0000000 --- a/Demo.playground/timeline.xctimeline +++ /dev/null @@ -1,6 +0,0 @@ - - - - - diff --git a/Experiments.playground/Contents.swift b/Experiments.playground/Contents.swift deleted file mode 100644 index f40485c..0000000 --- a/Experiments.playground/Contents.swift +++ /dev/null @@ -1,83 +0,0 @@ -//: Playground - noun: a place where people can play - -import UIKit -import DBNetworkStack -import XCPlayground -//import Alamofire - -XCPlaygroundPage.currentPage.needsIndefiniteExecution = true - -struct Formular { - let text: String - let image: UIImage -} - -struct Report { - init(data: NSData) throws { - - } -} - -// Mock - -struct MyNetworkTask: NetworkTask { - func cancel() { - - } - func resume() { - - } - func suspend() { - - } - - var progress = NSProgress() -} -struct UploadAccessMock: MultipartFormDataUploadAccessProviding { - func upload(request: NetworkRequestRepresening, relativeToBaseURL: NSURL, multipartFormData: (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock?) { - - dispatch_async(dispatch_get_main_queue()) { - onNetworkTaskCreation?(MyNetworkTask()) - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(2.0)*Int64(NSEC_PER_SEC)), dispatch_get_main_queue(), { - callback(NSData(),nil,nil) - }) - } - - } -} - -enum APIs: String, BaseURLKey { - case BFA - - var name: String { - return rawValue - } - var URL: NSURL { - return NSURL(string: "https://dbbfa.herokuapp.com/")! - } -} - -let formular = Formular(text: "hallo", image: UIImage()) -let ressource = MultipartFormDataRessource( - request: NetworkRequest(path: "", baseURLKey: APIs.BFA), - parse: { try Report(data: $0) }, - encodingMemoryThreshold: 1000, - encodeInMultipartFormData: {multipartFormData in - multipartFormData.appendBodyPart(data: formular.text.dataUsingEncoding(NSUTF8StringEncoding)!, name: "text") - multipartFormData.appendBodyPart(data: UIImagePNGRepresentation(formular.image)!, name: "image") -}) -let baseURL = APIs.BFA -let service = MultipartFormDataUploadService( - uploadAccess: UploadAccessMock(), - endPoints: [baseURL.name:baseURL.URL] -) - -service.upload(ressource, onCompletion: { report in - print("Nicey: \(report)") -}, onError: { error in - print("Error: \(error)") -}, onNetworkTaskCreation: { task in - print("Task created") - -}) diff --git a/Experiments.playground/contents.xcplayground b/Experiments.playground/contents.xcplayground deleted file mode 100644 index 5da2641..0000000 --- a/Experiments.playground/contents.xcplayground +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From 2bbb511765ec93a0aae64d2ebe83e675ce16b23a Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 11 Oct 2016 16:00:14 +0200 Subject: [PATCH 21/92] Cross platform support --- DBNetworkStack.xcodeproj/project.pbxproj | 14 ++++++++++++-- DBNetworkStack/DBNetworkStack.h | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index 87b35f3..d524c51 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -461,14 +461,18 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 9.0; + MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 2.3; - TARGETED_DEVICE_FAMILY = "1,2"; + 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; }; @@ -505,13 +509,17 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 9.0; + MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; SWIFT_VERSION = 2.3; - TARGETED_DEVICE_FAMILY = "1,2"; + 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; }; @@ -560,6 +568,7 @@ FRAMEWORK_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = DBNetworkStackTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.dbsystel.DBNetworkStackTests; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -571,6 +580,7 @@ FRAMEWORK_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = DBNetworkStackTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.dbsystel.DBNetworkStackTests; PRODUCT_NAME = "$(TARGET_NAME)"; }; diff --git a/DBNetworkStack/DBNetworkStack.h b/DBNetworkStack/DBNetworkStack.h index 50e5848..1205f6a 100644 --- a/DBNetworkStack/DBNetworkStack.h +++ b/DBNetworkStack/DBNetworkStack.h @@ -25,7 +25,7 @@ // Created by Lukas Schmidt on 22.08.16. // -#import +#import //! Project version number for DBNetworkStack. FOUNDATION_EXPORT double DBNetworkStackVersionNumber; From bae5e0f07c3a1b8418089aa0e5bfc4c1094aaad6 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 11 Oct 2016 16:00:49 +0200 Subject: [PATCH 22/92] Fixes tests --- DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift index 2deb75e..edf5fd2 100644 --- a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift +++ b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift @@ -37,7 +37,7 @@ class MultipartFormDataUploadServiceTests: XCTestCase { super.setUp() service = MultipartFormDataUploadService( uploadAccess: networkAccess, - endPoints: [ TestEndPoints.EndPoint.name: NSURL()] + endPoints: [ TestEndPoints.EndPoint.name: NSURL(string: "http://bahn.de")!] ) } From c1eff1966d79b1adf4a3d6e55e1d97926b49c2ce Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 11 Oct 2016 16:05:36 +0200 Subject: [PATCH 23/92] Cross Plattform Travis --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0a81592 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: objective-c +osx_image: xcode8 + +env: + - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' + - ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' + - ACTION=build PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' + - ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' + +script: + - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION | xcpretty \ No newline at end of file From 5d80605b9ad9f9b9ad736694796cfa9cbe5815f5 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 11 Oct 2016 16:08:54 +0200 Subject: [PATCH 24/92] Lint --- DBNetworkStack/BaseURLProviding.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/DBNetworkStack/BaseURLProviding.swift b/DBNetworkStack/BaseURLProviding.swift index 3c0162e..86755ca 100644 --- a/DBNetworkStack/BaseURLProviding.swift +++ b/DBNetworkStack/BaseURLProviding.swift @@ -25,7 +25,6 @@ // Created by Christian Himmelsbach on 29.09.16. // - import Foundation internal protocol BaseURLProviding { From 8ecc583254b3c23944d9ee799e77fadac66ff724 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 11 Oct 2016 16:36:05 +0200 Subject: [PATCH 25/92] Adds travis build badge --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7183c35..d466875 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # DBNetworkStack -[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) +[![Build Status](https://travis-ci.com/lightsprint09/DBNetworkStackTemp.svg?token=DoSuqFLfFsZgTxGUxHry&branch=feature/cross-plattorm-project)](https://travis-ci.com/lightsprint09/DBNetworkStackTemp) +[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) DBNetworkStack is a network abstraction for fetching request and mapping them to model objects. It is build completely on protocols so every layer can be exchanged and is well testable. The idea behind comes from this [article](https://talk.objc.io/episodes/S01E01-networking) From 313d739c0a7d551e5529d42259781642e355011a Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 11 Oct 2016 17:11:06 +0200 Subject: [PATCH 26/92] Simple demo example --- .../contents.xcworkspacedata | 3 +++ SimpleDemo.playground/Contents.swift | 22 +++++++++++++++++++ SimpleDemo.playground/contents.xcplayground | 4 ++++ 3 files changed, 29 insertions(+) create mode 100644 SimpleDemo.playground/Contents.swift create mode 100644 SimpleDemo.playground/contents.xcplayground diff --git a/DBNetworkStack.xcworkspace/contents.xcworkspacedata b/DBNetworkStack.xcworkspace/contents.xcworkspacedata index 4db1d7c..76ffa68 100644 --- a/DBNetworkStack.xcworkspace/contents.xcworkspacedata +++ b/DBNetworkStack.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,9 @@ + + diff --git a/SimpleDemo.playground/Contents.swift b/SimpleDemo.playground/Contents.swift new file mode 100644 index 0000000..6e8eeda --- /dev/null +++ b/SimpleDemo.playground/Contents.swift @@ -0,0 +1,22 @@ +//: Playground - noun: a place where people can play + +import UIKit +import DBNetworkStack +import XCPlayground + +XCPlaygroundPage.currentPage.needsIndefiniteExecution = true + +let url = NSURL(string: "https://httpbin.org")! +let baseURLKey = "httpBin" + +let networkAccess = NSURLSession(configuration: .defaultSessionConfiguration()) +let networkService = NetworkService(networkAccess: networkAccess, endPoints: [baseURLKey: url]) + +let request = NetworkRequest(path: "/", baseURLKey: baseURLKey) +let ressource = Ressource(request: request, parse: { String(data: $0, encoding: NSUTF8StringEncoding) }) + +networkService.request(ressource, onCompletion: { htmlText in + print(htmlText) + }, onError: { error in + //Handle errors +}) diff --git a/SimpleDemo.playground/contents.xcplayground b/SimpleDemo.playground/contents.xcplayground new file mode 100644 index 0000000..5da2641 --- /dev/null +++ b/SimpleDemo.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From 1a843db22d268e551969f8a791babb439fec2917 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Thu, 13 Oct 2016 06:43:13 +0200 Subject: [PATCH 27/92] More readme --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d466875..60196d2 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,12 @@ [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) -DBNetworkStack is a network abstraction for fetching request and mapping them to model objects. It is build completely on protocols so every layer can be exchanged and is well testable. The idea behind comes from this [article](https://talk.objc.io/episodes/S01E01-networking) +DBNetworkStack is a network abstraction for fetching request and mapping them to model objects. It is build completely on protocols so every layer can be exchanged and is well testable. The idea behind comes from this [article](https://talk.objc.io/episodes/S01E01-networking) + + | Main Features +---------|--------------- +🙅 | Typed network ressources +🏠 | Protocol oriented architecture +🔀| Exchangeable Implemntations +🚄 | Extendable API +✅ | Fully unit tested From 1cd089ae5125c04e8ade188b14e94b245ed2506d Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Thu, 13 Oct 2016 13:11:10 +0200 Subject: [PATCH 28/92] Adds two demo playgrounds --- .../contents.xcworkspacedata | 3 ++ JSONExample.playground/Contents.swift | 35 +++++++++++++++++++ JSONExample.playground/contents.xcplayground | 4 +++ SimpleDemo.playground/Contents.swift | 1 - 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 JSONExample.playground/Contents.swift create mode 100644 JSONExample.playground/contents.xcplayground diff --git a/DBNetworkStack.xcworkspace/contents.xcworkspacedata b/DBNetworkStack.xcworkspace/contents.xcworkspacedata index 76ffa68..73f046b 100644 --- a/DBNetworkStack.xcworkspace/contents.xcworkspacedata +++ b/DBNetworkStack.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,9 @@ + + diff --git a/JSONExample.playground/Contents.swift b/JSONExample.playground/Contents.swift new file mode 100644 index 0000000..818d2a6 --- /dev/null +++ b/JSONExample.playground/Contents.swift @@ -0,0 +1,35 @@ +//: Playground - noun: a place where people can play + +import DBNetworkStack +import XCPlayground + +XCPlaygroundPage.currentPage.needsIndefiniteExecution = true + +let url = NSURL(string: "https://httpbin.org")! +let baseURLKey = "httpBin" + +let networkAccess = NSURLSession(configuration: .defaultSessionConfiguration()) +let networkService = NetworkService(networkAccess: networkAccess, endPoints: [baseURLKey: url]) + +struct IPOrigin { + let ip: String +} + +extension IPOrigin: JSONMappable { + init(object: Dictionary) throws { + guard let ip = object["origin"] as? String else { + throw DBNetworkStackError.SerializationError(description: "", data: nil) + } + self.ip = ip + } +} + +let request = NetworkRequest(path: "/ip", baseURLKey: baseURLKey) +let ressource = JSONRessource(request: request) + +networkService.request(ressource, onCompletion: { htmlText in + print(htmlText) + }, onError: { error in + //Handle errors +}) + diff --git a/JSONExample.playground/contents.xcplayground b/JSONExample.playground/contents.xcplayground new file mode 100644 index 0000000..5da2641 --- /dev/null +++ b/JSONExample.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/SimpleDemo.playground/Contents.swift b/SimpleDemo.playground/Contents.swift index 6e8eeda..c956524 100644 --- a/SimpleDemo.playground/Contents.swift +++ b/SimpleDemo.playground/Contents.swift @@ -1,6 +1,5 @@ //: Playground - noun: a place where people can play -import UIKit import DBNetworkStack import XCPlayground From 9db7ab246f9c12c768d4eb84edd9729b84150b2c Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Thu, 13 Oct 2016 13:16:44 +0200 Subject: [PATCH 29/92] Adds documentation for ArrayRessourceModeling --- DBNetworkStack/ArrayRessourceModeling.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DBNetworkStack/ArrayRessourceModeling.swift b/DBNetworkStack/ArrayRessourceModeling.swift index b42df42..00c434c 100644 --- a/DBNetworkStack/ArrayRessourceModeling.swift +++ b/DBNetworkStack/ArrayRessourceModeling.swift @@ -27,6 +27,10 @@ import Foundation +/** + `ArrayRessourceModeling` describes a remote ressource of generic type structured in an array. + The ressource type can be fetched via HTTP(s) and parsed into the coresponding model object. + */ protocol ArrayRessourceModeling: RessourceModeling { associatedtype Element associatedtype Model = Array From b0dd640f36d32ec66e50024bd1d4ef56d4cd0beb Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Thu, 13 Oct 2016 13:25:36 +0200 Subject: [PATCH 30/92] Adds documentation --- DBNetworkStack/MultipartFormDataRepresenting.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/DBNetworkStack/MultipartFormDataRepresenting.swift b/DBNetworkStack/MultipartFormDataRepresenting.swift index 3b95706..3ba4bcd 100644 --- a/DBNetworkStack/MultipartFormDataRepresenting.swift +++ b/DBNetworkStack/MultipartFormDataRepresenting.swift @@ -23,6 +23,18 @@ // import Foundation +/// Constructs `multipart/form-data` for uploads within an HTTP or HTTPS body. There are currently two ways to encode +/// multipart form data. The first way is to encode the data directly in memory. This is very efficient, but can lead +/// to memory issues if the dataset is too large. The second way is designed for larger datasets and will write all the +/// data to a single file on disk with all the proper boundary segmentation. The second approach MUST be used for +/// larger datasets such as video content, otherwise your app may run out of memory when trying to encode the dataset. +/// +/// For more information on `multipart/form-data` in general, please refer to the RFC-2388 and RFC-2045 specs as well +/// and the w3 form documentation. +/// +/// - https://www.ietf.org/rfc/rfc2388.txt +/// - https://www.ietf.org/rfc/rfc2045.txt +/// - https://www.w3.org/TR/html401/interact/forms.html#h-17.13 public protocol MultipartFormDataRepresenting: class { // MARK: - Properties From 4faec89b72622aeb9311ebe8ecd5313732ae901c Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Thu, 13 Oct 2016 17:15:44 +0200 Subject: [PATCH 31/92] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 60196d2..8f9d6ec 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,6 @@ DBNetworkStack is a network abstraction for fetching request and mapping them to ---------|--------------- 🙅 | Typed network ressources 🏠 | Protocol oriented architecture -🔀| Exchangeable Implemntations +🔀| Exchangeable Implementations 🚄 | Extendable API ✅ | Fully unit tested From 15a03f38e889335b371d760d7a524030824d669c Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Thu, 13 Oct 2016 17:25:18 +0200 Subject: [PATCH 32/92] Updates readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f9d6ec..f639165 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) -DBNetworkStack is a network abstraction for fetching request and mapping them to model objects. It is build completely on protocols so every layer can be exchanged and is well testable. The idea behind comes from this [article](https://talk.objc.io/episodes/S01E01-networking) +DBNetworkStack is a network abstraction for fetching request and mapping them to model objects. | Main Features ---------|--------------- @@ -13,3 +13,5 @@ DBNetworkStack is a network abstraction for fetching request and mapping them to 🔀| Exchangeable Implementations 🚄 | Extendable API ✅ | Fully unit tested + +The idea behind this project comes from this [talk.objc.io article](https://talk.objc.io/episodes/S01E01-networking). From 66ab2da075da924122f8649cb90ff986413319b2 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Thu, 13 Oct 2016 18:14:55 +0200 Subject: [PATCH 33/92] Installation guide --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index f639165..d3dd22b 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,16 @@ DBNetworkStack is a network abstraction for fetching request and mapping them to ✅ | Fully unit tested The idea behind this project comes from this [talk.objc.io article](https://talk.objc.io/episodes/S01E01-networking). + +## Installation + +### Carthage + +[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. + +Specify the following in your `Cartfile`: + +```ogdl +github "dbsystel/dbnetworkstack" ~> 0.1 +``` + From 4623733798f94102a760bfe1d927c5bced695152 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 08:32:51 +0200 Subject: [PATCH 34/92] Service creation example --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d3dd22b..0fc6ea2 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,28 @@ DBNetworkStack is a network abstraction for fetching request and mapping them to | Main Features ---------|--------------- -🙅 | Typed network ressources +🛡 | Typed network ressources 🏠 | Protocol oriented architecture -🔀| Exchangeable Implementations +🔀| Exchangeable implementations 🚄 | Extendable API ✅ | Fully unit tested The idea behind this project comes from this [talk.objc.io article](https://talk.objc.io/episodes/S01E01-networking). +## Basic Demo +Lets say you want to fetch a ``html`` string. + +First you have to create a service, by providing a networkaccess. You can use NSURLSession out of the box or provide your own custom solution by implementing ```NetworkAccessProviding```. In addition you need to register baseURLs for request mapping. This gives you the flexability to change your baseURLs very easyly when your envionment changes. + +```swift +let url = NSURL(string: "https://httpbin.org")! +let baseURLKey = "httpBin" + +let networkAccess = NSURLSession(configuration: .defaultSessionConfiguration()) +let networkService = NetworkService(networkAccess: networkAccess, endPoints: [baseURLKey: url]) +``` + + ## Installation ### Carthage From 39f10efe5347c5a25461dea9950319ceb21a412b Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 08:37:30 +0200 Subject: [PATCH 35/92] Adds example for requesting ressources --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 0fc6ea2..92bc722 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,32 @@ Lets say you want to fetch a ``html`` string. First you have to create a service, by providing a networkaccess. You can use NSURLSession out of the box or provide your own custom solution by implementing ```NetworkAccessProviding```. In addition you need to register baseURLs for request mapping. This gives you the flexability to change your baseURLs very easyly when your envionment changes. ```swift + let url = NSURL(string: "https://httpbin.org")! let baseURLKey = "httpBin" let networkAccess = NSURLSession(configuration: .defaultSessionConfiguration()) let networkService = NetworkService(networkAccess: networkAccess, endPoints: [baseURLKey: url]) + +``` + +Create a ressource with a request to fetch your data. + +```swift + +let request = NetworkRequest(path: "/", baseURLKey: baseURLKey) +let ressource = Ressource(request: request, parse: { String(data: $0, encoding: NSUTF8StringEncoding) }) + ``` +Request your ressource and handle the response +```swift +networkService.request(ressource, onCompletion: { htmlText in + print(htmlText) + }, onError: { error in + //Handle errors +}) +``` ## Installation From 14244b5a0aa2ccd54a3cfdcebd30e197079d5c78 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 10:43:33 +0200 Subject: [PATCH 36/92] Fixes readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92bc722..7c07dea 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ The idea behind this project comes from this [talk.objc.io article](https://talk ## Basic Demo Lets say you want to fetch a ``html`` string. -First you have to create a service, by providing a networkaccess. You can use NSURLSession out of the box or provide your own custom solution by implementing ```NetworkAccessProviding```. In addition you need to register baseURLs for request mapping. This gives you the flexability to change your baseURLs very easyly when your envionment changes. +First you have to create a service, by providing a networkaccess. You can use NSURLSession out of the box or provide your own custom solution by implementing ```NetworkAccessProviding```. In addition you need to register baseURLs endpoints for request mapping. This gives you the flexability to change your endpoints very easyly when your envionment changes. ```swift From d13b1dadbda94e897404642e725d0da0b245a220 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 10:46:14 +0200 Subject: [PATCH 37/92] Adds system requirements to readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 7c07dea..a5c60eb 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,12 @@ networkService.request(ressource, onCompletion: { htmlText in ``` +## Requirements + +- iOS 9.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ +- Xcode 7.3+ +- Swift 2.2/2.3 + ## Installation ### Carthage From 661a88245ec57b04cc2c6763bd7f0afab98c32b9 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 11:03:47 +0200 Subject: [PATCH 38/92] Adds JSON mapping example to readme --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index a5c60eb..04412d4 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,28 @@ networkService.request(ressource, onCompletion: { htmlText in ``` +## JSON Mapping +```swift +struct IPOrigin { + let ipAdress: String +} + +extension IPOrigin: JSONMappable { + init(object: Dictionary) throws { + /// Do your mapping + } +} + +let request = NetworkRequest(path: "/ip", baseURLKey: baseURLKey) +let ressource = JSONRessource(request: request) + +networkService.request(ressource, onCompletion: { origin in + print(origin) + }, onError: { error in + //Handle errors +}) +``` + ## Requirements - iOS 9.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ From cece93dc7aeb87ebdce89049f2af4b72bc2dcc99 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 11:04:33 +0200 Subject: [PATCH 39/92] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 04412d4..8fcc635 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ networkService.request(ressource, onCompletion: { htmlText in ``` -## JSON Mapping +## JSON Mapping Demo ```swift struct IPOrigin { let ipAdress: String From d87775cabbaed14b0343ea04b61c08aad90a8aee Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 11:13:10 +0200 Subject: [PATCH 40/92] Update README.md --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 8fcc635..8453c65 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,6 @@ [![Build Status](https://travis-ci.com/lightsprint09/DBNetworkStackTemp.svg?token=DoSuqFLfFsZgTxGUxHry&branch=feature/cross-plattorm-project)](https://travis-ci.com/lightsprint09/DBNetworkStackTemp) [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) - -DBNetworkStack is a network abstraction for fetching request and mapping them to model objects. - | Main Features ---------|--------------- 🛡 | Typed network ressources From d9645bcc3256ef97bcd238b616cdcfb7c3be2535 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 11:23:55 +0200 Subject: [PATCH 41/92] Adds license file --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c3162d0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 DB Systel GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 224e9ddb2562081d89fd77689471df8d502152a0 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 11:24:32 +0200 Subject: [PATCH 42/92] Updates demo file --- JSONExample.playground/Contents.swift | 13 ++++++------- SimpleDemo.playground/Contents.swift | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/JSONExample.playground/Contents.swift b/JSONExample.playground/Contents.swift index 818d2a6..e174ca0 100644 --- a/JSONExample.playground/Contents.swift +++ b/JSONExample.playground/Contents.swift @@ -5,31 +5,30 @@ import XCPlayground XCPlaygroundPage.currentPage.needsIndefiniteExecution = true -let url = NSURL(string: "https://httpbin.org")! +let url: NSURL! = NSURL(string: "https://httpbin.org") let baseURLKey = "httpBin" let networkAccess = NSURLSession(configuration: .defaultSessionConfiguration()) let networkService = NetworkService(networkAccess: networkAccess, endPoints: [baseURLKey: url]) struct IPOrigin { - let ip: String + let ipAdress: String } extension IPOrigin: JSONMappable { init(object: Dictionary) throws { - guard let ip = object["origin"] as? String else { + guard let ipAdress = object["origin"] as? String else { throw DBNetworkStackError.SerializationError(description: "", data: nil) } - self.ip = ip + self.ipAdress = ipAdress } } let request = NetworkRequest(path: "/ip", baseURLKey: baseURLKey) let ressource = JSONRessource(request: request) -networkService.request(ressource, onCompletion: { htmlText in - print(htmlText) +networkService.request(ressource, onCompletion: { origin in + print(origin) }, onError: { error in //Handle errors }) - diff --git a/SimpleDemo.playground/Contents.swift b/SimpleDemo.playground/Contents.swift index c956524..08a325b 100644 --- a/SimpleDemo.playground/Contents.swift +++ b/SimpleDemo.playground/Contents.swift @@ -5,7 +5,7 @@ import XCPlayground XCPlaygroundPage.currentPage.needsIndefiniteExecution = true -let url = NSURL(string: "https://httpbin.org")! +let url: NSURL! = NSURL(string: "https://httpbin.org") let baseURLKey = "httpBin" let networkAccess = NSURLSession(configuration: .defaultSessionConfiguration()) From 4d2e46fde6b535beb3fbb94964eab205c965d7e5 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 11:40:04 +0200 Subject: [PATCH 43/92] fix intention --- DBNetworkStack/NetworkRequestRepresening.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DBNetworkStack/NetworkRequestRepresening.swift b/DBNetworkStack/NetworkRequestRepresening.swift index bcd42d0..6a1aa2f 100644 --- a/DBNetworkStack/NetworkRequestRepresening.swift +++ b/DBNetworkStack/NetworkRequestRepresening.swift @@ -89,7 +89,7 @@ extension NetworkRequestRepresening { guard let absoluteURL = NSURL(string: path, relativeToURL: baseURL) else { fatalError("Error createing absolute URL from path: \(path), with baseURL: \(baseURL)") } - let urlComponents = NSURLComponents(URL: absoluteURL, resolvingAgainstBaseURL: true) + let urlComponents = NSURLComponents(URL: absoluteURL, resolvingAgainstBaseURL: true) if let parameter = parameter, let urlComponents = urlComponents where !parameter.isEmpty { let percentEncodedQuery = parameter.map({ value in return "\(value.0)=\(value.1)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet()) From 262f29675eba9158ac7707540119feea3f62d8cc Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 13:23:17 +0200 Subject: [PATCH 44/92] fixes swift lint --- .swiftlint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.swiftlint.yml b/.swiftlint.yml index 7d5153f..970f006 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -40,4 +40,5 @@ variable_name: excluded: # excluded via string array - id - URL + - url reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit) \ No newline at end of file From 62c969677d344a890f7728324a4e7340ea4e0be5 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 13:26:49 +0200 Subject: [PATCH 45/92] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8453c65..c92f2d0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The idea behind this project comes from this [talk.objc.io article](https://talk ## Basic Demo Lets say you want to fetch a ``html`` string. -First you have to create a service, by providing a networkaccess. You can use NSURLSession out of the box or provide your own custom solution by implementing ```NetworkAccessProviding```. In addition you need to register baseURLs endpoints for request mapping. This gives you the flexability to change your endpoints very easyly when your envionment changes. +First you have to create a service, by providing a networkaccess. You can use NSURLSession out of the box or provide your own custom solution by implementing ```NetworkAccessProviding```. In addition you need to register baseURLs endpoints for request mapping. This gives you the flexability to change your endpoints very easily when your envionment changes. ```swift From db519296544a0b4e5cbbd23052b2e07394717db5 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 13:57:46 +0200 Subject: [PATCH 46/92] travis fixes --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0a81592..95a9cb5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ env: - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' - ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' - ACTION=build PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' - - ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' + - ACTION=clean test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' script: - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION | xcpretty \ No newline at end of file From a1b31f7dd84617fafc06299be0250a4cd71fca4b Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 14:10:47 +0200 Subject: [PATCH 47/92] improves travis ci --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 95a9cb5..8738165 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,10 @@ language: objective-c osx_image: xcode8 env: - - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' - - ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' - - ACTION=build PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' - - ACTION=clean test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' + - ACTION=clean && test PLATFORM=Mac DESTINATION='platform=OS X' + - ACTION=clean && test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' + - ACTION=clean && build PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' + - ACTION=clean && test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' script: - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION | xcpretty \ No newline at end of file From 268868c601255e08ce3817e22d594fed3a6d2f55 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 14:15:19 +0200 Subject: [PATCH 48/92] travis --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8738165..432774f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,10 @@ language: objective-c osx_image: xcode8 env: - - ACTION=clean && test PLATFORM=Mac DESTINATION='platform=OS X' - - ACTION=clean && test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' - - ACTION=clean && build PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' - - ACTION=clean && test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' + - ACTION='clean test' PLATFORM=Mac DESTINATION='platform=OS X' + - ACTION='clean && test' PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' + - ACTION='clean && build' PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' + - ACTION='clean && test' PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' script: - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION | xcpretty \ No newline at end of file From 090645f2f3b029005346d3ab9bc810f67c062055 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 14:29:00 +0200 Subject: [PATCH 49/92] travis clean & test --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 432774f..e45803f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,9 @@ osx_image: xcode8 env: - ACTION='clean test' PLATFORM=Mac DESTINATION='platform=OS X' - - ACTION='clean && test' PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' - - ACTION='clean && build' PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' - - ACTION='clean && test' PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' + - ACTION='clean test' PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' + - ACTION='clean build' PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' + - ACTION='clean test' PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' script: - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION | xcpretty \ No newline at end of file From 211a468c64480c6a164980cc0f84f6ea96808047 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 14:45:26 +0200 Subject: [PATCH 50/92] Adds swift 3 support --- DBNetworkStack.xcodeproj/project.pbxproj | 6 +++ DBNetworkStack/BaseURLProviding.swift | 6 +-- DBNetworkStack/DBNetworkStackTypes.swift | 24 ++++----- DBNetworkStack/JSONArrayRessource.swift | 4 +- DBNetworkStack/JSONRessource.swift | 4 +- DBNetworkStack/JSONRessourceModeling.swift | 10 ++-- .../MultipartFormDataRepresenting.swift | 18 +++---- .../MultipartFormDataRessource.swift | 8 +-- .../MultipartFormDataRessourceModelling.swift | 2 +- ...ltipartFormDataUploadAccessProviding.swift | 12 ++--- .../MultipartFormDataUploadService.swift | 12 ++--- ...tipartFormDataUploadServiceProviding.swift | 6 +-- DBNetworkStack/NetworkAccessProviding.swift | 2 +- DBNetworkStack/NetworkRequest.swift | 4 +- .../NetworkRequestRepresening.swift | 26 ++++----- DBNetworkStack/NetworkService.swift | 6 +-- DBNetworkStack/NetworkServiceProviding.swift | 28 +++++----- DBNetworkStack/NetworkTask.swift | 2 +- DBNetworkStack/Ressource.swift | 4 +- DBNetworkStack/RessourceModeling.swift | 2 +- DBNetworkStack/URLSessionNetworkAccess.swift | 16 +++--- .../DBNetworkStackErrorTest.swift | 16 +++--- .../MulitpartFormDataRepresentingMock.swift | 28 +++++----- .../MultipartFormDataUploadServiceTests.swift | 8 +-- DBNetworkStackTests/NetworkRequestTest.swift | 12 ++--- DBNetworkStackTests/NetworkServiceMock.swift | 12 ++--- DBNetworkStackTests/NetworkServiceTest.swift | 54 +++++++++---------- DBNetworkStackTests/NetworkTaskMock.swift | 4 +- DBNetworkStackTests/RessourceTest.swift | 6 +-- DBNetworkStackTests/TrainModel.swift | 16 +++--- .../UploadAccessServiceMock.swift | 20 +++---- 31 files changed, 192 insertions(+), 186 deletions(-) diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index d524c51..bc10221 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -300,9 +300,11 @@ TargetAttributes = { C60BE65A1D6B2BF3006B0364 = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0800; }; C60BE6641D6B2BF3006B0364 = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0800; }; }; }; @@ -540,6 +542,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -559,6 +562,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.dbsystel.DBNetworkStack; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -571,6 +575,7 @@ "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.dbsystel.DBNetworkStackTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -583,6 +588,7 @@ "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.dbsystel.DBNetworkStackTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/DBNetworkStack/BaseURLProviding.swift b/DBNetworkStack/BaseURLProviding.swift index 86755ca..ffb58e7 100644 --- a/DBNetworkStack/BaseURLProviding.swift +++ b/DBNetworkStack/BaseURLProviding.swift @@ -29,7 +29,7 @@ import Foundation internal protocol BaseURLProviding { - var endPoints: [String:NSURL] {get} + var endPoints: [String:URL] {get} /** Provides an baseURL for a given ressource. @@ -40,12 +40,12 @@ internal protocol BaseURLProviding { - return matching baseURL to the given ressource */ - func baseURL(with ressource: T) -> NSURL + func baseURL(with ressource: T) -> URL } extension BaseURLProviding { - func baseURL(with ressource: T) -> NSURL { + func baseURL(with ressource: T) -> URL { guard let baseURL = endPoints[ressource.request.baseURLKey.name] else { fatalError("Missing baseurl for key: \(ressource.request.baseURLKey.name)") diff --git a/DBNetworkStack/DBNetworkStackTypes.swift b/DBNetworkStack/DBNetworkStackTypes.swift index b25d029..341bcb0 100644 --- a/DBNetworkStack/DBNetworkStackTypes.swift +++ b/DBNetworkStack/DBNetworkStackTypes.swift @@ -35,27 +35,27 @@ public typealias DBNetworkRequestErrorBlock = (DBNetworkStackError) -> () /** `DBNetworkStackError` provides a collection of error types which can occur during execution. */ -public enum DBNetworkStackError: ErrorType { - case UnknownError - case Unauthorized(response: NSHTTPURLResponse) - case ClientError(response: NSHTTPURLResponse?) - case SerializationError(description: String, data: NSData?) - case RequestError(error: NSError) - case ServerError(response: NSHTTPURLResponse?) - case MissingBaseURL +public enum DBNetworkStackError: Error { + case unknownError + case unauthorized(response: HTTPURLResponse) + case clientError(response: HTTPURLResponse?) + case serializationError(description: String, data: Data?) + case requestError(error: Error) + case serverError(response: HTTPURLResponse?) + case missingBaseURL - init?(response: NSHTTPURLResponse?) { + init?(response: HTTPURLResponse?) { guard let response = response else { return nil } switch response.statusCode { case 200..<300: return nil case 401: - self = .Unauthorized(response: response) + self = .unauthorized(response: response) case 400...451: - self = .ClientError(response: response) + self = .clientError(response: response) case 500...511: - self = .ServerError(response: response) + self = .serverError(response: response) default: return nil } diff --git a/DBNetworkStack/JSONArrayRessource.swift b/DBNetworkStack/JSONArrayRessource.swift index be5fbb6..fd44bfc 100644 --- a/DBNetworkStack/JSONArrayRessource.swift +++ b/DBNetworkStack/JSONArrayRessource.swift @@ -37,7 +37,7 @@ import Foundation public struct JSONArrayRessource: JSONRessourceModeling, ArrayRessourceModeling { public typealias Element = Element_ public let request: NetworkRequestRepresening - public var parse: (data: NSData) throws -> Array { + public var parse: (_ data: Data) throws -> Array { return parseFunction } @@ -45,7 +45,7 @@ public struct JSONArrayRessource: JSONRessourceModeling, self.request = request } - public func parse(jsonPayload: Array>) throws -> Array { + public func parse(_ jsonPayload: Array>) throws -> Array { return try Array(JSONArray: jsonPayload) } } diff --git a/DBNetworkStack/JSONRessource.swift b/DBNetworkStack/JSONRessource.swift index a6be76e..6f261b8 100644 --- a/DBNetworkStack/JSONRessource.swift +++ b/DBNetworkStack/JSONRessource.swift @@ -35,7 +35,7 @@ import Foundation */ public struct JSONRessource: JSONRessourceModeling { public let request: NetworkRequestRepresening - public var parse: (data: NSData) throws -> Model { + public var parse: (_ data: Data) throws -> Model { return parseFunction } @@ -43,7 +43,7 @@ public struct JSONRessource: JSONRessourceModeling { self.request = request } - public func parse(jsonPayload: Dictionary) throws -> Model { + public func parse(_ jsonPayload: Dictionary) throws -> Model { return try Model(object: jsonPayload) } } diff --git a/DBNetworkStack/JSONRessourceModeling.swift b/DBNetworkStack/JSONRessourceModeling.swift index 5d8a0e3..e406d92 100644 --- a/DBNetworkStack/JSONRessourceModeling.swift +++ b/DBNetworkStack/JSONRessourceModeling.swift @@ -47,7 +47,7 @@ public protocol JSONRessourceModeling: RessourceModeling { - Throws: If parsing fails */ - func parse(jsonPayload: Container) throws -> Model + func parse(_ jsonPayload: Container) throws -> Model } extension JSONRessourceModeling { @@ -61,7 +61,7 @@ extension JSONRessourceModeling { - Throws: If parsing fails */ - func parseFunction(data: NSData) throws -> Model { + func parseFunction(_ data: Data) throws -> Model { let container: Container = try parseContainer(data) return try parse(container) @@ -76,10 +76,10 @@ extension JSONRessourceModeling { - Throws: If parsing fails */ - private func parseContainer(data: NSData) throws -> Container { - let jsonObject = try NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers) + fileprivate func parseContainer(_ data: Data) throws -> Container { + let jsonObject = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) guard let container = jsonObject as? Container else { - let userInfo = ["error": "Expected container of type: \(Container.self), but got \(jsonObject.dynamicType)"] + let userInfo = ["error": "Expected container of type: \(Container.self), but got \(type(of: (jsonObject) as AnyObject))"] throw NSError(domain: "Parsing Error", code: 0, userInfo: userInfo) } diff --git a/DBNetworkStack/MultipartFormDataRepresenting.swift b/DBNetworkStack/MultipartFormDataRepresenting.swift index 3ba4bcd..421f192 100644 --- a/DBNetworkStack/MultipartFormDataRepresenting.swift +++ b/DBNetworkStack/MultipartFormDataRepresenting.swift @@ -62,7 +62,7 @@ public protocol MultipartFormDataRepresenting: class { - parameter data: The data to encode into the multipart form data. - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header. */ - func appendBodyPart(data data: NSData, name: String) + func appendBodyPart(data: Data, name: String) /** Creates a body part from the data and appends it to the multipart form data object. @@ -78,7 +78,7 @@ public protocol MultipartFormDataRepresenting: class { - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header. - parameter mimeType: The MIME type to associate with the data content type in the `Content-Type` HTTP header. */ - func appendBodyPart(data data: NSData, name: String, mimeType: String) + func appendBodyPart(data: Data, name: String, mimeType: String) /** Creates a body part from the data and appends it to the multipart form data object. @@ -95,7 +95,7 @@ public protocol MultipartFormDataRepresenting: class { - parameter fileName: The filename to associate with the data in the `Content-Disposition` HTTP header. - parameter mimeType: The MIME type to associate with the data in the `Content-Type` HTTP header. */ - func appendBodyPart(data data: NSData, name: String, fileName: String, mimeType: String) + func appendBodyPart(data: Data, name: String, fileName: String, mimeType: String) /** Creates a body part from the file and appends it to the multipart form data object. @@ -114,7 +114,7 @@ public protocol MultipartFormDataRepresenting: class { - parameter fileURL: The URL of the file whose content will be encoded into the multipart form data. - parameter name: The name to associate with the file content in the `Content-Disposition` HTTP header. */ - func appendBodyPart(fileURL fileURL: NSURL, name: String) + func appendBodyPart(fileURL: URL, name: String) /** Creates a body part from the file and appends it to the multipart form data object. @@ -131,7 +131,7 @@ public protocol MultipartFormDataRepresenting: class { - parameter fileName: The filename to associate with the file content in the `Content-Disposition` HTTP header. - parameter mimeType: The MIME type to associate with the file content in the `Content-Type` HTTP header. */ - func appendBodyPart(fileURL fileURL: NSURL, name: String, fileName: String, mimeType: String) + func appendBodyPart(fileURL: URL, name: String, fileName: String, mimeType: String) /** Creates a body part from the stream and appends it to the multipart form data object. @@ -150,7 +150,7 @@ public protocol MultipartFormDataRepresenting: class { - parameter mimeType: The MIME type to associate with the stream content in the `Content-Type` HTTP header. */ func appendBodyPart( - stream stream: NSInputStream, + stream: InputStream, length: UInt64, name: String, fileName: String, @@ -169,7 +169,7 @@ public protocol MultipartFormDataRepresenting: class { - parameter length: The content length of the stream. - parameter headers: The HTTP headers for the body part. */ - func appendBodyPart(stream stream: NSInputStream, length: UInt64, headers: [String: String]) + func appendBodyPart(stream: InputStream, length: UInt64, headers: [String: String]) // MARK: - Data Encoding @@ -184,7 +184,7 @@ public protocol MultipartFormDataRepresenting: class { - returns: The encoded `NSData` if encoding is successful. */ - func encode() throws -> NSData + func encode() throws -> Data /** Writes the appended body parts into the given file URL. @@ -196,6 +196,6 @@ public protocol MultipartFormDataRepresenting: class { - throws: An `NSError` if encoding encounters an error. */ - func writeEncodedDataToDisk(fileURL: NSURL) throws + func writeEncodedDataToDisk(_ fileURL: URL) throws } diff --git a/DBNetworkStack/MultipartFormDataRessource.swift b/DBNetworkStack/MultipartFormDataRessource.swift index a4cdf09..d34ba74 100644 --- a/DBNetworkStack/MultipartFormDataRessource.swift +++ b/DBNetworkStack/MultipartFormDataRessource.swift @@ -30,12 +30,12 @@ import Foundation public struct MultipartFormDataRessource: MultipartFormDataRessourceModelling { public var request: NetworkRequestRepresening - public var parse: (data: NSData) throws -> Model + public var parse: (_ data: Data) throws -> Model public var encodingMemoryThreshold: UInt64 - public var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void + public var encodeInMultipartFormData: (MultipartFormDataRepresenting) -> Void - public init(request: NetworkRequestRepresening, parse: (data: NSData) throws -> Model, - encodingMemoryThreshold: UInt64, encodeInMultipartFormData: MultipartFormDataRepresenting -> Void) { + public init(request: NetworkRequestRepresening, parse: @escaping (_ data: Data) throws -> Model, + encodingMemoryThreshold: UInt64, encodeInMultipartFormData: @escaping (MultipartFormDataRepresenting) -> Void) { self.request = request self.parse = parse self.encodingMemoryThreshold = encodingMemoryThreshold diff --git a/DBNetworkStack/MultipartFormDataRessourceModelling.swift b/DBNetworkStack/MultipartFormDataRessourceModelling.swift index d216cb7..dfa6396 100644 --- a/DBNetworkStack/MultipartFormDataRessourceModelling.swift +++ b/DBNetworkStack/MultipartFormDataRessourceModelling.swift @@ -29,6 +29,6 @@ import Foundation public protocol MultipartFormDataRessourceModelling: RessourceModeling { - var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void { get } + var encodeInMultipartFormData: (MultipartFormDataRepresenting) -> Void { get } var encodingMemoryThreshold: UInt64 { get } } diff --git a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift index 5744e10..1d056cb 100644 --- a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift @@ -30,22 +30,22 @@ import Foundation public protocol MultipartFormDataUploadAccessProviding { func upload( - request: NetworkRequestRepresening, - relativeToBaseURL baseURL: NSURL, + _ request: NetworkRequestRepresening, + relativeToBaseURL baseURL: URL, multipartFormData: (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, - callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), + callback: (Data?, HTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? ) } extension MultipartFormDataUploadAccessProviding { func upload( - request: NetworkRequestRepresening, - relativeToBaseURL baseURL: NSURL, + _ request: NetworkRequestRepresening, + relativeToBaseURL baseURL: URL, multipartFormData: (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, - callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), + callback: (Data?, HTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil ) { upload(request, relativeToBaseURL: baseURL, multipartFormData: multipartFormData, encodingMemoryThreshold: encodingMemoryThreshold, diff --git a/DBNetworkStack/MultipartFormDataUploadService.swift b/DBNetworkStack/MultipartFormDataUploadService.swift index 6c79d56..590fe10 100644 --- a/DBNetworkStack/MultipartFormDataUploadService.swift +++ b/DBNetworkStack/MultipartFormDataUploadService.swift @@ -30,8 +30,8 @@ import Foundation public final class MultipartFormDataUploadService: MultipartFormDataUploadServiceProviding, NetworkResponseProcessing, BaseURLProviding { - private let uploadAccess: MultipartFormDataUploadAccessProviding - let endPoints: Dictionary + fileprivate let uploadAccess: MultipartFormDataUploadAccessProviding + let endPoints: Dictionary /** Creates an `MultipartFormDataUploadService` instance with a given uploadAccess and a map of endPoints @@ -39,13 +39,13 @@ public final class MultipartFormDataUploadService: MultipartFormDataUploadServic - parameter uploadAccess: provides basic access to the network. - parameter endPoints: map of baseURLKey -> baseURLs */ - public init(uploadAccess: MultipartFormDataUploadAccessProviding, endPoints: Dictionary) { + public init(uploadAccess: MultipartFormDataUploadAccessProviding, endPoints: Dictionary) { self.uploadAccess = uploadAccess self.endPoints = endPoints } - public func upload(ressource: T, onCompletion: (T.Model) -> (), - onError: (DBNetworkStackError) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil) { + public func upload(_ ressource: T, onCompletion: @escaping (T.Model) -> (), + onError: @escaping (DBNetworkStackError) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil) { let baseURL = self.baseURL(with: ressource) uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, @@ -53,7 +53,7 @@ public final class MultipartFormDataUploadService: MultipartFormDataUploadServic self.processAsyncResponse(response: response, ressource: ressource, data: data, error: error, onCompletion: onCompletion, onError: onError) }, onNetworkTaskCreation: { task in - dispatch_async(dispatch_get_main_queue(), { + DispatchQueue.main.async(execute: { onNetworkTaskCreation?(task) }) }) diff --git a/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift index 7557aeb..4c062b4 100644 --- a/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift @@ -30,7 +30,7 @@ import Foundation public protocol MultipartFormDataUploadServiceProviding { func upload( - ressource: T, + _ ressource: T, onCompletion: (T.Model) -> (), onError: DBNetworkRequestErrorBlock, onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? @@ -38,8 +38,8 @@ public protocol MultipartFormDataUploadServiceProviding { } extension MultipartFormDataUploadServiceProviding { - func upload( - ressource: T, + public func upload( + _ ressource: T, onCompletion: (T.Model) -> (), onError: DBNetworkRequestErrorBlock, onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil diff --git a/DBNetworkStack/NetworkAccessProviding.swift b/DBNetworkStack/NetworkAccessProviding.swift index 121d3d6..660b584 100644 --- a/DBNetworkStack/NetworkAccessProviding.swift +++ b/DBNetworkStack/NetworkAccessProviding.swift @@ -39,5 +39,5 @@ public protocol NetworkAccessProviding { - returns: the running network task */ - func load(request request: NSURLRequest, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> NetworkTask + func load(request: URLRequest, callback: @escaping (Data?, HTTPURLResponse?, Error?) -> ()) -> NetworkTask } diff --git a/DBNetworkStack/NetworkRequest.swift b/DBNetworkStack/NetworkRequest.swift index 622fa09..b2e6dfa 100644 --- a/DBNetworkStack/NetworkRequest.swift +++ b/DBNetworkStack/NetworkRequest.swift @@ -35,13 +35,13 @@ public struct NetworkRequest: NetworkRequestRepresening { public let baseURLKey: BaseURLKey public let HTTPMethod: DBNetworkStack.HTTPMethod public let parameter: Dictionary? - public let body: NSData? + public let body: Data? public let allHTTPHeaderFields: Dictionary? } public extension NetworkRequest { // swiftlint:disable line_length - public init(path: String, baseURLKey: BaseURLKey, HTTPMethod: DBNetworkStack.HTTPMethod = .GET, parameter: Dictionary? = nil, body: NSData? = nil, allHTTPHeaderField: Dictionary? = nil) { + public init(path: String, baseURLKey: BaseURLKey, HTTPMethod: DBNetworkStack.HTTPMethod = .GET, parameter: Dictionary? = nil, body: Data? = nil, allHTTPHeaderField: Dictionary? = nil) { self.path = path self.baseURLKey = baseURLKey self.HTTPMethod = HTTPMethod diff --git a/DBNetworkStack/NetworkRequestRepresening.swift b/DBNetworkStack/NetworkRequestRepresening.swift index 6a1aa2f..a9e9005 100644 --- a/DBNetworkStack/NetworkRequestRepresening.swift +++ b/DBNetworkStack/NetworkRequestRepresening.swift @@ -59,7 +59,7 @@ public protocol NetworkRequestRepresening { /** Data payload of the request */ - var body: NSData? { get } + var body: Data? { get } } extension NetworkRequestRepresening { @@ -69,14 +69,14 @@ extension NetworkRequestRepresening { - parameter baseURL: baseURL for the resulting request. - returns: the equivalent request */ - public func urlRequest(with baseURL: NSURL) -> NSURLRequest { + public func urlRequest(with baseURL: URL) -> URLRequest { let absoluteURL = absoluteURLWith(baseURL) - let request = NSMutableURLRequest(URL: absoluteURL) + let request = NSMutableURLRequest(url: absoluteURL) request.allHTTPHeaderFields = allHTTPHeaderFields - request.HTTPMethod = HTTPMethod.rawValue - request.HTTPBody = body + request.httpMethod = HTTPMethod.rawValue + request.httpBody = body - return request + return request as URLRequest } /** @@ -85,18 +85,18 @@ extension NetworkRequestRepresening { - parameter baseURL: baseURL for the resulting url. - returns: absolute url for the request. */ - private func absoluteURLWith(baseURL: NSURL) -> NSURL { - guard let absoluteURL = NSURL(string: path, relativeToURL: baseURL) else { + fileprivate func absoluteURLWith(_ baseURL: URL) -> URL { + guard let absoluteURL = URL(string: path, relativeTo: baseURL) else { fatalError("Error createing absolute URL from path: \(path), with baseURL: \(baseURL)") } - let urlComponents = NSURLComponents(URL: absoluteURL, resolvingAgainstBaseURL: true) - if let parameter = parameter, let urlComponents = urlComponents where !parameter.isEmpty { + let urlComponents = URLComponents(url: absoluteURL, resolvingAgainstBaseURL: true) + if let parameter = parameter, var urlComponents = urlComponents , !parameter.isEmpty { let percentEncodedQuery = parameter.map({ value in - return "\(value.0)=\(value.1)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet()) + return "\(value.0)=\(value.1)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) }).flatMap { $0 } - urlComponents.percentEncodedQuery = percentEncodedQuery.joinWithSeparator("&") + urlComponents.percentEncodedQuery = percentEncodedQuery.joined(separator: "&") - guard let absoluteURL = urlComponents.URL else { + guard let absoluteURL = urlComponents.url else { fatalError("Error createing absolute URL from path: \(path), with baseURL: \(baseURL)") } return absoluteURL diff --git a/DBNetworkStack/NetworkService.swift b/DBNetworkStack/NetworkService.swift index 62b904d..2b33b83 100644 --- a/DBNetworkStack/NetworkService.swift +++ b/DBNetworkStack/NetworkService.swift @@ -32,7 +32,7 @@ import Foundation */ public final class NetworkService: NetworkServiceProviding, BaseURLProviding { let networkAccess: NetworkAccessProviding - let endPoints: Dictionary + let endPoints: Dictionary /** Creates an `NetworkService` instance with a given networkAccess and a map of endPoints @@ -40,12 +40,12 @@ public final class NetworkService: NetworkServiceProviding, BaseURLProviding { - parameter networkAccess: provides basic access to the network. - parameter endPoints: map of baseURLKey -> baseURLs */ - public init(networkAccess: NetworkAccessProviding, endPoints: Dictionary) { + public init(networkAccess: NetworkAccessProviding, endPoints: Dictionary) { self.networkAccess = networkAccess self.endPoints = endPoints } - public func request(ressource: T, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> ()) -> NetworkTask { + public func request(_ ressource: T, onCompletion: @escaping (T.Model) -> (), onError: @escaping (DBNetworkStackError) -> ()) -> NetworkTask { let baseURL = self.baseURL(with: ressource) let reuqest = ressource.request.urlRequest(with: baseURL) let dataTask = networkAccess.load(request: reuqest, callback: { data, response, error in diff --git a/DBNetworkStack/NetworkServiceProviding.swift b/DBNetworkStack/NetworkServiceProviding.swift index c7bb8cc..602cdeb 100644 --- a/DBNetworkStack/NetworkServiceProviding.swift +++ b/DBNetworkStack/NetworkServiceProviding.swift @@ -40,7 +40,7 @@ public protocol NetworkServiceProviding: NetworkResponseProcessing { - returns: the request */ - func request(ressource: T, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> ()) -> NetworkTask + func request(_ ressource: T, onCompletion: @escaping (T.Model) -> (), onError: @escaping (DBNetworkStackError) -> ()) -> NetworkTask } public protocol NetworkResponseProcessing { @@ -56,33 +56,33 @@ public protocol NetworkResponseProcessing { - returns: the parsed model object. */ - func process(response response: NSHTTPURLResponse?, ressource: T, data: NSData?, error: NSError?) throws -> T.Model + func process(response: HTTPURLResponse?, ressource: T, data: Data?, error: Error?) throws -> T.Model } extension NetworkResponseProcessing { - public func process(response response: NSHTTPURLResponse?, ressource: T, data: NSData?, error: NSError?) throws -> T.Model { + public func process(response: HTTPURLResponse?, ressource: T, data: Data?, error: Error?) throws -> T.Model { if let error = error { - throw DBNetworkStackError.RequestError(error: error) + throw DBNetworkStackError.requestError(error: error) } if let responseError = DBNetworkStackError(response: response) { throw responseError } guard let data = data else { - throw DBNetworkStackError.SerializationError(description: "No data to serialize revied from the server", data: nil) + throw DBNetworkStackError.serializationError(description: "No data to serialize revied from the server", data: nil) } do { - return try ressource.parse(data: data) + return try ressource.parse(data) } catch let error as CustomStringConvertible { - throw DBNetworkStackError.SerializationError(description: error.description, data: data) + throw DBNetworkStackError.serializationError(description: error.description, data: data) } catch { - throw DBNetworkStackError.SerializationError(description: "Unknown serialization error", data: data) + throw DBNetworkStackError.serializationError(description: "Unknown serialization error", data: data) } } } extension NetworkResponseProcessing { - func processAsyncResponse(response response: NSHTTPURLResponse?, ressource: T, data: NSData?, - error: NSError?, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> ()) { + func processAsyncResponse(response: HTTPURLResponse?, ressource: T, data: Data?, + error: Error?, onCompletion: @escaping (T.Model) -> (), onError: @escaping (DBNetworkStackError) -> ()) { do { let parsed = try self.process( response: response, @@ -90,16 +90,16 @@ extension NetworkResponseProcessing { data: data, error: error ) - dispatch_async(dispatch_get_main_queue()) { + DispatchQueue.main.async { onCompletion(parsed) } } catch let parsingError as DBNetworkStackError { - dispatch_async(dispatch_get_main_queue()) { + DispatchQueue.main.async { return onError(parsingError) } } catch { - dispatch_async(dispatch_get_main_queue()) { - return onError(.UnknownError) + DispatchQueue.main.async { + return onError(.unknownError) } } } diff --git a/DBNetworkStack/NetworkTask.swift b/DBNetworkStack/NetworkTask.swift index 9b1b45a..254eaa1 100644 --- a/DBNetworkStack/NetworkTask.swift +++ b/DBNetworkStack/NetworkTask.swift @@ -49,5 +49,5 @@ public protocol NetworkTask { /** Contains the current progress of a running task. */ - var progress: NSProgress { get } + var progress: Progress { get } } diff --git a/DBNetworkStack/Ressource.swift b/DBNetworkStack/Ressource.swift index cc79f9a..3f1ab9e 100644 --- a/DBNetworkStack/Ressource.swift +++ b/DBNetworkStack/Ressource.swift @@ -29,9 +29,9 @@ import Foundation public struct Ressource: RessourceModeling { public let request: NetworkRequestRepresening - public let parse: (data: NSData) throws -> Model + public let parse: (_ data: Data) throws -> Model - public init(request: NetworkRequestRepresening, parse: (NSData) throws -> Model) { + public init(request: NetworkRequestRepresening, parse: @escaping (Data) throws -> Model) { self.request = request self.parse = parse } diff --git a/DBNetworkStack/RessourceModeling.swift b/DBNetworkStack/RessourceModeling.swift index 7f908c9..57b868a 100644 --- a/DBNetworkStack/RessourceModeling.swift +++ b/DBNetworkStack/RessourceModeling.swift @@ -44,5 +44,5 @@ public protocol RessourceModeling { /** Parses data into given Model */ - var parse: (data: NSData) throws -> Model { get } + var parse: (_ data: Data) throws -> Model { get } } diff --git a/DBNetworkStack/URLSessionNetworkAccess.swift b/DBNetworkStack/URLSessionNetworkAccess.swift index 57c2383..5316b2e 100644 --- a/DBNetworkStack/URLSessionNetworkAccess.swift +++ b/DBNetworkStack/URLSessionNetworkAccess.swift @@ -30,21 +30,21 @@ import Foundation /** Adds conformens to `NetworkAccessProviding`. `NSURLSession` can now be used as a networkprovider. */ -extension NSURLSession: NetworkAccessProviding { - public func load(request request: NSURLRequest, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> NetworkTask { - let task = dataTaskWithRequest(request) { data, response, error in - callback(data, response as? NSHTTPURLResponse, error) - } +extension URLSession: NetworkAccessProviding { + public func load(request: URLRequest, callback: @escaping (Data?, HTTPURLResponse?, Error?) -> ()) -> NetworkTask { + let task = dataTask(with: request, completionHandler: { data, response, error in + callback(data, response as? HTTPURLResponse, error) + }) task.resume() return task } } -extension NSURLSessionTask: NetworkTask { - public var progress: NSProgress { +extension URLSessionTask: NetworkTask { + public var progress: Progress { let totalBytesExpected = response?.expectedContentLength ?? NSURLSessionTransferSizeUnknown - let progress = NSProgress(totalUnitCount: totalBytesExpected) + let progress = Progress(totalUnitCount: totalBytesExpected) progress.totalUnitCount = totalBytesExpected progress.completedUnitCount = countOfBytesReceived diff --git a/DBNetworkStackTests/DBNetworkStackErrorTest.swift b/DBNetworkStackTests/DBNetworkStackErrorTest.swift index d817d74..98fbac8 100644 --- a/DBNetworkStackTests/DBNetworkStackErrorTest.swift +++ b/DBNetworkStackTests/DBNetworkStackErrorTest.swift @@ -33,7 +33,7 @@ class DBNetworkStackErrorTest: XCTestCase { func testInitFrom400() { //Given let statusCode = 400 - let response = NSHTTPURLResponse(URL: NSURL(), statusCode: statusCode, HTTPVersion: nil, headerFields: nil) + let response = HTTPURLResponse(url: URL(), statusCode: statusCode, httpVersion: nil, headerFields: nil) //When guard let error = DBNetworkStackError(response: response) else { @@ -42,7 +42,7 @@ class DBNetworkStackErrorTest: XCTestCase { //Then switch error { - case .ClientError(let response): + case .clientError(let response): XCTAssertEqual(response, response) default: XCTFail() @@ -52,7 +52,7 @@ class DBNetworkStackErrorTest: XCTestCase { func testInitFrom401() { //Given let statusCode = 401 - let response = NSHTTPURLResponse(URL: NSURL(), statusCode: statusCode, HTTPVersion: nil, headerFields: nil) + let response = HTTPURLResponse(url: URL(), statusCode: statusCode, httpVersion: nil, headerFields: nil) //When guard let error = DBNetworkStackError(response: response) else { @@ -61,7 +61,7 @@ class DBNetworkStackErrorTest: XCTestCase { //Then switch error { - case .Unauthorized(let response): + case .unauthorized(let response): XCTAssertEqual(response, response) default: XCTFail() @@ -71,7 +71,7 @@ class DBNetworkStackErrorTest: XCTestCase { func testInitFrom2xx() { //Given let statusCode = 200 - let response = NSHTTPURLResponse(URL: NSURL(), statusCode: statusCode, HTTPVersion: nil, headerFields: nil) + let response = HTTPURLResponse(url: URL(), statusCode: statusCode, httpVersion: nil, headerFields: nil) //When let error = DBNetworkStackError(response: response) @@ -83,7 +83,7 @@ class DBNetworkStackErrorTest: XCTestCase { func testInitFrom5xx() { //Given let statusCode = 511 - let response = NSHTTPURLResponse(URL: NSURL(), statusCode: statusCode, HTTPVersion: nil, headerFields: nil) + let response = HTTPURLResponse(url: URL(), statusCode: statusCode, httpVersion: nil, headerFields: nil) //When guard let error = DBNetworkStackError(response: response) else { @@ -92,7 +92,7 @@ class DBNetworkStackErrorTest: XCTestCase { //Then switch error { - case .ServerError(let response): + case .serverError(let response): XCTAssertEqual(response, response) default: XCTFail() @@ -102,7 +102,7 @@ class DBNetworkStackErrorTest: XCTestCase { func testInitFromInvalid() { //Given let statusCode = 900 - let response = NSHTTPURLResponse(URL: NSURL(), statusCode: statusCode, HTTPVersion: nil, headerFields: nil) + let response = HTTPURLResponse(url: URL(), statusCode: statusCode, httpVersion: nil, headerFields: nil) //When let error = DBNetworkStackError(response: response) diff --git a/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift b/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift index 09f6bc5..f85acae 100644 --- a/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift +++ b/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift @@ -9,43 +9,43 @@ import Foundation import DBNetworkStack -public class MulitpartFormDataRepresentingMock: MultipartFormDataRepresenting { - public var contentType: String = "multipart/form-data" - public var contentLength: UInt64 = 128 - public var boundary: String = "" +open class MulitpartFormDataRepresentingMock: MultipartFormDataRepresenting { + open var contentType: String = "multipart/form-data" + open var contentLength: UInt64 = 128 + open var boundary: String = "" - public func appendBodyPart(data data: NSData, name: String) { + open func appendBodyPart(data: Data, name: String) { } - public func appendBodyPart(data data: NSData, name: String, mimeType: String) { + open func appendBodyPart(data: Data, name: String, mimeType: String) { } - public func appendBodyPart(fileURL fileURL: NSURL, name: String, fileName: String, mimeType: String) { + open func appendBodyPart(fileURL: URL, name: String, fileName: String, mimeType: String) { } - public func appendBodyPart(fileURL fileURL: NSURL, name: String) { + open func appendBodyPart(fileURL: URL, name: String) { } - public func appendBodyPart(data data: NSData, name: String, fileName: String, mimeType: String) { + open func appendBodyPart(data: Data, name: String, fileName: String, mimeType: String) { } - public func appendBodyPart(stream stream: NSInputStream, length: UInt64, headers: [String : String]) { + open func appendBodyPart(stream: InputStream, length: UInt64, headers: [String : String]) { } - public func appendBodyPart(stream stream: NSInputStream, length: UInt64, name: String, fileName: String, mimeType: String) { + open func appendBodyPart(stream: InputStream, length: UInt64, name: String, fileName: String, mimeType: String) { } - public func encode() throws -> NSData { - return NSData() + open func encode() throws -> Data { + return Data() } - public func writeEncodedDataToDisk(fileURL: NSURL) throws { + open func writeEncodedDataToDisk(_ fileURL: URL) throws { } } diff --git a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift index edf5fd2..296d750 100644 --- a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift +++ b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift @@ -37,13 +37,13 @@ class MultipartFormDataUploadServiceTests: XCTestCase { super.setUp() service = MultipartFormDataUploadService( uploadAccess: networkAccess, - endPoints: [ TestEndPoints.EndPoint.name: NSURL(string: "http://bahn.de")!] + endPoints: [ TestEndPoints.endPoint.name: URL(string: "http://bahn.de")!] ) } func testUpload() { //Given - let request = NetworkRequest(path: "/train", baseURLKey: TestEndPoints.EndPoint) + let request = NetworkRequest(path: "/train", baseURLKey: TestEndPoints.endPoint) let ressource = MultipartFormDataRessource(request: request, parse: { $0 }, encodingMemoryThreshold: 200, encodeInMultipartFormData: { formdata in @@ -51,7 +51,7 @@ class MultipartFormDataUploadServiceTests: XCTestCase { networkAccess.changeMock(data: Train.validJSONData, response: nil, error: nil) var didCreateTask = false //When - let expection = expectationWithDescription("loadValidRequest") + let expection = expectation(description: "loadValidRequest") service.upload(ressource, onCompletion: { data in XCTAssertEqual(Train.validJSONData, data) XCTAssert(didCreateTask) @@ -62,7 +62,7 @@ class MultipartFormDataUploadServiceTests: XCTestCase { }, onNetworkTaskCreation: { task in didCreateTask = true }) - waitForExpectationsWithTimeout(5, handler: nil) + waitForExpectations(timeout: 5, handler: nil) } } diff --git a/DBNetworkStackTests/NetworkRequestTest.swift b/DBNetworkStackTests/NetworkRequestTest.swift index e348a0e..1606acb 100644 --- a/DBNetworkStackTests/NetworkRequestTest.swift +++ b/DBNetworkStackTests/NetworkRequestTest.swift @@ -35,10 +35,10 @@ class NetworkRequestTest: XCTestCase { let path = "/index.html" let baseURLKey = "Key" let httpMethod = HTTPMethod.GET - let parameter = ["test1": 1, "test2": "2"] - let body = "hallo body data".dataUsingEncoding(NSUTF8StringEncoding)! + let parameter = ["test1": 1, "test2": "2"] as [String : Any] + let body = "hallo body data".data(using: String.Encoding.utf8)! let headerFields: Dictionary = [:] - let baseURL = NSURL(string: "https://www.bahn.de/")! + let baseURL = URL(string: "https://www.bahn.de/")! //When let request = NetworkRequest(path: path, baseURLKey: baseURLKey, HTTPMethod: httpMethod, parameter: parameter, body: body, allHTTPHeaderFields: headerFields) @@ -46,9 +46,9 @@ class NetworkRequestTest: XCTestCase { //Then let urlRequest = request.urlRequest(with: baseURL) - XCTAssertEqual(urlRequest.URL?.absoluteString, "https://www.bahn.de/index.html?test2=2&test1=1") - XCTAssertEqual(urlRequest.HTTPMethod, httpMethod.rawValue) - XCTAssertEqual(urlRequest.HTTPBody, body) + XCTAssertEqual(urlRequest.url?.absoluteString, "https://www.bahn.de/index.html?test2=2&test1=1") + XCTAssertEqual(urlRequest.httpMethod, httpMethod.rawValue) + XCTAssertEqual(urlRequest.httpBody, body) XCTAssertEqual(urlRequest.allHTTPHeaderFields!, headerFields) } } diff --git a/DBNetworkStackTests/NetworkServiceMock.swift b/DBNetworkStackTests/NetworkServiceMock.swift index 95dafbd..9520b54 100644 --- a/DBNetworkStackTests/NetworkServiceMock.swift +++ b/DBNetworkStackTests/NetworkServiceMock.swift @@ -29,20 +29,20 @@ import Foundation import DBNetworkStack class NetworkAccessMock: NetworkAccessProviding { - private(set) var data: NSData? - private(set) var response: NSHTTPURLResponse? - private(set) var error: NSError? + fileprivate(set) var data: Data? + fileprivate(set) var response: HTTPURLResponse? + fileprivate(set) var error: NSError? - private(set) var request: NSURLRequest? + fileprivate(set) var request: URLRequest? - func load(request request: NSURLRequest, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> NetworkTask { + func load(request: URLRequest, callback: (Data?, HTTPURLResponse?, NSError?) -> ()) -> NetworkTask { self.request = request callback(data, response, error) return NetworkTaskMock() } - func changeMock(data data: NSData?, response: NSHTTPURLResponse?, error: NSError?) { + func changeMock(data: Data?, response: HTTPURLResponse?, error: NSError?) { self.data = data self.response = response self.error = error diff --git a/DBNetworkStackTests/NetworkServiceTest.swift b/DBNetworkStackTests/NetworkServiceTest.swift index 91a23c1..2a6dfcc 100644 --- a/DBNetworkStackTests/NetworkServiceTest.swift +++ b/DBNetworkStackTests/NetworkServiceTest.swift @@ -29,7 +29,7 @@ import XCTest @testable import DBNetworkStack enum TestEndPoints: BaseURLKey { - case EndPoint + case endPoint var name: String { return "endPointTestKey" @@ -42,7 +42,7 @@ class NetworkServiceTest: XCTestCase { var networkAccess = NetworkAccessMock() let trainName: NSString = "ICE" - let baseURL = NSURL(string: "//bahn.de")! + let baseURL = URL(string: "//bahn.de")! override func setUp() { networkService = NetworkService(networkAccess: networkAccess, endPoints: ["endPointTestKey": baseURL]) @@ -50,38 +50,38 @@ class NetworkServiceTest: XCTestCase { func testValidRequest() { //Given - let request = NetworkRequest(path: "/train", baseURLKey: TestEndPoints.EndPoint) + let request = NetworkRequest(path: "/train", baseURLKey: TestEndPoints.endPoint) let ressource = JSONRessource(request: request) networkAccess.changeMock(data: Train.validJSONData, response: nil, error: nil) //When - let expection = expectationWithDescription("loadValidRequest") + let expection = expectation(description: "loadValidRequest") networkService.request(ressource, onCompletion: { train in //Then XCTAssertEqual(train.name, self.trainName) - XCTAssertEqual(self.networkAccess.request?.URL?.absoluteString, "//bahn.de/train") + XCTAssertEqual(self.networkAccess.request?.url?.absoluteString, "//bahn.de/train") expection.fulfill() }, onError: { err in XCTFail() }) - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectations(timeout: 1, handler: nil) } func testNoData() { //Given - let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.EndPoint) + let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.endPoint) let ressource = JSONRessource(request: request) networkAccess.changeMock(data: nil, response: nil, error: nil) //When - let expection = expectationWithDescription("testNoData") + let expection = expectation(description: "testNoData") networkService.request(ressource, onCompletion: { fetchedTrain in XCTFail() }, onError: { error in switch error { - case .SerializationError(let description, let data): + case .serializationError(let description, let data): XCTAssertEqual("No data to serialize revied from the server", description) XCTAssertNil(data) expection.fulfill() @@ -90,68 +90,68 @@ class NetworkServiceTest: XCTestCase { } }) - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectations(timeout: 1, handler: nil) } func testInvalidData() { //Given - let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.EndPoint) + let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.endPoint) let ressource = JSONRessource(request: request) networkAccess.changeMock(data: Train.invalidJSONData, response: nil, error: nil) //When - let expection = expectationWithDescription("testInvalidData") + let expection = expectation(description: "testInvalidData") networkService.request(ressource, onCompletion: { fetchedTrain in XCTFail() }, onError: { error in //Then switch error { - case .SerializationError(_, _): + case .serializationError(_, _): expection.fulfill() default: XCTFail() } }) - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectations(timeout: 1, handler: nil) } func testInvalidJSONKeyData() { //Given - let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.EndPoint) + let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.endPoint) let ressource = JSONRessource(request: request) networkAccess.changeMock(data: Train.JSONDataWithInvalidKey, response: nil, error: nil) //When - let expection = expectationWithDescription("testInvalidJSONKeyData") + let expection = expectation(description: "testInvalidJSONKeyData") networkService.request(ressource, onCompletion: { fetchedTrain in XCTFail() }, onError: { error in switch error { - case .SerializationError(_, _): + case .serializationError(_, _): expection.fulfill() default: XCTFail() } }) - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectations(timeout: 1, handler: nil) } func testOnError() { //Given let error = NSError(domain: "", code: 0, userInfo: nil) - let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.EndPoint) + let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.endPoint) let ressource = JSONRessource(request: request) networkAccess.changeMock(data: nil, response: nil, error: error) //When - let expection = expectationWithDescription("testOnError") + let expection = expectation(description: "testOnError") networkService.request(ressource, onCompletion: { fetchedTrain in }, onError: { resultError in //Then switch resultError { - case .RequestError(let err): + case .requestError(let err): XCTAssertEqual(err, error) expection.fulfill() default: @@ -159,23 +159,23 @@ class NetworkServiceTest: XCTestCase { } }) - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectations(timeout: 1, handler: nil) } func testOnStatusCodeError() { //Given - let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.EndPoint) + let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.endPoint) let ressource = JSONRessource(request: request) - let response = NSHTTPURLResponse(URL: NSURL(), statusCode: 401, HTTPVersion: nil, headerFields: nil) + let response = HTTPURLResponse(url: URL(), statusCode: 401, httpVersion: nil, headerFields: nil) networkAccess.changeMock(data: nil, response: response, error: nil) //When - let expection = expectationWithDescription("testOnError") + let expection = expectation(description: "testOnError") networkService.request(ressource, onCompletion: { fetchedTrain in }, onError: { resultError in //Then switch resultError { - case .Unauthorized(let res): + case .unauthorized(let res): XCTAssertEqual(res, response) expection.fulfill() default: @@ -183,6 +183,6 @@ class NetworkServiceTest: XCTestCase { } }) - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectations(timeout: 1, handler: nil) } } diff --git a/DBNetworkStackTests/NetworkTaskMock.swift b/DBNetworkStackTests/NetworkTaskMock.swift index cca136e..88ccbe5 100644 --- a/DBNetworkStackTests/NetworkTaskMock.swift +++ b/DBNetworkStackTests/NetworkTaskMock.swift @@ -42,7 +42,7 @@ class NetworkTaskMock: NetworkTask { } - var progress: NSProgress { - return NSProgress() + var progress: Progress { + return Progress() } } diff --git a/DBNetworkStackTests/RessourceTest.swift b/DBNetworkStackTests/RessourceTest.swift index afd4469..519038d 100644 --- a/DBNetworkStackTests/RessourceTest.swift +++ b/DBNetworkStackTests/RessourceTest.swift @@ -32,9 +32,9 @@ class RessourceTest: XCTestCase { func testRessource() { //Given - let validData = "ICE".dataUsingEncoding(NSUTF8StringEncoding)! + let validData = "ICE".data(using: String.Encoding.utf8)! let request = NetworkRequest(path: "/train", baseURLKey: "") - let ressource = Ressource(request: request, parse: { String(data: $0, encoding: NSUTF8StringEncoding) }) + let ressource = Ressource(request: request, parse: { String(data: $0, encoding: String.Encoding.utf8) }) //When let name = try? ressource.parse(data: validData) @@ -46,7 +46,7 @@ class RessourceTest: XCTestCase { func testRessourceWithInvalidData() { //Given - let validData = NSData() + let validData = Data() let request = NetworkRequest(path: "/train", baseURLKey: "") let ressource = JSONRessource(request: request) diff --git a/DBNetworkStackTests/TrainModel.swift b/DBNetworkStackTests/TrainModel.swift index fa84049..3e67e96 100644 --- a/DBNetworkStackTests/TrainModel.swift +++ b/DBNetworkStackTests/TrainModel.swift @@ -43,19 +43,19 @@ extension Train: JSONMappable { } extension Train { - static var validJSONData: NSData { - return "{ \"name\": \"ICE\"}".dataUsingEncoding(NSUTF8StringEncoding)! + static var validJSONData: Data { + return "{ \"name\": \"ICE\"}".data(using: String.Encoding.utf8)! } - static var invalidJSONData: NSData { - return "{ name: \"ICE\"}".dataUsingEncoding(NSUTF8StringEncoding)! + static var invalidJSONData: Data { + return "{ name: \"ICE\"}".data(using: String.Encoding.utf8)! } - static var JSONDataWithInvalidKey: NSData { - return "{ \"namee\": \"ICE\"}".dataUsingEncoding(NSUTF8StringEncoding)! + static var JSONDataWithInvalidKey: Data { + return "{ \"namee\": \"ICE\"}".data(using: String.Encoding.utf8)! } - static var validJSONArrayData: NSData { - return "[{ \"name\": \"ICE\"}, { \"name\": \"IC\"}, { \"name\": \"TGV\"}]".dataUsingEncoding(NSUTF8StringEncoding)! + static var validJSONArrayData: Data { + return "[{ \"name\": \"ICE\"}, { \"name\": \"IC\"}, { \"name\": \"TGV\"}]".data(using: String.Encoding.utf8)! } } diff --git a/DBNetworkStackTests/UploadAccessServiceMock.swift b/DBNetworkStackTests/UploadAccessServiceMock.swift index 5163986..fe1a456 100644 --- a/DBNetworkStackTests/UploadAccessServiceMock.swift +++ b/DBNetworkStackTests/UploadAccessServiceMock.swift @@ -30,29 +30,29 @@ import DBNetworkStack class UploadAccessServiceMock: MultipartFormDataUploadAccessProviding { - var uploadData: NSData? + var uploadData: Data? - private var reponseData: NSData? - private var responseError: NSError? - private var response: NSHTTPURLResponse? - private var multipartFormData: ((MultipartFormDataRepresenting) -> ())? + fileprivate var reponseData: Data? + fileprivate var responseError: NSError? + fileprivate var response: HTTPURLResponse? + fileprivate var multipartFormData: ((MultipartFormDataRepresenting) -> ())? - func upload(request: NetworkRequestRepresening, relativeToBaseURL: NSURL, multipartFormData: (MultipartFormDataRepresenting) -> (), - encodingMemoryThreshold: UInt64, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), + func upload(_ request: NetworkRequestRepresening, relativeToBaseURL: URL, multipartFormData: (MultipartFormDataRepresenting) -> (), + encodingMemoryThreshold: UInt64, callback: @escaping (Data?, HTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock?) { - dispatch_async(dispatch_get_main_queue()) { + DispatchQueue.main.async { multipartFormData(MulitpartFormDataRepresentingMock()) onNetworkTaskCreation?(NetworkTaskMock()) - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(2.0)*Int64(NSEC_PER_SEC)), dispatch_get_main_queue(), { + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(2.0)*Int64(NSEC_PER_SEC)) / Double(NSEC_PER_SEC), execute: { callback(self.reponseData, self.response, self.responseError) }) } } - func changeMock(data data: NSData?, response: NSHTTPURLResponse?, error: NSError?) { + func changeMock(data: Data?, response: HTTPURLResponse?, error: NSError?) { self.reponseData = data self.response = response self.responseError = error From 338980fb319fa1cea0d8fb6b16486bcdce0a684b Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 18 Oct 2016 15:37:39 +0200 Subject: [PATCH 51/92] Migrates tests to swift 3 --- DBNetworkStack.xcodeproj/project.pbxproj | 4 ++-- .../xcschemes/DBNetworkStack.xcscheme | 3 +-- DBNetworkStack/DBNetworkStackTypes.swift | 5 ----- ...ltipartFormDataUploadAccessProviding.swift | 21 +++--------------- .../MultipartFormDataUploadService.swift | 4 ++-- ...tipartFormDataUploadServiceProviding.swift | 22 +++---------------- DBNetworkStack/NetworkRequest.swift | 4 ++-- .../NetworkRequestRepresening.swift | 2 +- .../DBNetworkStackErrorTest.swift | 12 +++++----- .../JSONArrayRessourceTest.swift | 6 ++--- DBNetworkStackTests/JSONRessourceTest.swift | 4 ++-- DBNetworkStackTests/NetworkRequestTest.swift | 4 ++-- DBNetworkStackTests/NetworkServiceMock.swift | 2 +- DBNetworkStackTests/NetworkServiceTest.swift | 6 ++--- DBNetworkStackTests/RessourceTest.swift | 4 ++-- .../UploadAccessServiceMock.swift | 6 ++--- 16 files changed, 36 insertions(+), 73 deletions(-) diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index bc10221..aabc575 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -469,7 +469,7 @@ SDKROOT = iphoneos; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2,3,4"; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -515,7 +515,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2,3,4"; TVOS_DEPLOYMENT_TARGET = 9.0; VALIDATE_PRODUCT = YES; diff --git a/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme b/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme index 5099767..0fc3742 100644 --- a/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme +++ b/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme @@ -26,8 +26,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES" - codeCoverageEnabled = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES"> diff --git a/DBNetworkStack/DBNetworkStackTypes.swift b/DBNetworkStack/DBNetworkStackTypes.swift index 341bcb0..88305d3 100644 --- a/DBNetworkStack/DBNetworkStackTypes.swift +++ b/DBNetworkStack/DBNetworkStackTypes.swift @@ -27,11 +27,6 @@ import Foundation -public typealias DBNetworkTaskCreationCompletionBlock = (NetworkTask) -> () -// TODO: Use typealiases for functions with generic types in Swift 3.x -//typealias NetworkRequestCompletionBlock = (T.Model) -> () -public typealias DBNetworkRequestErrorBlock = (DBNetworkStackError) -> () - /** `DBNetworkStackError` provides a collection of error types which can occur during execution. */ diff --git a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift index 1d056cb..38ae07a 100644 --- a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift @@ -32,24 +32,9 @@ public protocol MultipartFormDataUploadAccessProviding { func upload( _ request: NetworkRequestRepresening, relativeToBaseURL baseURL: URL, - multipartFormData: (MultipartFormDataRepresenting) -> (), + multipartFormData: @escaping (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, - callback: (Data?, HTTPURLResponse?, NSError?) -> (), - onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? + callback: @escaping (Data?, HTTPURLResponse?, NSError?) -> (), + onNetworkTaskCreation: @escaping (NetworkTask) -> () ) } - -extension MultipartFormDataUploadAccessProviding { - func upload( - _ request: NetworkRequestRepresening, - relativeToBaseURL baseURL: URL, - multipartFormData: (MultipartFormDataRepresenting) -> (), - encodingMemoryThreshold: UInt64, - callback: (Data?, HTTPURLResponse?, NSError?) -> (), - onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil - ) { - upload(request, relativeToBaseURL: baseURL, multipartFormData: multipartFormData, encodingMemoryThreshold: encodingMemoryThreshold, - callback: callback, onNetworkTaskCreation: onNetworkTaskCreation) - } - -} diff --git a/DBNetworkStack/MultipartFormDataUploadService.swift b/DBNetworkStack/MultipartFormDataUploadService.swift index 590fe10..f8333bc 100644 --- a/DBNetworkStack/MultipartFormDataUploadService.swift +++ b/DBNetworkStack/MultipartFormDataUploadService.swift @@ -45,7 +45,7 @@ public final class MultipartFormDataUploadService: MultipartFormDataUploadServic } public func upload(_ ressource: T, onCompletion: @escaping (T.Model) -> (), - onError: @escaping (DBNetworkStackError) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil) { + onError: @escaping (DBNetworkStackError) -> (), onNetworkTaskCreation: @escaping (NetworkTask) -> ()) { let baseURL = self.baseURL(with: ressource) uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, @@ -54,7 +54,7 @@ public final class MultipartFormDataUploadService: MultipartFormDataUploadServic }, onNetworkTaskCreation: { task in DispatchQueue.main.async(execute: { - onNetworkTaskCreation?(task) + onNetworkTaskCreation(task) }) }) } diff --git a/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift index 4c062b4..de3a783 100644 --- a/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift @@ -31,24 +31,8 @@ import Foundation public protocol MultipartFormDataUploadServiceProviding { func upload( _ ressource: T, - onCompletion: (T.Model) -> (), - onError: DBNetworkRequestErrorBlock, - onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? + onCompletion: @escaping (T.Model) -> (), + onError: @escaping (DBNetworkStackError) -> (), + onNetworkTaskCreation: @escaping (NetworkTask) -> () ) } - -extension MultipartFormDataUploadServiceProviding { - public func upload( - _ ressource: T, - onCompletion: (T.Model) -> (), - onError: DBNetworkRequestErrorBlock, - onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil - ) { - upload( - ressource, - onCompletion: onCompletion, - onError: onError, - onNetworkTaskCreation: onNetworkTaskCreation - ) - } -} diff --git a/DBNetworkStack/NetworkRequest.swift b/DBNetworkStack/NetworkRequest.swift index b2e6dfa..d3db148 100644 --- a/DBNetworkStack/NetworkRequest.swift +++ b/DBNetworkStack/NetworkRequest.swift @@ -34,14 +34,14 @@ public struct NetworkRequest: NetworkRequestRepresening { public let path: String public let baseURLKey: BaseURLKey public let HTTPMethod: DBNetworkStack.HTTPMethod - public let parameter: Dictionary? + public let parameter: Dictionary? public let body: Data? public let allHTTPHeaderFields: Dictionary? } public extension NetworkRequest { // swiftlint:disable line_length - public init(path: String, baseURLKey: BaseURLKey, HTTPMethod: DBNetworkStack.HTTPMethod = .GET, parameter: Dictionary? = nil, body: Data? = nil, allHTTPHeaderField: Dictionary? = nil) { + public init(path: String, baseURLKey: BaseURLKey, HTTPMethod: DBNetworkStack.HTTPMethod = .GET, parameter: Dictionary? = nil, body: Data? = nil, allHTTPHeaderField: Dictionary? = nil) { self.path = path self.baseURLKey = baseURLKey self.HTTPMethod = HTTPMethod diff --git a/DBNetworkStack/NetworkRequestRepresening.swift b/DBNetworkStack/NetworkRequestRepresening.swift index a9e9005..5a4eded 100644 --- a/DBNetworkStack/NetworkRequestRepresening.swift +++ b/DBNetworkStack/NetworkRequestRepresening.swift @@ -54,7 +54,7 @@ public protocol NetworkRequestRepresening { /** Parameters which will be send with the request. */ - var parameter: [String : AnyObject]? { get } + var parameter: [String : Any]? { get } /** Data payload of the request diff --git a/DBNetworkStackTests/DBNetworkStackErrorTest.swift b/DBNetworkStackTests/DBNetworkStackErrorTest.swift index 98fbac8..24f43cd 100644 --- a/DBNetworkStackTests/DBNetworkStackErrorTest.swift +++ b/DBNetworkStackTests/DBNetworkStackErrorTest.swift @@ -29,11 +29,11 @@ import XCTest @testable import DBNetworkStack class DBNetworkStackErrorTest: XCTestCase { - + let url = URL(string: "https://bahn.de")! func testInitFrom400() { //Given let statusCode = 400 - let response = HTTPURLResponse(url: URL(), statusCode: statusCode, httpVersion: nil, headerFields: nil) + let response = HTTPURLResponse(url: url, statusCode: statusCode, httpVersion: nil, headerFields: nil) //When guard let error = DBNetworkStackError(response: response) else { @@ -52,7 +52,7 @@ class DBNetworkStackErrorTest: XCTestCase { func testInitFrom401() { //Given let statusCode = 401 - let response = HTTPURLResponse(url: URL(), statusCode: statusCode, httpVersion: nil, headerFields: nil) + let response = HTTPURLResponse(url: url, statusCode: statusCode, httpVersion: nil, headerFields: nil) //When guard let error = DBNetworkStackError(response: response) else { @@ -71,7 +71,7 @@ class DBNetworkStackErrorTest: XCTestCase { func testInitFrom2xx() { //Given let statusCode = 200 - let response = HTTPURLResponse(url: URL(), statusCode: statusCode, httpVersion: nil, headerFields: nil) + let response = HTTPURLResponse(url: url, statusCode: statusCode, httpVersion: nil, headerFields: nil) //When let error = DBNetworkStackError(response: response) @@ -83,7 +83,7 @@ class DBNetworkStackErrorTest: XCTestCase { func testInitFrom5xx() { //Given let statusCode = 511 - let response = HTTPURLResponse(url: URL(), statusCode: statusCode, httpVersion: nil, headerFields: nil) + let response = HTTPURLResponse(url: url, statusCode: statusCode, httpVersion: nil, headerFields: nil) //When guard let error = DBNetworkStackError(response: response) else { @@ -102,7 +102,7 @@ class DBNetworkStackErrorTest: XCTestCase { func testInitFromInvalid() { //Given let statusCode = 900 - let response = HTTPURLResponse(url: URL(), statusCode: statusCode, httpVersion: nil, headerFields: nil) + let response = HTTPURLResponse(url: url, statusCode: statusCode, httpVersion: nil, headerFields: nil) //When let error = DBNetworkStackError(response: response) diff --git a/DBNetworkStackTests/JSONArrayRessourceTest.swift b/DBNetworkStackTests/JSONArrayRessourceTest.swift index c1b7f69..da86b97 100644 --- a/DBNetworkStackTests/JSONArrayRessourceTest.swift +++ b/DBNetworkStackTests/JSONArrayRessourceTest.swift @@ -35,7 +35,7 @@ class JSONArrayRessourceTest: XCTestCase { let ressource = JSONArrayRessource(request: request) //When - let fetchedTrains = try? ressource.parse(data: Train.validJSONArrayData) + let fetchedTrains = try? ressource.parse(Train.validJSONArrayData) //Then XCTAssertNotNil(fetchedTrains) @@ -51,7 +51,7 @@ class JSONArrayRessourceTest: XCTestCase { //When do { - let _ = try ressource.parse(data: Train.invalidJSONData) + let _ = try ressource.parse(Train.invalidJSONData) XCTFail() } catch { @@ -65,7 +65,7 @@ class JSONArrayRessourceTest: XCTestCase { //When do { - let _ = try ressource.parse(data: Train.validJSONData) + let _ = try ressource.parse(Train.validJSONData) XCTFail() } catch { } diff --git a/DBNetworkStackTests/JSONRessourceTest.swift b/DBNetworkStackTests/JSONRessourceTest.swift index 706865d..31d66d3 100644 --- a/DBNetworkStackTests/JSONRessourceTest.swift +++ b/DBNetworkStackTests/JSONRessourceTest.swift @@ -35,7 +35,7 @@ class JSONRessourceTest: XCTestCase { let ressource = JSONRessource(request: request) //When - let fetchedTrain = try? ressource.parse(data: Train.validJSONData) + let fetchedTrain = try? ressource.parse(Train.validJSONData) //Then XCTAssertNotNil(fetchedTrain) @@ -49,7 +49,7 @@ class JSONRessourceTest: XCTestCase { //When do { - let _ = try ressource.parse(data: Train.invalidJSONData) + let _ = try ressource.parse(Train.invalidJSONData) XCTFail() } catch { } diff --git a/DBNetworkStackTests/NetworkRequestTest.swift b/DBNetworkStackTests/NetworkRequestTest.swift index 1606acb..9340f61 100644 --- a/DBNetworkStackTests/NetworkRequestTest.swift +++ b/DBNetworkStackTests/NetworkRequestTest.swift @@ -35,7 +35,7 @@ class NetworkRequestTest: XCTestCase { let path = "/index.html" let baseURLKey = "Key" let httpMethod = HTTPMethod.GET - let parameter = ["test1": 1, "test2": "2"] as [String : Any] + let parameter: [String : Any] = ["test1": 1, "test2": "2"] as [String : Any] let body = "hallo body data".data(using: String.Encoding.utf8)! let headerFields: Dictionary = [:] let baseURL = URL(string: "https://www.bahn.de/")! @@ -46,7 +46,7 @@ class NetworkRequestTest: XCTestCase { //Then let urlRequest = request.urlRequest(with: baseURL) - XCTAssertEqual(urlRequest.url?.absoluteString, "https://www.bahn.de/index.html?test2=2&test1=1") + XCTAssertEqual(urlRequest.url?.absoluteString, "https://www.bahn.de/index.html?test1=1&test2=2") XCTAssertEqual(urlRequest.httpMethod, httpMethod.rawValue) XCTAssertEqual(urlRequest.httpBody, body) XCTAssertEqual(urlRequest.allHTTPHeaderFields!, headerFields) diff --git a/DBNetworkStackTests/NetworkServiceMock.swift b/DBNetworkStackTests/NetworkServiceMock.swift index 9520b54..6382b66 100644 --- a/DBNetworkStackTests/NetworkServiceMock.swift +++ b/DBNetworkStackTests/NetworkServiceMock.swift @@ -35,7 +35,7 @@ class NetworkAccessMock: NetworkAccessProviding { fileprivate(set) var request: URLRequest? - func load(request: URLRequest, callback: (Data?, HTTPURLResponse?, NSError?) -> ()) -> NetworkTask { + func load(request: URLRequest, callback: @escaping (Data?, HTTPURLResponse?, Error?) -> ()) -> NetworkTask { self.request = request callback(data, response, error) diff --git a/DBNetworkStackTests/NetworkServiceTest.swift b/DBNetworkStackTests/NetworkServiceTest.swift index 2a6dfcc..219e534 100644 --- a/DBNetworkStackTests/NetworkServiceTest.swift +++ b/DBNetworkStackTests/NetworkServiceTest.swift @@ -40,7 +40,7 @@ class NetworkServiceTest: XCTestCase { var networkService: NetworkServiceProviding! var networkAccess = NetworkAccessMock() - let trainName: NSString = "ICE" + let trainName: String = "ICE" let baseURL = URL(string: "//bahn.de")! @@ -152,7 +152,7 @@ class NetworkServiceTest: XCTestCase { //Then switch resultError { case .requestError(let err): - XCTAssertEqual(err, error) + XCTAssertEqual(err as NSError, error) expection.fulfill() default: XCTFail() @@ -166,7 +166,7 @@ class NetworkServiceTest: XCTestCase { //Given let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.endPoint) let ressource = JSONRessource(request: request) - let response = HTTPURLResponse(url: URL(), statusCode: 401, httpVersion: nil, headerFields: nil) + let response = HTTPURLResponse(url: URL(string: "https://bahn.de")!, statusCode: 401, httpVersion: nil, headerFields: nil) networkAccess.changeMock(data: nil, response: response, error: nil) //When diff --git a/DBNetworkStackTests/RessourceTest.swift b/DBNetworkStackTests/RessourceTest.swift index 519038d..e7fa9a3 100644 --- a/DBNetworkStackTests/RessourceTest.swift +++ b/DBNetworkStackTests/RessourceTest.swift @@ -37,7 +37,7 @@ class RessourceTest: XCTestCase { let ressource = Ressource(request: request, parse: { String(data: $0, encoding: String.Encoding.utf8) }) //When - let name = try? ressource.parse(data: validData) + let name = try? ressource.parse(validData) //Then XCTAssertNotNil(name) @@ -52,7 +52,7 @@ class RessourceTest: XCTestCase { //When do { - let _ = try ressource.parse(data: validData) + let _ = try ressource.parse(validData) XCTFail() } catch { } } diff --git a/DBNetworkStackTests/UploadAccessServiceMock.swift b/DBNetworkStackTests/UploadAccessServiceMock.swift index fe1a456..607f512 100644 --- a/DBNetworkStackTests/UploadAccessServiceMock.swift +++ b/DBNetworkStackTests/UploadAccessServiceMock.swift @@ -37,13 +37,13 @@ class UploadAccessServiceMock: MultipartFormDataUploadAccessProviding { fileprivate var response: HTTPURLResponse? fileprivate var multipartFormData: ((MultipartFormDataRepresenting) -> ())? - func upload(_ request: NetworkRequestRepresening, relativeToBaseURL: URL, multipartFormData: (MultipartFormDataRepresenting) -> (), + func upload(_ request: NetworkRequestRepresening, relativeToBaseURL: URL, multipartFormData: @escaping (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, callback: @escaping (Data?, HTTPURLResponse?, NSError?) -> (), - onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock?) { + onNetworkTaskCreation: @escaping (NetworkTask) -> ()) { DispatchQueue.main.async { multipartFormData(MulitpartFormDataRepresentingMock()) - onNetworkTaskCreation?(NetworkTaskMock()) + onNetworkTaskCreation(NetworkTaskMock()) DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(2.0)*Int64(NSEC_PER_SEC)) / Double(NSEC_PER_SEC), execute: { callback(self.reponseData, self.response, self.responseError) From f569e30b9b4a983cdff6b662fa258f517fdb1dfe Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 18 Oct 2016 17:19:11 +0200 Subject: [PATCH 52/92] Multipart form data interface documentation --- .../MultipartFormDataRessourceModelling.swift | 10 ++++++++++ .../MultipartFormDataUploadAccessProviding.swift | 15 +++++++++++++++ .../MultipartFormDataUploadService.swift | 7 +++++-- .../MultipartFormDataUploadServiceProviding.swift | 13 +++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/DBNetworkStack/MultipartFormDataRessourceModelling.swift b/DBNetworkStack/MultipartFormDataRessourceModelling.swift index d216cb7..e91ad0f 100644 --- a/DBNetworkStack/MultipartFormDataRessourceModelling.swift +++ b/DBNetworkStack/MultipartFormDataRessourceModelling.swift @@ -28,7 +28,17 @@ import Foundation +/** + `MultipartFormDataRessourceModelling` describes a multipart form data ressource. + It can be uploaded via HTTP(s) and the response parsed into the coresponding model object. + */ public protocol MultipartFormDataRessourceModelling: RessourceModeling { + /** + Encodes all parts to be sent to the remote. + */ var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void { get } + /** + Defines the size in bytes up to which data is encoded in memory. + */ var encodingMemoryThreshold: UInt64 { get } } diff --git a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift index 5744e10..951c545 100644 --- a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift @@ -28,7 +28,22 @@ import Foundation +/** + `MultipartFormDataUploadAccessProviding` provides access to the network for multipart formdata Requests. + */ public protocol MultipartFormDataUploadAccessProviding { + + /** + Uploads a multipart formdata ressource asynchrony to remote location. + + - parameter request: The ressource to upload. + - parameter relativeToBaseURL: The base URL on wich the request is based on + - parameter multipartFormData: Closure which configures the multipart form data body + - parameter encodingMemoryThreshold: Encoding threshold in bytes. + - parameter callback: Callback which gets called when the request finishes. + - parameter onNetworkTaskCreation: Callback which gets called, after encoding data and starting the upload. The closure gets access to the created network task. + + */ func upload( request: NetworkRequestRepresening, relativeToBaseURL baseURL: NSURL, diff --git a/DBNetworkStack/MultipartFormDataUploadService.swift b/DBNetworkStack/MultipartFormDataUploadService.swift index 6c79d56..165f817 100644 --- a/DBNetworkStack/MultipartFormDataUploadService.swift +++ b/DBNetworkStack/MultipartFormDataUploadService.swift @@ -28,6 +28,9 @@ import Foundation +/** + `MultipartFormDataUploadService` handles network request for multipart form data ressources by using a given MultipartFormDataUploadAccessProviding + */ public final class MultipartFormDataUploadService: MultipartFormDataUploadServiceProviding, NetworkResponseProcessing, BaseURLProviding { private let uploadAccess: MultipartFormDataUploadAccessProviding @@ -36,8 +39,8 @@ public final class MultipartFormDataUploadService: MultipartFormDataUploadServic /** Creates an `MultipartFormDataUploadService` instance with a given uploadAccess and a map of endPoints - - parameter uploadAccess: provides basic access to the network. - - parameter endPoints: map of baseURLKey -> baseURLs + - parameter uploadAccess: Provides basic access to the network. + - parameter endPoints: Map of baseURLKey -> baseURLs */ public init(uploadAccess: MultipartFormDataUploadAccessProviding, endPoints: Dictionary) { self.uploadAccess = uploadAccess diff --git a/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift index 7557aeb..d69151b 100644 --- a/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift @@ -28,7 +28,20 @@ import Foundation +/** + `MultipartFormDataUploadServiceProviding` provides access to upload multipart formdata resources. + */ public protocol MultipartFormDataUploadServiceProviding { + + /** + Uploads a multipart formdata resource to a remote location. + + - parameter ressource: The ressource to upload to. + - parameter onCompletion: Callback which gets called when uploading and tranforming the response into model succeeds. + - parameter onError: Callback which gets called when uploading or tranforming the response fails. + - parameter onNetworkTaskCreation: Callback which gets called, after encoding data and starting the upload. + The closure gets access to the created network task. + */ func upload( ressource: T, onCompletion: (T.Model) -> (), From 32c4607001ab84c23eb5398e86acfacada5c4444 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Wed, 19 Oct 2016 08:02:24 +0200 Subject: [PATCH 53/92] Makes Array Ressource public --- DBNetworkStack/ArrayRessourceModeling.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DBNetworkStack/ArrayRessourceModeling.swift b/DBNetworkStack/ArrayRessourceModeling.swift index 00c434c..e51a04c 100644 --- a/DBNetworkStack/ArrayRessourceModeling.swift +++ b/DBNetworkStack/ArrayRessourceModeling.swift @@ -31,7 +31,7 @@ import Foundation `ArrayRessourceModeling` describes a remote ressource of generic type structured in an array. The ressource type can be fetched via HTTP(s) and parsed into the coresponding model object. */ -protocol ArrayRessourceModeling: RessourceModeling { +public protocol ArrayRessourceModeling: RessourceModeling { associatedtype Element associatedtype Model = Array } From a72a120323ff90a5b4438f22c895098f8824d604 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 25 Oct 2016 08:49:31 +0200 Subject: [PATCH 54/92] Updates project settings --- DBNetworkStack.xcodeproj/project.pbxproj | 9 ++++++++- .../xcshareddata/xcschemes/DBNetworkStack.xcscheme | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index aabc575..8e85e21 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -295,7 +295,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = DBSystel; TargetAttributes = { C60BE65A1D6B2BF3006B0364 = { @@ -438,8 +438,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -492,8 +494,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -515,6 +519,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2,3,4"; TVOS_DEPLOYMENT_TARGET = 9.0; @@ -530,6 +535,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -551,6 +557,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; diff --git a/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme b/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme index 0fc3742..1ebfecb 100644 --- a/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme +++ b/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme @@ -1,6 +1,6 @@ Date: Tue, 25 Oct 2016 10:31:13 +0200 Subject: [PATCH 55/92] Fix build badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c92f2d0..14b24ca 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DBNetworkStack -[![Build Status](https://travis-ci.com/lightsprint09/DBNetworkStackTemp.svg?token=DoSuqFLfFsZgTxGUxHry&branch=feature/cross-plattorm-project)](https://travis-ci.com/lightsprint09/DBNetworkStackTemp) +[![Build Status](https://travis-ci.com/lightsprint09/DBNetworkStack.svg?token=DoSuqFLfFsZgTxGUxHry&branch=develop)](https://travis-ci.com/lightsprint09/DBNetworkStack) [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) | Main Features From cfead485bb5c390988bbfe94167568cc53246738 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 25 Oct 2016 10:44:39 +0200 Subject: [PATCH 56/92] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 14b24ca..b6eeb5a 100644 --- a/README.md +++ b/README.md @@ -85,4 +85,12 @@ Specify the following in your `Cartfile`: ```ogdl github "dbsystel/dbnetworkstack" ~> 0.1 ``` +## Contributing +Feel free to submit a pull request with new features, improvements on tests or documentation and bug fixes. Keep in mind that we welcome code that is well tested and documented. +## Contact +Lukas Schmidt ([Mail](mailto:lukas.la.schmidt@deutschebahn.com), [@lightsprint09](https://twitter.com/lightsprint09)), +Christian Himmelsbach ([Mail](mailto:christian.himmelsbach@deutschebahn.com)) + +## License +DBNetworkStack is released under the MIT license. See LICENSE for details. From 3558a8b00e36766a054ead9e2332383fb112ef22 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 25 Oct 2016 11:25:39 +0200 Subject: [PATCH 57/92] Updated project settings --- DBNetworkStack.xcodeproj/project.pbxproj | 9 ++++++++- .../xcshareddata/xcschemes/DBNetworkStack.xcscheme | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index d524c51..6e898f4 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -295,7 +295,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0810; ORGANIZATIONNAME = DBSystel; TargetAttributes = { C60BE65A1D6B2BF3006B0364 = { @@ -436,8 +436,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -490,8 +492,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -513,6 +517,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 2.3; TARGETED_DEVICE_FAMILY = "1,2,3,4"; TVOS_DEPLOYMENT_TARGET = 9.0; @@ -528,6 +533,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -548,6 +554,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; diff --git a/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme b/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme index 5099767..2ff83a9 100644 --- a/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme +++ b/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme @@ -1,6 +1,6 @@ Date: Tue, 25 Oct 2016 12:33:36 +0200 Subject: [PATCH 58/92] trys to fix travis --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e45803f..959cd71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,10 @@ language: objective-c osx_image: xcode8 env: - - ACTION='clean test' PLATFORM=Mac DESTINATION='platform=OS X' - - ACTION='clean test' PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' - - ACTION='clean build' PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' - - ACTION='clean test' PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' + - ACTION='clean test' PLATFORM=Mac DESTINATION='platform=OS X' SIGN='' + - ACTION='clean test' PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' SIGN='' + - ACTION='clean build' PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' SIGN='' + - ACTION='clean test' PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' SIGN='CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO' script: - - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION | xcpretty \ No newline at end of file + - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION $SIGN | xcpretty \ No newline at end of file From 08dc61f983a0471b03a2e03cd721751d853a605b Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 25 Oct 2016 13:10:18 +0200 Subject: [PATCH 59/92] Fixes swift3 issues on demos --- JSONExample.playground/Contents.swift | 10 +++++----- SimpleDemo.playground/Contents.swift | 12 +++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/JSONExample.playground/Contents.swift b/JSONExample.playground/Contents.swift index e174ca0..c602d97 100644 --- a/JSONExample.playground/Contents.swift +++ b/JSONExample.playground/Contents.swift @@ -1,14 +1,14 @@ //: Playground - noun: a place where people can play import DBNetworkStack -import XCPlayground +import PlaygroundSupport -XCPlaygroundPage.currentPage.needsIndefiniteExecution = true +PlaygroundPage.current.needsIndefiniteExecution = true -let url: NSURL! = NSURL(string: "https://httpbin.org") +let url: URL! = URL(string: "https://httpbin.org") let baseURLKey = "httpBin" -let networkAccess = NSURLSession(configuration: .defaultSessionConfiguration()) +let networkAccess = URLSession(configuration: .default) let networkService = NetworkService(networkAccess: networkAccess, endPoints: [baseURLKey: url]) struct IPOrigin { @@ -18,7 +18,7 @@ struct IPOrigin { extension IPOrigin: JSONMappable { init(object: Dictionary) throws { guard let ipAdress = object["origin"] as? String else { - throw DBNetworkStackError.SerializationError(description: "", data: nil) + throw DBNetworkStackError.serializationError(description: "", data: nil) } self.ipAdress = ipAdress } diff --git a/SimpleDemo.playground/Contents.swift b/SimpleDemo.playground/Contents.swift index 08a325b..90f2820 100644 --- a/SimpleDemo.playground/Contents.swift +++ b/SimpleDemo.playground/Contents.swift @@ -1,18 +1,16 @@ //: Playground - noun: a place where people can play import DBNetworkStack -import XCPlayground +import PlaygroundSupport -XCPlaygroundPage.currentPage.needsIndefiniteExecution = true - -let url: NSURL! = NSURL(string: "https://httpbin.org") +PlaygroundPage.current.needsIndefiniteExecution = true +let url: URL! = URL(string: "https://httpbin.org") let baseURLKey = "httpBin" -let networkAccess = NSURLSession(configuration: .defaultSessionConfiguration()) +let networkAccess = URLSession(configuration: .default) let networkService = NetworkService(networkAccess: networkAccess, endPoints: [baseURLKey: url]) - let request = NetworkRequest(path: "/", baseURLKey: baseURLKey) -let ressource = Ressource(request: request, parse: { String(data: $0, encoding: NSUTF8StringEncoding) }) +let ressource = Ressource(request: request, parse: { String(data: $0, encoding: .utf8) }) networkService.request(ressource, onCompletion: { htmlText in print(htmlText) From 65ac74fac5ed2b6589c2eb61e83c6113b31a13e1 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 25 Oct 2016 13:10:29 +0200 Subject: [PATCH 60/92] improves documentation --- DBNetworkStack/Ressource.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DBNetworkStack/Ressource.swift b/DBNetworkStack/Ressource.swift index 3f1ab9e..4e0ddad 100644 --- a/DBNetworkStack/Ressource.swift +++ b/DBNetworkStack/Ressource.swift @@ -27,6 +27,10 @@ import Foundation +/** + `Ressource` describes a remote ressource of generic type. + The type can be fetched via HTTP(s) and parsed into the coresponding model object. + */ public struct Ressource: RessourceModeling { public let request: NetworkRequestRepresening public let parse: (_ data: Data) throws -> Model From ef946a5dec691902d155bcc195162b251442469b Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 25 Oct 2016 13:19:53 +0200 Subject: [PATCH 61/92] Improves linting --- .swiftlint.yml | 2 +- DBNetworkStack/MultipartFormDataRessource.swift | 1 - DBNetworkStack/MultipartFormDataRessourceModelling.swift | 1 - .../MultipartFormDataUploadServiceTests.swift | 3 ++- DBNetworkStackTests/NetworkRequestTest.swift | 8 +++++--- DBNetworkStackTests/RessourceTest.swift | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 970f006..49043d3 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,10 +1,10 @@ disabled_rules: # rule identifiers to exclude from running - trailing_whitespace + - missing_docs opt_in_rules: # some rules are only opt-in - conditional_returns_on_newline - force_unwrapping - empty_count - - missing_docs - vertical_whitespace - private_outlet excluded: # paths to ignore during linting. Takes precedence over `included`. diff --git a/DBNetworkStack/MultipartFormDataRessource.swift b/DBNetworkStack/MultipartFormDataRessource.swift index a4cdf09..fde0ce4 100644 --- a/DBNetworkStack/MultipartFormDataRessource.swift +++ b/DBNetworkStack/MultipartFormDataRessource.swift @@ -25,7 +25,6 @@ // Created by Christian Himmelsbach on 27.09.16. // - import Foundation public struct MultipartFormDataRessource: MultipartFormDataRessourceModelling { diff --git a/DBNetworkStack/MultipartFormDataRessourceModelling.swift b/DBNetworkStack/MultipartFormDataRessourceModelling.swift index e91ad0f..5a078e4 100644 --- a/DBNetworkStack/MultipartFormDataRessourceModelling.swift +++ b/DBNetworkStack/MultipartFormDataRessourceModelling.swift @@ -25,7 +25,6 @@ // Created by Christian Himmelsbach on 27.09.16. // - import Foundation /** diff --git a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift index edf5fd2..c460f19 100644 --- a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift +++ b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift @@ -35,9 +35,10 @@ class MultipartFormDataUploadServiceTests: XCTestCase { override func setUp() { super.setUp() + let url: NSURL! = NSURL(string: "http://bahn.de") service = MultipartFormDataUploadService( uploadAccess: networkAccess, - endPoints: [ TestEndPoints.EndPoint.name: NSURL(string: "http://bahn.de")!] + endPoints: [ TestEndPoints.EndPoint.name: url] ) } diff --git a/DBNetworkStackTests/NetworkRequestTest.swift b/DBNetworkStackTests/NetworkRequestTest.swift index e348a0e..1128949 100644 --- a/DBNetworkStackTests/NetworkRequestTest.swift +++ b/DBNetworkStackTests/NetworkRequestTest.swift @@ -36,12 +36,14 @@ class NetworkRequestTest: XCTestCase { let baseURLKey = "Key" let httpMethod = HTTPMethod.GET let parameter = ["test1": 1, "test2": "2"] - let body = "hallo body data".dataUsingEncoding(NSUTF8StringEncoding)! + let body: NSData! = "hallo body data".dataUsingEncoding(NSUTF8StringEncoding) let headerFields: Dictionary = [:] - let baseURL = NSURL(string: "https://www.bahn.de/")! + let baseURL: NSURL! = NSURL(string: "https://www.bahn.de/") //When - let request = NetworkRequest(path: path, baseURLKey: baseURLKey, HTTPMethod: httpMethod, parameter: parameter, body: body, allHTTPHeaderFields: headerFields) + let request = NetworkRequest(path: path, baseURLKey: baseURLKey, + HTTPMethod: httpMethod, parameter: parameter, + body: body, allHTTPHeaderFields: headerFields) //Then let urlRequest = request.urlRequest(with: baseURL) diff --git a/DBNetworkStackTests/RessourceTest.swift b/DBNetworkStackTests/RessourceTest.swift index afd4469..3a74aa5 100644 --- a/DBNetworkStackTests/RessourceTest.swift +++ b/DBNetworkStackTests/RessourceTest.swift @@ -32,7 +32,7 @@ class RessourceTest: XCTestCase { func testRessource() { //Given - let validData = "ICE".dataUsingEncoding(NSUTF8StringEncoding)! + let validData: NSData = "ICE".dataUsingEncoding(NSUTF8StringEncoding)! let request = NetworkRequest(path: "/train", baseURLKey: "") let ressource = Ressource(request: request, parse: { String(data: $0, encoding: NSUTF8StringEncoding) }) From 11b2d9424bd0affa15120db04afd7881b715bb3b Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 25 Oct 2016 12:44:40 +0200 Subject: [PATCH 62/92] Moved DBNetworkStackError back to own file --- DBNetworkStack.xcodeproj/project.pbxproj | 4 ++ DBNetworkStack/DBNetworkStackError.swift | 59 ++++++++++++++++++++++++ DBNetworkStack/DBNetworkStackTypes.swift | 30 ------------ 3 files changed, 63 insertions(+), 30 deletions(-) create mode 100644 DBNetworkStack/DBNetworkStackError.swift diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index 6e898f4..d2071a1 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 7C235E0B1DBF6E8500628DC9 /* DBNetworkStackError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C235E0A1DBF6E8500628DC9 /* DBNetworkStackError.swift */; }; 7C40B9E31D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E21D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift */; }; 7C40B9E51D9AA38600620563 /* MultipartFormDataRepresenting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */; }; 7C40B9E71D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E61D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift */; }; @@ -60,6 +61,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 7C235E0A1DBF6E8500628DC9 /* DBNetworkStackError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DBNetworkStackError.swift; sourceTree = ""; }; 7C40B9E21D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultipartFormDataRepresenting.swift; sourceTree = ""; }; 7C40B9E61D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadServiceProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -166,6 +168,7 @@ 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */, C60BE65E1D6B2BF3006B0364 /* DBNetworkStack.h */, C60BE6601D6B2BF3006B0364 /* Info.plist */, + 7C235E0A1DBF6E8500628DC9 /* DBNetworkStackError.swift */, ); path = DBNetworkStack; sourceTree = ""; @@ -373,6 +376,7 @@ C60BE6921D6B2C46006B0364 /* JSONArrayRessource.swift in Sources */, C65F08821D75AC8D00239CC1 /* BaseURLKey.swift in Sources */, 7C40B9F61D9D028000620563 /* MultipartFormDataUploadService.swift in Sources */, + 7C235E0B1DBF6E8500628DC9 /* DBNetworkStackError.swift in Sources */, C65F087B1D757A3C00239CC1 /* JSONMappable.swift in Sources */, C60BE68E1D6B2C46006B0364 /* JSONRessourceModeling.swift in Sources */, C6F235D51D7DA75000E628D8 /* URLSessionNetworkAccess.swift in Sources */, diff --git a/DBNetworkStack/DBNetworkStackError.swift b/DBNetworkStack/DBNetworkStackError.swift new file mode 100644 index 0000000..e036a4c --- /dev/null +++ b/DBNetworkStack/DBNetworkStackError.swift @@ -0,0 +1,59 @@ +// +// DBNetworkStackError.swift +// +// Copyright (C) 2016 DB Systel GmbH. +// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// Created by Lukas Schmidt on 23.08.16. +// + +import Foundation + +/** + `DBNetworkStackError` provides a collection of error types which can occur during execution. + */ +public enum DBNetworkStackError: ErrorType { + case UnknownError + case Unauthorized(response: NSHTTPURLResponse) + case ClientError(response: NSHTTPURLResponse?) + case SerializationError(description: String, data: NSData?) + case RequestError(error: NSError) + case ServerError(response: NSHTTPURLResponse?) + case MissingBaseURL + + init?(response: NSHTTPURLResponse?) { + guard let response = response else { + return nil + } + switch response.statusCode { + case 200..<300: return nil + case 401: + self = .Unauthorized(response: response) + case 400...451: + self = .ClientError(response: response) + case 500...511: + self = .ServerError(response: response) + default: + return nil + } + } + +} diff --git a/DBNetworkStack/DBNetworkStackTypes.swift b/DBNetworkStack/DBNetworkStackTypes.swift index b25d029..e826db1 100644 --- a/DBNetworkStack/DBNetworkStackTypes.swift +++ b/DBNetworkStack/DBNetworkStackTypes.swift @@ -32,33 +32,3 @@ public typealias DBNetworkTaskCreationCompletionBlock = (NetworkTask) -> () //typealias NetworkRequestCompletionBlock = (T.Model) -> () public typealias DBNetworkRequestErrorBlock = (DBNetworkStackError) -> () -/** - `DBNetworkStackError` provides a collection of error types which can occur during execution. - */ -public enum DBNetworkStackError: ErrorType { - case UnknownError - case Unauthorized(response: NSHTTPURLResponse) - case ClientError(response: NSHTTPURLResponse?) - case SerializationError(description: String, data: NSData?) - case RequestError(error: NSError) - case ServerError(response: NSHTTPURLResponse?) - case MissingBaseURL - - init?(response: NSHTTPURLResponse?) { - guard let response = response else { - return nil - } - switch response.statusCode { - case 200..<300: return nil - case 401: - self = .Unauthorized(response: response) - case 400...451: - self = .ClientError(response: response) - case 500...511: - self = .ServerError(response: response) - default: - return nil - } - } - -} From 7e8dfc89675ad9387b2cdea5b21785b3b6037be7 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 25 Oct 2016 13:51:40 +0200 Subject: [PATCH 63/92] Multipart networking is no longer part of the public interface --- DBNetworkStack/DBNetworkStackTypes.swift | 1 - .../MultipartFormDataRepresenting.swift | 2 +- .../MultipartFormDataRessource.swift | 3 +- .../MultipartFormDataRessourceModelling.swift | 3 +- ...ltipartFormDataUploadAccessProviding.swift | 6 ++-- .../MultipartFormDataUploadService.swift | 7 ++--- ...tipartFormDataUploadServiceProviding.swift | 3 +- DBNetworkStack/NetworkRequest.swift | 2 +- .../MulitpartFormDataRepresentingMock.swift | 28 +++++++++---------- .../UploadAccessServiceMock.swift | 2 +- 10 files changed, 26 insertions(+), 31 deletions(-) diff --git a/DBNetworkStack/DBNetworkStackTypes.swift b/DBNetworkStack/DBNetworkStackTypes.swift index e826db1..c85e08a 100644 --- a/DBNetworkStack/DBNetworkStackTypes.swift +++ b/DBNetworkStack/DBNetworkStackTypes.swift @@ -31,4 +31,3 @@ public typealias DBNetworkTaskCreationCompletionBlock = (NetworkTask) -> () // TODO: Use typealiases for functions with generic types in Swift 3.x //typealias NetworkRequestCompletionBlock = (T.Model) -> () public typealias DBNetworkRequestErrorBlock = (DBNetworkStackError) -> () - diff --git a/DBNetworkStack/MultipartFormDataRepresenting.swift b/DBNetworkStack/MultipartFormDataRepresenting.swift index 3ba4bcd..05a1470 100644 --- a/DBNetworkStack/MultipartFormDataRepresenting.swift +++ b/DBNetworkStack/MultipartFormDataRepresenting.swift @@ -35,7 +35,7 @@ import Foundation /// - https://www.ietf.org/rfc/rfc2388.txt /// - https://www.ietf.org/rfc/rfc2045.txt /// - https://www.w3.org/TR/html401/interact/forms.html#h-17.13 -public protocol MultipartFormDataRepresenting: class { +protocol MultipartFormDataRepresenting: class { // MARK: - Properties diff --git a/DBNetworkStack/MultipartFormDataRessource.swift b/DBNetworkStack/MultipartFormDataRessource.swift index a4cdf09..efae5dd 100644 --- a/DBNetworkStack/MultipartFormDataRessource.swift +++ b/DBNetworkStack/MultipartFormDataRessource.swift @@ -25,10 +25,9 @@ // Created by Christian Himmelsbach on 27.09.16. // - import Foundation -public struct MultipartFormDataRessource: MultipartFormDataRessourceModelling { +struct MultipartFormDataRessource: MultipartFormDataRessourceModelling { public var request: NetworkRequestRepresening public var parse: (data: NSData) throws -> Model public var encodingMemoryThreshold: UInt64 diff --git a/DBNetworkStack/MultipartFormDataRessourceModelling.swift b/DBNetworkStack/MultipartFormDataRessourceModelling.swift index e91ad0f..d044803 100644 --- a/DBNetworkStack/MultipartFormDataRessourceModelling.swift +++ b/DBNetworkStack/MultipartFormDataRessourceModelling.swift @@ -25,14 +25,13 @@ // Created by Christian Himmelsbach on 27.09.16. // - import Foundation /** `MultipartFormDataRessourceModelling` describes a multipart form data ressource. It can be uploaded via HTTP(s) and the response parsed into the coresponding model object. */ -public protocol MultipartFormDataRessourceModelling: RessourceModeling { +protocol MultipartFormDataRessourceModelling: RessourceModeling { /** Encodes all parts to be sent to the remote. */ diff --git a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift index 951c545..b2b393c 100644 --- a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift @@ -25,13 +25,12 @@ // Created by Christian Himmelsbach on 27.09.16. // - import Foundation /** `MultipartFormDataUploadAccessProviding` provides access to the network for multipart formdata Requests. */ -public protocol MultipartFormDataUploadAccessProviding { +protocol MultipartFormDataUploadAccessProviding { /** Uploads a multipart formdata ressource asynchrony to remote location. @@ -41,7 +40,8 @@ public protocol MultipartFormDataUploadAccessProviding { - parameter multipartFormData: Closure which configures the multipart form data body - parameter encodingMemoryThreshold: Encoding threshold in bytes. - parameter callback: Callback which gets called when the request finishes. - - parameter onNetworkTaskCreation: Callback which gets called, after encoding data and starting the upload. The closure gets access to the created network task. + - parameter onNetworkTaskCreation: Callback which gets called, after encoding data and starting the upload. + The closure gets access to the created network task. */ func upload( diff --git a/DBNetworkStack/MultipartFormDataUploadService.swift b/DBNetworkStack/MultipartFormDataUploadService.swift index 165f817..0edd2d4 100644 --- a/DBNetworkStack/MultipartFormDataUploadService.swift +++ b/DBNetworkStack/MultipartFormDataUploadService.swift @@ -25,13 +25,12 @@ // Created by Christian Himmelsbach on 29.09.16. // - import Foundation /** `MultipartFormDataUploadService` handles network request for multipart form data ressources by using a given MultipartFormDataUploadAccessProviding */ -public final class MultipartFormDataUploadService: MultipartFormDataUploadServiceProviding, NetworkResponseProcessing, BaseURLProviding { +final class MultipartFormDataUploadService: MultipartFormDataUploadServiceProviding, NetworkResponseProcessing, BaseURLProviding { private let uploadAccess: MultipartFormDataUploadAccessProviding let endPoints: Dictionary @@ -42,12 +41,12 @@ public final class MultipartFormDataUploadService: MultipartFormDataUploadServic - parameter uploadAccess: Provides basic access to the network. - parameter endPoints: Map of baseURLKey -> baseURLs */ - public init(uploadAccess: MultipartFormDataUploadAccessProviding, endPoints: Dictionary) { + init(uploadAccess: MultipartFormDataUploadAccessProviding, endPoints: Dictionary) { self.uploadAccess = uploadAccess self.endPoints = endPoints } - public func upload(ressource: T, onCompletion: (T.Model) -> (), + func upload(ressource: T, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> (), onNetworkTaskCreation: DBNetworkTaskCreationCompletionBlock? = nil) { let baseURL = self.baseURL(with: ressource) diff --git a/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift index d69151b..28af9c6 100644 --- a/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift @@ -25,13 +25,12 @@ // Created by Christian Himmelsbach on 27.09.16. // - import Foundation /** `MultipartFormDataUploadServiceProviding` provides access to upload multipart formdata resources. */ -public protocol MultipartFormDataUploadServiceProviding { +protocol MultipartFormDataUploadServiceProviding { /** Uploads a multipart formdata resource to a remote location. diff --git a/DBNetworkStack/NetworkRequest.swift b/DBNetworkStack/NetworkRequest.swift index 622fa09..79acfc4 100644 --- a/DBNetworkStack/NetworkRequest.swift +++ b/DBNetworkStack/NetworkRequest.swift @@ -28,7 +28,7 @@ import Foundation /** - See `NetworkRequestRepresening` for details. + `NetworkRequest` represents a networkreuqest with all components needed to retrieve correct ressources. */ public struct NetworkRequest: NetworkRequestRepresening { public let path: String diff --git a/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift b/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift index 09f6bc5..6792b42 100644 --- a/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift +++ b/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift @@ -7,45 +7,45 @@ // import Foundation -import DBNetworkStack +@testable import DBNetworkStack -public class MulitpartFormDataRepresentingMock: MultipartFormDataRepresenting { - public var contentType: String = "multipart/form-data" - public var contentLength: UInt64 = 128 - public var boundary: String = "" +class MulitpartFormDataRepresentingMock: MultipartFormDataRepresenting { + var contentType: String = "multipart/form-data" + var contentLength: UInt64 = 128 + var boundary: String = "" - public func appendBodyPart(data data: NSData, name: String) { + func appendBodyPart(data data: NSData, name: String) { } - public func appendBodyPart(data data: NSData, name: String, mimeType: String) { + func appendBodyPart(data data: NSData, name: String, mimeType: String) { } - public func appendBodyPart(fileURL fileURL: NSURL, name: String, fileName: String, mimeType: String) { + func appendBodyPart(fileURL fileURL: NSURL, name: String, fileName: String, mimeType: String) { } - public func appendBodyPart(fileURL fileURL: NSURL, name: String) { + func appendBodyPart(fileURL fileURL: NSURL, name: String) { } - public func appendBodyPart(data data: NSData, name: String, fileName: String, mimeType: String) { + func appendBodyPart(data data: NSData, name: String, fileName: String, mimeType: String) { } - public func appendBodyPart(stream stream: NSInputStream, length: UInt64, headers: [String : String]) { + func appendBodyPart(stream stream: NSInputStream, length: UInt64, headers: [String : String]) { } - public func appendBodyPart(stream stream: NSInputStream, length: UInt64, name: String, fileName: String, mimeType: String) { + func appendBodyPart(stream stream: NSInputStream, length: UInt64, name: String, fileName: String, mimeType: String) { } - public func encode() throws -> NSData { + func encode() throws -> NSData { return NSData() } - public func writeEncodedDataToDisk(fileURL: NSURL) throws { + func writeEncodedDataToDisk(fileURL: NSURL) throws { } } diff --git a/DBNetworkStackTests/UploadAccessServiceMock.swift b/DBNetworkStackTests/UploadAccessServiceMock.swift index 5163986..2a0d30d 100644 --- a/DBNetworkStackTests/UploadAccessServiceMock.swift +++ b/DBNetworkStackTests/UploadAccessServiceMock.swift @@ -26,7 +26,7 @@ // import Foundation -import DBNetworkStack +@testable import DBNetworkStack class UploadAccessServiceMock: MultipartFormDataUploadAccessProviding { From e573bd63a8c37189e115ed9d6bfd9ecb245f103e Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 25 Oct 2016 13:59:46 +0200 Subject: [PATCH 64/92] Adds more documentation --- DBNetworkStack/NetworkRequest.swift | 17 ++++++++++++++--- DBNetworkStack/Ressource.swift | 4 ++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/DBNetworkStack/NetworkRequest.swift b/DBNetworkStack/NetworkRequest.swift index 622fa09..27f2ecc 100644 --- a/DBNetworkStack/NetworkRequest.swift +++ b/DBNetworkStack/NetworkRequest.swift @@ -28,7 +28,7 @@ import Foundation /** - See `NetworkRequestRepresening` for details. + `NetworkRequest` represents a network reuqest with all components needed to retrieve correct ressources. */ public struct NetworkRequest: NetworkRequestRepresening { public let path: String @@ -40,8 +40,19 @@ public struct NetworkRequest: NetworkRequestRepresening { } public extension NetworkRequest { - // swiftlint:disable line_length - public init(path: String, baseURLKey: BaseURLKey, HTTPMethod: DBNetworkStack.HTTPMethod = .GET, parameter: Dictionary? = nil, body: NSData? = nil, allHTTPHeaderField: Dictionary? = nil) { + + /// Creates a instance of `NetworkRequest` with given parameters + /// + /// - Parameters: + /// - path: the relative path to the source without the base url. + /// - baseURLKey: a key to a baseurl which was registerd at `Networkservice` + /// - HTTPMethod: http method to fetch the request with + /// - parameter: url parameter for the request. + /// - body: the body of the request encoded as data + /// - allHTTPHeaderField: the http headerfileds for the request + public init(path: String, baseURLKey: BaseURLKey, + HTTPMethod: DBNetworkStack.HTTPMethod = .GET, parameter: Dictionary? = nil, + body: NSData? = nil, allHTTPHeaderField: Dictionary? = nil) { self.path = path self.baseURLKey = baseURLKey self.HTTPMethod = HTTPMethod diff --git a/DBNetworkStack/Ressource.swift b/DBNetworkStack/Ressource.swift index cc79f9a..ace8c04 100644 --- a/DBNetworkStack/Ressource.swift +++ b/DBNetworkStack/Ressource.swift @@ -27,6 +27,10 @@ import Foundation +/** + `Ressource` describes a remote ressource of generic type. + The type can be fetched via HTTP(s) and parsed into the coresponding model object. + */ public struct Ressource: RessourceModeling { public let request: NetworkRequestRepresening public let parse: (data: NSData) throws -> Model From df99ebfdb2990886f263531b8b481bae7ffbd5f3 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 25 Oct 2016 14:30:16 +0200 Subject: [PATCH 65/92] fixes Signed-off-by: Lukas Schmidt --- DBNetworkStackTests/NetworkServiceTest.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DBNetworkStackTests/NetworkServiceTest.swift b/DBNetworkStackTests/NetworkServiceTest.swift index 91a23c1..e4c033d 100644 --- a/DBNetworkStackTests/NetworkServiceTest.swift +++ b/DBNetworkStackTests/NetworkServiceTest.swift @@ -42,7 +42,7 @@ class NetworkServiceTest: XCTestCase { var networkAccess = NetworkAccessMock() let trainName: NSString = "ICE" - let baseURL = NSURL(string: "//bahn.de")! + let baseURL: NSURL! = NSURL(string: "//bahn.de") override func setUp() { networkService = NetworkService(networkAccess: networkAccess, endPoints: ["endPointTestKey": baseURL]) From b7b8821463059bf5cd28601344ad0c0b2823bffa Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 25 Oct 2016 14:47:33 +0200 Subject: [PATCH 66/92] disable code covarage on travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 959cd71..dc4a78c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,4 @@ env: - ACTION='clean test' PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' SIGN='CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO' script: - - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION $SIGN | xcpretty \ No newline at end of file + - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination -enableCodeCoverage NO "$DESTINATION" $ACTION $SIGN | xcpretty \ No newline at end of file From 4e6d2f8d1edc1040d52f910951b261321227e9fd Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 25 Oct 2016 14:57:58 +0200 Subject: [PATCH 67/92] fixes travis --- .travis.yml | 2 +- .../xcshareddata/xcschemes/DBNetworkStack.xcscheme | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index dc4a78c..959cd71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,4 @@ env: - ACTION='clean test' PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' SIGN='CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO' script: - - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination -enableCodeCoverage NO "$DESTINATION" $ACTION $SIGN | xcpretty \ No newline at end of file + - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION $SIGN | xcpretty \ No newline at end of file diff --git a/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme b/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme index 2ff83a9..d3a4e9c 100644 --- a/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme +++ b/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme @@ -26,8 +26,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES" - codeCoverageEnabled = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES"> From 0bd5e71a9eabbbe2a4e87ebd33897f27b2f5826a Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 25 Oct 2016 15:23:20 +0200 Subject: [PATCH 68/92] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c92f2d0..62728d1 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,8 @@ networkService.request(ressource, onCompletion: { origin in ## Requirements - iOS 9.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ -- Xcode 7.3+ -- Swift 2.2/2.3 +- Xcode 8.0+ +- Swift 3.0 ## Installation From 3ffed721798a098cfe9b71946748e6aa03b81192 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 25 Oct 2016 15:53:44 +0200 Subject: [PATCH 69/92] Naming NetworkTask => NetworkTaskRepresenting --- DBNetworkStack.xcodeproj/project.pbxproj | 18 +++++++++--------- DBNetworkStack/DBNetworkStackTypes.swift | 2 +- DBNetworkStack/NetworkAccessProviding.swift | 2 +- DBNetworkStack/NetworkService.swift | 2 +- DBNetworkStack/NetworkServiceProviding.swift | 2 +- ...ask.swift => NetworkTaskRepresenting.swift} | 6 +++--- DBNetworkStack/URLSessionNetworkAccess.swift | 4 ++-- DBNetworkStackTests/NetworkServiceMock.swift | 2 +- DBNetworkStackTests/NetworkTaskMock.swift | 2 +- .../URLSessionNetworkAccessTest.swift | 2 +- 10 files changed, 21 insertions(+), 21 deletions(-) rename DBNetworkStack/{NetworkTask.swift => NetworkTaskRepresenting.swift} (91%) diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index d2071a1..fa708fb 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -35,7 +35,7 @@ C60BE6921D6B2C46006B0364 /* JSONArrayRessource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6821D6B2C46006B0364 /* JSONArrayRessource.swift */; }; C60BE6931D6B2C46006B0364 /* NetworkRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6831D6B2C46006B0364 /* NetworkRequest.swift */; }; C60BE6A31D6B3807006B0364 /* NetworkServiceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */; }; - C60BE6AD1D6B3E81006B0364 /* NetworkTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */; }; + C60BE6AD1D6B3E81006B0364 /* NetworkTaskRepresenting.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6AC1D6B3E81006B0364 /* NetworkTaskRepresenting.swift */; }; C61348B91DACB4F2000F0583 /* ArrayRessourceModeling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C61348B81DACB4F2000F0583 /* ArrayRessourceModeling.swift */; }; C65F087B1D757A3C00239CC1 /* JSONMappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C65F087A1D757A3C00239CC1 /* JSONMappable.swift */; }; C65F08821D75AC8D00239CC1 /* BaseURLKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */; }; @@ -71,7 +71,7 @@ 7C40B9F71D9D034200620563 /* DBNetworkStackTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = DBNetworkStackTypes.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLProviding.swift; sourceTree = ""; }; 7C40B9FB1D9D661B00620563 /* UploadAccessServiceMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = UploadAccessServiceMock.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkTaskMock.swift; sourceTree = ""; }; + 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkTaskMock.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9FF1D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadServiceTests.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60425091D76F79F00FD3B38 /* NetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -84,7 +84,7 @@ C60BE66C1D6B2BF3006B0364 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = DBNetworkStackTests/Info.plist; sourceTree = ""; }; C60BE67B1D6B2C46006B0364 /* NetworkRequestRepresening.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkRequestRepresening.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60BE67C1D6B2C46006B0364 /* RessourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RessourceModeling.swift; sourceTree = ""; }; - C60BE67D1D6B2C46006B0364 /* NetworkServiceProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkServiceProviding.swift; sourceTree = ""; }; + C60BE67D1D6B2C46006B0364 /* NetworkServiceProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkServiceProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60BE67E1D6B2C46006B0364 /* JSONRessourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONRessourceModeling.swift; sourceTree = ""; }; C60BE67F1D6B2C46006B0364 /* HTTPMethod.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPMethod.swift; sourceTree = ""; }; C60BE6801D6B2C46006B0364 /* Ressource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Ressource.swift; sourceTree = ""; }; @@ -92,19 +92,19 @@ C60BE6821D6B2C46006B0364 /* JSONArrayRessource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONArrayRessource.swift; sourceTree = ""; }; C60BE6831D6B2C46006B0364 /* NetworkRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkRequest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkServiceTest.swift; sourceTree = ""; }; - C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkTask.swift; sourceTree = ""; }; + C60BE6AC1D6B3E81006B0364 /* NetworkTaskRepresenting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkTaskRepresenting.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C61348B81DACB4F2000F0583 /* ArrayRessourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayRessourceModeling.swift; sourceTree = ""; }; C65F087A1D757A3C00239CC1 /* JSONMappable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONMappable.swift; sourceTree = ""; }; C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLKey.swift; sourceTree = ""; }; - C6816E201D87C51C003B699A /* URLSessionNetworkAccessTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLSessionNetworkAccessTest.swift; sourceTree = ""; }; + C6816E201D87C51C003B699A /* URLSessionNetworkAccessTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = URLSessionNetworkAccessTest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C68CC28E1D8BED570019D940 /* BaseURLKeyTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLKeyTest.swift; sourceTree = ""; }; C699E0761D917501006FE7C6 /* DBNetworkStackErrorTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DBNetworkStackErrorTest.swift; sourceTree = ""; }; C6A5DED31D760CC900BC38B1 /* JSONRessourceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONRessourceTest.swift; sourceTree = ""; }; - C6A5DED51D760E5000BC38B1 /* NetworkServiceMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkServiceMock.swift; sourceTree = ""; }; + C6A5DED51D760E5000BC38B1 /* NetworkServiceMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkServiceMock.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C6A5DED91D76A06000BC38B1 /* TrainModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrainModel.swift; sourceTree = ""; }; C6AB45D81DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MulitpartFormDataRepresentingMock.swift; sourceTree = ""; }; C6C86F521D910CE500D6E59E /* NetworkRequestTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkRequestTest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - C6F235D41D7DA75000E628D8 /* URLSessionNetworkAccess.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLSessionNetworkAccess.swift; sourceTree = ""; }; + C6F235D41D7DA75000E628D8 /* URLSessionNetworkAccess.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = URLSessionNetworkAccess.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -198,7 +198,7 @@ C61348B81DACB4F2000F0583 /* ArrayRessourceModeling.swift */, C60BE67B1D6B2C46006B0364 /* NetworkRequestRepresening.swift */, C60BE67D1D6B2C46006B0364 /* NetworkServiceProviding.swift */, - C60BE6AC1D6B3E81006B0364 /* NetworkTask.swift */, + C60BE6AC1D6B3E81006B0364 /* NetworkTaskRepresenting.swift */, C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */, C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */, 7C40B9E21D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift */, @@ -386,7 +386,7 @@ 7C40B9E51D9AA38600620563 /* MultipartFormDataRepresenting.swift in Sources */, 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */, 7C40B9E71D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift in Sources */, - C60BE6AD1D6B3E81006B0364 /* NetworkTask.swift in Sources */, + C60BE6AD1D6B3E81006B0364 /* NetworkTaskRepresenting.swift in Sources */, C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */, C60BE68D1D6B2C46006B0364 /* NetworkServiceProviding.swift in Sources */, C60BE68B1D6B2C46006B0364 /* NetworkRequestRepresening.swift in Sources */, diff --git a/DBNetworkStack/DBNetworkStackTypes.swift b/DBNetworkStack/DBNetworkStackTypes.swift index c85e08a..67aba3b 100644 --- a/DBNetworkStack/DBNetworkStackTypes.swift +++ b/DBNetworkStack/DBNetworkStackTypes.swift @@ -27,7 +27,7 @@ import Foundation -public typealias DBNetworkTaskCreationCompletionBlock = (NetworkTask) -> () +public typealias DBNetworkTaskCreationCompletionBlock = (NetworkTaskRepresenting) -> () // TODO: Use typealiases for functions with generic types in Swift 3.x //typealias NetworkRequestCompletionBlock = (T.Model) -> () public typealias DBNetworkRequestErrorBlock = (DBNetworkStackError) -> () diff --git a/DBNetworkStack/NetworkAccessProviding.swift b/DBNetworkStack/NetworkAccessProviding.swift index 121d3d6..57f62bb 100644 --- a/DBNetworkStack/NetworkAccessProviding.swift +++ b/DBNetworkStack/NetworkAccessProviding.swift @@ -39,5 +39,5 @@ public protocol NetworkAccessProviding { - returns: the running network task */ - func load(request request: NSURLRequest, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> NetworkTask + func load(request request: NSURLRequest, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> NetworkTaskRepresenting } diff --git a/DBNetworkStack/NetworkService.swift b/DBNetworkStack/NetworkService.swift index f806ca4..c11e05b 100644 --- a/DBNetworkStack/NetworkService.swift +++ b/DBNetworkStack/NetworkService.swift @@ -45,7 +45,7 @@ public final class NetworkService: NetworkServiceProviding, BaseURLProviding { self.endPoints = endPoints } - public func request(ressource: T, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> ()) -> NetworkTask { + public func request(ressource: T, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> ()) -> NetworkTaskRepresenting { let baseURL = self.baseURL(with: ressource) let reuqest = ressource.request.urlRequest(with: baseURL) let dataTask = networkAccess.load(request: reuqest, callback: { data, response, error in diff --git a/DBNetworkStack/NetworkServiceProviding.swift b/DBNetworkStack/NetworkServiceProviding.swift index c7bb8cc..5a67361 100644 --- a/DBNetworkStack/NetworkServiceProviding.swift +++ b/DBNetworkStack/NetworkServiceProviding.swift @@ -40,7 +40,7 @@ public protocol NetworkServiceProviding: NetworkResponseProcessing { - returns: the request */ - func request(ressource: T, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> ()) -> NetworkTask + func request(ressource: T, onCompletion: (T.Model) -> (), onError: (DBNetworkStackError) -> ()) -> NetworkTaskRepresenting } public protocol NetworkResponseProcessing { diff --git a/DBNetworkStack/NetworkTask.swift b/DBNetworkStack/NetworkTaskRepresenting.swift similarity index 91% rename from DBNetworkStack/NetworkTask.swift rename to DBNetworkStack/NetworkTaskRepresenting.swift index 9b1b45a..6a04095 100644 --- a/DBNetworkStack/NetworkTask.swift +++ b/DBNetworkStack/NetworkTaskRepresenting.swift @@ -1,5 +1,5 @@ // -// CancelableRequest.swift +// NetworkTaskRepresenting.swift // // Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ @@ -28,9 +28,9 @@ import Foundation /** - `NetworkTask` is a task which runs async to fetch data. + `NetworkTaskRepresenting` is a task which runs async to fetch data. */ -public protocol NetworkTask { +public protocol NetworkTaskRepresenting { /** Cancels a task. */ diff --git a/DBNetworkStack/URLSessionNetworkAccess.swift b/DBNetworkStack/URLSessionNetworkAccess.swift index 57c2383..6746a61 100644 --- a/DBNetworkStack/URLSessionNetworkAccess.swift +++ b/DBNetworkStack/URLSessionNetworkAccess.swift @@ -31,7 +31,7 @@ import Foundation Adds conformens to `NetworkAccessProviding`. `NSURLSession` can now be used as a networkprovider. */ extension NSURLSession: NetworkAccessProviding { - public func load(request request: NSURLRequest, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> NetworkTask { + public func load(request request: NSURLRequest, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> NetworkTaskRepresenting { let task = dataTaskWithRequest(request) { data, response, error in callback(data, response as? NSHTTPURLResponse, error) } @@ -41,7 +41,7 @@ extension NSURLSession: NetworkAccessProviding { } } -extension NSURLSessionTask: NetworkTask { +extension NSURLSessionTask: NetworkTaskRepresenting { public var progress: NSProgress { let totalBytesExpected = response?.expectedContentLength ?? NSURLSessionTransferSizeUnknown let progress = NSProgress(totalUnitCount: totalBytesExpected) diff --git a/DBNetworkStackTests/NetworkServiceMock.swift b/DBNetworkStackTests/NetworkServiceMock.swift index 95dafbd..8d18807 100644 --- a/DBNetworkStackTests/NetworkServiceMock.swift +++ b/DBNetworkStackTests/NetworkServiceMock.swift @@ -35,7 +35,7 @@ class NetworkAccessMock: NetworkAccessProviding { private(set) var request: NSURLRequest? - func load(request request: NSURLRequest, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> NetworkTask { + func load(request request: NSURLRequest, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> NetworkTaskRepresenting { self.request = request callback(data, response, error) diff --git a/DBNetworkStackTests/NetworkTaskMock.swift b/DBNetworkStackTests/NetworkTaskMock.swift index cca136e..4c86d18 100644 --- a/DBNetworkStackTests/NetworkTaskMock.swift +++ b/DBNetworkStackTests/NetworkTaskMock.swift @@ -28,7 +28,7 @@ import Foundation import DBNetworkStack -class NetworkTaskMock: NetworkTask { +class NetworkTaskMock: NetworkTaskRepresenting { var isCanceld = false func cancel() { isCanceld = true diff --git a/DBNetworkStackTests/URLSessionNetworkAccessTest.swift b/DBNetworkStackTests/URLSessionNetworkAccessTest.swift index 82c3fea..9820c43 100644 --- a/DBNetworkStackTests/URLSessionNetworkAccessTest.swift +++ b/DBNetworkStackTests/URLSessionNetworkAccessTest.swift @@ -29,7 +29,7 @@ import XCTest @testable import DBNetworkStack //class URLSessionNetworkAccessTest: XCTestCase { -// var dataTask: NetworkTask! +// var dataTask: NetworkTaskRepresenting! // // func testExample() { // let expection = expectationWithDescription("wait") From 18b8b3c7f6d2c050f913f50831f31477ef284e23 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 1 Nov 2016 13:56:37 +0100 Subject: [PATCH 70/92] try to fix travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 959cd71..3502323 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ env: - ACTION='clean test' PLATFORM=Mac DESTINATION='platform=OS X' SIGN='' - ACTION='clean test' PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' SIGN='' - ACTION='clean build' PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' SIGN='' - - ACTION='clean test' PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' SIGN='CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO' + - ACTION='clean test' PLATFORM=tvOS SIGN='CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO' script: - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION $SIGN | xcpretty \ No newline at end of file From f9d064bdb96f2a1649728fb8cea3ab05358a6493 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 1 Nov 2016 14:56:57 +0100 Subject: [PATCH 71/92] tray travis --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3502323..b5d68b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,10 @@ language: objective-c osx_image: xcode8 env: - - ACTION='clean test' PLATFORM=Mac DESTINATION='platform=OS X' SIGN='' - - ACTION='clean test' PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' SIGN='' - - ACTION='clean build' PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' SIGN='' - - ACTION='clean test' PLATFORM=tvOS SIGN='CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO' + - ACTION='clean test' PLATFORM=Mac DESTINATION='-destination platform=OS X' SIGN='' + - ACTION='clean test' PLATFORM=iOS DESTINATION='-destination platform=iOS Simulator,name=iPhone 6S' SIGN='' + - ACTION='clean build' PLATFORM=watchOS DESTINATION='-destination platform=watchOS Simulator,name=Apple Watch - 38mm' SIGN='' + - ACTION='clean test' PLATFORM=tvOS DESTINATION='-destination platform=tvOS Simulator,name=Apple TV 1080p' SIGN='CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO' script: - - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION $SIGN | xcpretty \ No newline at end of file + - set -o pipefail && xcodebuild -scheme DBNetworkStack "$DESTINATION" $ACTION $SIGN | xcpretty \ No newline at end of file From 365143c20d67307c3b0e6159ec72cd6d400eb0c2 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 1 Nov 2016 16:25:45 +0100 Subject: [PATCH 72/92] Typo fix: Ressource => Resource --- DBNetworkStack.xcodeproj/project.pbxproj | 92 +++++++++---------- ...ling.swift => ArrayResourceModeling.swift} | 8 +- DBNetworkStack/BaseURLProviding.swift | 14 +-- ...essource.swift => JSONArrayResource.swift} | 8 +- ...JSONRessource.swift => JSONResource.swift} | 8 +- ...eling.swift => JSONResourceModeling.swift} | 8 +- ....swift => MultipartFormDataResource.swift} | 4 +- ... MultipartFormDataResourceModelling.swift} | 6 +- ...ltipartFormDataUploadAccessProviding.swift | 4 +- .../MultipartFormDataUploadService.swift | 12 +-- ...tipartFormDataUploadServiceProviding.swift | 6 +- DBNetworkStack/NetworkAccessProviding.swift | 4 +- DBNetworkStack/NetworkRequest.swift | 2 +- .../NetworkRequestRepresening.swift | 4 +- DBNetworkStack/NetworkService.swift | 10 +- DBNetworkStack/NetworkServiceProviding.swift | 22 ++--- .../{Ressource.swift => Resource.swift} | 6 +- ...eModeling.swift => ResourceModeling.swift} | 8 +- ...Test.swift => JSONArrayResourceTest.swift} | 22 ++--- ...ourceTest.swift => JSONResourceTest.swift} | 16 ++-- .../MultipartFormDataUploadServiceTests.swift | 4 +- DBNetworkStackTests/NetworkServiceTest.swift | 24 ++--- ...RessourceTest.swift => ResourceTest.swift} | 16 ++-- JSONExample.playground/Contents.swift | 4 +- README.md | 22 ++--- SimpleDemo.playground/Contents.swift | 4 +- 26 files changed, 169 insertions(+), 169 deletions(-) rename DBNetworkStack/{ArrayRessourceModeling.swift => ArrayResourceModeling.swift} (83%) rename DBNetworkStack/{JSONArrayRessource.swift => JSONArrayResource.swift} (86%) rename DBNetworkStack/{JSONRessource.swift => JSONResource.swift} (88%) rename DBNetworkStack/{JSONRessourceModeling.swift => JSONResourceModeling.swift} (93%) rename DBNetworkStack/{MultipartFormDataRessource.swift => MultipartFormDataResource.swift} (94%) rename DBNetworkStack/{MultipartFormDataRessourceModelling.swift => MultipartFormDataResourceModelling.swift} (89%) rename DBNetworkStack/{Ressource.swift => Resource.swift} (92%) rename DBNetworkStack/{RessourceModeling.swift => ResourceModeling.swift} (89%) rename DBNetworkStackTests/{JSONArrayRessourceTest.swift => JSONArrayResourceTest.swift} (77%) rename DBNetworkStackTests/{JSONRessourceTest.swift => JSONResourceTest.swift} (81%) rename DBNetworkStackTests/{RessourceTest.swift => ResourceTest.swift} (81%) diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index e2df602..4f17bb4 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -11,8 +11,8 @@ 7C40B9E31D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E21D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift */; }; 7C40B9E51D9AA38600620563 /* MultipartFormDataRepresenting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */; }; 7C40B9E71D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E61D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift */; }; - 7C40B9E91D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */; }; - 7C40B9EB1D9AA4DE00620563 /* MultipartFormDataRessource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataRessource.swift */; }; + 7C40B9E91D9AA4B800620563 /* MultipartFormDataResourceModelling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9E81D9AA4B800620563 /* MultipartFormDataResourceModelling.swift */; }; + 7C40B9EB1D9AA4DE00620563 /* MultipartFormDataResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataResource.swift */; }; 7C40B9F61D9D028000620563 /* MultipartFormDataUploadService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F51D9D028000620563 /* MultipartFormDataUploadService.swift */; }; 7C40B9FA1D9D0F6D00620563 /* BaseURLProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */; }; 7C40B9FC1D9D661B00620563 /* UploadAccessServiceMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9FB1D9D661B00620563 /* UploadAccessServiceMock.swift */; }; @@ -20,28 +20,28 @@ 7C40BA001D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C40B9FF1D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift */; }; C60425081D76F6F400FD3B38 /* NetworkAccessProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */; }; C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425091D76F79F00FD3B38 /* NetworkService.swift */; }; - C60425101D78002400FD3B38 /* JSONArrayRessourceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C604250F1D78002400FD3B38 /* JSONArrayRessourceTest.swift */; }; - C60425131D7803CA00FD3B38 /* RessourceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425121D7803CA00FD3B38 /* RessourceTest.swift */; }; + C60425101D78002400FD3B38 /* JSONArrayResourceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C604250F1D78002400FD3B38 /* JSONArrayResourceTest.swift */; }; + C60425131D7803CA00FD3B38 /* ResourceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60425121D7803CA00FD3B38 /* ResourceTest.swift */; }; C60BE65F1D6B2BF3006B0364 /* DBNetworkStack.h in Headers */ = {isa = PBXBuildFile; fileRef = C60BE65E1D6B2BF3006B0364 /* DBNetworkStack.h */; settings = {ATTRIBUTES = (Public, ); }; }; C60BE6661D6B2BF3006B0364 /* DBNetworkStack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C60BE65B1D6B2BF3006B0364 /* DBNetworkStack.framework */; }; C60BE68B1D6B2C46006B0364 /* NetworkRequestRepresening.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67B1D6B2C46006B0364 /* NetworkRequestRepresening.swift */; }; - C60BE68C1D6B2C46006B0364 /* RessourceModeling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67C1D6B2C46006B0364 /* RessourceModeling.swift */; }; + C60BE68C1D6B2C46006B0364 /* ResourceModeling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67C1D6B2C46006B0364 /* ResourceModeling.swift */; }; C60BE68D1D6B2C46006B0364 /* NetworkServiceProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67D1D6B2C46006B0364 /* NetworkServiceProviding.swift */; }; - C60BE68E1D6B2C46006B0364 /* JSONRessourceModeling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67E1D6B2C46006B0364 /* JSONRessourceModeling.swift */; }; + C60BE68E1D6B2C46006B0364 /* JSONResourceModeling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67E1D6B2C46006B0364 /* JSONResourceModeling.swift */; }; C60BE68F1D6B2C46006B0364 /* HTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE67F1D6B2C46006B0364 /* HTTPMethod.swift */; }; - C60BE6901D6B2C46006B0364 /* Ressource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6801D6B2C46006B0364 /* Ressource.swift */; }; - C60BE6911D6B2C46006B0364 /* JSONRessource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6811D6B2C46006B0364 /* JSONRessource.swift */; }; - C60BE6921D6B2C46006B0364 /* JSONArrayRessource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6821D6B2C46006B0364 /* JSONArrayRessource.swift */; }; + C60BE6901D6B2C46006B0364 /* Resource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6801D6B2C46006B0364 /* Resource.swift */; }; + C60BE6911D6B2C46006B0364 /* JSONResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6811D6B2C46006B0364 /* JSONResource.swift */; }; + C60BE6921D6B2C46006B0364 /* JSONArrayResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6821D6B2C46006B0364 /* JSONArrayResource.swift */; }; C60BE6931D6B2C46006B0364 /* NetworkRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6831D6B2C46006B0364 /* NetworkRequest.swift */; }; C60BE6A31D6B3807006B0364 /* NetworkServiceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */; }; C60BE6AD1D6B3E81006B0364 /* NetworkTaskRepresenting.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60BE6AC1D6B3E81006B0364 /* NetworkTaskRepresenting.swift */; }; - C61348B91DACB4F2000F0583 /* ArrayRessourceModeling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C61348B81DACB4F2000F0583 /* ArrayRessourceModeling.swift */; }; + C61348B91DACB4F2000F0583 /* ArrayResourceModeling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C61348B81DACB4F2000F0583 /* ArrayResourceModeling.swift */; }; C65F087B1D757A3C00239CC1 /* JSONMappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C65F087A1D757A3C00239CC1 /* JSONMappable.swift */; }; C65F08821D75AC8D00239CC1 /* BaseURLKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */; }; C6816E211D87C51C003B699A /* URLSessionNetworkAccessTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6816E201D87C51C003B699A /* URLSessionNetworkAccessTest.swift */; }; C68CC28F1D8BED570019D940 /* BaseURLKeyTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68CC28E1D8BED570019D940 /* BaseURLKeyTest.swift */; }; C699E0771D917501006FE7C6 /* DBNetworkStackErrorTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C699E0761D917501006FE7C6 /* DBNetworkStackErrorTest.swift */; }; - C6A5DED41D760CC900BC38B1 /* JSONRessourceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A5DED31D760CC900BC38B1 /* JSONRessourceTest.swift */; }; + C6A5DED41D760CC900BC38B1 /* JSONResourceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A5DED31D760CC900BC38B1 /* JSONResourceTest.swift */; }; C6A5DED61D760E5000BC38B1 /* NetworkServiceMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A5DED51D760E5000BC38B1 /* NetworkServiceMock.swift */; }; C6A5DEDA1D76A06000BC38B1 /* TrainModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A5DED91D76A06000BC38B1 /* TrainModel.swift */; }; C6AB45D91DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6AB45D81DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift */; }; @@ -64,40 +64,40 @@ 7C40B9E21D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultipartFormDataRepresenting.swift; sourceTree = ""; }; 7C40B9E61D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadServiceProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataRessourceModelling.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataRessource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataRessource.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + 7C40B9E81D9AA4B800620563 /* MultipartFormDataResourceModelling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataResourceModelling.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataResource.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9F51D9D028000620563 /* MultipartFormDataUploadService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLProviding.swift; sourceTree = ""; }; + 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = BaseURLProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9FB1D9D661B00620563 /* UploadAccessServiceMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = UploadAccessServiceMock.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9FD1D9D66A600620563 /* NetworkTaskMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkTaskMock.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7C40B9FF1D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MultipartFormDataUploadServiceTests.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60425071D76F6F400FD3B38 /* NetworkAccessProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkAccessProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60425091D76F79F00FD3B38 /* NetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkService.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - C604250F1D78002400FD3B38 /* JSONArrayRessourceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONArrayRessourceTest.swift; sourceTree = ""; }; - C60425121D7803CA00FD3B38 /* RessourceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RessourceTest.swift; sourceTree = ""; }; + C604250F1D78002400FD3B38 /* JSONArrayResourceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = JSONArrayResourceTest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + C60425121D7803CA00FD3B38 /* ResourceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = ResourceTest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60BE65B1D6B2BF3006B0364 /* DBNetworkStack.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DBNetworkStack.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C60BE65E1D6B2BF3006B0364 /* DBNetworkStack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DBNetworkStack.h; sourceTree = ""; }; C60BE6601D6B2BF3006B0364 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; C60BE6651D6B2BF3006B0364 /* DBNetworkStackTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DBNetworkStackTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; C60BE66C1D6B2BF3006B0364 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = DBNetworkStackTests/Info.plist; sourceTree = ""; }; C60BE67B1D6B2C46006B0364 /* NetworkRequestRepresening.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkRequestRepresening.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - C60BE67C1D6B2C46006B0364 /* RessourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RessourceModeling.swift; sourceTree = ""; }; + C60BE67C1D6B2C46006B0364 /* ResourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = ResourceModeling.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60BE67D1D6B2C46006B0364 /* NetworkServiceProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkServiceProviding.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - C60BE67E1D6B2C46006B0364 /* JSONRessourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONRessourceModeling.swift; sourceTree = ""; }; + C60BE67E1D6B2C46006B0364 /* JSONResourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = JSONResourceModeling.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60BE67F1D6B2C46006B0364 /* HTTPMethod.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPMethod.swift; sourceTree = ""; }; - C60BE6801D6B2C46006B0364 /* Ressource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Ressource.swift; sourceTree = ""; }; - C60BE6811D6B2C46006B0364 /* JSONRessource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONRessource.swift; sourceTree = ""; }; - C60BE6821D6B2C46006B0364 /* JSONArrayRessource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONArrayRessource.swift; sourceTree = ""; }; + C60BE6801D6B2C46006B0364 /* Resource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Resource.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + C60BE6811D6B2C46006B0364 /* JSONResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = JSONResource.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + C60BE6821D6B2C46006B0364 /* JSONArrayResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = JSONArrayResource.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60BE6831D6B2C46006B0364 /* NetworkRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkRequest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkServiceTest.swift; sourceTree = ""; }; + C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkServiceTest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C60BE6AC1D6B3E81006B0364 /* NetworkTaskRepresenting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkTaskRepresenting.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - C61348B81DACB4F2000F0583 /* ArrayRessourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayRessourceModeling.swift; sourceTree = ""; }; + C61348B81DACB4F2000F0583 /* ArrayResourceModeling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = ArrayResourceModeling.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C65F087A1D757A3C00239CC1 /* JSONMappable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONMappable.swift; sourceTree = ""; }; C65F08811D75AC8D00239CC1 /* BaseURLKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLKey.swift; sourceTree = ""; }; C6816E201D87C51C003B699A /* URLSessionNetworkAccessTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = URLSessionNetworkAccessTest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C68CC28E1D8BED570019D940 /* BaseURLKeyTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseURLKeyTest.swift; sourceTree = ""; }; C699E0761D917501006FE7C6 /* DBNetworkStackErrorTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DBNetworkStackErrorTest.swift; sourceTree = ""; }; - C6A5DED31D760CC900BC38B1 /* JSONRessourceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONRessourceTest.swift; sourceTree = ""; }; + C6A5DED31D760CC900BC38B1 /* JSONResourceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = JSONResourceTest.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C6A5DED51D760E5000BC38B1 /* NetworkServiceMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NetworkServiceMock.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; C6A5DED91D76A06000BC38B1 /* TrainModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrainModel.swift; sourceTree = ""; }; C6AB45D81DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MulitpartFormDataRepresentingMock.swift; sourceTree = ""; }; @@ -127,7 +127,7 @@ C60425111D7801A400FD3B38 /* protocol */ = { isa = PBXGroup; children = ( - C60BE67E1D6B2C46006B0364 /* JSONRessourceModeling.swift */, + C60BE67E1D6B2C46006B0364 /* JSONResourceModeling.swift */, ); name = protocol; sourceTree = ""; @@ -157,8 +157,8 @@ C60BE6A91D6B39BF006B0364 /* JSONParsing */, C60BE6A81D6B399A006B0364 /* protocol */, C60BE67F1D6B2C46006B0364 /* HTTPMethod.swift */, - C60BE6801D6B2C46006B0364 /* Ressource.swift */, - 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataRessource.swift */, + C60BE6801D6B2C46006B0364 /* Resource.swift */, + 7C40B9EA1D9AA4DE00620563 /* MultipartFormDataResource.swift */, C60BE6831D6B2C46006B0364 /* NetworkRequest.swift */, C6F235D41D7DA75000E628D8 /* URLSessionNetworkAccess.swift */, C60425091D76F79F00FD3B38 /* NetworkService.swift */, @@ -176,9 +176,9 @@ C6A5DED81D76A05300BC38B1 /* Helpers */, C6A5DED21D760C9E00BC38B1 /* Mocks */, C60BE6A01D6B3807006B0364 /* NetworkServiceTest.swift */, - C6A5DED31D760CC900BC38B1 /* JSONRessourceTest.swift */, - C604250F1D78002400FD3B38 /* JSONArrayRessourceTest.swift */, - C60425121D7803CA00FD3B38 /* RessourceTest.swift */, + C6A5DED31D760CC900BC38B1 /* JSONResourceTest.swift */, + C604250F1D78002400FD3B38 /* JSONArrayResourceTest.swift */, + C60425121D7803CA00FD3B38 /* ResourceTest.swift */, C6816E201D87C51C003B699A /* URLSessionNetworkAccessTest.swift */, C6C86F521D910CE500D6E59E /* NetworkRequestTest.swift */, C68CC28E1D8BED570019D940 /* BaseURLKeyTest.swift */, @@ -191,8 +191,8 @@ C60BE6A81D6B399A006B0364 /* protocol */ = { isa = PBXGroup; children = ( - C60BE67C1D6B2C46006B0364 /* RessourceModeling.swift */, - C61348B81DACB4F2000F0583 /* ArrayRessourceModeling.swift */, + C60BE67C1D6B2C46006B0364 /* ResourceModeling.swift */, + C61348B81DACB4F2000F0583 /* ArrayResourceModeling.swift */, C60BE67B1D6B2C46006B0364 /* NetworkRequestRepresening.swift */, C60BE67D1D6B2C46006B0364 /* NetworkServiceProviding.swift */, C60BE6AC1D6B3E81006B0364 /* NetworkTaskRepresenting.swift */, @@ -201,7 +201,7 @@ 7C40B9E21D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift */, 7C40B9E61D9AA48200620563 /* MultipartFormDataUploadServiceProviding.swift */, 7C40B9E41D9AA38600620563 /* MultipartFormDataRepresenting.swift */, - 7C40B9E81D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift */, + 7C40B9E81D9AA4B800620563 /* MultipartFormDataResourceModelling.swift */, 7C40B9F91D9D0F6D00620563 /* BaseURLProviding.swift */, ); name = protocol; @@ -211,8 +211,8 @@ isa = PBXGroup; children = ( C60425111D7801A400FD3B38 /* protocol */, - C60BE6811D6B2C46006B0364 /* JSONRessource.swift */, - C60BE6821D6B2C46006B0364 /* JSONArrayRessource.swift */, + C60BE6811D6B2C46006B0364 /* JSONResource.swift */, + C60BE6821D6B2C46006B0364 /* JSONArrayResource.swift */, C65F087A1D757A3C00239CC1 /* JSONMappable.swift */, ); name = JSONParsing; @@ -365,21 +365,21 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - C61348B91DACB4F2000F0583 /* ArrayRessourceModeling.swift in Sources */, + C61348B91DACB4F2000F0583 /* ArrayResourceModeling.swift in Sources */, C60BE6931D6B2C46006B0364 /* NetworkRequest.swift in Sources */, - C60BE6911D6B2C46006B0364 /* JSONRessource.swift in Sources */, - 7C40B9EB1D9AA4DE00620563 /* MultipartFormDataRessource.swift in Sources */, - C60BE6901D6B2C46006B0364 /* Ressource.swift in Sources */, - 7C40B9E91D9AA4B800620563 /* MultipartFormDataRessourceModelling.swift in Sources */, + C60BE6911D6B2C46006B0364 /* JSONResource.swift in Sources */, + 7C40B9EB1D9AA4DE00620563 /* MultipartFormDataResource.swift in Sources */, + C60BE6901D6B2C46006B0364 /* Resource.swift in Sources */, + 7C40B9E91D9AA4B800620563 /* MultipartFormDataResourceModelling.swift in Sources */, 7C40B9E31D9A9A7000620563 /* MultipartFormDataUploadAccessProviding.swift in Sources */, - C60BE6921D6B2C46006B0364 /* JSONArrayRessource.swift in Sources */, + C60BE6921D6B2C46006B0364 /* JSONArrayResource.swift in Sources */, C65F08821D75AC8D00239CC1 /* BaseURLKey.swift in Sources */, 7C40B9F61D9D028000620563 /* MultipartFormDataUploadService.swift in Sources */, 7C235E0B1DBF6E8500628DC9 /* DBNetworkStackError.swift in Sources */, C65F087B1D757A3C00239CC1 /* JSONMappable.swift in Sources */, - C60BE68E1D6B2C46006B0364 /* JSONRessourceModeling.swift in Sources */, + C60BE68E1D6B2C46006B0364 /* JSONResourceModeling.swift in Sources */, C6F235D51D7DA75000E628D8 /* URLSessionNetworkAccess.swift in Sources */, - C60BE68C1D6B2C46006B0364 /* RessourceModeling.swift in Sources */, + C60BE68C1D6B2C46006B0364 /* ResourceModeling.swift in Sources */, C60BE68F1D6B2C46006B0364 /* HTTPMethod.swift in Sources */, C604250A1D76F79F00FD3B38 /* NetworkService.swift in Sources */, 7C40B9E51D9AA38600620563 /* MultipartFormDataRepresenting.swift in Sources */, @@ -400,16 +400,16 @@ 7C40B9FE1D9D66A600620563 /* NetworkTaskMock.swift in Sources */, C699E0771D917501006FE7C6 /* DBNetworkStackErrorTest.swift in Sources */, C6A5DED61D760E5000BC38B1 /* NetworkServiceMock.swift in Sources */, - C60425131D7803CA00FD3B38 /* RessourceTest.swift in Sources */, + C60425131D7803CA00FD3B38 /* ResourceTest.swift in Sources */, 7C40BA001D9D67CD00620563 /* MultipartFormDataUploadServiceTests.swift in Sources */, C6A5DEDA1D76A06000BC38B1 /* TrainModel.swift in Sources */, C6816E211D87C51C003B699A /* URLSessionNetworkAccessTest.swift in Sources */, - C60425101D78002400FD3B38 /* JSONArrayRessourceTest.swift in Sources */, + C60425101D78002400FD3B38 /* JSONArrayResourceTest.swift in Sources */, C60BE6A31D6B3807006B0364 /* NetworkServiceTest.swift in Sources */, C68CC28F1D8BED570019D940 /* BaseURLKeyTest.swift in Sources */, C6AB45D91DA3DB4D00FD41D2 /* MulitpartFormDataRepresentingMock.swift in Sources */, 7C40B9FC1D9D661B00620563 /* UploadAccessServiceMock.swift in Sources */, - C6A5DED41D760CC900BC38B1 /* JSONRessourceTest.swift in Sources */, + C6A5DED41D760CC900BC38B1 /* JSONResourceTest.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/DBNetworkStack/ArrayRessourceModeling.swift b/DBNetworkStack/ArrayResourceModeling.swift similarity index 83% rename from DBNetworkStack/ArrayRessourceModeling.swift rename to DBNetworkStack/ArrayResourceModeling.swift index e51a04c..2fe607c 100644 --- a/DBNetworkStack/ArrayRessourceModeling.swift +++ b/DBNetworkStack/ArrayResourceModeling.swift @@ -1,5 +1,5 @@ // -// ArrayRessourceModeling.swift +// ArrayResourceModeling.swift // // Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ @@ -28,10 +28,10 @@ import Foundation /** - `ArrayRessourceModeling` describes a remote ressource of generic type structured in an array. - The ressource type can be fetched via HTTP(s) and parsed into the coresponding model object. + `ArrayResourceModeling` describes a remote resource of generic type structured in an array. + The resource type can be fetched via HTTP(s) and parsed into the coresponding model object. */ -public protocol ArrayRessourceModeling: RessourceModeling { +public protocol ArrayResourceModeling: ResourceModeling { associatedtype Element associatedtype Model = Array } diff --git a/DBNetworkStack/BaseURLProviding.swift b/DBNetworkStack/BaseURLProviding.swift index 4c07590..efea38c 100644 --- a/DBNetworkStack/BaseURLProviding.swift +++ b/DBNetworkStack/BaseURLProviding.swift @@ -31,24 +31,24 @@ internal protocol BaseURLProviding { var endPoints: [String: URL] {get} /** - Provides an baseURL for a given ressource. + Provides an baseURL for a given resource. To be more flexible, a request does only contain a path and not a full URL. Mapping has to be done in the service to get an registerd baseURL for the request. - - parameter ressource: The ressource you want to get a baseURL for. + - parameter resource: The resource you want to get a baseURL for. - - return matching baseURL to the given ressource + - return matching baseURL to the given resource */ - func baseURL(with ressource: T) -> URL + func baseURL(with resource: T) -> URL } extension BaseURLProviding { - func baseURL(with ressource: T) -> URL { + func baseURL(with resource: T) -> URL { - guard let baseURL = endPoints[ressource.request.baseURLKey.name] else { - fatalError("Missing baseurl for key: \(ressource.request.baseURLKey.name)") + guard let baseURL = endPoints[resource.request.baseURLKey.name] else { + fatalError("Missing baseurl for key: \(resource.request.baseURLKey.name)") } return baseURL diff --git a/DBNetworkStack/JSONArrayRessource.swift b/DBNetworkStack/JSONArrayResource.swift similarity index 86% rename from DBNetworkStack/JSONArrayRessource.swift rename to DBNetworkStack/JSONArrayResource.swift index fd44bfc..9cf6b63 100644 --- a/DBNetworkStack/JSONArrayRessource.swift +++ b/DBNetworkStack/JSONArrayResource.swift @@ -1,5 +1,5 @@ // -// JSONListRessource.swift +// JSONListResource.swift // // Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ @@ -28,13 +28,13 @@ import Foundation /** - `JSONRessource` represents a network ressource in JSON, which can be parsed into an array of Model Types. + `JSONResource` represents a network resource in JSON, which can be parsed into an array of Model Types. The root JSON payload must be an array. - See `RessourceModeling` for more details. + See `ResourceModeling` for more details. */ -public struct JSONArrayRessource: JSONRessourceModeling, ArrayRessourceModeling { +public struct JSONArrayResource: JSONResourceModeling, ArrayResourceModeling { public typealias Element = Element_ public let request: NetworkRequestRepresening public var parse: (_ data: Data) throws -> Array { diff --git a/DBNetworkStack/JSONRessource.swift b/DBNetworkStack/JSONResource.swift similarity index 88% rename from DBNetworkStack/JSONRessource.swift rename to DBNetworkStack/JSONResource.swift index 6f261b8..8ca3a67 100644 --- a/DBNetworkStack/JSONRessource.swift +++ b/DBNetworkStack/JSONResource.swift @@ -1,5 +1,5 @@ // -// JSONRessource.swift +// JSONResource.swift // // Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ @@ -27,13 +27,13 @@ import Foundation /** - `JSONRessource` represents a network ressource in JSON, which can be parsed into a Model Type. + `JSONResource` represents a network resource in JSON, which can be parsed into a Model Type. The root JSON payload must be an object. - See `RessourceModeling` for more details. + See `ResourceModeling` for more details. */ -public struct JSONRessource: JSONRessourceModeling { +public struct JSONResource: JSONResourceModeling { public let request: NetworkRequestRepresening public var parse: (_ data: Data) throws -> Model { return parseFunction diff --git a/DBNetworkStack/JSONRessourceModeling.swift b/DBNetworkStack/JSONResourceModeling.swift similarity index 93% rename from DBNetworkStack/JSONRessourceModeling.swift rename to DBNetworkStack/JSONResourceModeling.swift index e406d92..5b0f099 100644 --- a/DBNetworkStack/JSONRessourceModeling.swift +++ b/DBNetworkStack/JSONResourceModeling.swift @@ -1,5 +1,5 @@ // -// JSONRessourceModeling.swift +// JSONResourceModeling.swift // // Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ @@ -27,11 +27,11 @@ import Foundation /** - `JSONRessourceModeling` discribes ressource which can be parsed from JSON into Model Type. + `JSONResourceModeling` discribes resource which can be parsed from JSON into Model Type. It speciefies a JSON Container from which the model is parsed and a `parse` function to transform the container into the given Model. */ -public protocol JSONRessourceModeling: RessourceModeling { +public protocol JSONResourceModeling: ResourceModeling { /** The JSON container format represented as an foundation object e.g. {} becomes Dictionary, [] becomes Array> @@ -50,7 +50,7 @@ public protocol JSONRessourceModeling: RessourceModeling { func parse(_ jsonPayload: Container) throws -> Model } -extension JSONRessourceModeling { +extension JSONResourceModeling { /** Parses JSON to a speciefied generic Model diff --git a/DBNetworkStack/MultipartFormDataRessource.swift b/DBNetworkStack/MultipartFormDataResource.swift similarity index 94% rename from DBNetworkStack/MultipartFormDataRessource.swift rename to DBNetworkStack/MultipartFormDataResource.swift index 3ef5b0a..65a6cc6 100644 --- a/DBNetworkStack/MultipartFormDataRessource.swift +++ b/DBNetworkStack/MultipartFormDataResource.swift @@ -1,5 +1,5 @@ // -// MultipartFormDataRessource.swift +// MultipartFormDataResource.swift // // Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ @@ -27,7 +27,7 @@ import Foundation -struct MultipartFormDataRessource: MultipartFormDataRessourceModelling { +struct MultipartFormDataResource: MultipartFormDataResourceModelling { public var request: NetworkRequestRepresening public var parse: (_ data: Data) throws -> Model public var encodingMemoryThreshold: UInt64 diff --git a/DBNetworkStack/MultipartFormDataRessourceModelling.swift b/DBNetworkStack/MultipartFormDataResourceModelling.swift similarity index 89% rename from DBNetworkStack/MultipartFormDataRessourceModelling.swift rename to DBNetworkStack/MultipartFormDataResourceModelling.swift index 6a584cb..0f89a77 100644 --- a/DBNetworkStack/MultipartFormDataRessourceModelling.swift +++ b/DBNetworkStack/MultipartFormDataResourceModelling.swift @@ -1,5 +1,5 @@ // -// MultipartFormDataRessourceModelling.swift +// MultipartFormDataResourceModelling.swift // // Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ @@ -28,10 +28,10 @@ import Foundation /** - `MultipartFormDataRessourceModelling` describes a multipart form data ressource. + `MultipartFormDataResourceModelling` describes a multipart form data resource. It can be uploaded via HTTP(s) and the response parsed into the coresponding model object. */ -protocol MultipartFormDataRessourceModelling: RessourceModeling { +protocol MultipartFormDataResourceModelling: ResourceModeling { /** Encodes all parts to be sent to the remote. */ diff --git a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift index 7060d85..646c66f 100644 --- a/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadAccessProviding.swift @@ -33,9 +33,9 @@ import Foundation protocol MultipartFormDataUploadAccessProviding { /** - Uploads a multipart formdata ressource asynchrony to remote location. + Uploads a multipart formdata resource asynchrony to remote location. - - parameter request: The ressource to upload. + - parameter request: The resource to upload. - parameter relativeToBaseURL: The base URL on wich the request is based on - parameter multipartFormData: Closure which configures the multipart form data body - parameter encodingMemoryThreshold: Encoding threshold in bytes. diff --git a/DBNetworkStack/MultipartFormDataUploadService.swift b/DBNetworkStack/MultipartFormDataUploadService.swift index 0b1e014..73345b1 100644 --- a/DBNetworkStack/MultipartFormDataUploadService.swift +++ b/DBNetworkStack/MultipartFormDataUploadService.swift @@ -28,7 +28,7 @@ import Foundation /** - `MultipartFormDataUploadService` handles network request for multipart form data ressources by using a given MultipartFormDataUploadAccessProviding + `MultipartFormDataUploadService` handles network request for multipart form data resources by using a given MultipartFormDataUploadAccessProviding */ final class MultipartFormDataUploadService: MultipartFormDataUploadServiceProviding, NetworkResponseProcessing, BaseURLProviding { @@ -47,12 +47,12 @@ final class MultipartFormDataUploadService: MultipartFormDataUploadServiceProvid self.endPoints = endPoints } - func upload(_ ressource: T, onCompletion: @escaping (T.Model) -> (), + func upload(_ resource: T, onCompletion: @escaping (T.Model) -> (), onError: @escaping (DBNetworkStackError) -> (), onNetworkTaskCreation: @escaping (NetworkTaskRepresenting) -> Void) { - let baseURL = self.baseURL(with: ressource) - uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, - encodingMemoryThreshold: ressource.encodingMemoryThreshold, callback: { data, response, error in - self.processAsyncResponse(response: response, ressource: ressource, data: data, error: error, onCompletion: onCompletion, onError: onError) + let baseURL = self.baseURL(with: resource) + uploadAccess.upload(resource.request, relativeToBaseURL: baseURL, multipartFormData: resource.encodeInMultipartFormData, + encodingMemoryThreshold: resource.encodingMemoryThreshold, callback: { data, response, error in + self.processAsyncResponse(response: response, resource: resource, data: data, error: error, onCompletion: onCompletion, onError: onError) }, onNetworkTaskCreation: { task in DispatchQueue.main.async(execute: { diff --git a/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift index 84f6f9f..7a207fc 100644 --- a/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift +++ b/DBNetworkStack/MultipartFormDataUploadServiceProviding.swift @@ -35,14 +35,14 @@ protocol MultipartFormDataUploadServiceProviding { /** Uploads a multipart formdata resource to a remote location. - - parameter ressource: The ressource to upload to. + - parameter resource: The resource to upload to. - parameter onCompletion: Callback which gets called when uploading and tranforming the response into model succeeds. - parameter onError: Callback which gets called when uploading or tranforming the response fails. - parameter onNetworkTaskCreation: Callback which gets called, after encoding data and starting the upload. The closure gets access to the created network task. */ - func upload( - _ ressource: T, + func upload( + _ resource: T, onCompletion: @escaping (T.Model) -> (), onError: @escaping (DBNetworkStackError) -> (), onNetworkTaskCreation: @escaping (NetworkTaskRepresenting) -> () diff --git a/DBNetworkStack/NetworkAccessProviding.swift b/DBNetworkStack/NetworkAccessProviding.swift index aeabbc8..c264cf3 100644 --- a/DBNetworkStack/NetworkAccessProviding.swift +++ b/DBNetworkStack/NetworkAccessProviding.swift @@ -32,9 +32,9 @@ import Foundation */ public protocol NetworkAccessProviding { /** - Fetches a ressource asynchrony from remote location. + Fetches a resource asynchrony from remote location. - - parameter request: The ressource you want to fetch. + - parameter request: The resource you want to fetch. - parameter callback: Callback which gets called when the request finishes. - returns: the running network task diff --git a/DBNetworkStack/NetworkRequest.swift b/DBNetworkStack/NetworkRequest.swift index f882e01..15534dc 100644 --- a/DBNetworkStack/NetworkRequest.swift +++ b/DBNetworkStack/NetworkRequest.swift @@ -28,7 +28,7 @@ import Foundation /** - `NetworkRequest` represents a network reuqest with all components needed to retrieve correct ressources. + `NetworkRequest` represents a network reuqest with all components needed to retrieve correct resources. */ public struct NetworkRequest: NetworkRequestRepresening { public let path: String diff --git a/DBNetworkStack/NetworkRequestRepresening.swift b/DBNetworkStack/NetworkRequestRepresening.swift index 5a4eded..38bc946 100644 --- a/DBNetworkStack/NetworkRequestRepresening.swift +++ b/DBNetworkStack/NetworkRequestRepresening.swift @@ -28,11 +28,11 @@ import Foundation /** - `NetworkRequestRepresening` represents a networkreuqest with all components needed to retrieve correct ressources. + `NetworkRequestRepresening` represents a networkreuqest with all components needed to retrieve correct resources. */ public protocol NetworkRequestRepresening { /** - Path to the remote ressource. + Path to the remote resource. */ var path: String { get } diff --git a/DBNetworkStack/NetworkService.swift b/DBNetworkStack/NetworkService.swift index e55f318..7c75137 100644 --- a/DBNetworkStack/NetworkService.swift +++ b/DBNetworkStack/NetworkService.swift @@ -28,7 +28,7 @@ import Foundation /** - `NetworkService` handles network request for ressources by using a given `NetworkAccessProviding` + `NetworkService` handles network request for resources by using a given `NetworkAccessProviding` */ public final class NetworkService: NetworkServiceProviding, BaseURLProviding { let networkAccess: NetworkAccessProviding @@ -45,11 +45,11 @@ public final class NetworkService: NetworkServiceProviding, BaseURLProviding { self.endPoints = endPoints } - public func request(_ ressource: T, onCompletion: @escaping (T.Model) -> (), onError: @escaping (DBNetworkStackError) -> ()) -> NetworkTaskRepresenting { - let baseURL = self.baseURL(with: ressource) - let reuqest = ressource.request.urlRequest(with: baseURL) + public func request(_ resource: T, onCompletion: @escaping (T.Model) -> (), onError: @escaping (DBNetworkStackError) -> ()) -> NetworkTaskRepresenting { + let baseURL = self.baseURL(with: resource) + let reuqest = resource.request.urlRequest(with: baseURL) let dataTask = networkAccess.load(request: reuqest, callback: { data, response, error in - self.processAsyncResponse(response: response, ressource: ressource, data: data, error: error, onCompletion: onCompletion, onError: onError) + self.processAsyncResponse(response: response, resource: resource, data: data, error: error, onCompletion: onCompletion, onError: onError) }) return dataTask } diff --git a/DBNetworkStack/NetworkServiceProviding.swift b/DBNetworkStack/NetworkServiceProviding.swift index 63ce191..5a636d6 100644 --- a/DBNetworkStack/NetworkServiceProviding.swift +++ b/DBNetworkStack/NetworkServiceProviding.swift @@ -28,39 +28,39 @@ import Foundation /** - `NetworkServiceProviding` provides access to remote ressources. + `NetworkServiceProviding` provides access to remote resources. */ public protocol NetworkServiceProviding: NetworkResponseProcessing { /** - Fetches a ressource asynchrony from remote location + Fetches a resource asynchrony from remote location - - parameter ressource: The ressource you want to fetch. + - parameter resource: The resource you want to fetch. - parameter onComplition: Callback which gets called when fetching and tranforming into model succeeds. - parameter onError: Callback which gets called when fetching or tranforming fails. - returns: the request */ - func request(_ ressource: T, onCompletion: @escaping (T.Model) -> (), onError: @escaping (DBNetworkStackError) -> ()) -> NetworkTaskRepresenting + func request(_ resource: T, onCompletion: @escaping (T.Model) -> (), onError: @escaping (DBNetworkStackError) -> ()) -> NetworkTaskRepresenting } public protocol NetworkResponseProcessing { /** - Processes the results of an HTTPRequest and parses the result the matching Model type of the given ressource. + Processes the results of an HTTPRequest and parses the result the matching Model type of the given resource. Great error handling should be implemented here as well. - parameter response: response from the server. Could be nil - - parameter ressource: The ressource matching the response. + - parameter resource: The resource matching the response. - parameter data: Returned data. Could be nil. - parameter error: the return error. Could be nil. - returns: the parsed model object. */ - func process(response: HTTPURLResponse?, ressource: T, data: Data?, error: Error?) throws -> T.Model + func process(response: HTTPURLResponse?, resource: T, data: Data?, error: Error?) throws -> T.Model } extension NetworkResponseProcessing { - public func process(response: HTTPURLResponse?, ressource: T, data: Data?, error: Error?) throws -> T.Model { + public func process(response: HTTPURLResponse?, resource: T, data: Data?, error: Error?) throws -> T.Model { if let error = error { throw DBNetworkStackError.requestError(error: error) } @@ -71,7 +71,7 @@ extension NetworkResponseProcessing { throw DBNetworkStackError.serializationError(description: "No data to serialize revied from the server", data: nil) } do { - return try ressource.parse(data) + return try resource.parse(data) } catch let error as CustomStringConvertible { throw DBNetworkStackError.serializationError(description: error.description, data: data) } catch { @@ -81,12 +81,12 @@ extension NetworkResponseProcessing { } extension NetworkResponseProcessing { - func processAsyncResponse(response: HTTPURLResponse?, ressource: T, data: Data?, + func processAsyncResponse(response: HTTPURLResponse?, resource: T, data: Data?, error: Error?, onCompletion: @escaping (T.Model) -> (), onError: @escaping (DBNetworkStackError) -> ()) { do { let parsed = try self.process( response: response, - ressource: ressource, + resource: resource, data: data, error: error ) diff --git a/DBNetworkStack/Ressource.swift b/DBNetworkStack/Resource.swift similarity index 92% rename from DBNetworkStack/Ressource.swift rename to DBNetworkStack/Resource.swift index 4e0ddad..36f2248 100644 --- a/DBNetworkStack/Ressource.swift +++ b/DBNetworkStack/Resource.swift @@ -1,5 +1,5 @@ // -// Ressource.swift +// Resource.swift // // Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ @@ -28,10 +28,10 @@ import Foundation /** - `Ressource` describes a remote ressource of generic type. + `Resource` describes a remote resource of generic type. The type can be fetched via HTTP(s) and parsed into the coresponding model object. */ -public struct Ressource: RessourceModeling { +public struct Resource: ResourceModeling { public let request: NetworkRequestRepresening public let parse: (_ data: Data) throws -> Model diff --git a/DBNetworkStack/RessourceModeling.swift b/DBNetworkStack/ResourceModeling.swift similarity index 89% rename from DBNetworkStack/RessourceModeling.swift rename to DBNetworkStack/ResourceModeling.swift index 57b868a..8689ecd 100644 --- a/DBNetworkStack/RessourceModeling.swift +++ b/DBNetworkStack/ResourceModeling.swift @@ -1,5 +1,5 @@ // -// RessourceModeling.swift +// ResourceModeling.swift // // Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ @@ -27,12 +27,12 @@ import Foundation /** - `RessourceModeling` describes a remote ressource of generic type. + `ResourceModeling` describes a remote resource of generic type. The type can be fetched via HTTP(s) and parsed into the coresponding model object. */ -public protocol RessourceModeling { +public protocol ResourceModeling { /** - Model object which coresponds to the remote ressource + Model object which coresponds to the remote resource */ associatedtype Model diff --git a/DBNetworkStackTests/JSONArrayRessourceTest.swift b/DBNetworkStackTests/JSONArrayResourceTest.swift similarity index 77% rename from DBNetworkStackTests/JSONArrayRessourceTest.swift rename to DBNetworkStackTests/JSONArrayResourceTest.swift index da86b97..7115a36 100644 --- a/DBNetworkStackTests/JSONArrayRessourceTest.swift +++ b/DBNetworkStackTests/JSONArrayResourceTest.swift @@ -1,5 +1,5 @@ // -// JSONArrayRessourceTest.swift +// JSONArrayResourceTest.swift // // Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ @@ -28,14 +28,14 @@ import XCTest @testable import DBNetworkStack -class JSONArrayRessourceTest: XCTestCase { - func testRessource() { +class JSONArrayResourceTest: XCTestCase { + func testResource() { //Given let request = NetworkRequest(path: "/trains", baseURLKey: "") - let ressource = JSONArrayRessource(request: request) + let resource = JSONArrayResource(request: request) //When - let fetchedTrains = try? ressource.parse(Train.validJSONArrayData) + let fetchedTrains = try? resource.parse(Train.validJSONArrayData) //Then XCTAssertNotNil(fetchedTrains) @@ -44,28 +44,28 @@ class JSONArrayRessourceTest: XCTestCase { XCTAssertEqual(fetchedTrains?.last?.name, "TGV") } - func testRessourceWithInvalidData() { + func testResourceWithInvalidData() { //Given let request = NetworkRequest(path: "/trains", baseURLKey: "") - let ressource = JSONArrayRessource(request: request) + let resource = JSONArrayResource(request: request) //When do { - let _ = try ressource.parse(Train.invalidJSONData) + let _ = try resource.parse(Train.invalidJSONData) XCTFail() } catch { } } - func testRessourceWithInvalidContainer() { + func testResourceWithInvalidContainer() { //Given let request = NetworkRequest(path: "/trains", baseURLKey: "") - let ressource = JSONArrayRessource(request: request) + let resource = JSONArrayResource(request: request) //When do { - let _ = try ressource.parse(Train.validJSONData) + let _ = try resource.parse(Train.validJSONData) XCTFail() } catch { } diff --git a/DBNetworkStackTests/JSONRessourceTest.swift b/DBNetworkStackTests/JSONResourceTest.swift similarity index 81% rename from DBNetworkStackTests/JSONRessourceTest.swift rename to DBNetworkStackTests/JSONResourceTest.swift index 31d66d3..480009d 100644 --- a/DBNetworkStackTests/JSONRessourceTest.swift +++ b/DBNetworkStackTests/JSONResourceTest.swift @@ -1,5 +1,5 @@ // -// JSONRessourceTest.swift +// JSONResourceTest.swift // // Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ @@ -28,28 +28,28 @@ import XCTest @testable import DBNetworkStack -class JSONRessourceTest: XCTestCase { - func testRessource() { +class JSONResourceTest: XCTestCase { + func testResource() { //Given let request = NetworkRequest(path: "/train", baseURLKey: "") - let ressource = JSONRessource(request: request) + let resource = JSONResource(request: request) //When - let fetchedTrain = try? ressource.parse(Train.validJSONData) + let fetchedTrain = try? resource.parse(Train.validJSONData) //Then XCTAssertNotNil(fetchedTrain) XCTAssertEqual(fetchedTrain?.name, "ICE") } - func testRessourceWithInvalidData() { + func testResourceWithInvalidData() { //Given let request = NetworkRequest(path: "/train", baseURLKey: "") - let ressource = JSONRessource(request: request) + let resource = JSONResource(request: request) //When do { - let _ = try ressource.parse(Train.invalidJSONData) + let _ = try resource.parse(Train.invalidJSONData) XCTFail() } catch { } diff --git a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift index 6c48b4b..d8c12ad 100644 --- a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift +++ b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift @@ -45,7 +45,7 @@ class MultipartFormDataUploadServiceTests: XCTestCase { func testUpload() { //Given let request = NetworkRequest(path: "/train", baseURLKey: TestEndPoints.endPoint) - let ressource = MultipartFormDataRessource(request: request, parse: { $0 }, + let resource = MultipartFormDataResource(request: request, parse: { $0 }, encodingMemoryThreshold: 200, encodeInMultipartFormData: { formdata in }) @@ -53,7 +53,7 @@ class MultipartFormDataUploadServiceTests: XCTestCase { var didCreateTask = false //When let expection = expectation(description: "loadValidRequest") - service.upload(ressource, onCompletion: { data in + service.upload(resource, onCompletion: { data in XCTAssertEqual(Train.validJSONData, data) XCTAssert(didCreateTask) expection.fulfill() diff --git a/DBNetworkStackTests/NetworkServiceTest.swift b/DBNetworkStackTests/NetworkServiceTest.swift index 2467c4e..58cde0b 100644 --- a/DBNetworkStackTests/NetworkServiceTest.swift +++ b/DBNetworkStackTests/NetworkServiceTest.swift @@ -51,12 +51,12 @@ class NetworkServiceTest: XCTestCase { func testValidRequest() { //Given let request = NetworkRequest(path: "/train", baseURLKey: TestEndPoints.endPoint) - let ressource = JSONRessource(request: request) + let resource = JSONResource(request: request) networkAccess.changeMock(data: Train.validJSONData, response: nil, error: nil) //When let expection = expectation(description: "loadValidRequest") - networkService.request(ressource, onCompletion: { train in + networkService.request(resource, onCompletion: { train in //Then XCTAssertEqual(train.name, self.trainName) XCTAssertEqual(self.networkAccess.request?.url?.absoluteString, "//bahn.de/train") @@ -72,12 +72,12 @@ class NetworkServiceTest: XCTestCase { func testNoData() { //Given let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.endPoint) - let ressource = JSONRessource(request: request) + let resource = JSONResource(request: request) networkAccess.changeMock(data: nil, response: nil, error: nil) //When let expection = expectation(description: "testNoData") - networkService.request(ressource, onCompletion: { fetchedTrain in + networkService.request(resource, onCompletion: { fetchedTrain in XCTFail() }, onError: { error in switch error { @@ -96,12 +96,12 @@ class NetworkServiceTest: XCTestCase { func testInvalidData() { //Given let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.endPoint) - let ressource = JSONRessource(request: request) + let resource = JSONResource(request: request) networkAccess.changeMock(data: Train.invalidJSONData, response: nil, error: nil) //When let expection = expectation(description: "testInvalidData") - networkService.request(ressource, onCompletion: { fetchedTrain in + networkService.request(resource, onCompletion: { fetchedTrain in XCTFail() }, onError: { error in //Then @@ -119,12 +119,12 @@ class NetworkServiceTest: XCTestCase { func testInvalidJSONKeyData() { //Given let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.endPoint) - let ressource = JSONRessource(request: request) + let resource = JSONResource(request: request) networkAccess.changeMock(data: Train.JSONDataWithInvalidKey, response: nil, error: nil) //When let expection = expectation(description: "testInvalidJSONKeyData") - networkService.request(ressource, onCompletion: { fetchedTrain in + networkService.request(resource, onCompletion: { fetchedTrain in XCTFail() }, onError: { error in switch error { @@ -142,12 +142,12 @@ class NetworkServiceTest: XCTestCase { //Given let error = NSError(domain: "", code: 0, userInfo: nil) let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.endPoint) - let ressource = JSONRessource(request: request) + let resource = JSONResource(request: request) networkAccess.changeMock(data: nil, response: nil, error: error) //When let expection = expectation(description: "testOnError") - networkService.request(ressource, onCompletion: { fetchedTrain in + networkService.request(resource, onCompletion: { fetchedTrain in }, onError: { resultError in //Then switch resultError { @@ -165,13 +165,13 @@ class NetworkServiceTest: XCTestCase { func testOnStatusCodeError() { //Given let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.endPoint) - let ressource = JSONRessource(request: request) + let resource = JSONResource(request: request) let response = HTTPURLResponse(url: URL(string: "https://bahn.de")!, statusCode: 401, httpVersion: nil, headerFields: nil) networkAccess.changeMock(data: nil, response: response, error: nil) //When let expection = expectation(description: "testOnError") - networkService.request(ressource, onCompletion: { fetchedTrain in + networkService.request(resource, onCompletion: { fetchedTrain in }, onError: { resultError in //Then switch resultError { diff --git a/DBNetworkStackTests/RessourceTest.swift b/DBNetworkStackTests/ResourceTest.swift similarity index 81% rename from DBNetworkStackTests/RessourceTest.swift rename to DBNetworkStackTests/ResourceTest.swift index a4a2e91..a4812d1 100644 --- a/DBNetworkStackTests/RessourceTest.swift +++ b/DBNetworkStackTests/ResourceTest.swift @@ -1,5 +1,5 @@ // -// RessourceTest.swift +// ResourceTest.swift // // Copyright (C) 2016 DB Systel GmbH. // DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/ @@ -28,32 +28,32 @@ import XCTest @testable import DBNetworkStack -class RessourceTest: XCTestCase { +class ResourceTest: XCTestCase { - func testRessource() { + func testResource() { //Given let validData = "ICE".data(using: String.Encoding.utf8)! let request = NetworkRequest(path: "/train", baseURLKey: "") - let ressource = Ressource(request: request, parse: { String(data: $0, encoding: String.Encoding.utf8) }) + let resource = Resource(request: request, parse: { String(data: $0, encoding: String.Encoding.utf8) }) //When - let name = try? ressource.parse(validData) + let name = try? resource.parse(validData) //Then XCTAssertNotNil(name) XCTAssertEqual(name!!, "ICE") } - func testRessourceWithInvalidData() { + func testResourceWithInvalidData() { //Given let validData = Data() let request = NetworkRequest(path: "/train", baseURLKey: "") - let ressource = JSONRessource(request: request) + let resource = JSONResource(request: request) //When do { - let _ = try ressource.parse(validData) + let _ = try resource.parse(validData) XCTFail() } catch { } } diff --git a/JSONExample.playground/Contents.swift b/JSONExample.playground/Contents.swift index c602d97..78c9e8e 100644 --- a/JSONExample.playground/Contents.swift +++ b/JSONExample.playground/Contents.swift @@ -25,9 +25,9 @@ extension IPOrigin: JSONMappable { } let request = NetworkRequest(path: "/ip", baseURLKey: baseURLKey) -let ressource = JSONRessource(request: request) +let resource = JSONResource(request: request) -networkService.request(ressource, onCompletion: { origin in +networkService.request(resource, onCompletion: { origin in print(origin) }, onError: { error in //Handle errors diff --git a/README.md b/README.md index 07bceb6..a584c73 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ | Main Features ---------|--------------- -🛡 | Typed network ressources +🛡 | Typed network resources 🏠 | Protocol oriented architecture 🔀| Exchangeable implementations 🚄 | Extendable API @@ -16,7 +16,7 @@ The idea behind this project comes from this [talk.objc.io article](https://talk ## Basic Demo Lets say you want to fetch a ``html`` string. -First you have to create a service, by providing a networkaccess. You can use NSURLSession out of the box or provide your own custom solution by implementing ```NetworkAccessProviding```. In addition you need to register baseURLs endpoints for request mapping. This gives you the flexability to change your endpoints very easily when your envionment changes. +First you have to create a service, by providing a network access. You can use NSURLSession out of the box or provide your own custom solution by implementing ```NetworkAccessProviding```. In addition you need to register baseURLs endpoints for request mapping. This gives you the flexibility to change your endpoints very easily when your environment changes. ```swift @@ -28,19 +28,19 @@ let networkService = NetworkService(networkAccess: networkAccess, endPoints: [ba ``` -Create a ressource with a request to fetch your data. +Create a resource with a request to fetch your data. ```swift let request = NetworkRequest(path: "/", baseURLKey: baseURLKey) -let ressource = Ressource(request: request, parse: { String(data: $0, encoding: NSUTF8StringEncoding) }) +let resource = Resource(request: request, parse: { String(data: $0, encoding: NSUTF8StringEncoding) }) ``` -Request your ressource and handle the response +Request your resource and handle the response ```swift -networkService.request(ressource, onCompletion: { htmlText in +networkService.request(resource, onCompletion: { htmlText in print(htmlText) - }, onError: { error in +}, onError: { error in //Handle errors }) @@ -49,7 +49,7 @@ networkService.request(ressource, onCompletion: { htmlText in ## JSON Mapping Demo ```swift struct IPOrigin { - let ipAdress: String + let ipAddress: String } extension IPOrigin: JSONMappable { @@ -59,11 +59,11 @@ extension IPOrigin: JSONMappable { } let request = NetworkRequest(path: "/ip", baseURLKey: baseURLKey) -let ressource = JSONRessource(request: request) +let resource = JSONResource(request: request) -networkService.request(ressource, onCompletion: { origin in +networkService.request(resource, onCompletion: { origin in print(origin) - }, onError: { error in +}, onError: { error in //Handle errors }) ``` diff --git a/SimpleDemo.playground/Contents.swift b/SimpleDemo.playground/Contents.swift index 90f2820..172f358 100644 --- a/SimpleDemo.playground/Contents.swift +++ b/SimpleDemo.playground/Contents.swift @@ -10,9 +10,9 @@ let baseURLKey = "httpBin" let networkAccess = URLSession(configuration: .default) let networkService = NetworkService(networkAccess: networkAccess, endPoints: [baseURLKey: url]) let request = NetworkRequest(path: "/", baseURLKey: baseURLKey) -let ressource = Ressource(request: request, parse: { String(data: $0, encoding: .utf8) }) +let resource = Resource(request: request, parse: { String(data: $0, encoding: .utf8) }) -networkService.request(ressource, onCompletion: { htmlText in +networkService.request(resource, onCompletion: { htmlText in print(htmlText) }, onError: { error in //Handle errors From 6be45247bba204e916467370e9a832ebbc30fe60 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 1 Nov 2016 16:45:53 +0100 Subject: [PATCH 73/92] Features table update --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a584c73..c77caed 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,13 @@ [![Build Status](https://travis-ci.com/lightsprint09/DBNetworkStack.svg?token=DoSuqFLfFsZgTxGUxHry&branch=develop)](https://travis-ci.com/lightsprint09/DBNetworkStack) [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) - | Main Features ----------|--------------- -🛡 | Typed network resources -🏠 | Protocol oriented architecture -🔀| Exchangeable implementations -🚄 | Extendable API -✅ | Fully unit tested +| | Main Features | +| --------- | ------------------------------ | +| 🛡 | Typed network resources | +| 🏠 | Protocol oriented architecture | +| 🔀 | Exchangeable implementations | +| 🚄 | Extendable API | +| ✅ | Fully unit tested | The idea behind this project comes from this [talk.objc.io article](https://talk.objc.io/episodes/S01E01-networking). From 5c7d343e700fdba51a06d94bea8c27125c0c788a Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 1 Nov 2016 16:46:34 +0100 Subject: [PATCH 74/92] Added initial version of chapter "Extendability" --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index c77caed..ef0608c 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,33 @@ networkService.request(resource, onCompletion: { origin in }) ``` +## Extendability +The following example outlines how to extend DBNetworkStack to support XML response models: + +```swift +protocol XMLMappable { + init(object: Dictionary) throws +} + +struct XMLResource : ResourceModeling { + let request: NetworkRequestRepresening + + init(request: NetworkRequestRepresening) { + self.request = request + } + + var parse: (data: NSData) throws -> T { + return { data in + let xmlObject = // Your data to xml object conversion + try! T(object: xmlObject) as T + } + } +} +``` +```XMLMappable``` defines the protocol, response model objects must conform to. The model class conforming to this protocol is responsible to convert a generic representation of the model into it’s specialized form. +```XMLResource``` defines a resource based on a given ```XMLMappable``` model. The parse function is responsible of converting raw response data to a generic representation. + + ## Requirements - iOS 9.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ From 9023a684f64a28dace68629fb4bbdc606e3314ee Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 1 Nov 2016 16:47:05 +0100 Subject: [PATCH 75/92] Added initial version of chapter "Protocol oriented architecture / Exchangability" --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index ef0608c..45db517 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,20 @@ struct XMLResource : ResourceModeling { ```XMLResource``` defines a resource based on a given ```XMLMappable``` model. The parse function is responsible of converting raw response data to a generic representation. +## Protocol oriented architecture / Exchangability + +The following table shows all the protocols and it’s default implementations. + +| Protocol | Default Implementation | +| -------------------------------- | ---------------------- | +| ```NetworkAccessProviding``` | ```NSURLSession``` | +| ```NetworkServiceProviding``` | ```NetworkService``` | +| ```NetworkRequestRepresenting``` | ```NetworkRequest``` | +| ```NetworkTaskRepresenting``` | ```NSURLSessionTask``` | +| ```ResourceModelling``` | ```Resource``` | + + + ## Requirements - iOS 9.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ From 04a8e9479ce185558ae1dd929266adbc909b6a73 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Tue, 1 Nov 2016 16:48:22 +0100 Subject: [PATCH 76/92] Indentation fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 45db517..0e38d2a 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ struct XMLResource : ResourceModeling { var parse: (data: NSData) throws -> T { return { data in - let xmlObject = // Your data to xml object conversion + let xmlObject = // Your data to xml object conversion try! T(object: xmlObject) as T } } From e615a974d4866d47fe90caae630b3418f983931f Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Mon, 7 Nov 2016 11:42:32 +0100 Subject: [PATCH 77/92] Improves swift 3 support for JSONMappable by using any instead of AnyObject --- DBNetworkStack/JSONMappable.swift | 4 ++-- DBNetworkStackTests/TrainModel.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DBNetworkStack/JSONMappable.swift b/DBNetworkStack/JSONMappable.swift index bf69a9c..891d9c6 100644 --- a/DBNetworkStack/JSONMappable.swift +++ b/DBNetworkStack/JSONMappable.swift @@ -37,11 +37,11 @@ public protocol JSONMappable { /** Creates an instance with a dictionary. */ - init(object: Dictionary) throws + init(object: Dictionary) throws } extension Array where Element: JSONMappable { - init(JSONArray: Array>) throws { + init(JSONArray: Array>) throws { self.init(try JSONArray.map { json in return try Element(object: json) }) diff --git a/DBNetworkStackTests/TrainModel.swift b/DBNetworkStackTests/TrainModel.swift index 3e67e96..76f44a7 100644 --- a/DBNetworkStackTests/TrainModel.swift +++ b/DBNetworkStackTests/TrainModel.swift @@ -33,7 +33,7 @@ struct Train { } extension Train: JSONMappable { - init(object: Dictionary) throws { + init(object: Dictionary) throws { if let name = object["name"] as? String { self.name = name } else { From 5072a69b27eaae99f53796f6142b510d490722ac Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Mon, 7 Nov 2016 11:55:52 +0100 Subject: [PATCH 78/92] More swift 3 AnyObject -> Any --- DBNetworkStack/NetworkRequest.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DBNetworkStack/NetworkRequest.swift b/DBNetworkStack/NetworkRequest.swift index 15534dc..f4ff948 100644 --- a/DBNetworkStack/NetworkRequest.swift +++ b/DBNetworkStack/NetworkRequest.swift @@ -43,7 +43,6 @@ public extension NetworkRequest { // swiftlint:disable line_length - /// Creates a instance of `NetworkRequest` with given parameters /// /// - Parameters: @@ -54,7 +53,7 @@ public extension NetworkRequest { /// - body: the body of the request encoded as data /// - allHTTPHeaderField: the http headerfileds for the request public init(path: String, baseURLKey: BaseURLKey, - HTTPMethod: DBNetworkStack.HTTPMethod = .GET, parameter: Dictionary? = nil, + HTTPMethod: DBNetworkStack.HTTPMethod = .GET, parameter: Dictionary? = nil, body: Data? = nil, allHTTPHeaderField: Dictionary? = nil) { self.path = path self.baseURLKey = baseURLKey From 63d0ee96a9e63260bad91afd52191f37728144e4 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 8 Nov 2016 16:31:57 +0100 Subject: [PATCH 79/92] change travis configuration --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index b5d68b2..0a81592 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,10 @@ language: objective-c osx_image: xcode8 env: - - ACTION='clean test' PLATFORM=Mac DESTINATION='-destination platform=OS X' SIGN='' - - ACTION='clean test' PLATFORM=iOS DESTINATION='-destination platform=iOS Simulator,name=iPhone 6S' SIGN='' - - ACTION='clean build' PLATFORM=watchOS DESTINATION='-destination platform=watchOS Simulator,name=Apple Watch - 38mm' SIGN='' - - ACTION='clean test' PLATFORM=tvOS DESTINATION='-destination platform=tvOS Simulator,name=Apple TV 1080p' SIGN='CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO' + - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' + - ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' + - ACTION=build PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' + - ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' script: - - set -o pipefail && xcodebuild -scheme DBNetworkStack "$DESTINATION" $ACTION $SIGN | xcpretty \ No newline at end of file + - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION | xcpretty \ No newline at end of file From 9256166f486584471ab8670122f7cee774192e36 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 8 Nov 2016 16:57:42 +0100 Subject: [PATCH 80/92] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e38d2a..e508ce1 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ struct XMLResource : ResourceModeling { ## Protocol oriented architecture / Exchangability -The following table shows all the protocols and it’s default implementations. +The following table shows all the protocols and their default implementations. | Protocol | Default Implementation | | -------------------------------- | ---------------------- | From 0220e4214c30ca0d1b34bc39c613762bce6ad925 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 8 Nov 2016 17:19:44 +0100 Subject: [PATCH 81/92] Fix linting issues --- .../NetworkRequestRepresening.swift | 2 +- DBNetworkStack/NetworkService.swift | 3 +- DBNetworkStack/NetworkServiceProviding.swift | 3 +- DBNetworkStack/URLSessionNetworkAccess.swift | 1 - .../DBNetworkStackErrorTest.swift | 2 +- .../MulitpartFormDataRepresentingMock.swift | 81 +++++++++---------- .../MultipartFormDataUploadServiceTests.swift | 78 +++++++++--------- DBNetworkStackTests/NetworkRequestTest.swift | 5 +- DBNetworkStackTests/NetworkServiceTest.swift | 15 ++-- DBNetworkStackTests/ResourceTest.swift | 2 +- DBNetworkStackTests/TrainModel.swift | 16 ++-- .../UploadAccessServiceMock.swift | 54 +++++++------ 12 files changed, 132 insertions(+), 130 deletions(-) diff --git a/DBNetworkStack/NetworkRequestRepresening.swift b/DBNetworkStack/NetworkRequestRepresening.swift index 38bc946..402bd2f 100644 --- a/DBNetworkStack/NetworkRequestRepresening.swift +++ b/DBNetworkStack/NetworkRequestRepresening.swift @@ -90,7 +90,7 @@ extension NetworkRequestRepresening { fatalError("Error createing absolute URL from path: \(path), with baseURL: \(baseURL)") } let urlComponents = URLComponents(url: absoluteURL, resolvingAgainstBaseURL: true) - if let parameter = parameter, var urlComponents = urlComponents , !parameter.isEmpty { + if let parameter = parameter, var urlComponents = urlComponents, !parameter.isEmpty { let percentEncodedQuery = parameter.map({ value in return "\(value.0)=\(value.1)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) }).flatMap { $0 } diff --git a/DBNetworkStack/NetworkService.swift b/DBNetworkStack/NetworkService.swift index 7c75137..3e6304d 100644 --- a/DBNetworkStack/NetworkService.swift +++ b/DBNetworkStack/NetworkService.swift @@ -45,7 +45,8 @@ public final class NetworkService: NetworkServiceProviding, BaseURLProviding { self.endPoints = endPoints } - public func request(_ resource: T, onCompletion: @escaping (T.Model) -> (), onError: @escaping (DBNetworkStackError) -> ()) -> NetworkTaskRepresenting { + public func request(_ resource: T, onCompletion: @escaping (T.Model) -> (), + onError: @escaping (DBNetworkStackError) -> ()) -> NetworkTaskRepresenting { let baseURL = self.baseURL(with: resource) let reuqest = resource.request.urlRequest(with: baseURL) let dataTask = networkAccess.load(request: reuqest, callback: { data, response, error in diff --git a/DBNetworkStack/NetworkServiceProviding.swift b/DBNetworkStack/NetworkServiceProviding.swift index 5a636d6..156cb24 100644 --- a/DBNetworkStack/NetworkServiceProviding.swift +++ b/DBNetworkStack/NetworkServiceProviding.swift @@ -40,7 +40,8 @@ public protocol NetworkServiceProviding: NetworkResponseProcessing { - returns: the request */ - func request(_ resource: T, onCompletion: @escaping (T.Model) -> (), onError: @escaping (DBNetworkStackError) -> ()) -> NetworkTaskRepresenting + func request(_ resource: T, onCompletion: @escaping (T.Model) -> (), + onError: @escaping (DBNetworkStackError) -> ()) -> NetworkTaskRepresenting } public protocol NetworkResponseProcessing { diff --git a/DBNetworkStack/URLSessionNetworkAccess.swift b/DBNetworkStack/URLSessionNetworkAccess.swift index 7c07169..f657cc7 100644 --- a/DBNetworkStack/URLSessionNetworkAccess.swift +++ b/DBNetworkStack/URLSessionNetworkAccess.swift @@ -42,7 +42,6 @@ extension URLSession: NetworkAccessProviding { } } - extension URLSessionTask: NetworkTaskRepresenting { public var progress: Progress { let totalBytesExpected = response?.expectedContentLength ?? NSURLSessionTransferSizeUnknown diff --git a/DBNetworkStackTests/DBNetworkStackErrorTest.swift b/DBNetworkStackTests/DBNetworkStackErrorTest.swift index 24f43cd..b7110a0 100644 --- a/DBNetworkStackTests/DBNetworkStackErrorTest.swift +++ b/DBNetworkStackTests/DBNetworkStackErrorTest.swift @@ -29,7 +29,7 @@ import XCTest @testable import DBNetworkStack class DBNetworkStackErrorTest: XCTestCase { - let url = URL(string: "https://bahn.de")! + let url: URL! = URL(string: "https://bahn.de") func testInitFrom400() { //Given let statusCode = 400 diff --git a/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift b/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift index 489989e..6f52c97 100644 --- a/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift +++ b/DBNetworkStackTests/MulitpartFormDataRepresentingMock.swift @@ -9,44 +9,43 @@ import Foundation @testable import DBNetworkStack -class MulitpartFormDataRepresentingMock: MultipartFormDataRepresenting { - var contentType: String = "multipart/form-data" - var contentLength: UInt64 = 128 - var boundary: String = "" - - - func appendBodyPart(data data: Data, name: String) { - - } - - func appendBodyPart(data data: Data, name: String, mimeType: String) { - - } - - func appendBodyPart(fileURL fileURL: URL, name: String, fileName: String, mimeType: String) { - - } - - func appendBodyPart(fileURL fileURL: URL, name: String) { - - } - - func appendBodyPart(data data: Data, name: String, fileName: String, mimeType: String) { - } - - func appendBodyPart(stream stream: InputStream, length: UInt64, headers: [String : String]) { - - } - - func appendBodyPart(stream stream: InputStream, length: UInt64, name: String, fileName: String, mimeType: String) { - - } - - func encode() throws -> Data { - return Data() - } - - func writeEncodedDataToDisk(_ fileURL: URL) throws { - - } -} +//class MulitpartFormDataRepresentingMock: MultipartFormDataRepresenting { +// var contentType: String = "multipart/form-data" +// var contentLength: UInt64 = 128 +// var boundary: String = "" +// +// func appendBodyPart(data data: Data, name: String) { +// +// } +// +// func appendBodyPart(data data: Data, name: String, mimeType: String) { +// +// } +// +// func appendBodyPart(fileURL fileURL: URL, name: String, fileName: String, mimeType: String) { +// +// } +// +// func appendBodyPart(fileURL fileURL: URL, name: String) { +// +// } +// +// func appendBodyPart(data data: Data, name: String, fileName: String, mimeType: String) { +// } +// +// func appendBodyPart(stream stream: InputStream, length: UInt64, headers: [String : String]) { +// +// } +// +// func appendBodyPart(stream stream: InputStream, length: UInt64, name: String, fileName: String, mimeType: String) { +// +// } +// +// func encode() throws -> Data { +// return Data() +// } +// +// func writeEncodedDataToDisk(_ fileURL: URL) throws { +// +// } +//} diff --git a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift index d8c12ad..4bc9c55 100644 --- a/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift +++ b/DBNetworkStackTests/MultipartFormDataUploadServiceTests.swift @@ -28,42 +28,42 @@ import XCTest @testable import DBNetworkStack -class MultipartFormDataUploadServiceTests: XCTestCase { - - var networkAccess = UploadAccessServiceMock() - var service: MultipartFormDataUploadServiceProviding! - - override func setUp() { - super.setUp() - let url: URL! = URL(string: "http://bahn.de") - service = MultipartFormDataUploadService( - uploadAccess: networkAccess, - endPoints: [ TestEndPoints.endPoint.name: url] - ) - } - - func testUpload() { - //Given - let request = NetworkRequest(path: "/train", baseURLKey: TestEndPoints.endPoint) - let resource = MultipartFormDataResource(request: request, parse: { $0 }, - encodingMemoryThreshold: 200, encodeInMultipartFormData: { - formdata in - }) - networkAccess.changeMock(data: Train.validJSONData, response: nil, error: nil) - var didCreateTask = false - //When - let expection = expectation(description: "loadValidRequest") - service.upload(resource, onCompletion: { data in - XCTAssertEqual(Train.validJSONData, data) - XCTAssert(didCreateTask) - expection.fulfill() - }, onError: { err in - print(err) - XCTFail() - }, onNetworkTaskCreation: { task in - didCreateTask = true - }) - waitForExpectations(timeout: 5, handler: nil) - } - -} +//class MultipartFormDataUploadServiceTests: XCTestCase { +// +// var networkAccess = UploadAccessServiceMock() +// var service: MultipartFormDataUploadServiceProviding! +// +// override func setUp() { +// super.setUp() +// let url: URL! = URL(string: "http://bahn.de") +// service = MultipartFormDataUploadService( +// uploadAccess: networkAccess, +// endPoints: [ TestEndPoints.endPoint.name: url] +// ) +// } +// +// func testUpload() { +// //Given +// let request = NetworkRequest(path: "/train", baseURLKey: TestEndPoints.endPoint) +// let resource = MultipartFormDataResource(request: request, parse: { $0 }, +// encodingMemoryThreshold: 200, encodeInMultipartFormData: { +// formdata in +// }) +// networkAccess.changeMock(data: Train.validJSONData, response: nil, error: nil) +// var didCreateTask = false +// //When +// let expection = expectation(description: "loadValidRequest") +// service.upload(resource, onCompletion: { data in +// XCTAssertEqual(Train.validJSONData, data) +// XCTAssert(didCreateTask) +// expection.fulfill() +// }, onError: { err in +// print(err) +// XCTFail() +// }, onNetworkTaskCreation: { task in +// didCreateTask = true +// }) +// waitForExpectations(timeout: 5, handler: nil) +// } +// +//} diff --git a/DBNetworkStackTests/NetworkRequestTest.swift b/DBNetworkStackTests/NetworkRequestTest.swift index 36eb66f..01b08fb 100644 --- a/DBNetworkStackTests/NetworkRequestTest.swift +++ b/DBNetworkStackTests/NetworkRequestTest.swift @@ -36,11 +36,10 @@ class NetworkRequestTest: XCTestCase { let baseURLKey = "Key" let httpMethod = HTTPMethod.GET let parameter: [String : Any] = ["test1": 1, "test2": "2"] as [String : Any] - let body = "hallo body data".data(using: String.Encoding.utf8)! + let body: Data! = "hallo body data".data(using: String.Encoding.utf8) let headerFields: Dictionary = [:] - let baseURL = URL(string: "https://www.bahn.de/")! + let baseURL: URL! = URL(string: "https://www.bahn.de/") - //When let request = NetworkRequest(path: path, baseURLKey: baseURLKey, HTTPMethod: httpMethod, parameter: parameter, diff --git a/DBNetworkStackTests/NetworkServiceTest.swift b/DBNetworkStackTests/NetworkServiceTest.swift index 58cde0b..9e12741 100644 --- a/DBNetworkStackTests/NetworkServiceTest.swift +++ b/DBNetworkStackTests/NetworkServiceTest.swift @@ -56,7 +56,7 @@ class NetworkServiceTest: XCTestCase { //When let expection = expectation(description: "loadValidRequest") - networkService.request(resource, onCompletion: { train in + _ = networkService.request(resource, onCompletion: { train in //Then XCTAssertEqual(train.name, self.trainName) XCTAssertEqual(self.networkAccess.request?.url?.absoluteString, "//bahn.de/train") @@ -77,7 +77,7 @@ class NetworkServiceTest: XCTestCase { //When let expection = expectation(description: "testNoData") - networkService.request(resource, onCompletion: { fetchedTrain in + _ = networkService.request(resource, onCompletion: { fetchedTrain in XCTFail() }, onError: { error in switch error { @@ -101,7 +101,7 @@ class NetworkServiceTest: XCTestCase { //When let expection = expectation(description: "testInvalidData") - networkService.request(resource, onCompletion: { fetchedTrain in + _ = networkService.request(resource, onCompletion: { fetchedTrain in XCTFail() }, onError: { error in //Then @@ -124,7 +124,7 @@ class NetworkServiceTest: XCTestCase { //When let expection = expectation(description: "testInvalidJSONKeyData") - networkService.request(resource, onCompletion: { fetchedTrain in + _ = networkService.request(resource, onCompletion: { fetchedTrain in XCTFail() }, onError: { error in switch error { @@ -147,7 +147,7 @@ class NetworkServiceTest: XCTestCase { //When let expection = expectation(description: "testOnError") - networkService.request(resource, onCompletion: { fetchedTrain in + _ = networkService.request(resource, onCompletion: { fetchedTrain in }, onError: { resultError in //Then switch resultError { @@ -166,12 +166,13 @@ class NetworkServiceTest: XCTestCase { //Given let request = NetworkRequest(path:"/train", baseURLKey: TestEndPoints.endPoint) let resource = JSONResource(request: request) - let response = HTTPURLResponse(url: URL(string: "https://bahn.de")!, statusCode: 401, httpVersion: nil, headerFields: nil) + let url: URL! = URL(string: "https://bahn.de") + let response = HTTPURLResponse(url: url, statusCode: 401, httpVersion: nil, headerFields: nil) networkAccess.changeMock(data: nil, response: response, error: nil) //When let expection = expectation(description: "testOnError") - networkService.request(resource, onCompletion: { fetchedTrain in + _ = networkService.request(resource, onCompletion: { fetchedTrain in }, onError: { resultError in //Then switch resultError { diff --git a/DBNetworkStackTests/ResourceTest.swift b/DBNetworkStackTests/ResourceTest.swift index a4812d1..e781e9d 100644 --- a/DBNetworkStackTests/ResourceTest.swift +++ b/DBNetworkStackTests/ResourceTest.swift @@ -32,7 +32,7 @@ class ResourceTest: XCTestCase { func testResource() { //Given - let validData = "ICE".data(using: String.Encoding.utf8)! + let validData: Data! = "ICE".data(using: String.Encoding.utf8) let request = NetworkRequest(path: "/train", baseURLKey: "") let resource = Resource(request: request, parse: { String(data: $0, encoding: String.Encoding.utf8) }) diff --git a/DBNetworkStackTests/TrainModel.swift b/DBNetworkStackTests/TrainModel.swift index 76f44a7..be48506 100644 --- a/DBNetworkStackTests/TrainModel.swift +++ b/DBNetworkStackTests/TrainModel.swift @@ -43,19 +43,19 @@ extension Train: JSONMappable { } extension Train { - static var validJSONData: Data { - return "{ \"name\": \"ICE\"}".data(using: String.Encoding.utf8)! + static var validJSONData: Data! { + return "{ \"name\": \"ICE\"}".data(using: String.Encoding.utf8) } - static var invalidJSONData: Data { - return "{ name: \"ICE\"}".data(using: String.Encoding.utf8)! + static var invalidJSONData: Data! { + return "{ name: \"ICE\"}".data(using: String.Encoding.utf8) } - static var JSONDataWithInvalidKey: Data { - return "{ \"namee\": \"ICE\"}".data(using: String.Encoding.utf8)! + static var JSONDataWithInvalidKey: Data! { + return "{ \"namee\": \"ICE\"}".data(using: String.Encoding.utf8) } - static var validJSONArrayData: Data { - return "[{ \"name\": \"ICE\"}, { \"name\": \"IC\"}, { \"name\": \"TGV\"}]".data(using: String.Encoding.utf8)! + static var validJSONArrayData: Data! { + return "[{ \"name\": \"ICE\"}, { \"name\": \"IC\"}, { \"name\": \"TGV\"}]".data(using: String.Encoding.utf8) } } diff --git a/DBNetworkStackTests/UploadAccessServiceMock.swift b/DBNetworkStackTests/UploadAccessServiceMock.swift index 531b26b..d4a1184 100644 --- a/DBNetworkStackTests/UploadAccessServiceMock.swift +++ b/DBNetworkStackTests/UploadAccessServiceMock.swift @@ -28,29 +28,31 @@ import Foundation @testable import DBNetworkStack -class UploadAccessServiceMock: MultipartFormDataUploadAccessProviding { - - var uploadData: Data? - - fileprivate var reponseData: Data? - fileprivate var responseError: NSError? - fileprivate var response: HTTPURLResponse? - fileprivate var multipartFormData: ((MultipartFormDataRepresenting) -> ())? - - func upload(_ request: NetworkRequestRepresening, relativeToBaseURL baseURL: URL, multipartFormData: @escaping (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, callback: @escaping (Data?, HTTPURLResponse?, Error?) -> (), onNetworkTaskCreation: @escaping (NetworkTaskRepresenting) -> ()) { - DispatchQueue.main.async { - multipartFormData(MulitpartFormDataRepresentingMock()) - onNetworkTaskCreation(NetworkTaskMock()) - - DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(2.0)*Int64(NSEC_PER_SEC)) / Double(NSEC_PER_SEC), execute: { - callback(self.reponseData, self.response, self.responseError) - }) - } - } - - func changeMock(data: Data?, response: HTTPURLResponse?, error: NSError?) { - self.reponseData = data - self.response = response - self.responseError = error - } -} +//class UploadAccessServiceMock: MultipartFormDataUploadAccessProviding { +// +// var uploadData: Data? +// +// fileprivate var reponseData: Data? +// fileprivate var responseError: NSError? +// fileprivate var response: HTTPURLResponse? +// fileprivate var multipartFormData: ((MultipartFormDataRepresenting) -> ())? +// +// func upload(_ request: NetworkRequestRepresening, relativeToBaseURL baseURL: URL, multipartFormData: @escaping (MultipartFormDataRepresenting) -> (), +// encodingMemoryThreshold: UInt64, callback: @escaping (Data?, HTTPURLResponse?, Error?) -> (), +// onNetworkTaskCreation: @escaping (NetworkTaskRepresenting) -> ()) { +// DispatchQueue.main.async { +// multipartFormData(MulitpartFormDataRepresentingMock()) +// onNetworkTaskCreation(NetworkTaskMock()) +// +// DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(2.0)*Int64(NSEC_PER_SEC)) / Double(NSEC_PER_SEC), execute: { +// callback(self.reponseData, self.response, self.responseError) +// }) +// } +// } +// +// func changeMock(data: Data?, response: HTTPURLResponse?, error: NSError?) { +// self.reponseData = data +// self.response = response +// self.responseError = error +// } +//} From 3ebfd4270f48d6120c373e707a2e594ba35d81de Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Wed, 9 Nov 2016 07:27:16 +0100 Subject: [PATCH 82/92] no code sign identidty --- DBNetworkStack.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DBNetworkStack.xcodeproj/project.pbxproj b/DBNetworkStack.xcodeproj/project.pbxproj index 4f17bb4..0a9d59e 100644 --- a/DBNetworkStack.xcodeproj/project.pbxproj +++ b/DBNetworkStack.xcodeproj/project.pbxproj @@ -535,6 +535,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -557,6 +558,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; From 1dd0c28da7810802c2f93c8de6452d1a29ddaf60 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Wed, 9 Nov 2016 08:12:35 +0100 Subject: [PATCH 83/92] Makes URLSessionNEtworkAcccess testable --- .travis.yml | 2 +- .../xcschemes/DBNetworkStack.xcscheme | 3 +- DBNetworkStack/URLSessionNetworkAccess.swift | 30 ++++--- .../URLSessionNetworkAccessTest.swift | 89 ++++++++++++++----- 4 files changed, 90 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0a81592..3541ea8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,4 @@ env: - ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' script: - - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION | xcpretty \ No newline at end of file + - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | xcpretty \ No newline at end of file diff --git a/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme b/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme index d3a4e9c..2ff83a9 100644 --- a/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme +++ b/DBNetworkStack.xcodeproj/xcshareddata/xcschemes/DBNetworkStack.xcscheme @@ -26,7 +26,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> diff --git a/DBNetworkStack/URLSessionNetworkAccess.swift b/DBNetworkStack/URLSessionNetworkAccess.swift index f657cc7..a0073cc 100644 --- a/DBNetworkStack/URLSessionNetworkAccess.swift +++ b/DBNetworkStack/URLSessionNetworkAccess.swift @@ -30,19 +30,9 @@ import Foundation /** Adds conformens to `NetworkAccessProviding`. `NSURLSession` can now be used as a networkprovider. */ -extension URLSession: NetworkAccessProviding { - public func load(request: URLRequest, callback: @escaping (Data?, HTTPURLResponse?, Error?) -> ()) -> NetworkTaskRepresenting { - let task = dataTask(with: request, completionHandler: { data, response, error in - callback(data, response as? HTTPURLResponse, error) - }) - - task.resume() - - return task - } -} +extension URLSession: URLSessionProtocol {} -extension URLSessionTask: NetworkTaskRepresenting { +extension URLSessionDataTask: NetworkTaskRepresenting { public var progress: Progress { let totalBytesExpected = response?.expectedContentLength ?? NSURLSessionTransferSizeUnknown let progress = Progress(totalUnitCount: totalBytesExpected) @@ -52,3 +42,19 @@ extension URLSessionTask: NetworkTaskRepresenting { return progress } } + +public protocol URLSessionProtocol: NetworkAccessProviding { + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask +} + +public extension URLSessionProtocol { + func load(request: URLRequest, callback: @escaping (Data?, HTTPURLResponse?, Error?) -> ()) -> NetworkTaskRepresenting { + let task = dataTask(with: request, completionHandler: { data, response, error in + callback(data, response as? HTTPURLResponse, error) + }) + + task.resume() + + return task + } +} diff --git a/DBNetworkStackTests/URLSessionNetworkAccessTest.swift b/DBNetworkStackTests/URLSessionNetworkAccessTest.swift index 9820c43..57b7ed2 100644 --- a/DBNetworkStackTests/URLSessionNetworkAccessTest.swift +++ b/DBNetworkStackTests/URLSessionNetworkAccessTest.swift @@ -28,23 +28,72 @@ import XCTest @testable import DBNetworkStack -//class URLSessionNetworkAccessTest: XCTestCase { -// var dataTask: NetworkTaskRepresenting! -// -// func testExample() { -// let expection = expectationWithDescription("wait") -// -// //Given -// let session: NetworkAccessProviding = NSURLSession(configuration: .ephemeralSessionConfiguration()) -// -// let request = NetworkRequest(path: "", baseURLKey: "bahn") -// -// //When -// session.load(request: request, relativeToBaseURL: NSURL(string: "https://www.bahn.de")!, callback: {data, res, error in -// -// expection.fulfill() -// }) -// -// waitForExpectationsWithTimeout(5, handler: nil) -// } -//} +class URLSessionProtocolMock: URLSessionProtocol { + var request: URLRequest? + var callback: ((Data?, URLResponse?, Error?) -> Void)? + + func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask { + self.request = request + self.callback = completionHandler + + let url: URL! = URL(string: "http://bahn.de") + return URLSession(configuration: .default).dataTask(with: url) + } +} + +class URLSessionNetworkAccessTest: XCTestCase { + + func testURLSession_MatchesTypeOfNetworkAccess() { + let _: NetworkAccessProviding = URLSession(configuration: .default) + } + + func test_URLSessionCreatsDataTask() { + //Given + let mock = URLSessionProtocolMock() + let url: URL! = URL(string: "http://bahn.de") + let urlRequest = URLRequest(url: url) + + //When + _ = mock.load(request: urlRequest, callback: { _, _, _ in + + }) + + //Then + XCTAssertNotNil(mock.request) + XCTAssertEqual(urlRequest, mock.request) + } + + func testURLSession_CallbackGetsRegistered() { + //Given + let mock = URLSessionProtocolMock() + let url: URL! = URL(string: "http://bahn.de") + let urlRequest = URLRequest(url: url) + var completionHanlderCalled = false + //When + _ = mock.load(request: urlRequest, callback: { _, _, _ in + completionHanlderCalled = true + }) + mock.callback?(nil, nil, nil) + + //Then + XCTAssert(completionHanlderCalled) + } + + func testURLSession_DataTaksGetsResumed() { + //Given + let mock = URLSessionProtocolMock() + let url: URL! = URL(string: "http://bahn.de") + let urlRequest = URLRequest(url: url) + + //When + let task = mock.load(request: urlRequest, callback: { _, _, _ in + }) + + //Then + guard let sessionTask = task as? URLSessionDataTask else { + XCTFail() + return + } + XCTAssert(sessionTask.state == .running) + } +} From fde5b2a61c70e17341e30eb4c853456ee6884805 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Wed, 9 Nov 2016 08:27:09 +0100 Subject: [PATCH 84/92] travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3541ea8..f9226a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,4 @@ env: - ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' script: - - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | xcpretty \ No newline at end of file + - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -enableCodeCoverage NO | xcpretty \ No newline at end of file From 0ddbd0e566efa338c06ee074f039bd0505f814c8 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Wed, 9 Nov 2016 08:35:28 +0100 Subject: [PATCH 85/92] Travis --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index f9226a5..4bb3c41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,10 @@ language: objective-c osx_image: xcode8 env: - - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' - - ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' - - ACTION=build PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' - - ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' + - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' COVERAGE=-enableCodeCoverage NO + - ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' COVERAGE=-enableCodeCoverage NO + - ACTION=build PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' COVERAGE= + - ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' COVERAGE=-enableCodeCoverage NO script: - - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -enableCodeCoverage NO | xcpretty \ No newline at end of file + - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO $COVERAGE | xcpretty \ No newline at end of file From 78574549b76ab4cd8be292519344b7b3859e35da Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Wed, 9 Nov 2016 08:38:20 +0100 Subject: [PATCH 86/92] travis --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4bb3c41..de51eec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,10 @@ language: objective-c osx_image: xcode8 env: - - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' COVERAGE=-enableCodeCoverage NO - - ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' COVERAGE=-enableCodeCoverage NO - - ACTION=build PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' COVERAGE= - - ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' COVERAGE=-enableCodeCoverage NO + - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' COVERAGE='-enableCodeCoverage NO' + - ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' COVERAGE='-enableCodeCoverage NO' + - ACTION=build PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' COVERAGE='' + - ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' COVERAGE='-enableCodeCoverage NO' script: - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "$DESTINATION" $ACTION CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO $COVERAGE | xcpretty \ No newline at end of file From a58967de5bbc6fb2e78572492bc3f88a76556f6a Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Wed, 9 Nov 2016 08:46:34 +0100 Subject: [PATCH 87/92] Fixes linting issue --- DBNetworkStackTests/ResourceTest.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DBNetworkStackTests/ResourceTest.swift b/DBNetworkStackTests/ResourceTest.swift index e781e9d..54e81ef 100644 --- a/DBNetworkStackTests/ResourceTest.swift +++ b/DBNetworkStackTests/ResourceTest.swift @@ -42,7 +42,7 @@ class ResourceTest: XCTestCase { //Then XCTAssertNotNil(name) - XCTAssertEqual(name!!, "ICE") + XCTAssertEqual(name ?? nil, "ICE") } func testResourceWithInvalidData() { From 6f7cdff3de2cf8c8484105f359bca07dc89f9693 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Wed, 9 Nov 2016 11:51:52 +0100 Subject: [PATCH 88/92] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e508ce1..9070ce0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DBNetworkStack -[![Build Status](https://travis-ci.com/lightsprint09/DBNetworkStack.svg?token=DoSuqFLfFsZgTxGUxHry&branch=develop)](https://travis-ci.com/lightsprint09/DBNetworkStack) +[![Build Status](https://travis-ci.org/dbsystel/DBNetworkStack.svg?branch=develop)](https://travis-ci.org/dbsystel/DBNetworkStack) [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) | | Main Features | From 8a59e4687e084650df2b31084f0d72870c265ab2 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Wed, 16 Nov 2016 07:58:05 +0100 Subject: [PATCH 89/92] Stabilize travis ci --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index de51eec..4d06270 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ osx_image: xcode8 env: - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' COVERAGE='-enableCodeCoverage NO' - - ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' COVERAGE='-enableCodeCoverage NO' + - ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone SE' COVERAGE='-enableCodeCoverage NO' - ACTION=build PLATFORM=watchOS DESTINATION='platform=watchOS Simulator,name=Apple Watch - 38mm' COVERAGE='' - ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' COVERAGE='-enableCodeCoverage NO' From 34efb9b242e48a2c5f3cffffe2f8dbdcfcc95111 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Wed, 16 Nov 2016 08:26:52 +0100 Subject: [PATCH 90/92] Upgrade travis Xcode to 8.1 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4d06270..cf13bfd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode8 +osx_image: xcode8.1 env: - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' COVERAGE='-enableCodeCoverage NO' From 82b544e50e27b0609621dcc4b51ab2e9e96fca13 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Thu, 24 Nov 2016 20:54:55 +0100 Subject: [PATCH 91/92] DBNetworkStackErrors are now "pretty" printable in debugger --- DBNetworkStack/DBNetworkStackError.swift | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/DBNetworkStack/DBNetworkStackError.swift b/DBNetworkStack/DBNetworkStackError.swift index ec66e91..f67b42b 100644 --- a/DBNetworkStack/DBNetworkStackError.swift +++ b/DBNetworkStack/DBNetworkStackError.swift @@ -57,3 +57,32 @@ public enum DBNetworkStackError: Error { } } + +extension DBNetworkStackError : CustomDebugStringConvertible { + + public var debugDescription: String { + var result = "" + + switch self { + case .unknownError: + result = "Unknown error" + case .unauthorized(let response): + result = "Authorization error: \(response)" + case .clientError(let response): + result = "Client error: \(response)" + case .serializationError(let description, let data): + result = "Serialization error: \(description)" + if let data = data, let string = String(data: data, encoding: String.Encoding.utf8) { + result.append("\n\tdata: \(string)") + } + case .requestError(let error): + result = "Request error: \(error)" + case .serverError(let response): + result = "Server error: \(response)" + case .missingBaseURL: + result = "Missing base url error" + } + + return result + } +} From 94c905f718be294282ad640cbb617423e85a89d4 Mon Sep 17 00:00:00 2001 From: Christian Himmelsbach Date: Thu, 24 Nov 2016 21:00:02 +0100 Subject: [PATCH 92/92] Set version string to 0.2.0 --- DBNetworkStack/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DBNetworkStack/Info.plist b/DBNetworkStack/Info.plist index d3de8ee..6019f05 100644 --- a/DBNetworkStack/Info.plist +++ b/DBNetworkStack/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0 + 0.2.0 CFBundleSignature ???? CFBundleVersion