Files
plexswift/Sources/Plexswift/internal/client/Response.swift
2024-04-11 11:10:38 -05:00

122 lines
4.4 KiB
Swift

// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
import Foundation
#if os(Linux)
import FoundationNetworking
#endif
/// Describes any header values returned as part of a response to a call made to the API.
///
/// As per the HTTP RFCs, header values can be queried in a case-insensitive manner.
public struct ResponseHeaders {
private let httpResponse: HTTPURLResponse
init(httpResponse: HTTPURLResponse) {
self.httpResponse = httpResponse
}
public func value(forHeaderNamed name: String) -> String? {
return httpResponse.value(forHTTPHeaderField: name)
}
public subscript(name: String) -> String? {
return value(forHeaderNamed: name)
}
}
/// Describes the result of making a request to the API.
///
/// This type is returned by all functions which make calls to the API. It returns information about the response
/// and is parameterised by `T` over the type of data which is returned by the API operation.
public struct Response<T>: ResponseFields {
/// The HTTP status code returned by the server.
///
/// This property contains the HTTP status code returned by the server in response to the underlying network request
/// made to fulfill the given API operation.
public var statusCode: Int {
return httpResponse.statusCode
}
/// The media type returned by the server.
///
/// This property contains the media type returned by the server in response to the underlying network request
/// made to fulfill the given API operation.
public var contentType: String {
return httpResponse.contentType
}
/// The raw HTTP response object.
///
/// This property contains the [HTTPURLResponse](https://developer.apple.com/documentation/foundation/httpurlresponse) object
/// returned from making the underlying network request to fulfill the given API operation.
public let httpResponse: HTTPURLResponse
/// The response data.
///
/// This property contains any response data associated with the API operation.
public let data: T
public init(httpResponse: HTTPURLResponse, data: T) {
self.httpResponse = httpResponse
self.data = data
}
}
/// Describes the result of making a request to the API which can contain resulting response header fields.
///
/// This type is returned by all functions which make calls to the API. It returns information about the response
/// and is parameterised by `T` over the type of data which is returned by the API operation.
public struct ResponseWithHeaders<T>: ResponseFields {
/// The HTTP status code returned by the server.
///
/// This property contains the HTTP status code returned by the server in response to the underlying network request
/// made to fulfill the given API operation.
public var statusCode: Int {
return httpResponse.statusCode
}
/// The media type returned by the server.
///
/// This property contains the media type returned by the server in response to the underlying network request
/// made to fulfill the given API operation.
public var contentType: String {
return httpResponse.contentType
}
/// The raw HTTP response object.
///
/// This property contains the [HTTPURLResponse](https://developer.apple.com/documentation/foundation/httpurlresponse) object
/// returned from making the underlying network request to fulfill the given API operation.
public let httpResponse: HTTPURLResponse
/// Any response headers returned by the underlying network request made to fulfill the given API operation.
public let headers: ResponseHeaders?
/// The response data.
///
/// This property contains any response data associated with the API operation.
public let data: T
public init(httpResponse: HTTPURLResponse, data: T) {
self.httpResponse = httpResponse
self.data = data
self.headers = ResponseHeaders(httpResponse: httpResponse)
}
}
/// Describes the fields which are included in all responses to requests made to the API.
///
/// This protocol is adopted by ``Response`` and ``ResponseWithHeaders`` depending on the individual API operation.
public protocol ResponseFields {
associatedtype T;
var statusCode: Int { get }
var contentType: String { get }
var httpResponse: HTTPURLResponse { get }
var data: T { get }
init(httpResponse: HTTPURLResponse, data: T)
}