// Copyright © 2020 Metabolist. All rights reserved. import Foundation import Combine class MastodonClient: HTTPClient { var instanceURL: URL? var accessToken: String? init(session: Session) { super.init(session: session, decoder: MastodonDecoder()) } override func request(_ target: T) -> AnyPublisher { super.request(target, decodeErrorsAs: MastodonError.self) } } extension MastodonClient { func request(_ endpoint: E) -> AnyPublisher { guard let instanceURL = instanceURL else { return Fail(error: URLError(.badURL)).eraseToAnyPublisher() } return super.request( MastodonTarget(baseURL: instanceURL, endpoint: endpoint, accessToken: accessToken), decodeErrorsAs: MastodonError.self) } }