Sitelet https://github.com/ishkawa/APIKit/pull/303/files
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ jobs:
- xcode: "Xcode_12.5.1"
runsOn: macOS-11
name: "macOS 11, Xcode 12.5.1, Swift 5.4.2"
- xcode: "Xcode_11.7"
- xcode: "Xcode_12"
runsOn: macOS-10.15
name: "macOS 10.15, Xcode 11.7, Swift 5.2.4"
- xcode: "Xcode_10.3"
runsOn: macOS-10.15
name: "macOS 10.15, Xcode 10.3, Swift 5.0.1"
name: "macOS 10.15, Xcode 12.0.1, Swift 5.3"
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -62,15 +59,16 @@ jobs:
- xcode: "Xcode_13.4.1"
runsOn: macOS-12
name: "macOS 12, Xcode 13.4.1, Swift 5.6.1"
action: swift test -c debug
- xcode: "Xcode_12.5.1"
runsOn: macOS-11
name: "macOS 11, Xcode 12.5.1, Swift 5.4.2"
- xcode: "Xcode_11.7"
action: swift test -c debug
- xcode: "Xcode_12"
runsOn: macOS-10.15
name: "macOS 10.15, Xcode 11.7, Swift 5.2.4"
name: "macOS 10.15, Xcode 12.0.1, Swift 5.3"
action: swift build -c debug
steps:
- uses: actions/checkout@v2
- name: ${{ matrix.name }}
run: |
swift build
swift test
run: ${{ matrix.action }}
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

26 changes: 17 additions & 9 deletions APIKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
7F698E5A1D9D680C00F1561D /* URLSessionAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F698E481D9D680C00F1561D /* URLSessionAdapterTests.swift */; };
7F698E5B1D9D680C00F1561D /* SessionCallbackQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F698E491D9D680C00F1561D /* SessionCallbackQueueTests.swift */; };
7F698E5C1D9D680C00F1561D /* SessionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F698E4A1D9D680C00F1561D /* SessionTests.swift */; };
7F698E5D1D9D680C00F1561D /* test.json in Resources */ = {isa = PBXBuildFile; fileRef = 7F698E4B1D9D680C00F1561D /* test.json */; };
7F698E5E1D9D680C00F1561D /* TestRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F698E4D1D9D680C00F1561D /* TestRequest.swift */; };
7F698E5F1D9D680C00F1561D /* TestSessionAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F698E4E1D9D680C00F1561D /* TestSessionAdapter.swift */; };
7F698E601D9D680C00F1561D /* TestSessionTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F698E4F1D9D680C00F1561D /* TestSessionTask.swift */; };
Expand All @@ -48,6 +47,7 @@
7F7048F11D9D8A12003C99F6 /* SessionTaskError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F7048EE1D9D8A12003C99F6 /* SessionTaskError.swift */; };
7F7048F31D9D8A1F003C99F6 /* URLEncodedSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F7048F21D9D8A1F003C99F6 /* URLEncodedSerialization.swift */; };
7FA1690D1D9D8C80006C982B /* HTTPStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FA1690C1D9D8C80006C982B /* HTTPStub.swift */; };
C5FF1DC128A80FFD0059573D /* test.json in Resources */ = {isa = PBXBuildFile; fileRef = C5FF1DC028A80FFD0059573D /* test.json */; };
ECA831481DE4DDBF004EB1B5 /* ProtobufDataParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA831471DE4DDBF004EB1B5 /* ProtobufDataParser.swift */; };
ECA8314A1DE4DEBE004EB1B5 /* ProtobufDataParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA831491DE4DEBE004EB1B5 /* ProtobufDataParserTests.swift */; };
ECA8314C1DE4E677004EB1B5 /* ProtobufBodyParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA8314B1DE4E677004EB1B5 /* ProtobufBodyParameters.swift */; };
Expand Down Expand Up @@ -100,7 +100,6 @@
7F698E481D9D680C00F1561D /* URLSessionAdapterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLSessionAdapterTests.swift; sourceTree = "<group>"; };
7F698E491D9D680C00F1561D /* SessionCallbackQueueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SessionCallbackQueueTests.swift; sourceTree = "<group>"; };
7F698E4A1D9D680C00F1561D /* SessionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SessionTests.swift; sourceTree = "<group>"; };
7F698E4B1D9D680C00F1561D /* test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = test.json; sourceTree = "<group>"; };
7F698E4D1D9D680C00F1561D /* TestRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestRequest.swift; sourceTree = "<group>"; };
7F698E4E1D9D680C00F1561D /* TestSessionAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestSessionAdapter.swift; sourceTree = "<group>"; };
7F698E4F1D9D680C00F1561D /* TestSessionTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestSessionTask.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -129,6 +128,7 @@
7F7048F21D9D8A1F003C99F6 /* URLEncodedSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = URLEncodedSerialization.swift; path = Sources/APIKit/Serializations/URLEncodedSerialization.swift; sourceTree = SOURCE_ROOT; };
7F8ECDFD1B6A799E00234E04 /* Demo.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Demo.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
7FA1690C1D9D8C80006C982B /* HTTPStub.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPStub.swift; sourceTree = "<group>"; };
C5FF1DC028A80FFD0059573D /* test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = test.json; sourceTree = "<group>"; };
ECA831471DE4DDBF004EB1B5 /* ProtobufDataParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProtobufDataParser.swift; path = Sources/APIKit/DataParser/ProtobufDataParser.swift; sourceTree = SOURCE_ROOT; };
ECA831491DE4DEBE004EB1B5 /* ProtobufDataParserTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProtobufDataParserTests.swift; sourceTree = "<group>"; };
ECA8314B1DE4E677004EB1B5 /* ProtobufBodyParameters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProtobufBodyParameters.swift; path = Sources/APIKit/BodyParameters/ProtobufBodyParameters.swift; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -201,17 +201,17 @@
ECA8314B1DE4E677004EB1B5 /* ProtobufBodyParameters.swift */,
7F7048D81D9D89FB003C99F6 /* AbstractInputStream.m */,
);
path = APIKit/BodyParameters;
name = BodyParameters;
path = APIKit/BodyParameters;
sourceTree = "<group>";
};
7F18BD161C9730ED003A31DF /* Serializations */ = {
isa = PBXGroup;
children = (
7F7048F21D9D8A1F003C99F6 /* URLEncodedSerialization.swift */,
);
path = APIKit/Serializations;
name = Serializations;
path = APIKit/Serializations;
sourceTree = "<group>";
};
7F45FCD31A94D02C006863BB = {
Expand Down Expand Up @@ -245,6 +245,7 @@
7F698E401D9D680C00F1561D /* DataParserType */,
7F698E461D9D680C00F1561D /* SessionAdapterType */,
7F698E4C1D9D680C00F1561D /* TestComponents */,
C5FF1DBF28A80FFD0059573D /* Resources */,
7F698E611D9D681500F1561D /* Supporting Files */,
);
path = APIKitTests;
Expand Down Expand Up @@ -297,7 +298,6 @@
isa = PBXGroup;
children = (
7F698E441D9D680C00F1561D /* Info.plist */,
7F698E4B1D9D680C00F1561D /* test.json */,
);
name = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -336,8 +336,8 @@
7F7048D41D9D89F2003C99F6 /* SessionAdapter.swift */,
7F7048D51D9D89F2003C99F6 /* URLSessionAdapter.swift */,
);
path = APIKit/SessionAdapter;
name = SessionAdapter;
path = APIKit/SessionAdapter;
sourceTree = "<group>";
};
7FA19A3D1C9CBF2A005D25AE /* Error */ = {
Expand All @@ -347,8 +347,8 @@
7F7048EC1D9D8A12003C99F6 /* RequestError.swift */,
7F7048ED1D9D8A12003C99F6 /* ResponseError.swift */,
);
path = APIKit/Error;
name = Error;
path = APIKit/Error;
sourceTree = "<group>";
};
7FA19A441C9CC9A2005D25AE /* DataParser */ = {
Expand All @@ -360,8 +360,16 @@
ECA831471DE4DDBF004EB1B5 /* ProtobufDataParser.swift */,
7F7048E71D9D8A08003C99F6 /* StringDataParser.swift */,
);
path = APIKit/DataParser;
name = DataParser;
path = APIKit/DataParser;
sourceTree = "<group>";
};
C5FF1DBF28A80FFD0059573D /* Resources */ = {
isa = PBXGroup;
children = (
C5FF1DC028A80FFD0059573D /* test.json */,
);
path = Resources;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -464,7 +472,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7F698E5D1D9D680C00F1561D /* test.json in Resources */,
C5FF1DC128A80FFD0059573D /* test.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.0
// swift-tools-version:5.3
import PackageDescription

let package = Package(
Expand All @@ -18,7 +18,8 @@ let package = Package(
),
.testTarget(
name: "APIKitTests",
dependencies: ["APIKit"]
dependencies: ["APIKit"],
resources: [.process("Resources")]
),
],
swiftLanguageVersions: [.v5]
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Session.send(request) { result in

## Requirements

- Swift 5.0 or later
- Swift 5.3 or later
- iOS 9.0 or later
- Mac OS 10.10 or later
- watchOS 2.0 or later
Expand All @@ -40,6 +40,8 @@ If you use Swift 2.2 or 2.3, try [APIKit 2.0.5](https://github.com/ishkawa/APIKi

If you use Swift 4.2 or before, try [APIKit 4.1.0](https://github.com/ishkawa/APIKit/tree/4.1.0).

If you use Swift 5.2 or before, try [APIKit 5.3.0](https://github.com/ishkawa/APIKit/tree/5.3.0).

## Installation

#### [Carthage](https://github.com/Carthage/Carthage)
Expand Down
47 changes: 18 additions & 29 deletions Tests/APIKitTests/BodyParametersType/JSONBodyParametersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,47 @@ import XCTest
import APIKit

class JSONBodyParametersTests: XCTestCase {
func testJSONSuccess() {
func testJSONSuccess() throws {
let object = ["foo": 1, "bar": 2, "baz": 3]
let parameters = JSONBodyParameters(JSONObject: object)
XCTAssertEqual(parameters.contentType, "application/json")

do {
guard case .data(let data) = try parameters.buildEntity() else {
XCTFail()
return
}

let dictionary = try JSONSerialization.jsonObject(with: data, options: [])
XCTAssertEqual((dictionary as? [String: Int])?["foo"], 1)
XCTAssertEqual((dictionary as? [String: Int])?["bar"], 2)
XCTAssertEqual((dictionary as? [String: Int])?["baz"], 3)
} catch {
guard case .data(let data) = try parameters.buildEntity() else {
XCTFail()
return
}
let dictionary = try JSONSerialization.jsonObject(with: data, options: [])
XCTAssertEqual((dictionary as? [String: Int])?["foo"], 1)
XCTAssertEqual((dictionary as? [String: Int])?["bar"], 2)
XCTAssertEqual((dictionary as? [String: Int])?["baz"], 3)
}

func testJSONFailure() {
let object = NSObject()
let parameters = JSONBodyParameters(JSONObject: object)

do {
try _ = parameters.buildEntity()
XCTFail()
} catch {
XCTAssertThrowsError(try parameters.buildEntity()) { error in
let nserror = error as NSError
XCTAssertEqual(nserror.domain, NSCocoaErrorDomain)
XCTAssertEqual(nserror.code, 3840)
}
}

func testDictionaryLiteral() {
func testDictionaryLiteral() throws {
let object = ["foo": 1, "bar": 2, "baz": 3]

let parameters1: JSONBodyParameters = .init(JSONObject: object)
let parameters2: JSONBodyParameters = ["foo": 1, "bar": 2, "baz": 3]
do {
guard case .data(let data1) = try parameters1.buildEntity(),
case .data(let data2) = try parameters2.buildEntity() else {
XCTFail()
return
}
let dictionary1 = try JSONSerialization.jsonObject(with: data1, options: [])
let dictionary2 = try JSONSerialization.jsonObject(with: data2, options: [])
XCTAssertEqual((dictionary1 as? [String: Int])?["foo"], (dictionary2 as? [String: Int])?["foo"])
XCTAssertEqual((dictionary1 as? [String: Int])?["bar"], (dictionary2 as? [String: Int])?["bar"])
XCTAssertEqual((dictionary1 as? [String: Int])?["baz"], (dictionary2 as? [String: Int])?["baz"])
} catch {

guard case .data(let data1) = try parameters1.buildEntity(),
case .data(let data2) = try parameters2.buildEntity() else {
XCTFail()
return
}
let dictionary1 = try JSONSerialization.jsonObject(with: data1, options: [])
let dictionary2 = try JSONSerialization.jsonObject(with: data2, options: [])
XCTAssertEqual((dictionary1 as? [String: Int])?["foo"], (dictionary2 as? [String: Int])?["foo"])
XCTAssertEqual((dictionary1 as? [String: Int])?["bar"], (dictionary2 as? [String: Int])?["bar"])
XCTAssertEqual((dictionary1 as? [String: Int])?["baz"], (dictionary2 as? [String: Int])?["baz"])
}
}
Loading