Skip to content

Commit

Permalink
Update stable OpenAPI client
Browse files Browse the repository at this point in the history
  • Loading branch information
jellyfin-bot committed Jun 17, 2022
1 parent fffcf20 commit daef2c1
Show file tree
Hide file tree
Showing 678 changed files with 27,450 additions and 10,055 deletions.
254 changes: 240 additions & 14 deletions .openapi-generator/FILES

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.2.1-SNAPSHOT
6.0.1-SNAPSHOT
1 change: 0 additions & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

github "Flight-School/AnyCodable" ~> 0.6.1
4 changes: 2 additions & 2 deletions JellyfinAPI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Pod::Spec.new do |s|
s.osx.deployment_target = '10.11'
s.tvos.deployment_target = '9.0'
s.watchos.deployment_target = '3.0'
s.version = '10.7.6'
s.source = { :git => '[email protected]:OpenAPITools/openapi-generator.git', :tag => 'v10.7.6' }
s.version = '10.8.0'
s.source = { :git => '[email protected]:OpenAPITools/openapi-generator.git', :tag => 'v10.8.0' }
s.authors = 'OpenAPI Generator'
s.license = 'Proprietary'
s.homepage = 'https://github.com/OpenAPITools/openapi-generator'
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import PackageDescription
let package = Package(
name: "JellyfinAPI",
platforms: [
.iOS(.v13),
.iOS(.v9),
.macOS(.v10_11),
.tvOS(.v13),
.watchOS(.v5),
.tvOS(.v9),
.watchOS(.v3),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
Expand Down
149 changes: 130 additions & 19 deletions README.md

Large diffs are not rendered by default.

25 changes: 20 additions & 5 deletions Sources/JellyfinAPI/APIHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ public struct APIHelper {
public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] {
return source.reduce(into: [String: String]()) { result, item in
if let collection = item.value as? [Any?] {
result[item.key] = collection.filter { $0 != nil }.map { "\($0!)" }.joined(separator: ",")
result[item.key] = collection
.compactMap { value in
guard let value = value else { return nil }
return "\(value)"
}
.joined(separator: ",")
} else if let value: Any = item.value {
result[item.key] = "\(value)"
}
Expand All @@ -47,17 +52,27 @@ public struct APIHelper {

public static func mapValueToPathItem(_ source: Any) -> Any {
if let collection = source as? [Any?] {
return collection.filter { $0 != nil }.map { "\($0!)" }.joined(separator: ",")
return collection
.compactMap { value in
guard let value = value else { return nil }
return "\(value)"
}
.joined(separator: ",")
}
return source
}

public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? {
let destination = source.filter { $0.value != nil }.reduce(into: [URLQueryItem]()) { result, item in
if let collection = item.value as? [Any?] {
collection.filter { $0 != nil }.map { "\($0!)" }.forEach { value in
result.append(URLQueryItem(name: item.key, value: value))
}
collection
.compactMap { value in
guard let value = value else { return nil }
return "\(value)"
}
.forEach { value in
result.append(URLQueryItem(name: item.key, value: value))
}
} else if let value = item.value {
result.append(URLQueryItem(name: item.key, value: "\(value)"))
}
Expand Down
22 changes: 15 additions & 7 deletions Sources/JellyfinAPI/APIs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

import Foundation

@available(*, deprecated, renamed: "JellyfinAPI")
public typealias JellyfinAPIAPI = JellyfinAPI
// We reverted the change of JellyfinAPIAPI to JellyfinAPI introduced in https://github.com/OpenAPITools/openapi-generator/pull/9624
// Because it was causing the following issue https://github.com/OpenAPITools/openapi-generator/issues/9953
// If you are affected by this issue, please consider removing the following two lines,
// By setting the option removeMigrationProjectNameClass to true in the generator
@available(*, deprecated, renamed: "JellyfinAPIAPI")
public typealias JellyfinAPI = JellyfinAPIAPI

open class JellyfinAPI {
public static var basePath = "http://localhost:8096"
open class JellyfinAPIAPI {
public static var basePath = "http://localhost"
public static var customHeaders: [String: String] = [:]
public static var credential: URLCredential?
public static var requestBuilderFactory: RequestBuilderFactory = URLSessionRequestBuilderFactory()
Expand All @@ -23,6 +27,7 @@ open class RequestBuilder<T> {
public let parameters: [String: Any]?
public let method: String
public let URLString: String
public let requestTask: RequestTask = RequestTask()

/// Optional block to obtain a reference to the request's progress instance when available.
/// With the URLSession http client the request's progress only works on iOS 11.0, macOS 10.13, macCatalyst 13.0, tvOS 11.0, watchOS 4.0.
Expand All @@ -35,7 +40,7 @@ open class RequestBuilder<T> {
self.parameters = parameters
self.headers = headers

addHeaders(JellyfinAPI.customHeaders)
addHeaders(JellyfinAPIAPI.customHeaders)
}

open func addHeaders(_ aHeaders: [String: String]) {
Expand All @@ -44,7 +49,10 @@ open class RequestBuilder<T> {
}
}

open func execute(_ apiResponseQueue: DispatchQueue = JellyfinAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, Error>) -> Void) { }
@discardableResult
open func execute(_ apiResponseQueue: DispatchQueue = JellyfinAPIAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) -> RequestTask {
return requestTask
}

public func addHeader(name: String, value: String) -> Self {
if !value.isEmpty {
Expand All @@ -54,7 +62,7 @@ open class RequestBuilder<T> {
}

open func addCredential() -> Self {
credential = JellyfinAPI.credential
credential = JellyfinAPIAPI.credential
return self
}
}
Expand Down
44 changes: 25 additions & 19 deletions Sources/JellyfinAPI/APIs/ActivityLogAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,51 @@
// https://openapi-generator.tech
//

import AnyCodable
import Foundation
#if canImport(Combine)
import Combine
#endif
#if canImport(AnyCodable)
import AnyCodable
#endif

open class ActivityLogAPI {

/**
Gets activity log entries.

- parameter startIndex: (query) Optional. The record index to start at. All items with a lower index will be dropped from the results. (optional)
- parameter limit: (query) Optional. The maximum number of records to return. (optional)
- parameter minDate: (query) Optional. The minimum date. Format &#x3D; ISO. (optional)
- parameter hasUserId: (query) Optional. Filter log entries if it has user id, or not. (optional)
- parameter apiResponseQueue: The queue on which api response is dispatched.
- returns: AnyPublisher<ActivityLogEntryQueryResult, Error>
*/
#if canImport(Combine)
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
open class func getLogEntries(startIndex: Int? = nil, limit: Int? = nil, minDate: Date? = nil, hasUserId: Bool? = nil, apiResponseQueue: DispatchQueue = JellyfinAPI.apiResponseQueue) -> AnyPublisher<ActivityLogEntryQueryResult, Error> {
return Future<ActivityLogEntryQueryResult, Error>.init { promise in
getLogEntriesWithRequestBuilder(startIndex: startIndex, limit: limit, minDate: minDate, hasUserId: hasUserId).execute(apiResponseQueue) { result -> Void in
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
open class func getLogEntries(startIndex: Int? = nil, limit: Int? = nil, minDate: Date? = nil, hasUserId: Bool? = nil) -> AnyPublisher<ActivityLogEntryQueryResult, Error> {
var requestTask: RequestTask?
return Future<ActivityLogEntryQueryResult, Error> { promise in
requestTask = getLogEntriesWithRequestBuilder(startIndex: startIndex, limit: limit, minDate: minDate, hasUserId: hasUserId).execute { result in
switch result {
case let .success(response):
promise(.success(response.body!))
promise(.success(response.body))
case let .failure(error):
promise(.failure(error))
}
}
}.eraseToAnyPublisher()
}
.handleEvents(receiveCancel: {
requestTask?.cancel()
})
.eraseToAnyPublisher()
}
#endif

/**
Gets activity log entries.
- GET /System/ActivityLog/Entries
- API Key:
- type: apiKey X-Emby-Authorization
- type: apiKey Authorization
- name: CustomAuthentication
- parameter startIndex: (query) Optional. The record index to start at. All items with a lower index will be dropped from the results. (optional)
- parameter limit: (query) Optional. The maximum number of records to return. (optional)
Expand All @@ -51,27 +58,26 @@ open class ActivityLogAPI {
- returns: RequestBuilder<ActivityLogEntryQueryResult>
*/
open class func getLogEntriesWithRequestBuilder(startIndex: Int? = nil, limit: Int? = nil, minDate: Date? = nil, hasUserId: Bool? = nil) -> RequestBuilder<ActivityLogEntryQueryResult> {
let urlPath = "/System/ActivityLog/Entries"
let URLString = JellyfinAPI.basePath + urlPath
let parameters: [String: Any]? = nil
let localVariablePath = "/System/ActivityLog/Entries"
let localVariableURLString = JellyfinAPIAPI.basePath + localVariablePath
let localVariableParameters: [String: Any]? = nil

var urlComponents = URLComponents(string: URLString)
urlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"startIndex": startIndex?.encodeToJSON(),
"limit": limit?.encodeToJSON(),
"minDate": minDate?.encodeToJSON(),
"hasUserId": hasUserId?.encodeToJSON(),
])

let nillableHeaders: [String: Any?] = [
let localVariableNillableHeaders: [String: Any?] = [
:
]

let headerParameters = APIHelper.rejectNilHeaders(nillableHeaders)
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)

let requestBuilder: RequestBuilder<ActivityLogEntryQueryResult>.Type = JellyfinAPI.requestBuilderFactory.getBuilder()
let localVariableRequestBuilder: RequestBuilder<ActivityLogEntryQueryResult>.Type = JellyfinAPIAPI.requestBuilderFactory.getBuilder()

return requestBuilder.init(method: "GET", URLString: (urlComponents?.string ?? URLString), parameters: parameters, headers: headerParameters)
return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
}

}
Loading

0 comments on commit daef2c1

Please sign in to comment.