-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from ishkawa/si-swift3
Swift 3 support
- Loading branch information
Showing
54 changed files
with
1,048 additions
and
1,072 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
github "antitypical/Result" ~> 2.1.2 | ||
github "antitypical/Result" ~> 3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
github "ikesyo/OHHTTPStubs" "swift2.3" | ||
github "AliSoftware/OHHTTPStubs" "5.2.1-swift3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
github "ikesyo/OHHTTPStubs" "b9abbd044ebeecbedf8db10721ed24e4bfe07f29" | ||
github "antitypical/Result" "2.1.2" | ||
github "AliSoftware/OHHTTPStubs" "5.2.1-swift3" | ||
github "antitypical/Result" "3.0.0" |
Submodule OHHTTPStubs
updated
28 files
Submodule Result
updated
11 files
+1 −1 | .swift-version | |
+11 −19 | .travis.yml | |
+2 −2 | Result.podspec | |
+61 −25 | Result.xcodeproj/project.pbxproj | |
+1 −1 | Result/Info.plist | |
+48 −123 | Result/Result.swift | |
+182 −0 | Result/ResultProtocol.swift | |
+0 −264 | Result/ResultType.swift | |
+1 −1 | Tests/LinuxMain.swift | |
+1 −1 | Tests/ResultTests/Info.plist | |
+35 −52 | Tests/ResultTests/ResultTests.swift |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Foundation | ||
|
||
/// `RequestBodyEntity` represents entity of HTTP body. | ||
public enum RequestBodyEntity { | ||
/// Expresses entity as `Data`. The associated value will be set to `URLRequest.httpBody`. | ||
case data(Data) | ||
|
||
/// Expresses entity as `InputStream`. The associated value will be set to `URLRequest.httpBodyStream`. | ||
case inputStream(InputStream) | ||
} | ||
|
||
/// `BodyParameters` provides interface to parse HTTP response body and to state `Content-Type` to accept. | ||
public protocol BodyParameters { | ||
/// `Content-Type` to send. The value for this property will be set to `Accept` HTTP header field. | ||
var contentType: String { get } | ||
|
||
/// Builds `RequestBodyEntity`. | ||
/// Throws: `ErrorType` | ||
func buildEntity() throws -> RequestBodyEntity | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Foundation | ||
|
||
enum InputStreamError: Error { | ||
case invalidDataCapacity(Int) | ||
case unreadableStream(InputStream) | ||
} | ||
|
||
extension Data { | ||
init(inputStream: InputStream, capacity: Int = Int(UInt16.max)) throws { | ||
var data = Data(capacity: capacity) | ||
|
||
let bufferSize = Swift.min(Int(UInt16.max), capacity) | ||
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: bufferSize) | ||
|
||
var readSize: Int | ||
|
||
repeat { | ||
readSize = inputStream.read(buffer, maxLength: bufferSize) | ||
|
||
switch readSize { | ||
case let x where x > 0: | ||
data.append(buffer, count: readSize) | ||
|
||
case let x where x < 0: | ||
throw InputStreamError.unreadableStream(inputStream) | ||
|
||
default: | ||
break | ||
} | ||
} while readSize > 0 | ||
|
||
buffer.deallocate(capacity: bufferSize) | ||
|
||
self.init(data) | ||
} | ||
} |
14 changes: 7 additions & 7 deletions
14
...rsType/FormURLEncodedBodyParameters.swift → ...meters/FormURLEncodedBodyParameters.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
import Foundation | ||
|
||
/// `FormURLEncodedBodyParameters` serializes form object for HTTP body and states its content type is form. | ||
public struct FormURLEncodedBodyParameters: BodyParametersType { | ||
public struct FormURLEncodedBodyParameters: BodyParameters { | ||
/// The form object to be serialized. | ||
public let form: [String: AnyObject] | ||
public let form: [String: Any] | ||
|
||
/// The string encoding of the serialized form. | ||
public let encoding: NSStringEncoding | ||
public let encoding: String.Encoding | ||
|
||
/// Returns `FormURLEncodedBodyParameters` that is initialized with form object and encoding. | ||
public init(formObject: [String: AnyObject], encoding: NSStringEncoding = NSUTF8StringEncoding) { | ||
public init(formObject: [String: Any], encoding: String.Encoding = .utf8) { | ||
self.form = formObject | ||
self.encoding = encoding | ||
} | ||
|
||
// MARK: - BodyParametersType | ||
// MARK: - BodyParameters | ||
|
||
/// `Content-Type` to send. The value for this property will be set to `Accept` HTTP header field. | ||
public var contentType: String { | ||
return "application/x-www-form-urlencoded" | ||
} | ||
|
||
/// Builds `RequestBodyEntity.Data` that represents `form`. | ||
/// Builds `RequestBodyEntity.data` that represents `form`. | ||
/// - Throws: `URLEncodedSerialization.Error` if `URLEncodedSerialization` fails to serialize form object. | ||
public func buildEntity() throws -> RequestBodyEntity { | ||
return .Data(try URLEncodedSerialization.dataFromObject(form, encoding: encoding)) | ||
return .data(try URLEncodedSerialization.data(from: form, encoding: encoding)) | ||
} | ||
} |
18 changes: 9 additions & 9 deletions
18
...dyParametersType/JSONBodyParameters.swift → ...s/BodyParameters/JSONBodyParameters.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
import Foundation | ||
|
||
/// `JSONBodyParameters` serializes JSON object for HTTP body and states its content type is JSON. | ||
public struct JSONBodyParameters: BodyParametersType { | ||
public struct JSONBodyParameters: BodyParameters { | ||
/// The JSON object to be serialized. | ||
public let JSONObject: AnyObject | ||
public let JSONObject: Any | ||
|
||
/// The writing options for serialization. | ||
public let writingOptions: NSJSONWritingOptions | ||
public let writingOptions: JSONSerialization.WritingOptions | ||
|
||
/// Returns `JSONBodyParameters` that is initialized with JSON object and writing options. | ||
public init(JSONObject: AnyObject, writingOptions: NSJSONWritingOptions = []) { | ||
public init(JSONObject: Any, writingOptions: JSONSerialization.WritingOptions = []) { | ||
self.JSONObject = JSONObject | ||
self.writingOptions = writingOptions | ||
} | ||
|
||
// MARK: - BodyParametersType | ||
// MARK: - BodyParameters | ||
|
||
/// `Content-Type` to send. The value for this property will be set to `Accept` HTTP header field. | ||
public var contentType: String { | ||
return "application/json" | ||
} | ||
|
||
/// Builds `RequestBodyEntity.Data` that represents `JSONObject`. | ||
/// - Throws: `NSError` if `NSJSONSerialization` fails to serialize `JSONObject`. | ||
/// Builds `RequestBodyEntity.data` that represents `JSONObject`. | ||
/// - Throws: `NSError` if `JSONSerialization` fails to serialize `JSONObject`. | ||
public func buildEntity() throws -> RequestBodyEntity { | ||
// If isValidJSONObject(_:) is false, dataWithJSONObject(_:options:) throws NSException. | ||
guard NSJSONSerialization.isValidJSONObject(JSONObject) else { | ||
guard JSONSerialization.isValidJSONObject(JSONObject) else { | ||
throw NSError(domain: NSCocoaErrorDomain, code: 3840, userInfo: nil) | ||
} | ||
|
||
return .Data(try NSJSONSerialization.dataWithJSONObject(JSONObject, options: writingOptions)) | ||
return .data(try JSONSerialization.data(withJSONObject: JSONObject, options: writingOptions)) | ||
} | ||
} |
Oops, something went wrong.