Skip to content

Commit

Permalink
Updates dependencies + lints code
Browse files Browse the repository at this point in the history
  • Loading branch information
s4cha committed Apr 13, 2017
1 parent aea8d38 commit 69a7d0b
Show file tree
Hide file tree
Showing 20 changed files with 239 additions and 130 deletions.
25 changes: 25 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
disabled_rules:
- trailing_whitespace # this would rewrite every single file :/
- large_tuple
- type_name

opt_in_rules:
- empty_count
- attributes
- closure_spacing
- conditional_returns_on_newline
- overridden_super_call
- private_outlet
- private_unit_test
- prohibited_super_call
- redundant_nil_coalescing
- switch_case_on_newline
- sorted_imports
- first_where
- closure_end_indentation

variable_name:
min_length: 1

excluded:
- Carthage
6 changes: 3 additions & 3 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "Alamofire/Alamofire" "4.3.0"
github "s4cha/Arrow" "3.0.3"
github "s4cha/then" "2.0.2"
github "Alamofire/Alamofire" "4.4.0"
github "freshOS/Arrow" "3.0.5"
github "freshOS/then" "2.2.2"
6 changes: 3 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "Alamofire/Alamofire" "4.3.0"
github "s4cha/Arrow" "3.0.3"
github "s4cha/then" "2.0.2"
github "Alamofire/Alamofire" "4.4.0"
github "freshOS/Arrow" "3.0.5"
github "freshOS/then" "2.2.2"
2 changes: 1 addition & 1 deletion Carthage/Checkouts/Arrow
Submodule Arrow updated from 18889f to 8a398d
2 changes: 1 addition & 1 deletion Carthage/Checkouts/then
Submodule then updated from 775402 to 24e07d
Binary file removed ws.framework.zip
Binary file not shown.
17 changes: 17 additions & 0 deletions ws.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 996CABA41BF67A7C00931EAD /* Build configuration list for PBXNativeTarget "ws" */;
buildPhases = (
9925B8D81E9FB07A002C081D /* ShellScript */,
996CAB8B1BF67A7C00931EAD /* Sources */,
996CAB8C1BF67A7C00931EAD /* Frameworks */,
996CAB8D1BF67A7C00931EAD /* Headers */,
Expand Down Expand Up @@ -480,6 +481,22 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
9925B8D81E9FB07A002C081D /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
996CAB8B1BF67A7C00931EAD /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
22 changes: 16 additions & 6 deletions ws/WS+Requests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@ import Foundation

extension WS {

public func getRequest(_ url:String, params:[String:Any] = [String:Any]()) -> WSRequest {
public func getRequest(_ url: String, params: [String:Any] = [String: Any]()) -> WSRequest {
return call(url, verb: .get, params: params)
}

public func putRequest(_ url:String, params:[String:Any] = [String:Any]()) -> WSRequest {
public func putRequest(_ url: String, params: [String:Any] = [String: Any]()) -> WSRequest {
return call(url, verb: .put, params: params)
}

public func postRequest(_ url:String, params:[String:Any] = [String:Any]()) -> WSRequest {
public func postRequest(_ url: String, params: [String: Any] = [String: Any]()) -> WSRequest {
return call(url, verb: .post, params: params)
}

public func deleteRequest(_ url:String, params:[String:Any] = [String:Any]()) -> WSRequest {
public func deleteRequest(_ url: String, params: [String: Any] = [String: Any]()) -> WSRequest {
return call(url, verb: .delete, params: params)
}

public func postMultipartRequest(_ url:String, params:[String:Any] = [String:Any](), name:String, data:Data, fileName:String, mimeType:String) -> WSRequest {
public func postMultipartRequest(_ url: String,
params: [String: Any] = [String: Any](),
name: String,
data: Data,
fileName: String,
mimeType: String) -> WSRequest {
let c = call(url, verb: .post, params: params)
c.isMultipart = true
c.multipartData = data
Expand All @@ -36,7 +41,12 @@ extension WS {
return c
}

public func putMultipartRequest(_ url:String, params:[String:Any] = [String:Any](), name:String, data:Data, fileName:String, mimeType:String) -> WSRequest {
public func putMultipartRequest(_ url: String,
params: [String: Any] = [String: Any](),
name: String,
data: Data,
fileName: String,
mimeType: String) -> WSRequest {
let c = call(url, verb: .put, params: params)
c.isMultipart = true
c.multipartData = data
Expand Down
90 changes: 60 additions & 30 deletions ws/WS+TypedCalls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,50 @@
// Copyright © 2016 s4cha. All rights reserved.
//

import Foundation
import Arrow
import Foundation
import then


extension WS {

public func get<T:ArrowParsable>(_ url: String, params: [String: Any] = [String: Any](), keypath: String? = nil) -> Promise<[T]> {
public func get<T: ArrowParsable>(_ url: String,
params: [String: Any] = [String: Any](),
keypath: String? = nil) -> Promise<[T]> {
let keypath = keypath ?? defaultCollectionParsingKeyPath
return getRequest(url, params: params).fetch().registerThen { (json: JSON) -> [T] in
WSModelJSONParser<T>().toModels(json, keypath: keypath)
return getRequest(url, params: params).fetch()
.registerThen { (json: JSON) -> [T] in
WSModelJSONParser<T>().toModels(json, keypath: keypath)
}.resolveOnMainThread()
}

public func get<T:ArrowParsable>(_ url: String, params: [String: Any] = [String: Any](), keypath: String? = nil) -> Promise<T> {
public func get<T: ArrowParsable>(_ url: String,
params: [String: Any] = [String: Any](),
keypath: String? = nil) -> Promise<T> {
return resourceCall(.get, url: url, params: params, keypath: keypath)
}

public func post<T:ArrowParsable>(_ url: String, params: [String: Any] = [String: Any](), keypath: String? = nil) -> Promise<T> {
public func post<T: ArrowParsable>(_ url: String,
params: [String: Any] = [String: Any](),
keypath: String? = nil) -> Promise<T> {
return resourceCall(.post, url: url, params: params, keypath: keypath)
}

public func put<T:ArrowParsable>(_ url: String, params: [String: Any] = [String: Any](), keypath: String? = nil) -> Promise<T> {
public func put<T: ArrowParsable>(_ url: String,
params: [String: Any] = [String: Any](),
keypath: String? = nil) -> Promise<T> {
return resourceCall(.put, url: url, params: params, keypath: keypath)
}

public func delete<T:ArrowParsable>(_ url: String, params: [String: Any] = [String: Any](), keypath: String? = nil) -> Promise<T> {
public func delete<T: ArrowParsable>(_ url: String,
params: [String: Any] = [String: Any](),
keypath: String? = nil) -> Promise<T> {
return resourceCall(.delete, url: url, params: params, keypath: keypath)
}

private func resourceCall<T:ArrowParsable>(_ verb: WSHTTPVerb, url: String, params: [String: Any] = [String: Any](), keypath: String? = nil) -> Promise<T> {
private func resourceCall<T: ArrowParsable>(_ verb: WSHTTPVerb,
url: String,
params: [String: Any] = [String: Any](),
keypath: String? = nil) -> Promise<T> {
let c = defaultCall()
c.httpVerb = verb
c.URL = url
Expand All @@ -52,51 +65,68 @@ extension WS {

extension WS {

public func get<T: ArrowInitializable>(_ url: String, params: [String: Any] = [String: Any](), keypath: String? = nil) -> Promise<[T]> {
public func get<T: ArrowInitializable>(_ url: String,
params: [String: Any] = [String: Any](),
keypath: String? = nil) -> Promise<[T]> {
let keypath = keypath ?? defaultCollectionParsingKeyPath
return getRequest(url, params: params).fetch().registerThen { (json: JSON) in
Promise<[T]> { (resolve, reject) in
if let t: [T] = WSModelJSONParser<T>().toModels(json, keypath: keypath) {
resolve(t)
} else {
reject(WSError.unableToParseResponse)
return getRequest(url, params: params)
.fetch()
.registerThen { (json: JSON) in
Promise<[T]> { (resolve, reject) in
if let t: [T] = WSModelJSONParser<T>().toModels(json, keypath: keypath) {
resolve(t)
} else {
reject(WSError.unableToParseResponse)
}
}
}
}.resolveOnMainThread()
.resolveOnMainThread()
}

public func get<T: ArrowInitializable>(_ url: String, params: [String: Any] = [String: Any](), keypath: String? = nil) -> Promise<T> {
public func get<T: ArrowInitializable>(_ url: String,
params: [String: Any] = [String: Any](),
keypath: String? = nil) -> Promise<T> {
return typeCall(.get, url: url, params: params, keypath: keypath)
}

public func post<T: ArrowInitializable>(_ url: String, params: [String: Any] = [String: Any](), keypath: String? = nil) -> Promise<T> {
public func post<T: ArrowInitializable>(_ url: String,
params: [String: Any] = [String: Any](),
keypath: String? = nil) -> Promise<T> {
return typeCall(.post, url: url, params: params, keypath: keypath)
}

public func put<T: ArrowInitializable>(_ url: String, params: [String: Any] = [String: Any](), keypath: String? = nil) -> Promise<T> {
public func put<T: ArrowInitializable>(_ url: String,
params: [String: Any] = [String: Any](),
keypath: String? = nil) -> Promise<T> {
return typeCall(.put, url: url, params: params, keypath: keypath)
}

public func delete<T: ArrowInitializable>(_ url: String, params: [String: Any] = [String: Any](), keypath: String? = nil) -> Promise<T> {
public func delete<T: ArrowInitializable>(_ url: String,
params: [String: Any] = [String: Any](),
keypath: String? = nil) -> Promise<T> {
return typeCall(.delete, url: url, params: params, keypath: keypath)
}

private func typeCall<T: ArrowInitializable>(_ verb: WSHTTPVerb, url: String, params: [String: Any] = [String: Any](), keypath: String? = nil) -> Promise<T> {
private func typeCall<T: ArrowInitializable>(_ verb: WSHTTPVerb,
url: String, params: [String: Any] = [String: Any](),
keypath: String? = nil) -> Promise<T> {
let c = defaultCall()
c.httpVerb = verb
c.URL = url
c.params = params

// Apply corresponding JSON mapper
return c.fetch().registerThen { (json: JSON) in
Promise<T> { (resolve, reject) in
if let t: T = WSModelJSONParser<T>().toModel(json, keypath: keypath) {
resolve(t)
} else {
reject(WSError.unableToParseResponse)
return c.fetch()
.registerThen { (json: JSON) in
Promise<T> { (resolve, reject) in
if let t: T = WSModelJSONParser<T>().toModel(json, keypath: keypath) {
resolve(t)
} else {
reject(WSError.unableToParseResponse)
}
}
}
}.resolveOnMainThread()
.resolveOnMainThread()
}

}
Loading

0 comments on commit 69a7d0b

Please sign in to comment.