-
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 #312 from ishkawa/feature/decodable-data-parser
Add `NonSerializedJSONDataParser` for `Foundation.Decodable`
- Loading branch information
Showing
4 changed files
with
68 additions
and
26 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
19 changes: 19 additions & 0 deletions
19
Sources/APIKit/DataParser/NonSerializedJSONDataParser.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Foundation | ||
|
||
/// `NonSerializedJSONDataParser` response Data data. | ||
public class NonSerializedJSONDataParser: DataParser { | ||
/// Returns `NonSerializedJSONDataParser`. | ||
public init() {} | ||
|
||
// MARK: - DataParser | ||
|
||
/// Value for `Accept` header field of HTTP request. | ||
public var contentType: String? { | ||
return "application/json" | ||
} | ||
|
||
/// Return `Data` that expresses structure of Data response. | ||
public func parse(data: Data) throws -> Data { | ||
return data | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Tests/APIKitTests/DataParserType/NonSerializedJSONDataParserTests.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import XCTest | ||
import APIKit | ||
import XCTest | ||
|
||
class NonSerializedJSONDataParserTests: XCTestCase { | ||
func testContentType() { | ||
let parser = NonSerializedJSONDataParser() | ||
XCTAssertEqual(parser.contentType, "application/json") | ||
} | ||
|
||
func testJSONSuccess() throws { | ||
let data = try XCTUnwrap("data".data(using: .utf8)) | ||
let parser = NonSerializedJSONDataParser() | ||
|
||
let object = try parser.parse(data: data) | ||
XCTAssertEqual(object, data) | ||
} | ||
} |