diff --git a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Timeline.swift b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Timeline.swift index 944aad7ec..eb9271b02 100644 --- a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Timeline.swift +++ b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Timeline.swift @@ -14,7 +14,7 @@ extension Mastodon.API.Timeline { return Mastodon.API.endpointURL(domain: domain).appendingPathComponent("timelines/public") } - public static func create( + public static func `public`( session: URLSession, domain: String, query: PublicTimelineQuery @@ -45,7 +45,15 @@ extension Mastodon.API.Timeline { public let minID: Mastodon.Entity.Toot.ID? public let limit: Int? - public init(local: Bool?, remote: Bool?, onlyMedia: Bool?, maxID: Mastodon.Entity.Toot.ID?, sinceID: Mastodon.Entity.Toot.ID?, minID: Mastodon.Entity.Toot.ID?, limit: Int?) { + public init( + local: Bool? = nil, + remote: Bool? = nil, + onlyMedia: Bool? = nil, + maxID: Mastodon.Entity.Toot.ID? = nil, + sinceID: Mastodon.Entity.Toot.ID? = nil, + minID: Mastodon.Entity.Toot.ID? = nil, + limit: Int? = nil + ) { self.local = local self.remote = remote self.onlyMedia = onlyMedia diff --git a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API.swift b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API.swift index e8ea282f8..f86e1fc71 100644 --- a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API.swift +++ b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API.swift @@ -19,7 +19,18 @@ extension Mastodon.API { }() static let decoder: JSONDecoder = { let decoder = JSONDecoder() - decoder.dateDecodingStrategy = .iso8601 + decoder.dateDecodingStrategy = JSONDecoder.DateDecodingStrategy.custom { decoder throws -> Date in + let container = try decoder.singleValueContainer() + let string = try container.decode(String.self) + + let formatter = ISO8601DateFormatter() + formatter.formatOptions.insert(.withFractionalSeconds) + if let date = formatter.date(from: string) { + return date + } + + throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid date: \(string)") + } return decoder }() diff --git a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+User.swift b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+User.swift index 276ca8e4e..f1dd4f692 100644 --- a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+User.swift +++ b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+User.swift @@ -14,7 +14,7 @@ extension Mastodon.Entity { public let id: ID - public let username: Date + public let username: String public let acct: String public let displayName: String? public let avatar: String? diff --git a/MastodonSDK/Tests/MastodonSDKTests/MastodonSDKTests.swift b/MastodonSDK/Tests/MastodonSDKTests/MastodonSDKTests.swift index db8f0d315..380c7dd41 100644 --- a/MastodonSDK/Tests/MastodonSDKTests/MastodonSDKTests.swift +++ b/MastodonSDK/Tests/MastodonSDKTests/MastodonSDKTests.swift @@ -36,4 +36,27 @@ final class MastodonSDKTests: XCTestCase { wait(for: [theExpectation], timeout: 10.0) } + func testPublicTimeline() throws { + let theExpectation = expectation(description: "Create An Application") + + let query = Mastodon.API.Timeline.PublicTimelineQuery() + Mastodon.API.Timeline.public(session: session, domain: domain, query: query) + .receive(on: DispatchQueue.main) + .sink { completion in + switch completion { + case .failure(let error): + XCTFail(error.localizedDescription) + case .finished: + break + } + } receiveValue: { response in + XCTAssert(!response.value.isEmpty) + theExpectation.fulfill() + } + .store(in: &disposeBag) + + wait(for: [theExpectation], timeout: 10.0) + + } + }