aboutsummaryrefslogtreecommitdiff
path: root/Sources/LichessClient/LichessClient.swift
blob: d398538d4c80c2791cf1b927e1f40b311e37c76c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Foundation
import OpenAPIRuntime
import OpenAPIURLSession

public struct LichessClient {
  // Lichess has a separate endpoint for its tablebase server
  internal let underlyingClient: any APIProtocol
  internal let underlyingTablebaseClient: any APIProtocol

  internal init(underlyingClient: any APIProtocol, underlyingTablebaseClient: any APIProtocol) {
    self.underlyingClient = underlyingClient
    self.underlyingTablebaseClient = underlyingTablebaseClient
  }

  public init() {
    self.init(
      underlyingClient: Client(
        serverURL: URL(string: "https://lichess.org")!, transport: URLSessionTransport()),
      underlyingTablebaseClient: Client(
        serverURL: URL(string: "https://tablebase.lichess.ovh")!, transport: URLSessionTransport())
    )
  }

  enum LichessClientError: Error {
    case undocumentedResponse(statusCode: Int)
    case parsingError(error: Error)
  }

}