Documentation pass
This commit is contained in:
@@ -22,6 +22,10 @@ public struct Client {
|
||||
self.defaultHeaders = headers
|
||||
}
|
||||
|
||||
/// When all a client needs is the HTTP status code of an endpoint, this function should be used.
|
||||
/// - Parameter request: Any Emby or Jellyfin `Request` conforming to the `Request` protocol.
|
||||
/// - Throws:`RequestError.invalidResponse` if the response could not be coerced into a `HTTPURLResponse`.
|
||||
/// - Returns: The HTTP status code.
|
||||
func statusRequest(_ request: any Request) async throws -> Int {
|
||||
let urlRequest = try createRequestObject(for: request)
|
||||
let (_, response) = try await session.data(for: urlRequest)
|
||||
@@ -32,6 +36,10 @@ public struct Client {
|
||||
return response.statusCode
|
||||
}
|
||||
|
||||
/// Sends a request to an Emby or Jellyfin server, and builds a model object from that response.
|
||||
/// - Parameter request: Any Emby or Jellyfin `Request` conforming to the `Request` protocol.
|
||||
/// - Throws:`RequestError.invalidResponse` if the response could not be coerced into a `HTTPURLResponse`.
|
||||
/// - Returns: A `Codable` model object whose type is infered from the receiving variable.
|
||||
func dataRequest<T>(_ request: any Request) async throws -> T? where T: Codable {
|
||||
let urlRequest = try createRequestObject(for: request)
|
||||
let (data, response) = try await session.data(for: urlRequest)
|
||||
@@ -42,6 +50,11 @@ public struct Client {
|
||||
return try decoder.decode(T.self, from: data)
|
||||
}
|
||||
|
||||
/// Verifies and creates a `URLRequest` from information provided by the `Request`.
|
||||
/// Merges the `Request` headers, if any, with the default headers.
|
||||
/// - Parameter request: Any Emby or Jellyfin `Request` conforming to the `Request` protocol.
|
||||
/// - Throws: `RequestError.badURL` if unable to create a `URL` from the string.
|
||||
/// - Returns: A fully formed `URLRequest` ready to send.
|
||||
private func createRequestObject(for request: Request) throws -> URLRequest {
|
||||
guard let url = URL(string: "\(server)\(request.endpoint)") else {
|
||||
throw RequestError.badURL
|
||||
|
||||
@@ -5,12 +5,26 @@
|
||||
// Created by Alex Loren on 10/13/26.
|
||||
//
|
||||
|
||||
/// Contains the information of any `User` that is reported back by Emby or Jellyfin.
|
||||
/// This model does not currently contain all data reported by the server.
|
||||
/// Properties will become available as needed, not prior.
|
||||
struct User: Codable {
|
||||
// MARK: - Properties
|
||||
|
||||
/// A server generated unique Id for the `User`.
|
||||
var id: String
|
||||
|
||||
/// The `User` belongs to the server with this Id.
|
||||
var serverId: String
|
||||
|
||||
/// A `User` or server administer given name
|
||||
var name: String
|
||||
|
||||
/// If `true` the `User` must be authenticated before making requests on their behalf.
|
||||
var hasPassword: Bool
|
||||
var primaryImageTag: String
|
||||
|
||||
/// If not `nil` a request can be made to retreive the profile image for the `User`.
|
||||
var primaryImageTag: String?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id = "Id"
|
||||
|
||||
@@ -5,11 +5,18 @@
|
||||
// Created by Alex Loren on 10/13/26.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// The base for any `Request` made by JellyKit
|
||||
protocol Request {
|
||||
// MARK: - Properties
|
||||
|
||||
/// This must begin with a forward slash.
|
||||
/// Points to the resource on the Emby or Jellyfin server.
|
||||
var endpoint: String { get set }
|
||||
|
||||
/// What should this request be sent as?
|
||||
var method: String { get set }
|
||||
|
||||
/// Any additional headers that are specific to *this* request.
|
||||
/// Headers needed for every reqeust should be set at `Client` creation.
|
||||
var headers: [String:String]? { get set }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user