[0.1.3] Code quality

This commit is contained in:
Shial 2018-01-10 13:54:47 +11:00
parent e7ea34e0ad
commit 6acd9a4064
7 changed files with 103 additions and 100 deletions

View File

@ -1,99 +1,99 @@
import Foundation
extension Decodable {
public static func request(path: String, method: HTTPMethod, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func request(path: String, method: HTTPMethod, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: method, queryItems: queryItems, body: body, handler: handler)
}
public static func request<T: Encodable>(path: String, method: HTTPMethod, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func request<T: Encodable>(path: String, method: HTTPMethod, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: method, queryItems: queryItems, body: body, handler: handler)
}
public static func request<T: Encodable>(path: String, method: HTTPMethod, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func request<T: Encodable>(path: String, method: HTTPMethod, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: method, queryItems: queryItems, body: body, handler: handler)
}
public static func request(path: String, method: HTTPMethod, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func request(path: String, method: HTTPMethod, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: method, queryItems: queryItems, handler: handler)
}
public static func get(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func get(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, queryItems: queryItems, body: body, handler: handler)
}
public static func get<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func get<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, queryItems: queryItems, body: body, handler: handler)
}
public static func get<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func get<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, queryItems: queryItems, body: body, handler: handler)
}
public static func get(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func get(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, queryItems: queryItems, handler: handler)
}
public static func post(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func post(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .POST, queryItems: queryItems, body: body, handler: handler)
}
public static func post<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func post<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .POST, queryItems: queryItems, body: body, handler: handler)
}
public static func post<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func post<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .POST, queryItems: queryItems, body: body, handler: handler)
}
public static func post(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func post(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .POST, queryItems: queryItems, handler: handler)
}
public static func put(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func put(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .PUT, queryItems: queryItems, body: body, handler: handler)
}
public static func put<T: Encodable>(path: String, queryItems: [URLQueryItem]? = nil, body: T, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func put<T: Encodable>(path: String, queryItems: [URLQueryItem]? = nil, body: T, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .PUT, queryItems: queryItems, body: body, handler: handler)
}
public static func put<T: Encodable>(path: String, queryItems: [URLQueryItem]? = nil, body: [T], handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func put<T: Encodable>(path: String, queryItems: [URLQueryItem]? = nil, body: [T], handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .PUT, queryItems: queryItems, body: body, handler: handler)
}
public static func put(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func put(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .PUT, queryItems: queryItems, handler: handler)
}
public static func patch(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func patch(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .PATCH, queryItems: queryItems, body: body, handler: handler)
}
public static func patch<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func patch<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .PATCH, queryItems: queryItems, body: body, handler: handler)
}
public static func patch<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func patch<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .PATCH, queryItems: queryItems, body: body, handler: handler)
}
public static func patch(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func patch(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .PATCH, queryItems: queryItems, handler: handler)
}
public static func delete(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func delete(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .DELETE, queryItems: queryItems, body: body, handler: handler)
}
public static func delete<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func delete<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .DELETE, queryItems: queryItems, body: body, handler: handler)
}
public static func delete<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func delete<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .DELETE, queryItems: queryItems, body: body, handler: handler)
}
public static func delete(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func delete(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: Self?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<Default>.networkTask(path: path, method: .DELETE, queryItems: queryItems, handler: handler)
}
}

View File

@ -13,13 +13,7 @@ extension NSManagedObject {
/// - attributes: Entity attribute mapped by key - value
/// - Returns: Returns first object that meet the criteria specified by a given fetch request.
final class func find(_ context: NSManagedObjectContext?, by attributes: EntityAttribute...) throws -> NSManagedObject? {
guard let name = entityName else { return nil }
let fetchRequest: NSFetchRequest<NSManagedObject> = NSFetchRequest<NSManagedObject>(entityName: name)
var predicates: [NSPredicate] = []
attributes.forEach({ predicates.append(NSPredicate(format: "\($0.key) = %@", argumentArray: [$0.value])) })
if !predicates.isEmpty { fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: predicates) }
fetchRequest.fetchLimit = 1
return try context?.fetch(fetchRequest).first
return try find(context, by: attributes.map {$0})
}
/// Finds `NSManagedObject` by EntityAttribute parameters.
@ -32,8 +26,12 @@ extension NSManagedObject {
guard let name = entityName else { return nil }
let fetchRequest: NSFetchRequest<NSManagedObject> = NSFetchRequest<NSManagedObject>(entityName: name)
var predicates: [NSPredicate] = []
attributes.forEach({ predicates.append(NSPredicate(format: "\($0.key) = %@", argumentArray: [$0.value])) })
if !predicates.isEmpty { fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: predicates) }
attributes.forEach({
predicates.append(NSPredicate(format: "\($0.key) = %@", argumentArray: [$0.value]))
})
if !predicates.isEmpty {
fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: predicates)
}
fetchRequest.fetchLimit = 1
return try context?.fetch(fetchRequest).first
}

View File

@ -5,7 +5,7 @@ extension String {
///
/// in pattern `"/api/path/:id"`
///
/// `[":id":"\(123-XYZ-321)"]` `:id` key would be replaced with `"\(123-XYZ-321)"` value.
/// `["id":"\(123-XYZ-321)"]` `:id` key would be replaced with `"\(123-XYZ-321)"` value.
///
/// - Parameter arguments: Dictionary with key & value to replace.
/// - Returns: Path with values instead of keys.

View File

@ -1,99 +1,99 @@
import Foundation
public class Laze<C: LazeConfiguration, D: Decodable> {
public static func request(path: String, method: HTTPMethod, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func request(path: String, method: HTTPMethod, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: method, queryItems: queryItems, body: body, handler: handler)
}
public static func request<T: Encodable>(path: String, method: HTTPMethod, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func request<T: Encodable>(path: String, method: HTTPMethod, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: method, queryItems: queryItems, body: body, handler: handler)
}
public static func request<T: Encodable>(path: String, method: HTTPMethod, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func request<T: Encodable>(path: String, method: HTTPMethod, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: method, queryItems: queryItems, body: body, handler: handler)
}
public static func request(path: String, method: HTTPMethod, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func request(path: String, method: HTTPMethod, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: method, queryItems: queryItems, handler: handler)
}
public static func get(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func get(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, queryItems: queryItems, body: body, handler: handler)
}
public static func get<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func get<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, queryItems: queryItems, body: body, handler: handler)
}
public static func get<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func get<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, queryItems: queryItems, body: body, handler: handler)
}
public static func get(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func get(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, queryItems: queryItems, handler: handler)
}
public static func post(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func post(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .POST, queryItems: queryItems, body: body, handler: handler)
}
public static func post<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func post<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .POST, queryItems: queryItems, body: body, handler: handler)
}
public static func post<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func post<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .POST, queryItems: queryItems, body: body, handler: handler)
}
public static func post(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func post(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .POST, queryItems: queryItems, handler: handler)
}
public static func put(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func put(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .PUT, queryItems: queryItems, body: body, handler: handler)
}
public static func put<T: Encodable>(path: String, queryItems: [URLQueryItem]? = nil, body: T, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func put<T: Encodable>(path: String, queryItems: [URLQueryItem]? = nil, body: T, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .PUT, queryItems: queryItems, body: body, handler: handler)
}
public static func put<T: Encodable>(path: String, queryItems: [URLQueryItem]? = nil, body: [T], handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func put<T: Encodable>(path: String, queryItems: [URLQueryItem]? = nil, body: [T], handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .PUT, queryItems: queryItems, body: body, handler: handler)
}
public static func put(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func put(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .PUT, queryItems: queryItems, handler: handler)
}
public static func patch(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func patch(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .PATCH, queryItems: queryItems, body: body, handler: handler)
}
public static func patch<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func patch<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .PATCH, queryItems: queryItems, body: body, handler: handler)
}
public static func patch<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func patch<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .PATCH, queryItems: queryItems, body: body, handler: handler)
}
public static func patch(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func patch(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .PATCH, queryItems: queryItems, handler: handler)
}
public static func delete(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func delete(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .DELETE, queryItems: queryItems, body: body, handler: handler)
}
public static func delete<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func delete<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .DELETE, queryItems: queryItems, body: body, handler: handler)
}
public static func delete<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func delete<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .DELETE, queryItems: queryItems, body: body, handler: handler)
}
public static func delete(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> ()) -> URLSessionDataTask? {
public static func delete(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: D?, _ error: Error?) -> Void) -> URLSessionDataTask? {
return SLazeKit<C>.networkTask(path: path, method: .DELETE, queryItems: queryItems, handler: handler)
}
}

View File

@ -34,6 +34,7 @@ extension EntityMapping {
}
return model
}
private func findObject(_ context: NSManagedObjectContext?) throws -> NSManagedObject? {
return try Self.entityType.find(context, by: idAttributes ?? [])
}

View File

@ -5,13 +5,15 @@ public protocol StringInitializable {
}
extension KeyedDecodingContainerProtocol {
/// If you API have unstable JSON responses for number types. You can use this helper method to decode string as a number. However, first you need extend your desired number type with `StringInitializable` protocol.
/// If you API have unstable JSON responses for number types.
/// You can use this helper method to decode string as a number.
/// However, first you need extend your desired number type with `StringInitializable` protocol.
///
/// - Parameters:
/// - type: Type to decode
/// - key: JSON key under given type should be stored
/// - Returns: Desired type value
public func decodeUnstable<T: Decodable & StringInitializable>(_ type: T.Type = T.self, forKey key: Key) throws -> T? {
public func decodeWith<T: Decodable & StringInitializable>(_ type: T.Type = T.self, forKey key: Key) throws -> T? {
guard contains(key) else { return nil }
guard !(try decodeNil(forKey: key)) else { return nil }
@ -19,24 +21,26 @@ extension KeyedDecodingContainerProtocol {
guard let value = T.init(rawValue: string) else {
throw DecodingError.dataCorruptedError(forKey: key,
in: self,
debugDescription: "Found string that cannot be converted to \(T.self)")
debugDescription: "Cannot converted to \(T.self)")
}
return value
}
return try decode(T.self, forKey: key)
}
/// If you API have unstable JSON responses for number types. You can use this helper method to decode string as a number. However, first you need extend your desired number type with `StringInitializable` protocol.
/// If you API have unstable JSON responses for number types.
/// You can use this helper method to decode string as a number.
/// However, first you need extend your desired number type with `StringInitializable` protocol.
///
/// - Parameters:
/// - type: Type to decode
/// - key: JSON key under given type should be stored
/// - Returns: Desired type value
public func decodeUnstable<T: Decodable & StringInitializable>(_ type: T.Type = T.self, forKey key: Key) throws -> T {
public func decodeWith<T: Decodable & StringInitializable>(_ type: T.Type = T.self, forKey key: Key) throws -> T {
if let string = try? decode(String.self, forKey: key) {
guard let value = T.init(rawValue: string) else {
throw DecodingError.dataCorruptedError(forKey: key,
in: self,
debugDescription: "Found string that cannot be converted to \(T.self)")
debugDescription: "Cannot converted to \(T.self)")
}
return value
}

View File

@ -5,7 +5,7 @@ public typealias EntityMappingCodable = EntityMapping & Codable
public typealias EntityMappingDecodable = EntityMapping & Decodable
/// NetworkResponse tuple holding response `Data` and `HTTPURLResponse`
public typealias NetworkResponse = (data: Data?, urlResponse: HTTPURLResponse?)
public typealias NetworkResponse = (data: Data?, http: HTTPURLResponse?)
/// HTTPMethod types
public enum HTTPMethod {
@ -17,7 +17,7 @@ open class Default: LazeConfiguration {}
/// SLazeKit is an easy to use restful collection of extensions and classes. Maps your rest api request into models and provides coredata serialization.
public class SLazeKit<Config: LazeConfiguration> {
class func networkTask(request: URLRequest, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
class func networkTask(request: URLRequest, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
let task = Config.urlSession.dataTask(with: Config.setup(request)) { (data, response, error) in
Config.handle(response as? HTTPURLResponse)
handler((data, response as? HTTPURLResponse), error)
@ -26,7 +26,7 @@ public class SLazeKit<Config: LazeConfiguration> {
return task
}
class func networkTask<T: Decodable>(request: URLRequest, handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> ()) -> URLSessionDataTask? {
class func networkTask<T: Decodable>(request: URLRequest, handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> Void) -> URLSessionDataTask? {
let task = Config.urlSession.dataTask(with: Config.setup(request)) { (data, response, error) in
Config.handle(response as? HTTPURLResponse)
if let data = data, error == nil {
@ -45,7 +45,7 @@ public class SLazeKit<Config: LazeConfiguration> {
return task
}
class func networkTask(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: String, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
class func networkTask(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: String, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
guard let url = components(for: path, queryItems: queryItems)?.url else {
handler((nil,nil), NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil))
return nil
@ -56,7 +56,7 @@ public class SLazeKit<Config: LazeConfiguration> {
return networkTask(request: request, handler: handler)
}
class func networkTask<B: Encodable>(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: B, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
class func networkTask<B: Encodable>(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: B, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
guard let url = components(for: path, queryItems: queryItems)?.url else {
handler((nil,nil), NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil))
return nil
@ -73,9 +73,9 @@ public class SLazeKit<Config: LazeConfiguration> {
return networkTask(request: request, handler: handler)
}
class func networkTask<T: Decodable>(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: String, handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> ()) -> URLSessionDataTask? {
class func networkTask<T: Decodable>(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: String, handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> Void) -> URLSessionDataTask? {
guard let url = components(for: path, queryItems: queryItems)?.url else {
handler((nil,nil), nil, NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil))
handler((nil,nil), nil, NSError(domain: "Unable to create url from components", code: NSURLErrorBadURL, userInfo: nil))
return nil
}
@ -85,7 +85,7 @@ public class SLazeKit<Config: LazeConfiguration> {
return networkTask(request: request, handler: handler)
}
class func networkTask<T: Decodable, B: Encodable>(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: B, handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> ()) -> URLSessionDataTask? {
class func networkTask<T: Decodable, B: Encodable>(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: B, handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> Void) -> URLSessionDataTask? {
guard let url = components(for: path, queryItems: queryItems)?.url else {
handler((nil,nil), nil, NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil))
return nil
@ -102,7 +102,7 @@ public class SLazeKit<Config: LazeConfiguration> {
return networkTask(request: request, handler: handler)
}
class func networkTask<B: Encodable>(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: [B], handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
class func networkTask<B: Encodable>(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: [B], handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
guard let url = components(for: path, queryItems: queryItems)?.url else {
handler((nil,nil), NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil))
return nil
@ -119,7 +119,7 @@ public class SLazeKit<Config: LazeConfiguration> {
return networkTask(request: request, handler: handler)
}
class func networkTask<T: Decodable, B: Encodable>(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: [B], handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> ()) -> URLSessionDataTask? {
class func networkTask<T: Decodable, B: Encodable>(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: [B], handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> Void) -> URLSessionDataTask? {
guard let url = components(for: path, queryItems: queryItems)?.url else {
handler((nil,nil), nil, NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil))
return nil
@ -136,7 +136,7 @@ public class SLazeKit<Config: LazeConfiguration> {
return networkTask(request: request, handler: handler)
}
class func networkTask(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
class func networkTask(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
guard let url = components(for: path, queryItems: queryItems)?.url else {
handler((nil,nil), NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil))
return nil
@ -144,7 +144,7 @@ public class SLazeKit<Config: LazeConfiguration> {
return networkTask(request: urlRequest(url, method: method), handler: handler)
}
class func networkTask<T: Decodable>(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> ()) -> URLSessionDataTask? {
class func networkTask<T: Decodable>(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> Void) -> URLSessionDataTask? {
guard let url = components(for: path, queryItems: queryItems)?.url else {
handler((nil,nil), nil, NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil))
return nil
@ -180,99 +180,99 @@ public class SLazeKit<Config: LazeConfiguration> {
}
extension SLazeKit {
final public class func request(path: String, method: HTTPMethod, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func request(path: String, method: HTTPMethod, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: method, queryItems: queryItems, body: body, handler: handler)
}
final public class func request<T: Encodable>(path: String, method: HTTPMethod, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func request<T: Encodable>(path: String, method: HTTPMethod, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: method, queryItems: queryItems, body: body, handler: handler)
}
final public class func request<T: Encodable>(path: String, method: HTTPMethod, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func request<T: Encodable>(path: String, method: HTTPMethod, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: method, queryItems: queryItems, body: body, handler: handler)
}
final public class func request(path: String, method: HTTPMethod, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func request(path: String, method: HTTPMethod, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: method, queryItems: queryItems, handler: handler)
}
final public class func get(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func get(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, queryItems: queryItems, body: body, handler: handler)
}
final public class func get<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func get<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, queryItems: queryItems, body: body, handler: handler)
}
final public class func get<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func get<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, queryItems: queryItems, body: body, handler: handler)
}
final public class func get(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func get(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, queryItems: queryItems, handler: handler)
}
final public class func post(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func post(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .POST, queryItems: queryItems, body: body, handler: handler)
}
final public class func post<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func post<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .POST, queryItems: queryItems, body: body, handler: handler)
}
final public class func post<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func post<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .POST, queryItems: queryItems, body: body, handler: handler)
}
final public class func post(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func post(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .POST, queryItems: queryItems, handler: handler)
}
final public class func put(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func put(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .PUT, queryItems: queryItems, body: body, handler: handler)
}
final public class func put<T: Encodable>(path: String, queryItems: [URLQueryItem]? = nil, body: T, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func put<T: Encodable>(path: String, queryItems: [URLQueryItem]? = nil, body: T, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .PUT, queryItems: queryItems, body: body, handler: handler)
}
final public class func put<T: Encodable>(path: String, queryItems: [URLQueryItem]? = nil, body: [T], handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func put<T: Encodable>(path: String, queryItems: [URLQueryItem]? = nil, body: [T], handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .PUT, queryItems: queryItems, body: body, handler: handler)
}
final public class func put(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func put(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .PUT, queryItems: queryItems, handler: handler)
}
final public class func patch(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func patch(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .PATCH, queryItems: queryItems, body: body, handler: handler)
}
final public class func patch<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func patch<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .PATCH, queryItems: queryItems, body: body, handler: handler)
}
final public class func patch<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func patch<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .PATCH, queryItems: queryItems, body: body, handler: handler)
}
final public class func patch(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func patch(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .PATCH, queryItems: queryItems, handler: handler)
}
final public class func delete(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func delete(path: String, body: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .DELETE, queryItems: queryItems, body: body, handler: handler)
}
final public class func delete<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func delete<T: Encodable>(path: String, body: T, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .DELETE, queryItems: queryItems, body: body, handler: handler)
}
final public class func delete<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func delete<T: Encodable>(path: String, body: [T], queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .DELETE, queryItems: queryItems, body: body, handler: handler)
}
final public class func delete(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> ()) -> URLSessionDataTask? {
final public class func delete(path: String, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? {
return networkTask(path: path, method: .DELETE, queryItems: queryItems, handler: handler)
}
}