From e3ec8e111caa0880112dd9c837b60fb1712c4d76 Mon Sep 17 00:00:00 2001 From: ras0q Date: Sat, 21 Oct 2023 23:44:45 +0900 Subject: [PATCH] :boom: run with generator 7.0.1 --- .gitignore | 21 +- .openapi-generator/FILES | 2 + .openapi-generator/VERSION | 2 +- .swiftformat | 46 +- Cartfile | 2 +- Package.swift | 10 +- README.md | 23 +- Sources/Traq/APIHelper.swift | 64 +- Sources/Traq/APIs.swift | 36 +- Sources/Traq/APIs/ActivityAPI.swift | 58 +- Sources/Traq/APIs/AuthenticationAPI.swift | 188 +---- Sources/Traq/APIs/BotAPI.swift | 398 ++------- Sources/Traq/APIs/ChannelAPI.swift | 468 ++--------- Sources/Traq/APIs/ClipAPI.swift | 240 +----- Sources/Traq/APIs/FileAPI.swift | 176 +--- Sources/Traq/APIs/GroupAPI.swift | 338 +------- Sources/Traq/APIs/MeAPI.swift | 784 ++---------------- Sources/Traq/APIs/MessageAPI.swift | 450 ++-------- Sources/Traq/APIs/NotificationAPI.swift | 260 +----- Sources/Traq/APIs/Oauth2API.swift | 334 ++------ Sources/Traq/APIs/OgpAPI.swift | 56 +- Sources/Traq/APIs/PinAPI.swift | 104 +-- Sources/Traq/APIs/PublicAPI.swift | 52 +- Sources/Traq/APIs/StampAPI.swift | 448 ++-------- Sources/Traq/APIs/StarAPI.swift | 78 +- Sources/Traq/APIs/UserAPI.swift | 406 ++------- Sources/Traq/APIs/UserTagAPI.swift | 234 +----- Sources/Traq/APIs/WebhookAPI.swift | 250 +----- Sources/Traq/APIs/WebrtcAPI.swift | 52 +- Sources/Traq/CodableHelper.swift | 10 +- Sources/Traq/Configuration.swift | 13 +- Sources/Traq/Extensions.swift | 59 +- Sources/Traq/JSONDataEncoding.swift | 3 + Sources/Traq/Models.swift | 22 +- Sources/Traq/Models/Bot.swift | 1 + Sources/Traq/Models/BotDetail.swift | 1 + Sources/Traq/Models/Channel.swift | 1 + Sources/Traq/Models/ClipFolder.swift | 2 + Sources/Traq/Models/MyUserDetail.swift | 4 + Sources/Traq/Models/OAuth2Client.swift | 2 + Sources/Traq/Models/OAuth2ClientDetail.swift | 2 + Sources/Traq/Models/PatchBotRequest.swift | 2 + Sources/Traq/Models/PatchChannelRequest.swift | 1 + Sources/Traq/Models/PatchClientRequest.swift | 2 + .../Traq/Models/PatchClipFolderRequest.swift | 2 + .../Traq/Models/PatchGroupMemberRequest.swift | 1 + Sources/Traq/Models/PatchMeRequest.swift | 3 + .../Models/PatchStampPaletteRequest.swift | 2 + Sources/Traq/Models/PatchStampRequest.swift | 1 + .../Traq/Models/PatchUserGroupRequest.swift | 1 + Sources/Traq/Models/PatchUserRequest.swift | 2 + Sources/Traq/Models/PatchWebhookRequest.swift | 3 + Sources/Traq/Models/PostBotRequest.swift | 3 + Sources/Traq/Models/PostChannelRequest.swift | 1 + Sources/Traq/Models/PostClientRequest.swift | 2 + .../Traq/Models/PostClipFolderRequest.swift | 2 + Sources/Traq/Models/PostLoginRequest.swift | 2 + Sources/Traq/Models/PostMessageRequest.swift | 1 + .../Traq/Models/PostMessageStampRequest.swift | 1 + .../Traq/Models/PostStampPaletteRequest.swift | 2 + .../Traq/Models/PostUserGroupRequest.swift | 1 + Sources/Traq/Models/PostUserRequest.swift | 2 + Sources/Traq/Models/PostUserTagRequest.swift | 1 + Sources/Traq/Models/PostWebhookRequest.swift | 3 + .../Traq/Models/PutChannelTopicRequest.swift | 1 + .../Traq/Models/PutMyPasswordRequest.swift | 2 + .../Traq/Models/PutUserPasswordRequest.swift | 1 + Sources/Traq/Models/Stamp.swift | 1 + Sources/Traq/Models/StampPalette.swift | 2 + Sources/Traq/Models/Tag.swift | 1 + Sources/Traq/Models/User.swift | 2 + Sources/Traq/Models/UserDetail.swift | 4 + Sources/Traq/Models/UserGroupMember.swift | 1 + Sources/Traq/OpenISO8601DateFormatter.swift | 14 +- Sources/Traq/URLSessionImplementations.swift | 185 +++-- Sources/Traq/Validation.swift | 126 +++ Traq.podspec | 10 +- project.yml | 2 +- 78 files changed, 1242 insertions(+), 4851 deletions(-) create mode 100644 Sources/Traq/Validation.swift diff --git a/.gitignore b/.gitignore index 47a06da..2da6f32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -# Created by https://www.toptal.com/developers/gitignore/api/swift,xcode -# Edit at https://www.toptal.com/developers/gitignore?templates=swift,xcode +# Created by https://www.toptal.com/developers/gitignore/api/xcode,swift +# Edit at https://www.toptal.com/developers/gitignore?templates=xcode,swift ### Swift ### # Xcode @@ -64,9 +64,9 @@ playground.xcworkspace Carthage/Build/ -# Add this lines if you are using Accio dependency management (Deprecated since Xcode 12) -# Dependencies/ -# .accio/ +# Accio dependency management +Dependencies/ +.accio/ # fastlane # It is recommended to not store the screenshots in the git repo. @@ -86,22 +86,17 @@ fastlane/test_output iOSInjectionProject/ ### Xcode ### -# Xcode -# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore - - - -## Gcc Patch -/*.gcno +## Xcode 8 and earlier ### Xcode Patch ### *.xcodeproj/* !*.xcodeproj/project.pbxproj !*.xcodeproj/xcshareddata/ !*.xcworkspace/contents.xcworkspacedata +/*.gcno **/xcshareddata/WorkspaceSettings.xcsettings -# End of https://www.toptal.com/developers/gitignore/api/swift,xcode +# End of https://www.toptal.com/developers/gitignore/api/xcode,swift Packages/ openapi-generator-cli.jar diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index 07bfc5f..81f1d4f 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -1,4 +1,5 @@ .gitignore +.swiftformat Cartfile Package.swift README.md @@ -154,6 +155,7 @@ Sources/Traq/Models/Webhook.swift Sources/Traq/OpenISO8601DateFormatter.swift Sources/Traq/SynchronizedDictionary.swift Sources/Traq/URLSessionImplementations.swift +Sources/Traq/Validation.swift Traq.podspec docs/ActiveOAuth2Token.md docs/ActivityAPI.md diff --git a/.openapi-generator/VERSION b/.openapi-generator/VERSION index 9fe9ff9..73a86b1 100644 --- a/.openapi-generator/VERSION +++ b/.openapi-generator/VERSION @@ -1 +1 @@ -7.0.1 +7.0.1 \ No newline at end of file diff --git a/.swiftformat b/.swiftformat index 6d35783..9300725 100644 --- a/.swiftformat +++ b/.swiftformat @@ -1 +1,45 @@ ---disable enumNamespaces +# This file is auto-generated by OpenAPI Generator: https://openapi-generator.tech/ +# +# For rules on SwiftFormat, please refer to https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md +# +# file options + +# uncomment below to exclude files, folders +#--exclude path/to/test1.swift,Snapshots,Build + +# format options + +--allman false +--binarygrouping 4,8 +--commas always +--comments indent +--decimalgrouping 3,6 +--elseposition same-line +--empty void +--exponentcase lowercase +--exponentgrouping disabled +--fractiongrouping disabled +--header ignore +--hexgrouping 4,8 +--hexliteralcase uppercase +--ifdef indent +--indent 4 +--indentcase false +--importgrouping testable-bottom +--linebreaks lf +--maxwidth none +--octalgrouping 4,8 +--operatorfunc spaced +--patternlet hoist +--ranges spaced +--self remove +--semicolons inline +--stripunusedargs always +--swiftversion 5.4 +--trimwhitespace always +--wraparguments preserve +--wrapcollections preserve + +# rules + +--enable isEmpty diff --git a/Cartfile b/Cartfile index 3f7e630..92bac17 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "Flight-School/AnyCodable" ~> 0.6.1 +github "Flight-School/AnyCodable" ~> 0.6 diff --git a/Package.swift b/Package.swift index 006e5a4..3e9aa82 100644 --- a/Package.swift +++ b/Package.swift @@ -5,10 +5,10 @@ import PackageDescription let package = Package( name: "Traq", platforms: [ - .iOS(.v9), - .macOS(.v10_11), - .tvOS(.v9), - .watchOS(.v3), + .iOS(.v11), + .macOS(.v10_13), + .tvOS(.v11), + .watchOS(.v4), ], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. @@ -19,7 +19,7 @@ let package = Package( ], dependencies: [ // Dependencies declare other packages that this package depends on. - .package(url: "https://github.com/Flight-School/AnyCodable", from: "0.6.1"), + .package(url: "https://github.com/Flight-School/AnyCodable", .upToNextMajor(from: "0.6.1")), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/README.md b/README.md index 8efc554..b9fb597 100644 --- a/README.md +++ b/README.md @@ -352,10 +352,20 @@ Class | Method | HTTP request | Description - [Webhook](docs/Webhook.md) + ## Documentation For Authorization -## OAuth2 +Authentication schemes defined for the API: + +### cookieAuth + +- **Type**: API key +- **API key parameter name**: r_session +- **Location**: + + +### OAuth2 - **Type**: OAuth - **Flow**: accessCode @@ -365,15 +375,10 @@ Class | Method | HTTP request | Description - **write**: 書き込みスコープ - **manage_bot**: bot関連読み書きスコープ -## bearerAuth + +### bearerAuth -- **Type**: HTTP basic authentication - -## cookieAuth - -- **Type**: API key -- **API key parameter name**: r_session -- **Location**: +- **Type**: HTTP Bearer Token authentication ## Author diff --git a/Sources/Traq/APIHelper.swift b/Sources/Traq/APIHelper.swift index 049b7f6..5a43862 100644 --- a/Sources/Traq/APIHelper.swift +++ b/Sources/Traq/APIHelper.swift @@ -6,7 +6,7 @@ import Foundation -public struct APIHelper { +public enum APIHelper { public static func rejectNil(_ source: [String: Any?]) -> [String: Any]? { let destination = source.reduce(into: [String: Any]()) { result, item in if let value = item.value { @@ -21,16 +21,13 @@ public struct APIHelper { } public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] { - return source.reduce(into: [String: String]()) { result, item in + source.reduce(into: [String: String]()) { result, item in if let collection = item.value as? [Any?] { result[item.key] = collection - .compactMap { value in - guard let value = value else { return nil } - return "\(value)" - } + .compactMap { value in convertAnyToString(value) } .joined(separator: ",") } else if let value: Any = item.value { - result[item.key] = "\(value)" + result[item.key] = convertAnyToString(value) } } } @@ -50,31 +47,66 @@ public struct APIHelper { } } + public static func convertAnyToString(_ value: Any?) -> String? { + guard let value = value else { return nil } + if let value = value as? any RawRepresentable { + return "\(value.rawValue)" + } else { + return "\(value)" + } + } + public static func mapValueToPathItem(_ source: Any) -> Any { if let collection = source as? [Any?] { return collection - .compactMap { value in - guard let value = value else { return nil } - return "\(value)" - } + .compactMap { value in convertAnyToString(value) } .joined(separator: ",") } return source } + /// maps all values from source to query parameters + /// + /// explode attribute is respected: collection values might be either joined or split up into separate key value pairs + public static func mapValuesToQueryItems(_ source: [String: (wrappedValue: Any?, isExplode: Bool)]) -> [URLQueryItem]? { + let destination = source.filter { $0.value.wrappedValue != nil }.reduce(into: [URLQueryItem]()) { result, item in + if let collection = item.value.wrappedValue as? [Any?] { + let collectionValues: [String] = collection.compactMap { value in convertAnyToString(value) } + + if !item.value.isExplode { + result.append(URLQueryItem(name: item.key, value: collectionValues.joined(separator: ","))) + } else { + collectionValues + .forEach { value in + result.append(URLQueryItem(name: item.key, value: value)) + } + } + + } else if let value = item.value.wrappedValue { + result.append(URLQueryItem(name: item.key, value: convertAnyToString(value))) + } + } + + if destination.isEmpty { + return nil + } + return destination + } + + /// maps all values from source to query parameters + /// + /// collection values are always exploded 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 - .compactMap { value in - guard let value = value else { return nil } - return "\(value)" - } + .compactMap { value in convertAnyToString(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)")) + result.append(URLQueryItem(name: item.key, value: convertAnyToString(value))) } } diff --git a/Sources/Traq/APIs.swift b/Sources/Traq/APIs.swift index ee38aee..f40a14c 100644 --- a/Sources/Traq/APIs.swift +++ b/Sources/Traq/APIs.swift @@ -5,6 +5,9 @@ // import Foundation +#if canImport(FoundationNetworking) + import FoundationNetworking +#endif open class TraqAPI { public static var basePath = "https://q.trap.jp/api/v3" public static var customHeaders: [String: String] = [:] @@ -20,17 +23,17 @@ open class RequestBuilder { public let method: String public let URLString: String public let requestTask: RequestTask = .init() + public let requiresAuthentication: Bool /// 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. - /// If you need to get the request's progress in older OS versions, please use Alamofire http client. public var onProgressReady: ((Progress) -> Void)? - public required init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:]) { + public required init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool) { self.method = method self.URLString = URLString self.parameters = parameters self.headers = headers + self.requiresAuthentication = requiresAuthentication addHeaders(TraqAPI.customHeaders) } @@ -43,7 +46,32 @@ open class RequestBuilder { @discardableResult open func execute(_: DispatchQueue = TraqAPI.apiResponseQueue, _: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { - return requestTask + requestTask + } + + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) + @discardableResult + open func execute() async throws -> Response { + try await withTaskCancellationHandler { + try Task.checkCancellation() + return try await withCheckedThrowingContinuation { continuation in + guard !Task.isCancelled else { + continuation.resume(throwing: CancellationError()) + return + } + + self.execute { result in + switch result { + case let .success(response): + continuation.resume(returning: response) + case let .failure(error): + continuation.resume(throwing: error) + } + } + } + } onCancel: { + self.requestTask.cancel() + } } public func addHeader(name: String, value: String) -> Self { diff --git a/Sources/Traq/APIs/ActivityAPI.swift b/Sources/Traq/APIs/ActivityAPI.swift index 03d9996..468ffeb 100644 --- a/Sources/Traq/APIs/ActivityAPI.swift +++ b/Sources/Traq/APIs/ActivityAPI.swift @@ -22,27 +22,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getActivityTimeline(limit: Int? = nil, all: Bool? = nil, perChannel: Bool? = nil) async throws -> [ActivityTimelineMessage] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getActivityTimelineWithRequestBuilder(limit: limit, all: all, perChannel: perChannel).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getActivityTimelineWithRequestBuilder(limit: limit, all: all, perChannel: perChannel).execute().body } /** @@ -52,7 +32,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter limit: (query) 取得する件数 (optional, default to 50) @@ -67,9 +47,9 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "limit": limit?.encodeToJSON(), - "all": all?.encodeToJSON(), - "per_channel": perChannel?.encodeToJSON(), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), + "all": (wrappedValue: all?.encodeToJSON(), isExplode: true), + "per_channel": (wrappedValue: perChannel?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -78,7 +58,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[ActivityTimelineMessage]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -88,27 +68,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getOnlineUsers() async throws -> [String] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getOnlineUsersWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getOnlineUsersWithRequestBuilder().execute().body } /** @@ -118,7 +78,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[String]> @@ -136,7 +96,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[String]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/AuthenticationAPI.swift b/Sources/Traq/APIs/AuthenticationAPI.swift index 9123377..4df4130 100644 --- a/Sources/Traq/APIs/AuthenticationAPI.swift +++ b/Sources/Traq/APIs/AuthenticationAPI.swift @@ -19,27 +19,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyExternalAccounts() async throws -> [ExternalProviderUser] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyExternalAccountsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyExternalAccountsWithRequestBuilder().execute().body } /** @@ -49,7 +29,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[ExternalProviderUser]> @@ -67,7 +47,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[ExternalProviderUser]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -77,27 +57,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMySessions() async throws -> [LoginSession] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMySessionsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMySessionsWithRequestBuilder().execute().body } /** @@ -107,7 +67,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[LoginSession]> @@ -125,7 +85,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[LoginSession]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -136,27 +96,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func linkExternalAccount(postLinkExternalAccount: PostLinkExternalAccount? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = linkExternalAccountWithRequestBuilder(postLinkExternalAccount: postLinkExternalAccount).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await linkExternalAccountWithRequestBuilder(postLinkExternalAccount: postLinkExternalAccount).execute().body } /** @@ -166,7 +106,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postLinkExternalAccount: (body) (optional) @@ -185,7 +125,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -197,27 +137,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func login(redirect: String? = nil, postLoginRequest: PostLoginRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = loginWithRequestBuilder(redirect: redirect, postLoginRequest: postLoginRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await loginWithRequestBuilder(redirect: redirect, postLoginRequest: postLoginRequest).execute().body } /** @@ -227,7 +147,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter redirect: (query) リダイレクト先 (optional) @@ -241,7 +161,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "redirect": redirect?.encodeToJSON(), + "redirect": (wrappedValue: redirect?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -250,7 +170,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -262,27 +182,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func logout(redirect: String? = nil, all: Bool? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = logoutWithRequestBuilder(redirect: redirect, all: all).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await logoutWithRequestBuilder(redirect: redirect, all: all).execute().body } /** @@ -292,7 +192,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter redirect: (query) リダイレクト先 (optional) @@ -306,8 +206,8 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "redirect": redirect?.encodeToJSON(), - "all": all?.encodeToJSON(), + "redirect": (wrappedValue: redirect?.encodeToJSON(), isExplode: true), + "all": (wrappedValue: all?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -316,7 +216,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -327,27 +227,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func revokeMySession(sessionId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = revokeMySessionWithRequestBuilder(sessionId: sessionId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await revokeMySessionWithRequestBuilder(sessionId: sessionId).execute().body } /** @@ -357,7 +237,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter sessionId: (path) セッションUUID @@ -379,7 +259,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -390,27 +270,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func unlinkExternalAccount(postUnlinkExternalAccount: PostUnlinkExternalAccount? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = unlinkExternalAccountWithRequestBuilder(postUnlinkExternalAccount: postUnlinkExternalAccount).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await unlinkExternalAccountWithRequestBuilder(postUnlinkExternalAccount: postUnlinkExternalAccount).execute().body } /** @@ -420,7 +280,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postUnlinkExternalAccount: (body) (optional) @@ -439,7 +299,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/BotAPI.swift b/Sources/Traq/APIs/BotAPI.swift index 0afc0db..833d71f 100644 --- a/Sources/Traq/APIs/BotAPI.swift +++ b/Sources/Traq/APIs/BotAPI.swift @@ -20,27 +20,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func activateBot(botId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = activateBotWithRequestBuilder(botId: botId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await activateBotWithRequestBuilder(botId: botId).execute().body } /** @@ -50,7 +30,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter botId: (path) BOTUUID @@ -72,7 +52,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -84,27 +64,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func changeBotIcon(botId: UUID, file: URL) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = changeBotIconWithRequestBuilder(botId: botId, file: file).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await changeBotIconWithRequestBuilder(botId: botId, file: file).execute().body } /** @@ -114,7 +74,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter botId: (path) BOTUUID @@ -144,7 +104,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -154,27 +114,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func connectBotWS() async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = connectBotWSWithRequestBuilder().execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await connectBotWSWithRequestBuilder().execute().body } /** @@ -184,7 +124,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder @@ -202,7 +142,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -213,27 +153,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func createBot(postBotRequest: PostBotRequest? = nil) async throws -> BotDetail { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = createBotWithRequestBuilder(postBotRequest: postBotRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await createBotWithRequestBuilder(postBotRequest: postBotRequest).execute().body } /** @@ -243,7 +163,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postBotRequest: (body) (optional) @@ -262,7 +182,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -273,27 +193,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func deleteBot(botId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = deleteBotWithRequestBuilder(botId: botId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await deleteBotWithRequestBuilder(botId: botId).execute().body } /** @@ -303,7 +203,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter botId: (path) BOTUUID @@ -325,7 +225,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -337,27 +237,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editBot(botId: UUID, patchBotRequest: PatchBotRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editBotWithRequestBuilder(botId: botId, patchBotRequest: patchBotRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editBotWithRequestBuilder(botId: botId, patchBotRequest: patchBotRequest).execute().body } /** @@ -367,7 +247,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter botId: (path) BOTUUID @@ -390,7 +270,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -402,27 +282,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getBot(botId: UUID, detail: Bool? = nil) async throws -> GetBot200Response { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getBotWithRequestBuilder(botId: botId, detail: detail).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getBotWithRequestBuilder(botId: botId, detail: detail).execute().body } /** @@ -432,7 +292,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter botId: (path) BOTUUID @@ -449,7 +309,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "detail": detail?.encodeToJSON(), + "detail": (wrappedValue: detail?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -458,7 +318,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -469,27 +329,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getBotIcon(botId: UUID) async throws -> URL { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getBotIconWithRequestBuilder(botId: botId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getBotIconWithRequestBuilder(botId: botId).execute().body } /** @@ -499,7 +339,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter botId: (path) BOTUUID @@ -521,7 +361,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -534,27 +374,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getBotLogs(botId: UUID, limit: Int? = nil, offset: Int? = nil) async throws -> [BotEventLog] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getBotLogsWithRequestBuilder(botId: botId, limit: limit, offset: offset).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getBotLogsWithRequestBuilder(botId: botId, limit: limit, offset: offset).execute().body } /** @@ -564,7 +384,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter botId: (path) BOTUUID @@ -582,8 +402,8 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "limit": limit?.encodeToJSON(), - "offset": offset?.encodeToJSON(), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), + "offset": (wrappedValue: offset?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -592,7 +412,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[BotEventLog]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -603,27 +423,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getBots(all: Bool? = nil) async throws -> [Bot] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getBotsWithRequestBuilder(all: all).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getBotsWithRequestBuilder(all: all).execute().body } /** @@ -633,7 +433,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter all: (query) 全てのBOTを取得するかどうか (optional, default to false) @@ -646,7 +446,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "all": all?.encodeToJSON(), + "all": (wrappedValue: all?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -655,7 +455,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[Bot]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -666,27 +466,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getChannelBots(channelId: UUID) async throws -> [BotUser] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getChannelBotsWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getChannelBotsWithRequestBuilder(channelId: channelId).execute().body } /** @@ -696,7 +476,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -718,7 +498,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[BotUser]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -729,27 +509,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func inactivateBot(botId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = inactivateBotWithRequestBuilder(botId: botId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await inactivateBotWithRequestBuilder(botId: botId).execute().body } /** @@ -759,7 +519,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter botId: (path) BOTUUID @@ -781,7 +541,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -793,27 +553,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func letBotJoinChannel(botId: UUID, postBotActionJoinRequest: PostBotActionJoinRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = letBotJoinChannelWithRequestBuilder(botId: botId, postBotActionJoinRequest: postBotActionJoinRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await letBotJoinChannelWithRequestBuilder(botId: botId, postBotActionJoinRequest: postBotActionJoinRequest).execute().body } /** @@ -823,7 +563,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter botId: (path) BOTUUID @@ -846,7 +586,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -858,27 +598,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func letBotLeaveChannel(botId: UUID, postBotActionLeaveRequest: PostBotActionLeaveRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = letBotLeaveChannelWithRequestBuilder(botId: botId, postBotActionLeaveRequest: postBotActionLeaveRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await letBotLeaveChannelWithRequestBuilder(botId: botId, postBotActionLeaveRequest: postBotActionLeaveRequest).execute().body } /** @@ -888,7 +608,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter botId: (path) BOTUUID @@ -911,7 +631,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -922,27 +642,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func reissueBot(botId: UUID) async throws -> BotTokens { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = reissueBotWithRequestBuilder(botId: botId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await reissueBotWithRequestBuilder(botId: botId).execute().body } /** @@ -952,7 +652,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter botId: (path) BOTUUID @@ -974,7 +674,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/ChannelAPI.swift b/Sources/Traq/APIs/ChannelAPI.swift index 5c986f2..e9e62b2 100644 --- a/Sources/Traq/APIs/ChannelAPI.swift +++ b/Sources/Traq/APIs/ChannelAPI.swift @@ -20,27 +20,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func createChannel(postChannelRequest: PostChannelRequest? = nil) async throws -> Channel { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = createChannelWithRequestBuilder(postChannelRequest: postChannelRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await createChannelWithRequestBuilder(postChannelRequest: postChannelRequest).execute().body } /** @@ -50,7 +30,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postChannelRequest: (body) (optional) @@ -69,7 +49,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -81,27 +61,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editChannel(channelId: UUID, patchChannelRequest: PatchChannelRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editChannelWithRequestBuilder(channelId: channelId, patchChannelRequest: patchChannelRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editChannelWithRequestBuilder(channelId: channelId, patchChannelRequest: patchChannelRequest).execute().body } /** @@ -111,7 +71,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -134,7 +94,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -146,27 +106,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editChannelSubscribers(channelId: UUID, patchChannelSubscribersRequest: PatchChannelSubscribersRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editChannelSubscribersWithRequestBuilder(channelId: channelId, patchChannelSubscribersRequest: patchChannelSubscribersRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editChannelSubscribersWithRequestBuilder(channelId: channelId, patchChannelSubscribersRequest: patchChannelSubscribersRequest).execute().body } /** @@ -176,7 +116,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -199,7 +139,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -211,27 +151,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editChannelTopic(channelId: UUID, putChannelTopicRequest: PutChannelTopicRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editChannelTopicWithRequestBuilder(channelId: channelId, putChannelTopicRequest: putChannelTopicRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editChannelTopicWithRequestBuilder(channelId: channelId, putChannelTopicRequest: putChannelTopicRequest).execute().body } /** @@ -241,7 +161,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -264,7 +184,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -275,27 +195,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getChannel(channelId: UUID) async throws -> Channel { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getChannelWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getChannelWithRequestBuilder(channelId: channelId).execute().body } /** @@ -305,7 +205,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -327,7 +227,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -338,27 +238,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getChannelBots(channelId: UUID) async throws -> [BotUser] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getChannelBotsWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getChannelBotsWithRequestBuilder(channelId: channelId).execute().body } /** @@ -368,7 +248,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -390,7 +270,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[BotUser]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -415,27 +295,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getChannelEvents(channelId: UUID, limit: Int? = nil, offset: Int? = nil, since: Date? = nil, until: Date? = nil, inclusive: Bool? = nil, order: Order_getChannelEvents? = nil) async throws -> [ChannelEvent] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getChannelEventsWithRequestBuilder(channelId: channelId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getChannelEventsWithRequestBuilder(channelId: channelId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order).execute().body } /** @@ -445,7 +305,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - responseHeaders: [X-TRAQ-MORE(Bool)] @@ -468,12 +328,12 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "limit": limit?.encodeToJSON(), - "offset": offset?.encodeToJSON(), - "since": since?.encodeToJSON(), - "until": until?.encodeToJSON(), - "inclusive": inclusive?.encodeToJSON(), - "order": order?.encodeToJSON(), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), + "offset": (wrappedValue: offset?.encodeToJSON(), isExplode: true), + "since": (wrappedValue: since?.encodeToJSON(), isExplode: true), + "until": (wrappedValue: until?.encodeToJSON(), isExplode: true), + "inclusive": (wrappedValue: inclusive?.encodeToJSON(), isExplode: true), + "order": (wrappedValue: order?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -482,7 +342,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[ChannelEvent]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -493,27 +353,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getChannelPins(channelId: UUID) async throws -> [Pin] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getChannelPinsWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getChannelPinsWithRequestBuilder(channelId: channelId).execute().body } /** @@ -523,7 +363,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -545,7 +385,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[Pin]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -556,27 +396,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getChannelStats(channelId: UUID) async throws -> ChannelStats { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getChannelStatsWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getChannelStatsWithRequestBuilder(channelId: channelId).execute().body } /** @@ -586,7 +406,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -608,7 +428,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -619,27 +439,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getChannelSubscribers(channelId: UUID) async throws -> [UUID] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getChannelSubscribersWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getChannelSubscribersWithRequestBuilder(channelId: channelId).execute().body } /** @@ -649,7 +449,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -671,7 +471,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UUID]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -682,27 +482,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getChannelTopic(channelId: UUID) async throws -> ChannelTopic { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getChannelTopicWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getChannelTopicWithRequestBuilder(channelId: channelId).execute().body } /** @@ -712,7 +492,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -734,7 +514,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -745,27 +525,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getChannelViewers(channelId: UUID) async throws -> [ChannelViewer] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getChannelViewersWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getChannelViewersWithRequestBuilder(channelId: channelId).execute().body } /** @@ -775,7 +535,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -797,7 +557,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[ChannelViewer]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -808,27 +568,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getChannels(includeDm: Bool? = nil) async throws -> ChannelList { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getChannelsWithRequestBuilder(includeDm: includeDm).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getChannelsWithRequestBuilder(includeDm: includeDm).execute().body } /** @@ -838,7 +578,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter includeDm: (query) ダイレクトメッセージチャンネルをレスポンスに含めるかどうか (optional, default to false) @@ -851,7 +591,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "include-dm": includeDm?.encodeToJSON(), + "include-dm": (wrappedValue: includeDm?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -860,7 +600,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -885,27 +625,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMessages(channelId: UUID, limit: Int? = nil, offset: Int? = nil, since: Date? = nil, until: Date? = nil, inclusive: Bool? = nil, order: Order_getMessages? = nil) async throws -> [Message] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMessagesWithRequestBuilder(channelId: channelId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMessagesWithRequestBuilder(channelId: channelId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order).execute().body } /** @@ -915,7 +635,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - responseHeaders: [X-TRAQ-MORE(Bool)] @@ -938,12 +658,12 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "limit": limit?.encodeToJSON(), - "offset": offset?.encodeToJSON(), - "since": since?.encodeToJSON(), - "until": until?.encodeToJSON(), - "inclusive": inclusive?.encodeToJSON(), - "order": order?.encodeToJSON(), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), + "offset": (wrappedValue: offset?.encodeToJSON(), isExplode: true), + "since": (wrappedValue: since?.encodeToJSON(), isExplode: true), + "until": (wrappedValue: until?.encodeToJSON(), isExplode: true), + "inclusive": (wrappedValue: inclusive?.encodeToJSON(), isExplode: true), + "order": (wrappedValue: order?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -952,7 +672,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[Message]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -963,27 +683,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUserDMChannel(userId: String) async throws -> DMChannel { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUserDMChannelWithRequestBuilder(userId: userId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUserDMChannelWithRequestBuilder(userId: userId).execute().body } /** @@ -993,7 +693,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) @@ -1015,7 +715,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1027,27 +727,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func postMessage(channelId: UUID, postMessageRequest: PostMessageRequest? = nil) async throws -> Message { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = postMessageWithRequestBuilder(channelId: channelId, postMessageRequest: postMessageRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await postMessageWithRequestBuilder(channelId: channelId, postMessageRequest: postMessageRequest).execute().body } /** @@ -1057,7 +737,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -1080,7 +760,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1092,27 +772,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func setChannelSubscribers(channelId: UUID, putChannelSubscribersRequest: PutChannelSubscribersRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = setChannelSubscribersWithRequestBuilder(channelId: channelId, putChannelSubscribersRequest: putChannelSubscribersRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await setChannelSubscribersWithRequestBuilder(channelId: channelId, putChannelSubscribersRequest: putChannelSubscribersRequest).execute().body } /** @@ -1122,7 +782,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -1145,7 +805,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/ClipAPI.swift b/Sources/Traq/APIs/ClipAPI.swift index 25af155..1d5f97b 100644 --- a/Sources/Traq/APIs/ClipAPI.swift +++ b/Sources/Traq/APIs/ClipAPI.swift @@ -21,27 +21,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func clipMessage(folderId: UUID, postClipFolderMessageRequest: PostClipFolderMessageRequest? = nil) async throws -> ClippedMessage { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = clipMessageWithRequestBuilder(folderId: folderId, postClipFolderMessageRequest: postClipFolderMessageRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await clipMessageWithRequestBuilder(folderId: folderId, postClipFolderMessageRequest: postClipFolderMessageRequest).execute().body } /** @@ -51,7 +31,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter folderId: (path) クリップフォルダUUID @@ -74,7 +54,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -85,27 +65,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func createClipFolder(postClipFolderRequest: PostClipFolderRequest? = nil) async throws -> ClipFolder { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = createClipFolderWithRequestBuilder(postClipFolderRequest: postClipFolderRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await createClipFolderWithRequestBuilder(postClipFolderRequest: postClipFolderRequest).execute().body } /** @@ -115,7 +75,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postClipFolderRequest: (body) (optional) @@ -134,7 +94,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -145,27 +105,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func deleteClipFolder(folderId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = deleteClipFolderWithRequestBuilder(folderId: folderId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await deleteClipFolderWithRequestBuilder(folderId: folderId).execute().body } /** @@ -175,7 +115,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter folderId: (path) クリップフォルダUUID @@ -197,7 +137,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -209,27 +149,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editClipFolder(folderId: UUID, patchClipFolderRequest: PatchClipFolderRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editClipFolderWithRequestBuilder(folderId: folderId, patchClipFolderRequest: patchClipFolderRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editClipFolderWithRequestBuilder(folderId: folderId, patchClipFolderRequest: patchClipFolderRequest).execute().body } /** @@ -239,7 +159,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter folderId: (path) クリップフォルダUUID @@ -262,7 +182,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -273,27 +193,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getClipFolder(folderId: UUID) async throws -> ClipFolder { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getClipFolderWithRequestBuilder(folderId: folderId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getClipFolderWithRequestBuilder(folderId: folderId).execute().body } /** @@ -303,7 +203,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter folderId: (path) クリップフォルダUUID @@ -325,7 +225,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -335,27 +235,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getClipFolders() async throws -> [ClipFolder] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getClipFoldersWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getClipFoldersWithRequestBuilder().execute().body } /** @@ -365,7 +245,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[ClipFolder]> @@ -383,7 +263,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[ClipFolder]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -405,27 +285,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getClips(folderId: UUID, limit: Int? = nil, offset: Int? = nil, order: Order_getClips? = nil) async throws -> [ClippedMessage] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getClipsWithRequestBuilder(folderId: folderId, limit: limit, offset: offset, order: order).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getClipsWithRequestBuilder(folderId: folderId, limit: limit, offset: offset, order: order).execute().body } /** @@ -435,7 +295,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter folderId: (path) クリップフォルダUUID @@ -454,9 +314,9 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "limit": limit?.encodeToJSON(), - "offset": offset?.encodeToJSON(), - "order": order?.encodeToJSON(), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), + "offset": (wrappedValue: offset?.encodeToJSON(), isExplode: true), + "order": (wrappedValue: order?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -465,7 +325,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[ClippedMessage]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -476,27 +336,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMessageClips(messageId: UUID) async throws -> [MessageClip] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMessageClipsWithRequestBuilder(messageId: messageId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMessageClipsWithRequestBuilder(messageId: messageId).execute().body } /** @@ -506,7 +346,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -528,7 +368,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[MessageClip]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -540,27 +380,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func unclipMessage(folderId: UUID, messageId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = unclipMessageWithRequestBuilder(folderId: folderId, messageId: messageId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await unclipMessageWithRequestBuilder(folderId: folderId, messageId: messageId).execute().body } /** @@ -570,7 +390,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter folderId: (path) クリップフォルダUUID @@ -596,7 +416,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/FileAPI.swift b/Sources/Traq/APIs/FileAPI.swift index 5f9676e..e28e1fc 100644 --- a/Sources/Traq/APIs/FileAPI.swift +++ b/Sources/Traq/APIs/FileAPI.swift @@ -20,27 +20,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func deleteFile(fileId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = deleteFileWithRequestBuilder(fileId: fileId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await deleteFileWithRequestBuilder(fileId: fileId).execute().body } /** @@ -50,7 +30,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter fileId: (path) ファイルUUID @@ -72,7 +52,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -84,27 +64,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getFile(fileId: UUID, dl: Int? = nil) async throws -> URL { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getFileWithRequestBuilder(fileId: fileId, dl: dl).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getFileWithRequestBuilder(fileId: fileId, dl: dl).execute().body } /** @@ -114,7 +74,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - responseHeaders: [Content-Disposition(String)] @@ -132,7 +92,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "dl": dl?.encodeToJSON(), + "dl": (wrappedValue: dl?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -141,7 +101,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -152,27 +112,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getFileMeta(fileId: UUID) async throws -> FileInfo { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getFileMetaWithRequestBuilder(fileId: fileId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getFileMetaWithRequestBuilder(fileId: fileId).execute().body } /** @@ -182,7 +122,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter fileId: (path) ファイルUUID @@ -204,7 +144,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -230,27 +170,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getFiles(channelId: UUID? = nil, limit: Int? = nil, offset: Int? = nil, since: Date? = nil, until: Date? = nil, inclusive: Bool? = nil, order: Order_getFiles? = nil, mine: Bool? = nil) async throws -> [FileInfo] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getFilesWithRequestBuilder(channelId: channelId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order, mine: mine).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getFilesWithRequestBuilder(channelId: channelId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order, mine: mine).execute().body } /** @@ -260,7 +180,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - responseHeaders: [X-TRAQ-MORE(Bool)] @@ -281,14 +201,14 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "channelId": channelId?.encodeToJSON(), - "limit": limit?.encodeToJSON(), - "offset": offset?.encodeToJSON(), - "since": since?.encodeToJSON(), - "until": until?.encodeToJSON(), - "inclusive": inclusive?.encodeToJSON(), - "order": order?.encodeToJSON(), - "mine": mine?.encodeToJSON(), + "channelId": (wrappedValue: channelId?.encodeToJSON(), isExplode: true), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), + "offset": (wrappedValue: offset?.encodeToJSON(), isExplode: true), + "since": (wrappedValue: since?.encodeToJSON(), isExplode: true), + "until": (wrappedValue: until?.encodeToJSON(), isExplode: true), + "inclusive": (wrappedValue: inclusive?.encodeToJSON(), isExplode: true), + "order": (wrappedValue: order?.encodeToJSON(), isExplode: true), + "mine": (wrappedValue: mine?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -297,7 +217,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[FileInfo]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -309,27 +229,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getThumbnailImage(fileId: UUID, type: ThumbnailType? = nil) async throws -> URL { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getThumbnailImageWithRequestBuilder(fileId: fileId, type: type).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getThumbnailImageWithRequestBuilder(fileId: fileId, type: type).execute().body } /** @@ -339,7 +239,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter fileId: (path) ファイルUUID @@ -356,7 +256,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "type": type?.encodeToJSON(), + "type": (wrappedValue: type?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -365,7 +265,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -377,27 +277,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func postFile(file: URL, channelId: UUID) async throws -> FileInfo { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = postFileWithRequestBuilder(file: file, channelId: channelId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await postFileWithRequestBuilder(file: file, channelId: channelId).execute().body } /** @@ -407,7 +287,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter file: (form) ファイル本体 @@ -435,7 +315,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/GroupAPI.swift b/Sources/Traq/APIs/GroupAPI.swift index 27f2cde..fac2d6e 100644 --- a/Sources/Traq/APIs/GroupAPI.swift +++ b/Sources/Traq/APIs/GroupAPI.swift @@ -21,27 +21,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func addUserGroupAdmin(groupId: UUID, postUserGroupAdminRequest: PostUserGroupAdminRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = addUserGroupAdminWithRequestBuilder(groupId: groupId, postUserGroupAdminRequest: postUserGroupAdminRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await addUserGroupAdminWithRequestBuilder(groupId: groupId, postUserGroupAdminRequest: postUserGroupAdminRequest).execute().body } /** @@ -51,7 +31,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter groupId: (path) ユーザーグループUUID @@ -74,7 +54,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -86,27 +66,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func addUserGroupMember(groupId: UUID, userGroupMember: UserGroupMember? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = addUserGroupMemberWithRequestBuilder(groupId: groupId, userGroupMember: userGroupMember).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await addUserGroupMemberWithRequestBuilder(groupId: groupId, userGroupMember: userGroupMember).execute().body } /** @@ -116,7 +76,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter groupId: (path) ユーザーグループUUID @@ -139,7 +99,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -151,27 +111,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func changeUserGroupIcon(groupId: UUID, file: URL) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = changeUserGroupIconWithRequestBuilder(groupId: groupId, file: file).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await changeUserGroupIconWithRequestBuilder(groupId: groupId, file: file).execute().body } /** @@ -181,7 +121,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter groupId: (path) ユーザーグループUUID @@ -211,7 +151,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -222,27 +162,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func createUserGroup(postUserGroupRequest: PostUserGroupRequest? = nil) async throws -> UserGroup { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = createUserGroupWithRequestBuilder(postUserGroupRequest: postUserGroupRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await createUserGroupWithRequestBuilder(postUserGroupRequest: postUserGroupRequest).execute().body } /** @@ -252,7 +172,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postUserGroupRequest: (body) (optional) @@ -271,7 +191,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -282,27 +202,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func deleteUserGroup(groupId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = deleteUserGroupWithRequestBuilder(groupId: groupId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await deleteUserGroupWithRequestBuilder(groupId: groupId).execute().body } /** @@ -312,7 +212,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter groupId: (path) ユーザーグループUUID @@ -334,7 +234,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -346,27 +246,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editUserGroup(groupId: UUID, patchUserGroupRequest: PatchUserGroupRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editUserGroupWithRequestBuilder(groupId: groupId, patchUserGroupRequest: patchUserGroupRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editUserGroupWithRequestBuilder(groupId: groupId, patchUserGroupRequest: patchUserGroupRequest).execute().body } /** @@ -376,7 +256,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter groupId: (path) ユーザーグループUUID @@ -399,7 +279,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -412,27 +292,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editUserGroupMember(groupId: UUID, userId: UUID, patchGroupMemberRequest: PatchGroupMemberRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editUserGroupMemberWithRequestBuilder(groupId: groupId, userId: userId, patchGroupMemberRequest: patchGroupMemberRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editUserGroupMemberWithRequestBuilder(groupId: groupId, userId: userId, patchGroupMemberRequest: patchGroupMemberRequest).execute().body } /** @@ -442,7 +302,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter groupId: (path) ユーザーグループUUID @@ -469,7 +329,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -480,27 +340,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUserGroup(groupId: UUID) async throws -> UserGroup { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUserGroupWithRequestBuilder(groupId: groupId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUserGroupWithRequestBuilder(groupId: groupId).execute().body } /** @@ -510,7 +350,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter groupId: (path) ユーザーグループUUID @@ -532,7 +372,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -543,27 +383,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUserGroupAdmins(groupId: UUID) async throws -> [UUID] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUserGroupAdminsWithRequestBuilder(groupId: groupId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUserGroupAdminsWithRequestBuilder(groupId: groupId).execute().body } /** @@ -573,7 +393,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter groupId: (path) ユーザーグループUUID @@ -595,7 +415,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UUID]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -606,27 +426,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUserGroupMembers(groupId: UUID) async throws -> [UserGroupMember] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUserGroupMembersWithRequestBuilder(groupId: groupId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUserGroupMembersWithRequestBuilder(groupId: groupId).execute().body } /** @@ -636,7 +436,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter groupId: (path) ユーザーグループUUID @@ -658,7 +458,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UserGroupMember]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -668,27 +468,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUserGroups() async throws -> [UserGroup] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUserGroupsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUserGroupsWithRequestBuilder().execute().body } /** @@ -698,7 +478,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[UserGroup]> @@ -716,7 +496,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UserGroup]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -728,27 +508,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func removeUserGroupAdmin(groupId: UUID, userId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = removeUserGroupAdminWithRequestBuilder(groupId: groupId, userId: userId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await removeUserGroupAdminWithRequestBuilder(groupId: groupId, userId: userId).execute().body } /** @@ -758,7 +518,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter groupId: (path) ユーザーグループUUID @@ -784,7 +544,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -796,27 +556,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func removeUserGroupMember(groupId: UUID, userId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = removeUserGroupMemberWithRequestBuilder(groupId: groupId, userId: userId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await removeUserGroupMemberWithRequestBuilder(groupId: groupId, userId: userId).execute().body } /** @@ -826,7 +566,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter groupId: (path) ユーザーグループUUID @@ -852,7 +592,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/MeAPI.swift b/Sources/Traq/APIs/MeAPI.swift index f2f174f..011a3c4 100644 --- a/Sources/Traq/APIs/MeAPI.swift +++ b/Sources/Traq/APIs/MeAPI.swift @@ -20,27 +20,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func addMyStar(postStarRequest: PostStarRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = addMyStarWithRequestBuilder(postStarRequest: postStarRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await addMyStarWithRequestBuilder(postStarRequest: postStarRequest).execute().body } /** @@ -50,7 +30,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postStarRequest: (body) (optional) @@ -69,7 +49,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -80,27 +60,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func addMyUserTag(postUserTagRequest: PostUserTagRequest? = nil) async throws -> UserTag { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = addMyUserTagWithRequestBuilder(postUserTagRequest: postUserTagRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await addMyUserTagWithRequestBuilder(postUserTagRequest: postUserTagRequest).execute().body } /** @@ -110,7 +70,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postUserTagRequest: (body) (optional) @@ -129,7 +89,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -140,27 +100,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func changeMyIcon(file: URL) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = changeMyIconWithRequestBuilder(file: file).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await changeMyIconWithRequestBuilder(file: file).execute().body } /** @@ -170,7 +110,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter file: (form) アイコン画像(1MBまでのpng, jpeg, gif) @@ -196,7 +136,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -207,27 +147,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func changeMyNotifyCitation(putNotifyCitationRequest: PutNotifyCitationRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = changeMyNotifyCitationWithRequestBuilder(putNotifyCitationRequest: putNotifyCitationRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await changeMyNotifyCitationWithRequestBuilder(putNotifyCitationRequest: putNotifyCitationRequest).execute().body } /** @@ -237,7 +157,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter putNotifyCitationRequest: (body) (optional) @@ -256,7 +176,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -267,27 +187,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func changeMyPassword(putMyPasswordRequest: PutMyPasswordRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = changeMyPasswordWithRequestBuilder(putMyPasswordRequest: putMyPasswordRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await changeMyPasswordWithRequestBuilder(putMyPasswordRequest: putMyPasswordRequest).execute().body } /** @@ -297,7 +197,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter putMyPasswordRequest: (body) (optional) @@ -316,7 +216,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -327,27 +227,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editMe(patchMeRequest: PatchMeRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editMeWithRequestBuilder(patchMeRequest: patchMeRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editMeWithRequestBuilder(patchMeRequest: patchMeRequest).execute().body } /** @@ -357,7 +237,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter patchMeRequest: (body) (optional) @@ -376,7 +256,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -388,27 +268,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editMyUserTag(tagId: UUID, patchUserTagRequest: PatchUserTagRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editMyUserTagWithRequestBuilder(tagId: tagId, patchUserTagRequest: patchUserTagRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editMyUserTagWithRequestBuilder(tagId: tagId, patchUserTagRequest: patchUserTagRequest).execute().body } /** @@ -418,7 +278,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter tagId: (path) タグUUID @@ -441,7 +301,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -451,27 +311,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMe() async throws -> MyUserDetail { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMeWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMeWithRequestBuilder().execute().body } /** @@ -481,7 +321,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder @@ -499,7 +339,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -509,27 +349,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyChannelSubscriptions() async throws -> [UserSubscribeState] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyChannelSubscriptionsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyChannelSubscriptionsWithRequestBuilder().execute().body } /** @@ -539,7 +359,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[UserSubscribeState]> @@ -557,7 +377,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UserSubscribeState]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -567,27 +387,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyExternalAccounts() async throws -> [ExternalProviderUser] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyExternalAccountsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyExternalAccountsWithRequestBuilder().execute().body } /** @@ -597,7 +397,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[ExternalProviderUser]> @@ -615,7 +415,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[ExternalProviderUser]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -625,27 +425,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyIcon() async throws -> URL { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyIconWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyIconWithRequestBuilder().execute().body } /** @@ -655,7 +435,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder @@ -673,7 +453,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -683,27 +463,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyNotifyCitation() async throws -> GetNotifyCitation { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyNotifyCitationWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyNotifyCitationWithRequestBuilder().execute().body } /** @@ -713,7 +473,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder @@ -731,7 +491,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -742,27 +502,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyQRCode(token: Bool? = nil) async throws -> URL { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyQRCodeWithRequestBuilder(token: token).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyQRCodeWithRequestBuilder(token: token).execute().body } /** @@ -772,7 +512,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter token: (query) 画像でなくトークン文字列で返すかどうか (optional, default to false) @@ -785,7 +525,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "token": token?.encodeToJSON(), + "token": (wrappedValue: token?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -794,7 +534,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -804,27 +544,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMySessions() async throws -> [LoginSession] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMySessionsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMySessionsWithRequestBuilder().execute().body } /** @@ -834,7 +554,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[LoginSession]> @@ -852,7 +572,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[LoginSession]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -863,27 +583,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyStampHistory(limit: Int? = nil) async throws -> [StampHistoryEntry] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyStampHistoryWithRequestBuilder(limit: limit).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyStampHistoryWithRequestBuilder(limit: limit).execute().body } /** @@ -893,7 +593,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter limit: (query) 件数 (optional, default to 100) @@ -906,7 +606,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "limit": limit?.encodeToJSON(), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -915,7 +615,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[StampHistoryEntry]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -925,27 +625,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyStars() async throws -> [UUID] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyStarsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyStarsWithRequestBuilder().execute().body } /** @@ -955,7 +635,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[UUID]> @@ -973,7 +653,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UUID]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -983,27 +663,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyTokens() async throws -> [ActiveOAuth2Token] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyTokensWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyTokensWithRequestBuilder().execute().body } /** @@ -1013,7 +673,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[ActiveOAuth2Token]> @@ -1031,7 +691,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[ActiveOAuth2Token]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1041,27 +701,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyUnreadChannels() async throws -> [UnreadChannel] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyUnreadChannelsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyUnreadChannelsWithRequestBuilder().execute().body } /** @@ -1071,7 +711,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[UnreadChannel]> @@ -1089,7 +729,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UnreadChannel]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1099,27 +739,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyUserTags() async throws -> [UserTag] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyUserTagsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyUserTagsWithRequestBuilder().execute().body } /** @@ -1129,7 +749,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[UserTag]> @@ -1147,7 +767,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UserTag]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1157,27 +777,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyViewStates() async throws -> [MyChannelViewState] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyViewStatesWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyViewStatesWithRequestBuilder().execute().body } /** @@ -1187,7 +787,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[MyChannelViewState]> @@ -1205,7 +805,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[MyChannelViewState]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1215,27 +815,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUserSettings() async throws -> UserSettings { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUserSettingsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUserSettingsWithRequestBuilder().execute().body } /** @@ -1245,7 +825,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder @@ -1263,7 +843,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1274,27 +854,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func linkExternalAccount(postLinkExternalAccount: PostLinkExternalAccount? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = linkExternalAccountWithRequestBuilder(postLinkExternalAccount: postLinkExternalAccount).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await linkExternalAccountWithRequestBuilder(postLinkExternalAccount: postLinkExternalAccount).execute().body } /** @@ -1304,7 +864,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postLinkExternalAccount: (body) (optional) @@ -1323,7 +883,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1334,27 +894,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func readChannel(channelId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = readChannelWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await readChannelWithRequestBuilder(channelId: channelId).execute().body } /** @@ -1364,7 +904,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -1386,7 +926,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1397,27 +937,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func registerFCMDevice(postMyFCMDeviceRequest: PostMyFCMDeviceRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = registerFCMDeviceWithRequestBuilder(postMyFCMDeviceRequest: postMyFCMDeviceRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await registerFCMDeviceWithRequestBuilder(postMyFCMDeviceRequest: postMyFCMDeviceRequest).execute().body } /** @@ -1427,7 +947,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postMyFCMDeviceRequest: (body) (optional) @@ -1446,7 +966,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1457,27 +977,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func removeMyStar(channelId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = removeMyStarWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await removeMyStarWithRequestBuilder(channelId: channelId).execute().body } /** @@ -1487,7 +987,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -1509,7 +1009,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1520,27 +1020,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func removeMyUserTag(tagId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = removeMyUserTagWithRequestBuilder(tagId: tagId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await removeMyUserTagWithRequestBuilder(tagId: tagId).execute().body } /** @@ -1550,7 +1030,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter tagId: (path) タグUUID @@ -1572,7 +1052,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1583,27 +1063,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func revokeMySession(sessionId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = revokeMySessionWithRequestBuilder(sessionId: sessionId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await revokeMySessionWithRequestBuilder(sessionId: sessionId).execute().body } /** @@ -1613,7 +1073,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter sessionId: (path) セッションUUID @@ -1635,7 +1095,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1646,27 +1106,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func revokeMyToken(tokenId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = revokeMyTokenWithRequestBuilder(tokenId: tokenId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await revokeMyTokenWithRequestBuilder(tokenId: tokenId).execute().body } /** @@ -1676,7 +1116,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter tokenId: (path) OAuth2トークンUUID @@ -1698,7 +1138,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1710,27 +1150,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func setChannelSubscribeLevel(channelId: UUID, putChannelSubscribeLevelRequest: PutChannelSubscribeLevelRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = setChannelSubscribeLevelWithRequestBuilder(channelId: channelId, putChannelSubscribeLevelRequest: putChannelSubscribeLevelRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await setChannelSubscribeLevelWithRequestBuilder(channelId: channelId, putChannelSubscribeLevelRequest: putChannelSubscribeLevelRequest).execute().body } /** @@ -1740,7 +1160,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -1763,7 +1183,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1774,27 +1194,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func unlinkExternalAccount(postUnlinkExternalAccount: PostUnlinkExternalAccount? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = unlinkExternalAccountWithRequestBuilder(postUnlinkExternalAccount: postUnlinkExternalAccount).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await unlinkExternalAccountWithRequestBuilder(postUnlinkExternalAccount: postUnlinkExternalAccount).execute().body } /** @@ -1804,7 +1204,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postUnlinkExternalAccount: (body) (optional) @@ -1823,7 +1223,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/MessageAPI.swift b/Sources/Traq/APIs/MessageAPI.swift index 87c4f9a..c5b78ef 100644 --- a/Sources/Traq/APIs/MessageAPI.swift +++ b/Sources/Traq/APIs/MessageAPI.swift @@ -22,27 +22,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func addMessageStamp(messageId: UUID, stampId: UUID, postMessageStampRequest: PostMessageStampRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = addMessageStampWithRequestBuilder(messageId: messageId, stampId: stampId, postMessageStampRequest: postMessageStampRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await addMessageStampWithRequestBuilder(messageId: messageId, stampId: stampId, postMessageStampRequest: postMessageStampRequest).execute().body } /** @@ -52,7 +32,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -79,7 +59,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -90,27 +70,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func createPin(messageId: UUID) async throws -> MessagePin { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = createPinWithRequestBuilder(messageId: messageId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await createPinWithRequestBuilder(messageId: messageId).execute().body } /** @@ -120,7 +80,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -142,7 +102,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -153,27 +113,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func deleteMessage(messageId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = deleteMessageWithRequestBuilder(messageId: messageId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await deleteMessageWithRequestBuilder(messageId: messageId).execute().body } /** @@ -183,7 +123,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -205,7 +145,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -217,27 +157,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editMessage(messageId: UUID, postMessageRequest: PostMessageRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editMessageWithRequestBuilder(messageId: messageId, postMessageRequest: postMessageRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editMessageWithRequestBuilder(messageId: messageId, postMessageRequest: postMessageRequest).execute().body } /** @@ -247,7 +167,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -270,7 +190,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -295,27 +215,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getDirectMessages(userId: UUID, limit: Int? = nil, offset: Int? = nil, since: Date? = nil, until: Date? = nil, inclusive: Bool? = nil, order: Order_getDirectMessages? = nil) async throws -> [Message] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getDirectMessagesWithRequestBuilder(userId: userId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getDirectMessagesWithRequestBuilder(userId: userId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order).execute().body } /** @@ -325,7 +225,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - responseHeaders: [X-TRAQ-MORE(Bool)] @@ -348,12 +248,12 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "limit": limit?.encodeToJSON(), - "offset": offset?.encodeToJSON(), - "since": since?.encodeToJSON(), - "until": until?.encodeToJSON(), - "inclusive": inclusive?.encodeToJSON(), - "order": order?.encodeToJSON(), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), + "offset": (wrappedValue: offset?.encodeToJSON(), isExplode: true), + "since": (wrappedValue: since?.encodeToJSON(), isExplode: true), + "until": (wrappedValue: until?.encodeToJSON(), isExplode: true), + "inclusive": (wrappedValue: inclusive?.encodeToJSON(), isExplode: true), + "order": (wrappedValue: order?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -362,7 +262,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[Message]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -373,27 +273,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMessage(messageId: UUID) async throws -> Message { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMessageWithRequestBuilder(messageId: messageId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMessageWithRequestBuilder(messageId: messageId).execute().body } /** @@ -403,7 +283,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -425,7 +305,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -436,27 +316,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMessageClips(messageId: UUID) async throws -> [MessageClip] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMessageClipsWithRequestBuilder(messageId: messageId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMessageClipsWithRequestBuilder(messageId: messageId).execute().body } /** @@ -466,7 +326,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -488,7 +348,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[MessageClip]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -499,27 +359,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMessageStamps(messageId: UUID) async throws -> [MessageStamp] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMessageStampsWithRequestBuilder(messageId: messageId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMessageStampsWithRequestBuilder(messageId: messageId).execute().body } /** @@ -529,7 +369,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -551,7 +391,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[MessageStamp]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -576,27 +416,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMessages(channelId: UUID, limit: Int? = nil, offset: Int? = nil, since: Date? = nil, until: Date? = nil, inclusive: Bool? = nil, order: Order_getMessages? = nil) async throws -> [Message] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMessagesWithRequestBuilder(channelId: channelId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMessagesWithRequestBuilder(channelId: channelId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order).execute().body } /** @@ -606,7 +426,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - responseHeaders: [X-TRAQ-MORE(Bool)] @@ -629,12 +449,12 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "limit": limit?.encodeToJSON(), - "offset": offset?.encodeToJSON(), - "since": since?.encodeToJSON(), - "until": until?.encodeToJSON(), - "inclusive": inclusive?.encodeToJSON(), - "order": order?.encodeToJSON(), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), + "offset": (wrappedValue: offset?.encodeToJSON(), isExplode: true), + "since": (wrappedValue: since?.encodeToJSON(), isExplode: true), + "until": (wrappedValue: until?.encodeToJSON(), isExplode: true), + "inclusive": (wrappedValue: inclusive?.encodeToJSON(), isExplode: true), + "order": (wrappedValue: order?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -643,7 +463,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[Message]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -654,27 +474,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getPin(messageId: UUID) async throws -> MessagePin { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getPinWithRequestBuilder(messageId: messageId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getPinWithRequestBuilder(messageId: messageId).execute().body } /** @@ -684,7 +484,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -706,7 +506,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -718,27 +518,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func postDirectMessage(userId: UUID, postMessageRequest: PostMessageRequest? = nil) async throws -> Message { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = postDirectMessageWithRequestBuilder(userId: userId, postMessageRequest: postMessageRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await postDirectMessageWithRequestBuilder(userId: userId, postMessageRequest: postMessageRequest).execute().body } /** @@ -748,7 +528,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -771,7 +551,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -783,27 +563,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func postMessage(channelId: UUID, postMessageRequest: PostMessageRequest? = nil) async throws -> Message { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = postMessageWithRequestBuilder(channelId: channelId, postMessageRequest: postMessageRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await postMessageWithRequestBuilder(channelId: channelId, postMessageRequest: postMessageRequest).execute().body } /** @@ -813,7 +573,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -836,7 +596,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -848,27 +608,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func removeMessageStamp(messageId: UUID, stampId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = removeMessageStampWithRequestBuilder(messageId: messageId, stampId: stampId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await removeMessageStampWithRequestBuilder(messageId: messageId, stampId: stampId).execute().body } /** @@ -878,7 +618,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -904,7 +644,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -915,27 +655,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func removePin(messageId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = removePinWithRequestBuilder(messageId: messageId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await removePinWithRequestBuilder(messageId: messageId).execute().body } /** @@ -945,7 +665,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -967,7 +687,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -975,9 +695,9 @@ extension TraqAPI { */ public enum Sort_searchMessages: String, CaseIterable { case createdat = "createdAt" - case createdatAsc = "-createdAt" + case createdat2 = "-createdAt" case updatedat = "updatedAt" - case updatedatAsc = "-updatedAt" + case updatedat2 = "-updatedAt" } /** @@ -1003,27 +723,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func searchMessages(word: String? = nil, after: Date? = nil, before: Date? = nil, _in: UUID? = nil, to: UUID? = nil, from: UUID? = nil, citation: UUID? = nil, bot: Bool? = nil, hasURL: Bool? = nil, hasAttachments: Bool? = nil, hasImage: Bool? = nil, hasVideo: Bool? = nil, hasAudio: Bool? = nil, limit: Int? = nil, offset: Int? = nil, sort: Sort_searchMessages? = nil) async throws -> MessageSearchResult { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = searchMessagesWithRequestBuilder(word: word, after: after, before: before, _in: _in, to: to, from: from, citation: citation, bot: bot, hasURL: hasURL, hasAttachments: hasAttachments, hasImage: hasImage, hasVideo: hasVideo, hasAudio: hasAudio, limit: limit, offset: offset, sort: sort).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await searchMessagesWithRequestBuilder(word: word, after: after, before: before, _in: _in, to: to, from: from, citation: citation, bot: bot, hasURL: hasURL, hasAttachments: hasAttachments, hasImage: hasImage, hasVideo: hasVideo, hasAudio: hasAudio, limit: limit, offset: offset, sort: sort).execute().body } /** @@ -1033,7 +733,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter word: (query) 検索ワード Simple-Query-String-Syntaxをパースして検索します (optional) @@ -1061,22 +761,22 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "word": word?.encodeToJSON(), - "after": after?.encodeToJSON(), - "before": before?.encodeToJSON(), - "in": _in?.encodeToJSON(), - "to": to?.encodeToJSON(), - "from": from?.encodeToJSON(), - "citation": citation?.encodeToJSON(), - "bot": bot?.encodeToJSON(), - "hasURL": hasURL?.encodeToJSON(), - "hasAttachments": hasAttachments?.encodeToJSON(), - "hasImage": hasImage?.encodeToJSON(), - "hasVideo": hasVideo?.encodeToJSON(), - "hasAudio": hasAudio?.encodeToJSON(), - "limit": limit?.encodeToJSON(), - "offset": offset?.encodeToJSON(), - "sort": sort?.encodeToJSON(), + "word": (wrappedValue: word?.encodeToJSON(), isExplode: true), + "after": (wrappedValue: after?.encodeToJSON(), isExplode: true), + "before": (wrappedValue: before?.encodeToJSON(), isExplode: true), + "in": (wrappedValue: _in?.encodeToJSON(), isExplode: true), + "to": (wrappedValue: to?.encodeToJSON(), isExplode: true), + "from": (wrappedValue: from?.encodeToJSON(), isExplode: true), + "citation": (wrappedValue: citation?.encodeToJSON(), isExplode: true), + "bot": (wrappedValue: bot?.encodeToJSON(), isExplode: true), + "hasURL": (wrappedValue: hasURL?.encodeToJSON(), isExplode: true), + "hasAttachments": (wrappedValue: hasAttachments?.encodeToJSON(), isExplode: true), + "hasImage": (wrappedValue: hasImage?.encodeToJSON(), isExplode: true), + "hasVideo": (wrappedValue: hasVideo?.encodeToJSON(), isExplode: true), + "hasAudio": (wrappedValue: hasAudio?.encodeToJSON(), isExplode: true), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), + "offset": (wrappedValue: offset?.encodeToJSON(), isExplode: true), + "sort": (wrappedValue: sort?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -1085,7 +785,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/NotificationAPI.swift b/Sources/Traq/APIs/NotificationAPI.swift index 44148d6..0f075d3 100644 --- a/Sources/Traq/APIs/NotificationAPI.swift +++ b/Sources/Traq/APIs/NotificationAPI.swift @@ -21,27 +21,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editChannelSubscribers(channelId: UUID, patchChannelSubscribersRequest: PatchChannelSubscribersRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editChannelSubscribersWithRequestBuilder(channelId: channelId, patchChannelSubscribersRequest: patchChannelSubscribersRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editChannelSubscribersWithRequestBuilder(channelId: channelId, patchChannelSubscribersRequest: patchChannelSubscribersRequest).execute().body } /** @@ -51,7 +31,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -74,7 +54,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -85,27 +65,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getChannelSubscribers(channelId: UUID) async throws -> [UUID] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getChannelSubscribersWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getChannelSubscribersWithRequestBuilder(channelId: channelId).execute().body } /** @@ -115,7 +75,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -137,7 +97,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UUID]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -147,27 +107,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyChannelSubscriptions() async throws -> [UserSubscribeState] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyChannelSubscriptionsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyChannelSubscriptionsWithRequestBuilder().execute().body } /** @@ -177,7 +117,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[UserSubscribeState]> @@ -195,7 +135,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UserSubscribeState]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -205,27 +145,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyUnreadChannels() async throws -> [UnreadChannel] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyUnreadChannelsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyUnreadChannelsWithRequestBuilder().execute().body } /** @@ -235,7 +155,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[UnreadChannel]> @@ -253,7 +173,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UnreadChannel]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -263,27 +183,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyViewStates() async throws -> [MyChannelViewState] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyViewStatesWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyViewStatesWithRequestBuilder().execute().body } /** @@ -293,7 +193,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[MyChannelViewState]> @@ -311,7 +211,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[MyChannelViewState]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -322,27 +222,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func readChannel(channelId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = readChannelWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await readChannelWithRequestBuilder(channelId: channelId).execute().body } /** @@ -352,7 +232,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -374,7 +254,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -385,27 +265,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func registerFCMDevice(postMyFCMDeviceRequest: PostMyFCMDeviceRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = registerFCMDeviceWithRequestBuilder(postMyFCMDeviceRequest: postMyFCMDeviceRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await registerFCMDeviceWithRequestBuilder(postMyFCMDeviceRequest: postMyFCMDeviceRequest).execute().body } /** @@ -415,7 +275,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postMyFCMDeviceRequest: (body) (optional) @@ -434,7 +294,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -446,27 +306,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func setChannelSubscribeLevel(channelId: UUID, putChannelSubscribeLevelRequest: PutChannelSubscribeLevelRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = setChannelSubscribeLevelWithRequestBuilder(channelId: channelId, putChannelSubscribeLevelRequest: putChannelSubscribeLevelRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await setChannelSubscribeLevelWithRequestBuilder(channelId: channelId, putChannelSubscribeLevelRequest: putChannelSubscribeLevelRequest).execute().body } /** @@ -476,7 +316,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -499,7 +339,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -511,27 +351,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func setChannelSubscribers(channelId: UUID, putChannelSubscribersRequest: PutChannelSubscribersRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = setChannelSubscribersWithRequestBuilder(channelId: channelId, putChannelSubscribersRequest: putChannelSubscribersRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await setChannelSubscribersWithRequestBuilder(channelId: channelId, putChannelSubscribersRequest: putChannelSubscribersRequest).execute().body } /** @@ -541,7 +361,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -564,7 +384,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -574,27 +394,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func ws() async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = wsWithRequestBuilder().execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await wsWithRequestBuilder().execute().body } /** @@ -604,7 +404,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder @@ -622,7 +422,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/Oauth2API.swift b/Sources/Traq/APIs/Oauth2API.swift index 92b162e..4dbd87c 100644 --- a/Sources/Traq/APIs/Oauth2API.swift +++ b/Sources/Traq/APIs/Oauth2API.swift @@ -20,27 +20,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func createClient(postClientRequest: PostClientRequest? = nil) async throws -> OAuth2ClientDetail { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = createClientWithRequestBuilder(postClientRequest: postClientRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await createClientWithRequestBuilder(postClientRequest: postClientRequest).execute().body } /** @@ -50,7 +30,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postClientRequest: (body) (optional) @@ -69,7 +49,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -80,27 +60,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func deleteClient(clientId: String) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = deleteClientWithRequestBuilder(clientId: clientId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await deleteClientWithRequestBuilder(clientId: clientId).execute().body } /** @@ -110,7 +70,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter clientId: (path) OAuth2クライアントUUID @@ -132,7 +92,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -144,27 +104,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editClient(clientId: String, patchClientRequest: PatchClientRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editClientWithRequestBuilder(clientId: clientId, patchClientRequest: patchClientRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editClientWithRequestBuilder(clientId: clientId, patchClientRequest: patchClientRequest).execute().body } /** @@ -174,7 +114,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter clientId: (path) OAuth2クライアントUUID @@ -197,7 +137,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -209,27 +149,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getClient(clientId: String, detail: Bool? = nil) async throws -> GetClient200Response { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getClientWithRequestBuilder(clientId: clientId, detail: detail).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getClientWithRequestBuilder(clientId: clientId, detail: detail).execute().body } /** @@ -239,7 +159,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter clientId: (path) OAuth2クライアントUUID @@ -256,7 +176,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "detail": detail?.encodeToJSON(), + "detail": (wrappedValue: detail?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -265,7 +185,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -276,27 +196,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getClients(all: Bool? = nil) async throws -> [OAuth2Client] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getClientsWithRequestBuilder(all: all).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getClientsWithRequestBuilder(all: all).execute().body } /** @@ -306,7 +206,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter all: (query) 全てのクライアントを取得するかどうか (optional, default to false) @@ -319,7 +219,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "all": all?.encodeToJSON(), + "all": (wrappedValue: all?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -328,7 +228,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[OAuth2Client]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -338,27 +238,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyTokens() async throws -> [ActiveOAuth2Token] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyTokensWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyTokensWithRequestBuilder().execute().body } /** @@ -368,7 +248,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[ActiveOAuth2Token]> @@ -386,7 +266,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[ActiveOAuth2Token]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -405,27 +285,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getOAuth2Authorize(clientId: String, responseType: OAuth2ResponseType? = nil, redirectUri: String? = nil, scope: String? = nil, state: String? = nil, codeChallenge: String? = nil, codeChallengeMethod: String? = nil, nonce: String? = nil, prompt: OAuth2Prompt? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getOAuth2AuthorizeWithRequestBuilder(clientId: clientId, responseType: responseType, redirectUri: redirectUri, scope: scope, state: state, codeChallenge: codeChallenge, codeChallengeMethod: codeChallengeMethod, nonce: nonce, prompt: prompt).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getOAuth2AuthorizeWithRequestBuilder(clientId: clientId, responseType: responseType, redirectUri: redirectUri, scope: scope, state: state, codeChallenge: codeChallenge, codeChallengeMethod: codeChallengeMethod, nonce: nonce, prompt: prompt).execute().body } /** @@ -435,7 +295,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter clientId: (query) @@ -456,15 +316,15 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "response_type": responseType?.encodeToJSON(), - "client_id": clientId.encodeToJSON(), - "redirect_uri": redirectUri?.encodeToJSON(), - "scope": scope?.encodeToJSON(), - "state": state?.encodeToJSON(), - "code_challenge": codeChallenge?.encodeToJSON(), - "code_challenge_method": codeChallengeMethod?.encodeToJSON(), - "nonce": nonce?.encodeToJSON(), - "prompt": prompt?.encodeToJSON(), + "response_type": (wrappedValue: responseType?.encodeToJSON(), isExplode: true), + "client_id": (wrappedValue: clientId.encodeToJSON(), isExplode: true), + "redirect_uri": (wrappedValue: redirectUri?.encodeToJSON(), isExplode: true), + "scope": (wrappedValue: scope?.encodeToJSON(), isExplode: true), + "state": (wrappedValue: state?.encodeToJSON(), isExplode: true), + "code_challenge": (wrappedValue: codeChallenge?.encodeToJSON(), isExplode: true), + "code_challenge_method": (wrappedValue: codeChallengeMethod?.encodeToJSON(), isExplode: true), + "nonce": (wrappedValue: nonce?.encodeToJSON(), isExplode: true), + "prompt": (wrappedValue: prompt?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -473,7 +333,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -492,27 +352,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func postOAuth2Authorize(clientId: String, responseType: OAuth2ResponseType? = nil, redirectUri: String? = nil, scope: String? = nil, state: String? = nil, codeChallenge: String? = nil, codeChallengeMethod: String? = nil, nonce: String? = nil, prompt: OAuth2Prompt? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = postOAuth2AuthorizeWithRequestBuilder(clientId: clientId, responseType: responseType, redirectUri: redirectUri, scope: scope, state: state, codeChallenge: codeChallenge, codeChallengeMethod: codeChallengeMethod, nonce: nonce, prompt: prompt).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await postOAuth2AuthorizeWithRequestBuilder(clientId: clientId, responseType: responseType, redirectUri: redirectUri, scope: scope, state: state, codeChallenge: codeChallenge, codeChallengeMethod: codeChallengeMethod, nonce: nonce, prompt: prompt).execute().body } /** @@ -522,7 +362,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter clientId: (form) @@ -564,7 +404,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -575,27 +415,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func postOAuth2AuthorizeDecide(submit: String) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = postOAuth2AuthorizeDecideWithRequestBuilder(submit: submit).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await postOAuth2AuthorizeDecideWithRequestBuilder(submit: submit).execute().body } /** @@ -605,7 +425,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter submit: (form) 承諾する場合は\\\"approve\\\" @@ -631,7 +451,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -651,27 +471,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func postOAuth2Token(grantType: String, code: String? = nil, redirectUri: String? = nil, clientId: String? = nil, codeVerifier: String? = nil, username: String? = nil, password: String? = nil, scope: String? = nil, refreshToken: String? = nil, clientSecret: String? = nil) async throws -> OAuth2Token { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = postOAuth2TokenWithRequestBuilder(grantType: grantType, code: code, redirectUri: redirectUri, clientId: clientId, codeVerifier: codeVerifier, username: username, password: password, scope: scope, refreshToken: refreshToken, clientSecret: clientSecret).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await postOAuth2TokenWithRequestBuilder(grantType: grantType, code: code, redirectUri: redirectUri, clientId: clientId, codeVerifier: codeVerifier, username: username, password: password, scope: scope, refreshToken: refreshToken, clientSecret: clientSecret).execute().body } /** @@ -681,7 +481,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter grantType: (form) @@ -725,7 +525,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -736,27 +536,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func revokeMyToken(tokenId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = revokeMyTokenWithRequestBuilder(tokenId: tokenId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await revokeMyTokenWithRequestBuilder(tokenId: tokenId).execute().body } /** @@ -766,7 +546,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter tokenId: (path) OAuth2トークンUUID @@ -788,7 +568,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -799,27 +579,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func revokeOAuth2Token(token: String) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = revokeOAuth2TokenWithRequestBuilder(token: token).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await revokeOAuth2TokenWithRequestBuilder(token: token).execute().body } /** @@ -829,7 +589,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter token: (form) 無効化するOAuth2トークンまたはOAuth2リフレッシュトークン @@ -855,7 +615,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/OgpAPI.swift b/Sources/Traq/APIs/OgpAPI.swift index 275a7ad..1abba75 100644 --- a/Sources/Traq/APIs/OgpAPI.swift +++ b/Sources/Traq/APIs/OgpAPI.swift @@ -20,27 +20,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func deleteOgpCache(url: String) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = deleteOgpCacheWithRequestBuilder(url: url).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await deleteOgpCacheWithRequestBuilder(url: url).execute().body } /** @@ -50,7 +30,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter url: (query) OGPのキャッシュを削除したいURL @@ -63,7 +43,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "url": url.encodeToJSON(), + "url": (wrappedValue: url.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -72,7 +52,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -83,27 +63,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getOgp(url: String) async throws -> Ogp { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getOgpWithRequestBuilder(url: url).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getOgpWithRequestBuilder(url: url).execute().body } /** @@ -113,7 +73,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter url: (query) OGPを取得したいURL @@ -126,7 +86,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "url": url.encodeToJSON(), + "url": (wrappedValue: url.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -135,7 +95,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/PinAPI.swift b/Sources/Traq/APIs/PinAPI.swift index fb3e410..008b6a4 100644 --- a/Sources/Traq/APIs/PinAPI.swift +++ b/Sources/Traq/APIs/PinAPI.swift @@ -20,27 +20,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func createPin(messageId: UUID) async throws -> MessagePin { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = createPinWithRequestBuilder(messageId: messageId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await createPinWithRequestBuilder(messageId: messageId).execute().body } /** @@ -50,7 +30,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -72,7 +52,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -83,27 +63,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getChannelPins(channelId: UUID) async throws -> [Pin] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getChannelPinsWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getChannelPinsWithRequestBuilder(channelId: channelId).execute().body } /** @@ -113,7 +73,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -135,7 +95,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[Pin]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -146,27 +106,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getPin(messageId: UUID) async throws -> MessagePin { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getPinWithRequestBuilder(messageId: messageId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getPinWithRequestBuilder(messageId: messageId).execute().body } /** @@ -176,7 +116,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -198,7 +138,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -209,27 +149,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func removePin(messageId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = removePinWithRequestBuilder(messageId: messageId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await removePinWithRequestBuilder(messageId: messageId).execute().body } /** @@ -239,7 +159,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -261,7 +181,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/PublicAPI.swift b/Sources/Traq/APIs/PublicAPI.swift index f26cfb2..2322a94 100644 --- a/Sources/Traq/APIs/PublicAPI.swift +++ b/Sources/Traq/APIs/PublicAPI.swift @@ -20,27 +20,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getPublicUserIcon(username: String) async throws -> URL { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getPublicUserIconWithRequestBuilder(username: username).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getPublicUserIconWithRequestBuilder(username: username).execute().body } /** @@ -50,7 +30,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter username: (path) ユーザー名 @@ -72,7 +52,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -82,27 +62,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getServerVersion() async throws -> Version { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getServerVersionWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getServerVersionWithRequestBuilder().execute().body } /** @@ -112,7 +72,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder @@ -130,7 +90,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/StampAPI.swift b/Sources/Traq/APIs/StampAPI.swift index 34d3b66..3ab901f 100644 --- a/Sources/Traq/APIs/StampAPI.swift +++ b/Sources/Traq/APIs/StampAPI.swift @@ -22,27 +22,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func addMessageStamp(messageId: UUID, stampId: UUID, postMessageStampRequest: PostMessageStampRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = addMessageStampWithRequestBuilder(messageId: messageId, stampId: stampId, postMessageStampRequest: postMessageStampRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await addMessageStampWithRequestBuilder(messageId: messageId, stampId: stampId, postMessageStampRequest: postMessageStampRequest).execute().body } /** @@ -52,7 +32,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -79,7 +59,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -91,27 +71,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func changeStampImage(stampId: UUID, file: URL) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = changeStampImageWithRequestBuilder(stampId: stampId, file: file).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await changeStampImageWithRequestBuilder(stampId: stampId, file: file).execute().body } /** @@ -121,7 +81,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter stampId: (path) スタンプUUID @@ -151,7 +111,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -163,27 +123,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func createStamp(name: String, file: URL) async throws -> Stamp { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = createStampWithRequestBuilder(name: name, file: file).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await createStampWithRequestBuilder(name: name, file: file).execute().body } /** @@ -193,7 +133,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter name: (form) スタンプ名 @@ -221,7 +161,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -232,27 +172,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func createStampPalette(postStampPaletteRequest: PostStampPaletteRequest? = nil) async throws -> StampPalette { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = createStampPaletteWithRequestBuilder(postStampPaletteRequest: postStampPaletteRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await createStampPaletteWithRequestBuilder(postStampPaletteRequest: postStampPaletteRequest).execute().body } /** @@ -262,7 +182,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postStampPaletteRequest: (body) (optional) @@ -281,7 +201,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -292,27 +212,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func deleteStamp(stampId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = deleteStampWithRequestBuilder(stampId: stampId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await deleteStampWithRequestBuilder(stampId: stampId).execute().body } /** @@ -322,7 +222,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter stampId: (path) スタンプUUID @@ -344,7 +244,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -355,27 +255,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func deleteStampPalette(paletteId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = deleteStampPaletteWithRequestBuilder(paletteId: paletteId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await deleteStampPaletteWithRequestBuilder(paletteId: paletteId).execute().body } /** @@ -385,7 +265,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter paletteId: (path) スタンプパレットUUID @@ -407,7 +287,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -419,27 +299,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editStamp(stampId: UUID, patchStampRequest: PatchStampRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editStampWithRequestBuilder(stampId: stampId, patchStampRequest: patchStampRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editStampWithRequestBuilder(stampId: stampId, patchStampRequest: patchStampRequest).execute().body } /** @@ -449,7 +309,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter stampId: (path) スタンプUUID @@ -472,7 +332,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -484,27 +344,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editStampPalette(paletteId: UUID, patchStampPaletteRequest: PatchStampPaletteRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editStampPaletteWithRequestBuilder(paletteId: paletteId, patchStampPaletteRequest: patchStampPaletteRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editStampPaletteWithRequestBuilder(paletteId: paletteId, patchStampPaletteRequest: patchStampPaletteRequest).execute().body } /** @@ -514,7 +354,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter paletteId: (path) スタンプパレットUUID @@ -537,7 +377,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -548,27 +388,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMessageStamps(messageId: UUID) async throws -> [MessageStamp] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMessageStampsWithRequestBuilder(messageId: messageId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMessageStampsWithRequestBuilder(messageId: messageId).execute().body } /** @@ -578,7 +398,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -600,7 +420,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[MessageStamp]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -611,27 +431,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyStampHistory(limit: Int? = nil) async throws -> [StampHistoryEntry] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyStampHistoryWithRequestBuilder(limit: limit).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyStampHistoryWithRequestBuilder(limit: limit).execute().body } /** @@ -641,7 +441,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter limit: (query) 件数 (optional, default to 100) @@ -654,7 +454,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "limit": limit?.encodeToJSON(), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -663,7 +463,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[StampHistoryEntry]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -674,27 +474,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getStamp(stampId: UUID) async throws -> Stamp { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getStampWithRequestBuilder(stampId: stampId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getStampWithRequestBuilder(stampId: stampId).execute().body } /** @@ -704,7 +484,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter stampId: (path) スタンプUUID @@ -726,7 +506,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -737,27 +517,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getStampImage(stampId: UUID) async throws -> URL { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getStampImageWithRequestBuilder(stampId: stampId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getStampImageWithRequestBuilder(stampId: stampId).execute().body } /** @@ -767,7 +527,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter stampId: (path) スタンプUUID @@ -789,7 +549,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -800,27 +560,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getStampPalette(paletteId: UUID) async throws -> StampPalette { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getStampPaletteWithRequestBuilder(paletteId: paletteId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getStampPaletteWithRequestBuilder(paletteId: paletteId).execute().body } /** @@ -830,7 +570,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter paletteId: (path) スタンプパレットUUID @@ -852,7 +592,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -862,27 +602,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getStampPalettes() async throws -> [StampPalette] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getStampPalettesWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getStampPalettesWithRequestBuilder().execute().body } /** @@ -892,7 +612,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[StampPalette]> @@ -910,7 +630,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[StampPalette]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -921,27 +641,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getStampStats(stampId: UUID) async throws -> StampStats { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getStampStatsWithRequestBuilder(stampId: stampId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getStampStatsWithRequestBuilder(stampId: stampId).execute().body } /** @@ -951,7 +651,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter stampId: (path) スタンプUUID @@ -973,7 +673,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -993,27 +693,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getStamps(includeUnicode: Bool? = nil, type: ModelType_getStamps? = nil) async throws -> [Stamp] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getStampsWithRequestBuilder(includeUnicode: includeUnicode, type: type).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getStampsWithRequestBuilder(includeUnicode: includeUnicode, type: type).execute().body } /** @@ -1023,7 +703,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter includeUnicode: (query) Unicode絵文字を含ませるかどうか Deprecated: typeクエリを指定しなければ全てのスタンプを取得できるため、そちらを利用してください (optional, default to true) @@ -1037,8 +717,8 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "include-unicode": includeUnicode?.encodeToJSON(), - "type": type?.encodeToJSON(), + "include-unicode": (wrappedValue: includeUnicode?.encodeToJSON(), isExplode: true), + "type": (wrappedValue: type?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -1047,7 +727,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[Stamp]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -1059,27 +739,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func removeMessageStamp(messageId: UUID, stampId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = removeMessageStampWithRequestBuilder(messageId: messageId, stampId: stampId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await removeMessageStampWithRequestBuilder(messageId: messageId, stampId: stampId).execute().body } /** @@ -1089,7 +749,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter messageId: (path) メッセージUUID @@ -1115,7 +775,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/StarAPI.swift b/Sources/Traq/APIs/StarAPI.swift index ca4415b..9bd587f 100644 --- a/Sources/Traq/APIs/StarAPI.swift +++ b/Sources/Traq/APIs/StarAPI.swift @@ -20,27 +20,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func addMyStar(postStarRequest: PostStarRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = addMyStarWithRequestBuilder(postStarRequest: postStarRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await addMyStarWithRequestBuilder(postStarRequest: postStarRequest).execute().body } /** @@ -50,7 +30,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postStarRequest: (body) (optional) @@ -69,7 +49,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -79,27 +59,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyStars() async throws -> [UUID] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyStarsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyStarsWithRequestBuilder().execute().body } /** @@ -109,7 +69,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[UUID]> @@ -127,7 +87,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UUID]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -138,27 +98,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func removeMyStar(channelId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = removeMyStarWithRequestBuilder(channelId: channelId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await removeMyStarWithRequestBuilder(channelId: channelId).execute().body } /** @@ -168,7 +108,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter channelId: (path) チャンネルUUID @@ -190,7 +130,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/UserAPI.swift b/Sources/Traq/APIs/UserAPI.swift index acdb602..adc669c 100644 --- a/Sources/Traq/APIs/UserAPI.swift +++ b/Sources/Traq/APIs/UserAPI.swift @@ -21,27 +21,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func addUserTag(userId: UUID, postUserTagRequest: PostUserTagRequest? = nil) async throws -> UserTag { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = addUserTagWithRequestBuilder(userId: userId, postUserTagRequest: postUserTagRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await addUserTagWithRequestBuilder(userId: userId, postUserTagRequest: postUserTagRequest).execute().body } /** @@ -51,7 +31,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -74,7 +54,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -86,27 +66,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func changeUserIcon(userId: UUID, file: URL) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = changeUserIconWithRequestBuilder(userId: userId, file: file).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await changeUserIconWithRequestBuilder(userId: userId, file: file).execute().body } /** @@ -116,7 +76,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -146,7 +106,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -158,27 +118,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func changeUserPassword(userId: UUID, putUserPasswordRequest: PutUserPasswordRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = changeUserPasswordWithRequestBuilder(userId: userId, putUserPasswordRequest: putUserPasswordRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await changeUserPasswordWithRequestBuilder(userId: userId, putUserPasswordRequest: putUserPasswordRequest).execute().body } /** @@ -188,7 +128,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -211,7 +151,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -222,27 +162,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func createUser(postUserRequest: PostUserRequest? = nil) async throws -> UserDetail { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = createUserWithRequestBuilder(postUserRequest: postUserRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await createUserWithRequestBuilder(postUserRequest: postUserRequest).execute().body } /** @@ -252,7 +172,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postUserRequest: (body) (optional) @@ -271,7 +191,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -283,27 +203,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editUser(userId: UUID, patchUserRequest: PatchUserRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editUserWithRequestBuilder(userId: userId, patchUserRequest: patchUserRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editUserWithRequestBuilder(userId: userId, patchUserRequest: patchUserRequest).execute().body } /** @@ -313,7 +213,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -336,7 +236,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -349,27 +249,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editUserTag(userId: UUID, tagId: UUID, patchUserTagRequest: PatchUserTagRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editUserTagWithRequestBuilder(userId: userId, tagId: tagId, patchUserTagRequest: patchUserTagRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editUserTagWithRequestBuilder(userId: userId, tagId: tagId, patchUserTagRequest: patchUserTagRequest).execute().body } /** @@ -379,7 +259,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -406,7 +286,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -431,27 +311,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getDirectMessages(userId: UUID, limit: Int? = nil, offset: Int? = nil, since: Date? = nil, until: Date? = nil, inclusive: Bool? = nil, order: Order_getDirectMessages? = nil) async throws -> [Message] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getDirectMessagesWithRequestBuilder(userId: userId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getDirectMessagesWithRequestBuilder(userId: userId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order).execute().body } /** @@ -461,7 +321,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - responseHeaders: [X-TRAQ-MORE(Bool)] @@ -484,12 +344,12 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "limit": limit?.encodeToJSON(), - "offset": offset?.encodeToJSON(), - "since": since?.encodeToJSON(), - "until": until?.encodeToJSON(), - "inclusive": inclusive?.encodeToJSON(), - "order": order?.encodeToJSON(), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), + "offset": (wrappedValue: offset?.encodeToJSON(), isExplode: true), + "since": (wrappedValue: since?.encodeToJSON(), isExplode: true), + "until": (wrappedValue: until?.encodeToJSON(), isExplode: true), + "inclusive": (wrappedValue: inclusive?.encodeToJSON(), isExplode: true), + "order": (wrappedValue: order?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -498,7 +358,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[Message]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -509,27 +369,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUser(userId: UUID) async throws -> UserDetail { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUserWithRequestBuilder(userId: userId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUserWithRequestBuilder(userId: userId).execute().body } /** @@ -539,7 +379,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -561,7 +401,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -572,27 +412,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUserDMChannel(userId: String) async throws -> DMChannel { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUserDMChannelWithRequestBuilder(userId: userId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUserDMChannelWithRequestBuilder(userId: userId).execute().body } /** @@ -602,7 +422,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) @@ -624,7 +444,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -635,27 +455,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUserIcon(userId: UUID) async throws -> URL { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUserIconWithRequestBuilder(userId: userId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUserIconWithRequestBuilder(userId: userId).execute().body } /** @@ -665,7 +465,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -687,7 +487,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -698,27 +498,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUserStats(userId: UUID) async throws -> UserStats { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUserStatsWithRequestBuilder(userId: userId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUserStatsWithRequestBuilder(userId: userId).execute().body } /** @@ -728,7 +508,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -750,7 +530,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -761,27 +541,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUserTags(userId: UUID) async throws -> [UserTag] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUserTagsWithRequestBuilder(userId: userId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUserTagsWithRequestBuilder(userId: userId).execute().body } /** @@ -791,7 +551,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -813,7 +573,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UserTag]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -825,27 +585,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUsers(includeSuspended: Bool? = nil, name: String? = nil) async throws -> [User] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUsersWithRequestBuilder(includeSuspended: includeSuspended, name: name).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUsersWithRequestBuilder(includeSuspended: includeSuspended, name: name).execute().body } /** @@ -855,7 +595,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter includeSuspended: (query) アカウントがアクティブでないユーザーを含め、全てのユーザーを取得するかどうか (optional, default to false) @@ -869,8 +609,8 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "include-suspended": includeSuspended?.encodeToJSON(), - "name": name?.encodeToJSON(), + "include-suspended": (wrappedValue: includeSuspended?.encodeToJSON(), isExplode: true), + "name": (wrappedValue: name?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -879,7 +619,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[User]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -891,27 +631,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func postDirectMessage(userId: UUID, postMessageRequest: PostMessageRequest? = nil) async throws -> Message { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = postDirectMessageWithRequestBuilder(userId: userId, postMessageRequest: postMessageRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await postDirectMessageWithRequestBuilder(userId: userId, postMessageRequest: postMessageRequest).execute().body } /** @@ -921,7 +641,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -944,7 +664,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -956,27 +676,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func removeUserTag(userId: UUID, tagId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = removeUserTagWithRequestBuilder(userId: userId, tagId: tagId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await removeUserTagWithRequestBuilder(userId: userId, tagId: tagId).execute().body } /** @@ -986,7 +686,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -1012,7 +712,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/UserTagAPI.swift b/Sources/Traq/APIs/UserTagAPI.swift index d41e898..410953c 100644 --- a/Sources/Traq/APIs/UserTagAPI.swift +++ b/Sources/Traq/APIs/UserTagAPI.swift @@ -20,27 +20,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func addMyUserTag(postUserTagRequest: PostUserTagRequest? = nil) async throws -> UserTag { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = addMyUserTagWithRequestBuilder(postUserTagRequest: postUserTagRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await addMyUserTagWithRequestBuilder(postUserTagRequest: postUserTagRequest).execute().body } /** @@ -50,7 +30,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postUserTagRequest: (body) (optional) @@ -69,7 +49,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -81,27 +61,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func addUserTag(userId: UUID, postUserTagRequest: PostUserTagRequest? = nil) async throws -> UserTag { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = addUserTagWithRequestBuilder(userId: userId, postUserTagRequest: postUserTagRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await addUserTagWithRequestBuilder(userId: userId, postUserTagRequest: postUserTagRequest).execute().body } /** @@ -111,7 +71,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -134,7 +94,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -146,27 +106,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editMyUserTag(tagId: UUID, patchUserTagRequest: PatchUserTagRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editMyUserTagWithRequestBuilder(tagId: tagId, patchUserTagRequest: patchUserTagRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editMyUserTagWithRequestBuilder(tagId: tagId, patchUserTagRequest: patchUserTagRequest).execute().body } /** @@ -176,7 +116,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter tagId: (path) タグUUID @@ -199,7 +139,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -212,27 +152,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editUserTag(userId: UUID, tagId: UUID, patchUserTagRequest: PatchUserTagRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editUserTagWithRequestBuilder(userId: userId, tagId: tagId, patchUserTagRequest: patchUserTagRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editUserTagWithRequestBuilder(userId: userId, tagId: tagId, patchUserTagRequest: patchUserTagRequest).execute().body } /** @@ -242,7 +162,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -269,7 +189,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -279,27 +199,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getMyUserTags() async throws -> [UserTag] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getMyUserTagsWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getMyUserTagsWithRequestBuilder().execute().body } /** @@ -309,7 +209,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[UserTag]> @@ -327,7 +227,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UserTag]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -338,27 +238,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getTag(tagId: UUID) async throws -> Tag { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getTagWithRequestBuilder(tagId: tagId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getTagWithRequestBuilder(tagId: tagId).execute().body } /** @@ -368,7 +248,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter tagId: (path) タグUUID @@ -390,7 +270,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -401,27 +281,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getUserTags(userId: UUID) async throws -> [UserTag] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getUserTagsWithRequestBuilder(userId: userId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getUserTagsWithRequestBuilder(userId: userId).execute().body } /** @@ -431,7 +291,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -453,7 +313,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[UserTag]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -464,27 +324,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func removeMyUserTag(tagId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = removeMyUserTagWithRequestBuilder(tagId: tagId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await removeMyUserTagWithRequestBuilder(tagId: tagId).execute().body } /** @@ -494,7 +334,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter tagId: (path) タグUUID @@ -516,7 +356,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -528,27 +368,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func removeUserTag(userId: UUID, tagId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = removeUserTagWithRequestBuilder(userId: userId, tagId: tagId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await removeUserTagWithRequestBuilder(userId: userId, tagId: tagId).execute().body } /** @@ -558,7 +378,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter userId: (path) ユーザーUUID @@ -584,7 +404,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/WebhookAPI.swift b/Sources/Traq/APIs/WebhookAPI.swift index 26a2cf2..ed4643d 100644 --- a/Sources/Traq/APIs/WebhookAPI.swift +++ b/Sources/Traq/APIs/WebhookAPI.swift @@ -21,27 +21,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func changeWebhookIcon(webhookId: UUID, file: URL) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = changeWebhookIconWithRequestBuilder(webhookId: webhookId, file: file).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await changeWebhookIconWithRequestBuilder(webhookId: webhookId, file: file).execute().body } /** @@ -51,7 +31,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter webhookId: (path) WebhookUUID @@ -81,7 +61,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PUT", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -92,27 +72,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func createWebhook(postWebhookRequest: PostWebhookRequest? = nil) async throws -> Webhook { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = createWebhookWithRequestBuilder(postWebhookRequest: postWebhookRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await createWebhookWithRequestBuilder(postWebhookRequest: postWebhookRequest).execute().body } /** @@ -122,7 +82,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postWebhookRequest: (body) (optional) @@ -141,7 +101,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -152,27 +112,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func deleteWebhook(webhookId: UUID) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = deleteWebhookWithRequestBuilder(webhookId: webhookId).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await deleteWebhookWithRequestBuilder(webhookId: webhookId).execute().body } /** @@ -182,7 +122,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter webhookId: (path) WebhookUUID @@ -204,7 +144,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "DELETE", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -216,27 +156,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func editWebhook(webhookId: UUID, patchWebhookRequest: PatchWebhookRequest? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = editWebhookWithRequestBuilder(webhookId: webhookId, patchWebhookRequest: patchWebhookRequest).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await editWebhookWithRequestBuilder(webhookId: webhookId, patchWebhookRequest: patchWebhookRequest).execute().body } /** @@ -246,7 +166,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter webhookId: (path) WebhookUUID @@ -269,7 +189,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "PATCH", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -280,27 +200,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getWebhook(webhookId: UUID) async throws -> Webhook { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getWebhookWithRequestBuilder(webhookId: webhookId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getWebhookWithRequestBuilder(webhookId: webhookId).execute().body } /** @@ -310,7 +210,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter webhookId: (path) WebhookUUID @@ -332,7 +232,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -343,27 +243,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getWebhookIcon(webhookId: UUID) async throws -> URL { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getWebhookIconWithRequestBuilder(webhookId: webhookId).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getWebhookIconWithRequestBuilder(webhookId: webhookId).execute().body } /** @@ -373,7 +253,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter webhookId: (path) WebhookUUID @@ -395,7 +275,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -420,27 +300,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getWebhookMessages(webhookId: UUID, limit: Int? = nil, offset: Int? = nil, since: Date? = nil, until: Date? = nil, inclusive: Bool? = nil, order: Order_getWebhookMessages? = nil) async throws -> [Message] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getWebhookMessagesWithRequestBuilder(webhookId: webhookId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getWebhookMessagesWithRequestBuilder(webhookId: webhookId, limit: limit, offset: offset, since: since, until: until, inclusive: inclusive, order: order).execute().body } /** @@ -450,7 +310,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - responseHeaders: [X-TRAQ-MORE(Bool)] @@ -473,12 +333,12 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "limit": limit?.encodeToJSON(), - "offset": offset?.encodeToJSON(), - "since": since?.encodeToJSON(), - "until": until?.encodeToJSON(), - "inclusive": inclusive?.encodeToJSON(), - "order": order?.encodeToJSON(), + "limit": (wrappedValue: limit?.encodeToJSON(), isExplode: true), + "offset": (wrappedValue: offset?.encodeToJSON(), isExplode: true), + "since": (wrappedValue: since?.encodeToJSON(), isExplode: true), + "until": (wrappedValue: until?.encodeToJSON(), isExplode: true), + "inclusive": (wrappedValue: inclusive?.encodeToJSON(), isExplode: true), + "order": (wrappedValue: order?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -487,7 +347,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[Message]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -498,27 +358,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getWebhooks(all: Bool? = nil) async throws -> [Webhook] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getWebhooksWithRequestBuilder(all: all).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getWebhooksWithRequestBuilder(all: all).execute().body } /** @@ -528,7 +368,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter all: (query) 全てのWebhookを取得します。権限が必要です。 (optional, default to false) @@ -541,7 +381,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "all": all?.encodeToJSON(), + "all": (wrappedValue: all?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [:] @@ -550,7 +390,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[Webhook]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -565,27 +405,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func postWebhook(webhookId: UUID, xTRAQSignature: String? = nil, xTRAQChannelId: String? = nil, embed: Int? = nil, body: String? = nil) async throws { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = postWebhookWithRequestBuilder(webhookId: webhookId, xTRAQSignature: xTRAQSignature, xTRAQChannelId: xTRAQChannelId, embed: embed, body: body).execute { result in - switch result { - case .success: - continuation.resume(returning: ()) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await postWebhookWithRequestBuilder(webhookId: webhookId, xTRAQSignature: xTRAQSignature, xTRAQChannelId: xTRAQChannelId, embed: embed, body: body).execute().body } /** @@ -595,7 +415,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter webhookId: (path) WebhookUUID @@ -615,7 +435,7 @@ extension TraqAPI { var localVariableUrlComponents = URLComponents(string: localVariableURLString) localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([ - "embed": embed?.encodeToJSON(), + "embed": (wrappedValue: embed?.encodeToJSON(), isExplode: true), ]) let localVariableNillableHeaders: [String: Any?] = [ @@ -627,7 +447,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getNonDecodableBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/APIs/WebrtcAPI.swift b/Sources/Traq/APIs/WebrtcAPI.swift index 436b1e7..379a219 100644 --- a/Sources/Traq/APIs/WebrtcAPI.swift +++ b/Sources/Traq/APIs/WebrtcAPI.swift @@ -19,27 +19,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func getWebRTCState() async throws -> [WebRTCUserState] { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = getWebRTCStateWithRequestBuilder().execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await getWebRTCStateWithRequestBuilder().execute().body } /** @@ -49,7 +29,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - returns: RequestBuilder<[WebRTCUserState]> @@ -67,7 +47,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder<[WebRTCUserState]>.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "GET", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } /** @@ -78,27 +58,7 @@ extension TraqAPI { */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) open class func postWebRTCAuthenticate(postWebRTCAuthenticateRequest: PostWebRTCAuthenticateRequest? = nil) async throws -> WebRTCAuthenticateResult { - var requestTask: RequestTask? - return try await withTaskCancellationHandler { - try Task.checkCancellation() - return try await withCheckedThrowingContinuation { continuation in - guard !Task.isCancelled else { - continuation.resume(throwing: CancellationError()) - return - } - - requestTask = postWebRTCAuthenticateWithRequestBuilder(postWebRTCAuthenticateRequest: postWebRTCAuthenticateRequest).execute { result in - switch result { - case let .success(response): - continuation.resume(returning: response.body) - case let .failure(error): - continuation.resume(throwing: error) - } - } - } - } onCancel: { [requestTask] in - requestTask?.cancel() - } + try await postWebRTCAuthenticateWithRequestBuilder(postWebRTCAuthenticateRequest: postWebRTCAuthenticateRequest).execute().body } /** @@ -108,7 +68,7 @@ extension TraqAPI { - OAuth: - type: oauth2 - name: OAuth2 - - BASIC: + - Bearer Token: - type: http - name: bearerAuth - parameter postWebRTCAuthenticateRequest: (body) (optional) @@ -127,7 +87,7 @@ extension TraqAPI { let localVariableRequestBuilder: RequestBuilder.Type = TraqAPI.requestBuilderFactory.getBuilder() - return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters) + return localVariableRequestBuilder.init(method: "POST", URLString: localVariableUrlComponents?.string ?? localVariableURLString, parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true) } } } diff --git a/Sources/Traq/CodableHelper.swift b/Sources/Traq/CodableHelper.swift index 66d1dd6..59a38db 100644 --- a/Sources/Traq/CodableHelper.swift +++ b/Sources/Traq/CodableHelper.swift @@ -27,25 +27,25 @@ open class CodableHelper { }() public static var dateFormatter: DateFormatter { - get { return customDateFormatter ?? defaultDateFormatter } + get { customDateFormatter ?? defaultDateFormatter } set { customDateFormatter = newValue } } public static var jsonDecoder: JSONDecoder { - get { return customJSONDecoder ?? defaultJSONDecoder } + get { customJSONDecoder ?? defaultJSONDecoder } set { customJSONDecoder = newValue } } public static var jsonEncoder: JSONEncoder { - get { return customJSONEncoder ?? defaultJSONEncoder } + get { customJSONEncoder ?? defaultJSONEncoder } set { customJSONEncoder = newValue } } open class func decode(_ type: T.Type, from data: Data) -> Swift.Result where T: Decodable { - return Swift.Result { try jsonDecoder.decode(type, from: data) } + Swift.Result { try jsonDecoder.decode(type, from: data) } } open class func encode(_ value: T) -> Swift.Result where T: Encodable { - return Swift.Result { try jsonEncoder.encode(value) } + Swift.Result { try jsonEncoder.encode(value) } } } diff --git a/Sources/Traq/Configuration.swift b/Sources/Traq/Configuration.swift index 1590df3..e7aeb88 100644 --- a/Sources/Traq/Configuration.swift +++ b/Sources/Traq/Configuration.swift @@ -5,15 +5,18 @@ // import Foundation +#if canImport(FoundationNetworking) + import FoundationNetworking +#endif @available(*, deprecated, renamed: "TraqAPI.Configuration") public typealias Configuration = TraqAPI.Configuration extension TraqAPI { - open class Configuration { - // This value is used to configure the date formatter that is used to serialize dates into JSON format. - // You must set it prior to encoding any dates, and it will only be read once. - @available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.") - public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" + open enum Configuration { + /// Configures the range of HTTP status codes that will result in a successful response + /// + /// If a HTTP status code is outside of this range the response will be interpreted as failed. + public static var successfulStatusCodeRange: Range = 200 ..< 300 } } diff --git a/Sources/Traq/Extensions.swift b/Sources/Traq/Extensions.swift index 9cf85b7..23e3498 100644 --- a/Sources/Traq/Extensions.swift +++ b/Sources/Traq/Extensions.swift @@ -5,6 +5,9 @@ // import Foundation +#if canImport(FoundationNetworking) + import FoundationNetworking +#endif #if canImport(AnyCodable) import AnyCodable #endif @@ -33,6 +36,10 @@ extension Double: JSONEncodable { func encodeToJSON() -> Any { self } } +extension Decimal: JSONEncodable { + func encodeToJSON() -> Any { self } +} + extension String: JSONEncodable { func encodeToJSON() -> Any { self } } @@ -46,7 +53,7 @@ extension UUID: JSONEncodable { } extension RawRepresentable where RawValue: JSONEncodable { - func encodeToJSON() -> Any { return rawValue } + func encodeToJSON() -> Any { rawValue } } private func encodeIfPossible(_ object: T) -> Any { @@ -59,13 +66,13 @@ private func encodeIfPossible(_ object: T) -> Any { extension Array: JSONEncodable { func encodeToJSON() -> Any { - return map(encodeIfPossible) + map(encodeIfPossible) } } extension Set: JSONEncodable { func encodeToJSON() -> Any { - return Array(self).encodeToJSON() + Array(self).encodeToJSON() } } @@ -81,13 +88,13 @@ extension Dictionary: JSONEncodable { extension Data: JSONEncodable { func encodeToJSON() -> Any { - return base64EncodedString(options: Data.Base64EncodingOptions()) + base64EncodedString(options: Data.Base64EncodingOptions()) } } extension Date: JSONEncodable { func encodeToJSON() -> Any { - return CodableHelper.dateFormatter.string(from: self) + CodableHelper.dateFormatter.string(from: self) } } @@ -102,7 +109,7 @@ extension JSONEncodable where Self: Encodable { extension String: CodingKey { public var stringValue: String { - return self + self } public init?(stringValue: String) { @@ -110,11 +117,11 @@ extension String: CodingKey { } public var intValue: Int? { - return nil + nil } public init?(intValue _: Int) { - return nil + nil } } @@ -141,6 +148,18 @@ public extension KeyedEncodingContainerProtocol { try encodeMap(pairs) } } + + mutating func encode(_ value: Decimal, forKey key: Self.Key) throws { + var mutableValue = value + let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US")) + try encode(stringValue, forKey: key) + } + + mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws { + if let value = value { + try encode(value, forKey: key) + } + } } public extension KeyedDecodingContainerProtocol { @@ -178,10 +197,32 @@ public extension KeyedDecodingContainerProtocol { return map } + + func decode(_ type: Decimal.Type, forKey key: Self.Key) throws -> Decimal { + let stringValue = try decode(String.self, forKey: key) + guard let decimalValue = Decimal(string: stringValue) else { + let context = DecodingError.Context(codingPath: [key], debugDescription: "The key \(key) couldn't be converted to a Decimal value") + throw DecodingError.typeMismatch(type, context) + } + + return decimalValue + } + + func decodeIfPresent(_ type: Decimal.Type, forKey key: Self.Key) throws -> Decimal? { + guard let stringValue = try decodeIfPresent(String.self, forKey: key) else { + return nil + } + guard let decimalValue = Decimal(string: stringValue) else { + let context = DecodingError.Context(codingPath: [key], debugDescription: "The key \(key) couldn't be converted to a Decimal value") + throw DecodingError.typeMismatch(type, context) + } + + return decimalValue + } } extension HTTPURLResponse { var isStatusCodeSuccessful: Bool { - return (200 ..< 300).contains(statusCode) + Configuration.successfulStatusCodeRange.contains(statusCode) } } diff --git a/Sources/Traq/JSONDataEncoding.swift b/Sources/Traq/JSONDataEncoding.swift index bb9a75a..1754c18 100644 --- a/Sources/Traq/JSONDataEncoding.swift +++ b/Sources/Traq/JSONDataEncoding.swift @@ -6,6 +6,9 @@ // import Foundation +#if canImport(FoundationNetworking) + import FoundationNetworking +#endif public struct JSONDataEncoding { // MARK: Properties diff --git a/Sources/Traq/Models.swift b/Sources/Traq/Models.swift index 2a0f975..fdae51b 100644 --- a/Sources/Traq/Models.swift +++ b/Sources/Traq/Models.swift @@ -5,6 +5,9 @@ // import Foundation +#if canImport(FoundationNetworking) + import FoundationNetworking +#endif protocol JSONEncodable { func encodeToJSON() -> Any @@ -86,33 +89,40 @@ open class Response { public let statusCode: Int public let header: [String: String] public let body: T + public let bodyData: Data? - public init(statusCode: Int, header: [String: String], body: T) { + public init(statusCode: Int, header: [String: String], body: T, bodyData: Data?) { self.statusCode = statusCode self.header = header self.body = body + self.bodyData = bodyData } - public convenience init(response: HTTPURLResponse, body: T) { + public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) { let rawHeader = response.allHeaderFields - var header = [String: String]() + var responseHeader = [String: String]() for (key, value) in rawHeader { if let key = key.base as? String, let value = value as? String { - header[key] = value + responseHeader[key] = value } } - self.init(statusCode: response.statusCode, header: header, body: body) + self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData) } } -public final class RequestTask { +public final class RequestTask: @unchecked Sendable { + private var lock = NSRecursiveLock() private var task: URLSessionTask? internal func set(task: URLSessionTask) { + lock.lock() + defer { lock.unlock() } self.task = task } public func cancel() { + lock.lock() + defer { lock.unlock() } task?.cancel() task = nil } diff --git a/Sources/Traq/Models/Bot.swift b/Sources/Traq/Models/Bot.swift index 96b0240..e10259a 100644 --- a/Sources/Traq/Models/Bot.swift +++ b/Sources/Traq/Models/Bot.swift @@ -16,6 +16,7 @@ public typealias Bot = TraqAPI.Bot public extension TraqAPI { /** BOT情報 */ struct Bot: Codable, JSONEncodable, Hashable { + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** BOT UUID */ public var id: UUID /** BOTユーザーUUID */ diff --git a/Sources/Traq/Models/BotDetail.swift b/Sources/Traq/Models/BotDetail.swift index 7fdbfa4..44f82c3 100644 --- a/Sources/Traq/Models/BotDetail.swift +++ b/Sources/Traq/Models/BotDetail.swift @@ -16,6 +16,7 @@ public typealias BotDetail = TraqAPI.BotDetail public extension TraqAPI { /** BOT詳細情報 */ struct BotDetail: Codable, JSONEncodable, Hashable { + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** BOT UUID */ public var id: UUID /** 更新日時 */ diff --git a/Sources/Traq/Models/Channel.swift b/Sources/Traq/Models/Channel.swift index 8f338a7..7e5b6de 100644 --- a/Sources/Traq/Models/Channel.swift +++ b/Sources/Traq/Models/Channel.swift @@ -16,6 +16,7 @@ public typealias Channel = TraqAPI.Channel public extension TraqAPI { /** チャンネル */ struct Channel: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9-_]{1,20}$/") /** チャンネルUUID */ public var id: UUID /** 親チャンネルUUID */ diff --git a/Sources/Traq/Models/ClipFolder.swift b/Sources/Traq/Models/ClipFolder.swift index 2b2a61a..cd8355d 100644 --- a/Sources/Traq/Models/ClipFolder.swift +++ b/Sources/Traq/Models/ClipFolder.swift @@ -16,6 +16,8 @@ public typealias ClipFolder = TraqAPI.ClipFolder public extension TraqAPI { /** クリップフォルダ情報 */ struct ClipFolder: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: 1, maxLength: 30, pattern: nil) + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** フォルダUUID */ public var id: UUID /** フォルダ名 */ diff --git a/Sources/Traq/Models/MyUserDetail.swift b/Sources/Traq/Models/MyUserDetail.swift index d729910..555f5b7 100644 --- a/Sources/Traq/Models/MyUserDetail.swift +++ b/Sources/Traq/Models/MyUserDetail.swift @@ -16,6 +16,10 @@ public typealias MyUserDetail = TraqAPI.MyUserDetail public extension TraqAPI { /** 自分のユーザー詳細情報 */ struct MyUserDetail: Codable, JSONEncodable, Hashable { + static let bioRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) + static let twitterIdRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9_]{1,15}$/") + static let nameRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9_-]{1,32}$/") + static let displayNameRule = StringRule(minLength: 0, maxLength: 32, pattern: nil) /** ユーザーUUID */ public var id: UUID /** 自己紹介(biography) */ diff --git a/Sources/Traq/Models/OAuth2Client.swift b/Sources/Traq/Models/OAuth2Client.swift index 6b8fd52..abf366c 100644 --- a/Sources/Traq/Models/OAuth2Client.swift +++ b/Sources/Traq/Models/OAuth2Client.swift @@ -16,6 +16,8 @@ public typealias OAuth2Client = TraqAPI.OAuth2Client public extension TraqAPI { /** OAuth2クライアント情報 */ struct OAuth2Client: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: 1, maxLength: 32, pattern: nil) + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** クライアントUUID */ public var id: String /** クライアント名 */ diff --git a/Sources/Traq/Models/OAuth2ClientDetail.swift b/Sources/Traq/Models/OAuth2ClientDetail.swift index 4a90d37..5b71df5 100644 --- a/Sources/Traq/Models/OAuth2ClientDetail.swift +++ b/Sources/Traq/Models/OAuth2ClientDetail.swift @@ -16,6 +16,8 @@ public typealias OAuth2ClientDetail = TraqAPI.OAuth2ClientDetail public extension TraqAPI { /** OAuth2クライアント詳細情報 */ struct OAuth2ClientDetail: Codable, JSONEncodable, Hashable { + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) + static let nameRule = StringRule(minLength: 1, maxLength: 32, pattern: nil) /** クライアントUUID */ public var id: String /** クライアント開発者UUID */ diff --git a/Sources/Traq/Models/PatchBotRequest.swift b/Sources/Traq/Models/PatchBotRequest.swift index a042952..61e6564 100644 --- a/Sources/Traq/Models/PatchBotRequest.swift +++ b/Sources/Traq/Models/PatchBotRequest.swift @@ -16,6 +16,8 @@ public typealias PatchBotRequest = TraqAPI.PatchBotRequest public extension TraqAPI { /** BOT情報変更リクエスト */ struct PatchBotRequest: Codable, JSONEncodable, Hashable { + static let displayNameRule = StringRule(minLength: nil, maxLength: 32, pattern: nil) + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** BOTユーザー表示名 */ public var displayName: String? /** BOTの説明 */ diff --git a/Sources/Traq/Models/PatchChannelRequest.swift b/Sources/Traq/Models/PatchChannelRequest.swift index 1657551..a4a40c2 100644 --- a/Sources/Traq/Models/PatchChannelRequest.swift +++ b/Sources/Traq/Models/PatchChannelRequest.swift @@ -16,6 +16,7 @@ public typealias PatchChannelRequest = TraqAPI.PatchChannelRequest public extension TraqAPI { /** チャンネル情報変更リクエスト */ struct PatchChannelRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9-_]{1,20}$/") /** チャンネル名 */ public var name: String? /** アーカイブされているかどうか */ diff --git a/Sources/Traq/Models/PatchClientRequest.swift b/Sources/Traq/Models/PatchClientRequest.swift index 52d4410..391820f 100644 --- a/Sources/Traq/Models/PatchClientRequest.swift +++ b/Sources/Traq/Models/PatchClientRequest.swift @@ -16,6 +16,8 @@ public typealias PatchClientRequest = TraqAPI.PatchClientRequest public extension TraqAPI { /** OAuth2クライアント情報変更リクエスト */ struct PatchClientRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: 1, maxLength: 32, pattern: nil) + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** クライアント名 */ public var name: String? /** 説明 */ diff --git a/Sources/Traq/Models/PatchClipFolderRequest.swift b/Sources/Traq/Models/PatchClipFolderRequest.swift index 8c71fe1..e0b6078 100644 --- a/Sources/Traq/Models/PatchClipFolderRequest.swift +++ b/Sources/Traq/Models/PatchClipFolderRequest.swift @@ -16,6 +16,8 @@ public typealias PatchClipFolderRequest = TraqAPI.PatchClipFolderRequest public extension TraqAPI { /** クリップフォルダ情報編集リクエスト */ struct PatchClipFolderRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: 1, maxLength: 30, pattern: nil) + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** フォルダ名 */ public var name: String? /** 説明 */ diff --git a/Sources/Traq/Models/PatchGroupMemberRequest.swift b/Sources/Traq/Models/PatchGroupMemberRequest.swift index d6f45ca..86e476e 100644 --- a/Sources/Traq/Models/PatchGroupMemberRequest.swift +++ b/Sources/Traq/Models/PatchGroupMemberRequest.swift @@ -16,6 +16,7 @@ public typealias PatchGroupMemberRequest = TraqAPI.PatchGroupMemberRequest public extension TraqAPI { /** ユーザーグループメンバー編集リクエスト */ struct PatchGroupMemberRequest: Codable, JSONEncodable, Hashable { + static let roleRule = StringRule(minLength: nil, maxLength: 100, pattern: nil) /** ユーザーの役割 */ public var role: String diff --git a/Sources/Traq/Models/PatchMeRequest.swift b/Sources/Traq/Models/PatchMeRequest.swift index 5efce32..51c66d7 100644 --- a/Sources/Traq/Models/PatchMeRequest.swift +++ b/Sources/Traq/Models/PatchMeRequest.swift @@ -16,6 +16,9 @@ public typealias PatchMeRequest = TraqAPI.PatchMeRequest public extension TraqAPI { /** 自分のユーザー情報変更リクエスト */ struct PatchMeRequest: Codable, JSONEncodable, Hashable { + static let displayNameRule = StringRule(minLength: 0, maxLength: 32, pattern: nil) + static let twitterIdRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9_]{1,15}$/") + static let bioRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** 新しい表示名 */ public var displayName: String? /** TwitterID */ diff --git a/Sources/Traq/Models/PatchStampPaletteRequest.swift b/Sources/Traq/Models/PatchStampPaletteRequest.swift index 880c8bd..cb0cc62 100644 --- a/Sources/Traq/Models/PatchStampPaletteRequest.swift +++ b/Sources/Traq/Models/PatchStampPaletteRequest.swift @@ -16,6 +16,8 @@ public typealias PatchStampPaletteRequest = TraqAPI.PatchStampPaletteRequest public extension TraqAPI { /** スタンプパレット情報変更リクエスト */ struct PatchStampPaletteRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: 1, maxLength: 30, pattern: nil) + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** パレット名 */ public var name: String? /** 説明 */ diff --git a/Sources/Traq/Models/PatchStampRequest.swift b/Sources/Traq/Models/PatchStampRequest.swift index 36a8201..6750fb3 100644 --- a/Sources/Traq/Models/PatchStampRequest.swift +++ b/Sources/Traq/Models/PatchStampRequest.swift @@ -16,6 +16,7 @@ public typealias PatchStampRequest = TraqAPI.PatchStampRequest public extension TraqAPI { /** スタンプ情報変更リクエスト */ struct PatchStampRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9_-]{1,32}$/") /** スタンプ名 */ public var name: String? /** 作成者UUID */ diff --git a/Sources/Traq/Models/PatchUserGroupRequest.swift b/Sources/Traq/Models/PatchUserGroupRequest.swift index c203210..8383425 100644 --- a/Sources/Traq/Models/PatchUserGroupRequest.swift +++ b/Sources/Traq/Models/PatchUserGroupRequest.swift @@ -16,6 +16,7 @@ public typealias PatchUserGroupRequest = TraqAPI.PatchUserGroupRequest public extension TraqAPI { /** ユーザーグループ編集リクエスト */ struct PatchUserGroupRequest: Codable, JSONEncodable, Hashable { + static let descriptionRule = StringRule(minLength: nil, maxLength: 100, pattern: nil) /** グループ名 */ public var name: String? /** グループ説明 */ diff --git a/Sources/Traq/Models/PatchUserRequest.swift b/Sources/Traq/Models/PatchUserRequest.swift index 119b41c..d435db3 100644 --- a/Sources/Traq/Models/PatchUserRequest.swift +++ b/Sources/Traq/Models/PatchUserRequest.swift @@ -16,6 +16,8 @@ public typealias PatchUserRequest = TraqAPI.PatchUserRequest public extension TraqAPI { /** ユーザー情報編集リクエスト */ struct PatchUserRequest: Codable, JSONEncodable, Hashable { + static let displayNameRule = StringRule(minLength: nil, maxLength: 32, pattern: nil) + static let twitterIdRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9_]{1,15}$/") /** 新しい表示名 */ public var displayName: String? /** TwitterID */ diff --git a/Sources/Traq/Models/PatchWebhookRequest.swift b/Sources/Traq/Models/PatchWebhookRequest.swift index acbb86e..6c0b2b0 100644 --- a/Sources/Traq/Models/PatchWebhookRequest.swift +++ b/Sources/Traq/Models/PatchWebhookRequest.swift @@ -16,6 +16,9 @@ public typealias PatchWebhookRequest = TraqAPI.PatchWebhookRequest public extension TraqAPI { /** Webhook情報変更リクエスト */ struct PatchWebhookRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: 1, maxLength: 32, pattern: nil) + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) + static let secretRule = StringRule(minLength: nil, maxLength: 50, pattern: nil) /** Webhookユーザー表示名 */ public var name: String? /** 説明 */ diff --git a/Sources/Traq/Models/PostBotRequest.swift b/Sources/Traq/Models/PostBotRequest.swift index 77fcaab..b8fc3b5 100644 --- a/Sources/Traq/Models/PostBotRequest.swift +++ b/Sources/Traq/Models/PostBotRequest.swift @@ -16,6 +16,9 @@ public typealias PostBotRequest = TraqAPI.PostBotRequest public extension TraqAPI { /** BOT作成リクエスト */ struct PostBotRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: nil, maxLength: 16, pattern: "/^[a-zA-Z0-9_-]{1,16}$/") + static let displayNameRule = StringRule(minLength: nil, maxLength: 32, pattern: nil) + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** BOTユーザーID 自動的に接頭辞\"BOT_\"が付与されます */ public var name: String /** BOTユーザー表示名 */ diff --git a/Sources/Traq/Models/PostChannelRequest.swift b/Sources/Traq/Models/PostChannelRequest.swift index b33cea3..1fd5f3c 100644 --- a/Sources/Traq/Models/PostChannelRequest.swift +++ b/Sources/Traq/Models/PostChannelRequest.swift @@ -16,6 +16,7 @@ public typealias PostChannelRequest = TraqAPI.PostChannelRequest public extension TraqAPI { /** チャンネル作成リクエスト */ struct PostChannelRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9-_]{1,20}$/") /** チャンネル名 */ public var name: String /** 親チャンネルのUUID ルートに作成する場合はnullを指定 */ diff --git a/Sources/Traq/Models/PostClientRequest.swift b/Sources/Traq/Models/PostClientRequest.swift index d7f2ff3..541e941 100644 --- a/Sources/Traq/Models/PostClientRequest.swift +++ b/Sources/Traq/Models/PostClientRequest.swift @@ -16,6 +16,8 @@ public typealias PostClientRequest = TraqAPI.PostClientRequest public extension TraqAPI { /** OAuth2クライアント作成リクエスト */ struct PostClientRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: 1, maxLength: 32, pattern: nil) + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** クライアント名 */ public var name: String /** コールバックURL */ diff --git a/Sources/Traq/Models/PostClipFolderRequest.swift b/Sources/Traq/Models/PostClipFolderRequest.swift index af0b214..ae197fb 100644 --- a/Sources/Traq/Models/PostClipFolderRequest.swift +++ b/Sources/Traq/Models/PostClipFolderRequest.swift @@ -16,6 +16,8 @@ public typealias PostClipFolderRequest = TraqAPI.PostClipFolderRequest public extension TraqAPI { /** クリップフォルダ作成リクエスト */ struct PostClipFolderRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: 1, maxLength: 30, pattern: nil) + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** フォルダ名 */ public var name: String /** 説明 */ diff --git a/Sources/Traq/Models/PostLoginRequest.swift b/Sources/Traq/Models/PostLoginRequest.swift index 8e38a5b..72f4c0b 100644 --- a/Sources/Traq/Models/PostLoginRequest.swift +++ b/Sources/Traq/Models/PostLoginRequest.swift @@ -16,6 +16,8 @@ public typealias PostLoginRequest = TraqAPI.PostLoginRequest public extension TraqAPI { /** ログインリクエスト */ struct PostLoginRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9_-]{1,32}$/") + static let passwordRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[\\\\x20-\\\\x7E]{10,32}$/") /** ユーザー名 */ public var name: String /** パスワード */ diff --git a/Sources/Traq/Models/PostMessageRequest.swift b/Sources/Traq/Models/PostMessageRequest.swift index 1ae1e59..25e8f2c 100644 --- a/Sources/Traq/Models/PostMessageRequest.swift +++ b/Sources/Traq/Models/PostMessageRequest.swift @@ -16,6 +16,7 @@ public typealias PostMessageRequest = TraqAPI.PostMessageRequest public extension TraqAPI { /** メッセージ投稿リクエスト */ struct PostMessageRequest: Codable, JSONEncodable, Hashable { + static let contentRule = StringRule(minLength: 1, maxLength: 10000, pattern: nil) /** メッセージ本文 */ public var content: String /** メンション・チャンネルリンクを自動埋め込みするか */ diff --git a/Sources/Traq/Models/PostMessageStampRequest.swift b/Sources/Traq/Models/PostMessageStampRequest.swift index 91c23e5..c661315 100644 --- a/Sources/Traq/Models/PostMessageStampRequest.swift +++ b/Sources/Traq/Models/PostMessageStampRequest.swift @@ -16,6 +16,7 @@ public typealias PostMessageStampRequest = TraqAPI.PostMessageStampRequest public extension TraqAPI { /** スタンプを押すリクエスト */ struct PostMessageStampRequest: Codable, JSONEncodable, Hashable { + static let countRule = NumericRule(minimum: 1, exclusiveMinimum: false, maximum: 100, exclusiveMaximum: false, multipleOf: nil) /** 押す数 */ public var count: Int diff --git a/Sources/Traq/Models/PostStampPaletteRequest.swift b/Sources/Traq/Models/PostStampPaletteRequest.swift index f680959..e333873 100644 --- a/Sources/Traq/Models/PostStampPaletteRequest.swift +++ b/Sources/Traq/Models/PostStampPaletteRequest.swift @@ -16,6 +16,8 @@ public typealias PostStampPaletteRequest = TraqAPI.PostStampPaletteRequest public extension TraqAPI { /** スタンプパレット作成リクエスト */ struct PostStampPaletteRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: nil, maxLength: 30, pattern: nil) + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** パレット内のスタンプのUUID配列 */ public var stamps: Set /** パレット名 */ diff --git a/Sources/Traq/Models/PostUserGroupRequest.swift b/Sources/Traq/Models/PostUserGroupRequest.swift index 38e63a2..7c70498 100644 --- a/Sources/Traq/Models/PostUserGroupRequest.swift +++ b/Sources/Traq/Models/PostUserGroupRequest.swift @@ -16,6 +16,7 @@ public typealias PostUserGroupRequest = TraqAPI.PostUserGroupRequest public extension TraqAPI { /** ユーザーグループ作成リクエスト */ struct PostUserGroupRequest: Codable, JSONEncodable, Hashable { + static let descriptionRule = StringRule(minLength: nil, maxLength: 100, pattern: nil) /** グループ名 */ public var name: String /** 説明 */ diff --git a/Sources/Traq/Models/PostUserRequest.swift b/Sources/Traq/Models/PostUserRequest.swift index cce028b..38bc464 100644 --- a/Sources/Traq/Models/PostUserRequest.swift +++ b/Sources/Traq/Models/PostUserRequest.swift @@ -16,6 +16,8 @@ public typealias PostUserRequest = TraqAPI.PostUserRequest public extension TraqAPI { /** ユーザー登録リクエスト */ struct PostUserRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9_-]{1,32}$/") + static let passwordRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[\\\\x20-\\\\x7E]{10,32}$/") /** ユーザー名 */ public var name: String /** パスワード */ diff --git a/Sources/Traq/Models/PostUserTagRequest.swift b/Sources/Traq/Models/PostUserTagRequest.swift index 737249a..395c11d 100644 --- a/Sources/Traq/Models/PostUserTagRequest.swift +++ b/Sources/Traq/Models/PostUserTagRequest.swift @@ -16,6 +16,7 @@ public typealias PostUserTagRequest = TraqAPI.PostUserTagRequest public extension TraqAPI { /** ユーザータグ追加リクエスト */ struct PostUserTagRequest: Codable, JSONEncodable, Hashable { + static let tagRule = StringRule(minLength: 1, maxLength: 30, pattern: nil) /** タグ文字列 */ public var tag: String diff --git a/Sources/Traq/Models/PostWebhookRequest.swift b/Sources/Traq/Models/PostWebhookRequest.swift index f5a2ee9..7c90398 100644 --- a/Sources/Traq/Models/PostWebhookRequest.swift +++ b/Sources/Traq/Models/PostWebhookRequest.swift @@ -16,6 +16,9 @@ public typealias PostWebhookRequest = TraqAPI.PostWebhookRequest public extension TraqAPI { /** Webhook作成リクエスト */ struct PostWebhookRequest: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: 1, maxLength: 32, pattern: nil) + static let descriptionRule = StringRule(minLength: 1, maxLength: 1000, pattern: nil) + static let secretRule = StringRule(minLength: nil, maxLength: 50, pattern: nil) /** Webhookユーザーの表示名 */ public var name: String /** 説明 */ diff --git a/Sources/Traq/Models/PutChannelTopicRequest.swift b/Sources/Traq/Models/PutChannelTopicRequest.swift index 292c051..2111190 100644 --- a/Sources/Traq/Models/PutChannelTopicRequest.swift +++ b/Sources/Traq/Models/PutChannelTopicRequest.swift @@ -16,6 +16,7 @@ public typealias PutChannelTopicRequest = TraqAPI.PutChannelTopicRequest public extension TraqAPI { /** チャンネルトピック編集リクエスト */ struct PutChannelTopicRequest: Codable, JSONEncodable, Hashable { + static let topicRule = StringRule(minLength: nil, maxLength: 200, pattern: nil) /** トピック */ public var topic: String diff --git a/Sources/Traq/Models/PutMyPasswordRequest.swift b/Sources/Traq/Models/PutMyPasswordRequest.swift index c9da6f2..0033da3 100644 --- a/Sources/Traq/Models/PutMyPasswordRequest.swift +++ b/Sources/Traq/Models/PutMyPasswordRequest.swift @@ -16,6 +16,8 @@ public typealias PutMyPasswordRequest = TraqAPI.PutMyPasswordRequest public extension TraqAPI { /** パスワード変更リクエスト */ struct PutMyPasswordRequest: Codable, JSONEncodable, Hashable { + static let passwordRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[\\x20-\\x7E]{10,32}$/") + static let newPasswordRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[\\x20-\\x7E]{10,32}$/") /** 現在のパスワード */ public var password: String /** 新しいパスワード */ diff --git a/Sources/Traq/Models/PutUserPasswordRequest.swift b/Sources/Traq/Models/PutUserPasswordRequest.swift index 2e94ac1..0784a80 100644 --- a/Sources/Traq/Models/PutUserPasswordRequest.swift +++ b/Sources/Traq/Models/PutUserPasswordRequest.swift @@ -16,6 +16,7 @@ public typealias PutUserPasswordRequest = TraqAPI.PutUserPasswordRequest public extension TraqAPI { /** ユーザーパスワード変更リクエスト */ struct PutUserPasswordRequest: Codable, JSONEncodable, Hashable { + static let newPasswordRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[\\x20-\\x7E]{10,32}$/") /** 新しいパスワード */ public var newPassword: String diff --git a/Sources/Traq/Models/Stamp.swift b/Sources/Traq/Models/Stamp.swift index 8095586..bdf9058 100644 --- a/Sources/Traq/Models/Stamp.swift +++ b/Sources/Traq/Models/Stamp.swift @@ -16,6 +16,7 @@ public typealias Stamp = TraqAPI.Stamp public extension TraqAPI { /** スタンプ情報 */ struct Stamp: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9_-]{1,32}$/") /** スタンプUUID */ public var id: UUID /** スタンプ名 */ diff --git a/Sources/Traq/Models/StampPalette.swift b/Sources/Traq/Models/StampPalette.swift index 08284cd..82687fd 100644 --- a/Sources/Traq/Models/StampPalette.swift +++ b/Sources/Traq/Models/StampPalette.swift @@ -16,6 +16,8 @@ public typealias StampPalette = TraqAPI.StampPalette public extension TraqAPI { /** スタンプパレット情報 */ struct StampPalette: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: nil, maxLength: 30, pattern: nil) + static let descriptionRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** スタンプパレットUUID */ public var id: UUID /** パレット名 */ diff --git a/Sources/Traq/Models/Tag.swift b/Sources/Traq/Models/Tag.swift index 3b65f14..278b806 100644 --- a/Sources/Traq/Models/Tag.swift +++ b/Sources/Traq/Models/Tag.swift @@ -16,6 +16,7 @@ public typealias Tag = TraqAPI.Tag public extension TraqAPI { /** タグ情報 */ struct Tag: Codable, JSONEncodable, Hashable { + static let tagRule = StringRule(minLength: 1, maxLength: 30, pattern: nil) /** タグUUID */ public var id: UUID /** タグ文字列 */ diff --git a/Sources/Traq/Models/User.swift b/Sources/Traq/Models/User.swift index 7e5d7fa..f114618 100644 --- a/Sources/Traq/Models/User.swift +++ b/Sources/Traq/Models/User.swift @@ -16,6 +16,8 @@ public typealias User = TraqAPI.User public extension TraqAPI { /** ユーザー情報 */ struct User: Codable, JSONEncodable, Hashable { + static let nameRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9_-]{1,32}$/") + static let displayNameRule = StringRule(minLength: 0, maxLength: 32, pattern: nil) /** ユーザーUUID */ public var id: UUID /** ユーザー名 */ diff --git a/Sources/Traq/Models/UserDetail.swift b/Sources/Traq/Models/UserDetail.swift index 6b03218..5497ffa 100644 --- a/Sources/Traq/Models/UserDetail.swift +++ b/Sources/Traq/Models/UserDetail.swift @@ -16,6 +16,10 @@ public typealias UserDetail = TraqAPI.UserDetail public extension TraqAPI { /** ユーザー詳細情報 */ struct UserDetail: Codable, JSONEncodable, Hashable { + static let displayNameRule = StringRule(minLength: 0, maxLength: 32, pattern: nil) + static let nameRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9_-]{1,32}$/") + static let twitterIdRule = StringRule(minLength: nil, maxLength: nil, pattern: "/^[a-zA-Z0-9_]{0,15}$/") + static let bioRule = StringRule(minLength: nil, maxLength: 1000, pattern: nil) /** ユーザーUUID */ public var id: UUID public var state: UserAccountState diff --git a/Sources/Traq/Models/UserGroupMember.swift b/Sources/Traq/Models/UserGroupMember.swift index 9ee6109..d7ac7d4 100644 --- a/Sources/Traq/Models/UserGroupMember.swift +++ b/Sources/Traq/Models/UserGroupMember.swift @@ -16,6 +16,7 @@ public typealias UserGroupMember = TraqAPI.UserGroupMember public extension TraqAPI { /** ユーザーグループメンバー */ struct UserGroupMember: Codable, JSONEncodable, Hashable { + static let roleRule = StringRule(minLength: nil, maxLength: 100, pattern: nil) /** ユーザーUUID */ public var id: UUID /** ユーザーの役割 */ diff --git a/Sources/Traq/OpenISO8601DateFormatter.swift b/Sources/Traq/OpenISO8601DateFormatter.swift index e062080..cc32888 100644 --- a/Sources/Traq/OpenISO8601DateFormatter.swift +++ b/Sources/Traq/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/Sources/Traq/URLSessionImplementations.swift b/Sources/Traq/URLSessionImplementations.swift index 2d75616..95b1f72 100644 --- a/Sources/Traq/URLSessionImplementations.swift +++ b/Sources/Traq/URLSessionImplementations.swift @@ -10,18 +10,18 @@ import Foundation #endif public protocol URLSessionProtocol { - func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask + func dataTask(with request: URLRequest, completionHandler: @escaping @Sendable (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask } extension URLSession: URLSessionProtocol {} class URLSessionRequestBuilderFactory: RequestBuilderFactory { func getNonDecodableBuilder() -> RequestBuilder.Type { - return URLSessionRequestBuilder.self + URLSessionRequestBuilder.self } func getBuilder() -> RequestBuilder.Type { - return URLSessionDecodableRequestBuilder.self + URLSessionDecodableRequestBuilder.self } } @@ -45,17 +45,8 @@ open class URLSessionRequestBuilder: RequestBuilder { */ public var taskDidReceiveChallenge: TraqAPIChallengeHandler? - /** - May be assigned if you want to do any of those things: - - control the task completion - - intercept and handle errors like authorization - - retry the request. - */ - @available(*, deprecated, message: "Please override execute() method to intercept and handle errors like authorization or retry the request. Check the Wiki for more info. https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-do-i-implement-bearer-token-authentication-with-urlsession-on-the-swift-api-client") - public var taskCompletionShouldRetry: ((Data?, URLResponse?, Error?, @escaping (Bool) -> Void) -> Void)? - - public required init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:]) { - super.init(method: method, URLString: URLString, parameters: parameters, headers: headers) + public required init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool) { + super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication) } /** @@ -63,7 +54,7 @@ open class URLSessionRequestBuilder: RequestBuilder { configuration. */ open func createURLSession() -> URLSessionProtocol { - return defaultURLSession + defaultURLSession } /** @@ -74,14 +65,14 @@ open class URLSessionRequestBuilder: RequestBuilder { the file extension). Return the desired Content-Type otherwise. */ open func contentTypeForFormPart(fileURL _: URL) -> String? { - return nil + nil } /** May be overridden by a subclass if you want to control the URLRequest configuration (e.g. to override the cache policy). */ - open func createURLRequest(urlSession _: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers: [String: String]) throws -> URLRequest { + open func createURLRequest(urlSession _: URLSessionProtocol, method: HTTPMethod, encoding: ParameterEncoding, headers _: [String: String]) throws -> URLRequest { guard let url = URL(string: URLString) else { throw DownloadException.requestMissingURL } @@ -90,10 +81,6 @@ open class URLSessionRequestBuilder: RequestBuilder { originalRequest.httpMethod = method.rawValue - headers.forEach { key, value in - originalRequest.setValue(value, forHTTPHeaderField: key) - } - buildHeaders().forEach { key, value in originalRequest.setValue(value, forHTTPHeaderField: key) } @@ -120,12 +107,14 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType == "application/json" { + if contentType.hasPrefix("application/json") { encoding = JSONDataEncoding() - } else if contentType == "multipart/form-data" { + } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) - } else if contentType == "application/x-www-form-urlencoded" { + } else if contentType.hasPrefix("application/x-www-form-urlencoded") { encoding = FormURLEncoding() + } else if contentType.hasPrefix("application/octet-stream") { + encoding = OctetStreamEncoding() } else { fatalError("Unsupported Media Type - \(contentType)") } @@ -143,31 +132,13 @@ open class URLSessionRequestBuilder: RequestBuilder { } let dataTask = urlSession.dataTask(with: request) { data, response, error in - - if let taskCompletionShouldRetry = self.taskCompletionShouldRetry { - taskCompletionShouldRetry(data, response, error) { shouldRetry in - - if shouldRetry { - cleanupRequest() - self.execute(apiResponseQueue, completion) - } else { - apiResponseQueue.async { - self.processRequestResponse(urlRequest: request, data: data, response: response, error: error, completion: completion) - cleanupRequest() - } - } - } - } else { - apiResponseQueue.async { - self.processRequestResponse(urlRequest: request, data: data, response: response, error: error, completion: completion) - cleanupRequest() - } + apiResponseQueue.async { + self.processRequestResponse(urlRequest: request, data: data, response: response, error: error, completion: completion) + cleanupRequest() } } - if #available(iOS 11.0, macOS 10.13, macCatalyst 13.0, tvOS 11.0, watchOS 4.0, *) { - onProgressReady?(dataTask.progress) - } + onProgressReady?(dataTask.progress) taskIdentifier = dataTask.taskIdentifier challengeHandlerStore[dataTask.taskIdentifier] = taskDidReceiveChallenge @@ -204,7 +175,7 @@ open class URLSessionRequestBuilder: RequestBuilder { switch T.self { case is Void.Type: - completion(.success(Response(response: httpResponse, body: () as! T))) + completion(.success(Response(response: httpResponse, body: () as! T, bodyData: data))) default: fatalError("Unsupported Response Body Type - \(String(describing: T.self))") @@ -213,10 +184,10 @@ open class URLSessionRequestBuilder: RequestBuilder { open func buildHeaders() -> [String: String] { var httpHeaders: [String: String] = [:] - for (key, value) in headers { + for (key, value) in TraqAPI.customHeaders { httpHeaders[key] = value } - for (key, value) in TraqAPI.customHeaders { + for (key, value) in headers { httpHeaders[key] = value } return httpHeaders @@ -290,7 +261,7 @@ open class URLSessionDecodableRequestBuilder: URLSessionRequestBui let body = data.flatMap { String(data: $0, encoding: .utf8) } ?? "" - completion(.success(Response(response: httpResponse, body: body as! T))) + completion(.success(Response(response: httpResponse, body: body as! T, bodyData: data))) case is URL.Type: do { @@ -320,7 +291,7 @@ open class URLSessionDecodableRequestBuilder: URLSessionRequestBui try fileManager.createDirectory(atPath: directoryPath, withIntermediateDirectories: true, attributes: nil) try data.write(to: filePath, options: .atomic) - completion(.success(Response(response: httpResponse, body: filePath as! T))) + completion(.success(Response(response: httpResponse, body: filePath as! T, bodyData: data))) } catch let requestParserError as DownloadException { completion(.failure(ErrorResponse.error(400, data, response, requestParserError))) @@ -330,30 +301,30 @@ open class URLSessionDecodableRequestBuilder: URLSessionRequestBui case is Void.Type: - completion(.success(Response(response: httpResponse, body: () as! T))) + completion(.success(Response(response: httpResponse, body: () as! T, bodyData: data))) case is Data.Type: - completion(.success(Response(response: httpResponse, body: data as! T))) + completion(.success(Response(response: httpResponse, body: data as! T, bodyData: data))) default: - guard let data = data, !data.isEmpty else { - if T.self is ExpressibleByNilLiteral.Type { - completion(.success(Response(response: httpResponse, body: T?.none as! T))) + guard let unwrappedData = data, !unwrappedData.isEmpty else { + if let expressibleByNilLiteralType = T.self as? ExpressibleByNilLiteral.Type { + completion(.success(Response(response: httpResponse, body: expressibleByNilLiteralType.init(nilLiteral: ()) as! T, bodyData: data))) } else { completion(.failure(ErrorResponse.error(httpResponse.statusCode, nil, response, DecodableRequestBuilderError.emptyDataResponse))) } return } - let decodeResult = CodableHelper.decode(T.self, from: data) + let decodeResult = CodableHelper.decode(T.self, from: unwrappedData) switch decodeResult { case let .success(decodableObj): - completion(.success(Response(response: httpResponse, body: decodableObj))) + completion(.success(Response(response: httpResponse, body: decodableObj, bodyData: unwrappedData))) case let .failure(error): - completion(.failure(ErrorResponse.error(httpResponse.statusCode, data, response, error))) + completion(.failure(ErrorResponse.error(httpResponse.statusCode, unwrappedData, response, error))) } } } @@ -437,49 +408,62 @@ private class FormDataEncoding: ParameterEncoding { urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type") for (key, value) in parameters { - switch value { - case let fileURL as URL: + for value in value as? Array ?? [value] { + switch value { + case let fileURL as URL: - urlRequest = try configureFileUploadRequest( - urlRequest: urlRequest, - boundary: boundary, - name: key, - fileURL: fileURL - ) - - case let string as String: - - if let data = string.data(using: .utf8) { - urlRequest = configureDataUploadRequest( + urlRequest = try configureFileUploadRequest( urlRequest: urlRequest, boundary: boundary, name: key, - data: data + fileURL: fileURL ) - } - case let number as NSNumber: + case let string as String: + + if let data = string.data(using: .utf8) { + urlRequest = configureDataUploadRequest( + urlRequest: urlRequest, + boundary: boundary, + name: key, + data: data + ) + } + + case let number as NSNumber: + + if let data = number.stringValue.data(using: .utf8) { + urlRequest = configureDataUploadRequest( + urlRequest: urlRequest, + boundary: boundary, + name: key, + data: data + ) + } + + case let data as Data: - if let data = number.stringValue.data(using: .utf8) { urlRequest = configureDataUploadRequest( urlRequest: urlRequest, boundary: boundary, name: key, data: data ) - } - case let data as Data: + case let uuid as UUID: - urlRequest = configureDataUploadRequest( - urlRequest: urlRequest, - boundary: boundary, - name: key, - data: data - ) + if let data = uuid.uuidString.data(using: .utf8) { + urlRequest = configureDataUploadRequest( + urlRequest: urlRequest, + boundary: boundary, + name: key, + data: data + ) + } - default: - fatalError("Unprocessable value \(value) with key \(key)") + default: + fatalError("Unprocessable value \(value) with key \(key)") + } } } @@ -504,7 +488,7 @@ private class FormDataEncoding: ParameterEncoding { let fileName = fileURL.lastPathComponent // If we already added something then we need an additional newline. - if body.count > 0 { + if !body.isEmpty { body.append("\r\n") } @@ -532,7 +516,7 @@ private class FormDataEncoding: ParameterEncoding { var body = urlRequest.httpBody.orEmpty // If we already added something then we need an additional newline. - if body.count > 0 { + if !body.isEmpty { body.append("\r\n") } @@ -556,10 +540,10 @@ private class FormDataEncoding: ParameterEncoding { func mimeType(for url: URL) -> String { let pathExtension = url.pathExtension - if let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension as NSString, nil)?.takeRetainedValue() { - if let mimetype = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() { - return mimetype as String - } + if let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension as NSString, nil)?.takeRetainedValue(), + let mimetype = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() + { + return mimetype as String } return "application/octet-stream" } @@ -582,6 +566,23 @@ private class FormURLEncoding: ParameterEncoding { } } +private class OctetStreamEncoding: ParameterEncoding { + func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest { + var urlRequest = urlRequest + + var requestBodyComponents = URLComponents() + requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + + if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { + urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type") + } + + urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8) + + return urlRequest + } +} + private extension Data { /// Append string to Data /// diff --git a/Sources/Traq/Validation.swift b/Sources/Traq/Validation.swift new file mode 100644 index 0000000..0e490e6 --- /dev/null +++ b/Sources/Traq/Validation.swift @@ -0,0 +1,126 @@ +// Validation.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +public struct StringRule { + public var minLength: Int? + public var maxLength: Int? + public var pattern: String? +} + +public struct NumericRule { + public var minimum: T? + public var exclusiveMinimum = false + public var maximum: T? + public var exclusiveMaximum = false + public var multipleOf: T? +} + +public enum StringValidationErrorKind: Error { + case minLength, maxLength, pattern +} + +public enum NumericValidationErrorKind: Error { + case minimum, maximum, multipleOf +} + +public struct ValidationError: Error { + public fileprivate(set) var kinds: Set +} + +public enum Validator { + /// Validate a string against a rule. + /// - Parameter string: The String you wish to validate. + /// - Parameter rule: The StringRule you wish to use for validation. + /// - Returns: A validated string. + /// - Throws: `ValidationError` if the string is invalid against the rule, + /// `NSError` if the rule.pattern is invalid. + public static func validate(_ string: String, against rule: StringRule) throws -> String { + var error = ValidationError(kinds: []) + if let minLength = rule.minLength, !(minLength <= string.count) { + error.kinds.insert(.minLength) + } + if let maxLength = rule.maxLength, !(string.count <= maxLength) { + error.kinds.insert(.maxLength) + } + if let pattern = rule.pattern { + let matches = try NSRegularExpression(pattern: pattern, options: .caseInsensitive) + .matches(in: string, range: .init(location: 0, length: string.utf16.count)) + if matches.isEmpty { + error.kinds.insert(.pattern) + } + } + guard error.kinds.isEmpty else { + throw error + } + return string + } + + /// Validate a integer against a rule. + /// - Parameter numeric: The integer you wish to validate. + /// - Parameter rule: The NumericRule you wish to use for validation. + /// - Returns: A validated integer. + /// - Throws: `ValidationError` if the numeric is invalid against the rule. + public static func validate(_ numeric: T, against rule: NumericRule) throws -> T { + var error = ValidationError(kinds: []) + if let minium = rule.minimum { + if !rule.exclusiveMinimum, minium > numeric { + error.kinds.insert(.minimum) + } + if rule.exclusiveMinimum, minium >= numeric { + error.kinds.insert(.minimum) + } + } + if let maximum = rule.maximum { + if !rule.exclusiveMaximum, numeric > maximum { + error.kinds.insert(.maximum) + } + if rule.exclusiveMaximum, numeric >= maximum { + error.kinds.insert(.maximum) + } + } + if let multipleOf = rule.multipleOf, !numeric.isMultiple(of: multipleOf) { + error.kinds.insert(.multipleOf) + } + guard error.kinds.isEmpty else { + throw error + } + return numeric + } + + /// Validate a fractional number against a rule. + /// - Parameter numeric: The fractional number you wish to validate. + /// - Parameter rule: The NumericRule you wish to use for validation. + /// - Returns: A validated fractional number. + /// - Throws: `ValidationError` if the numeric is invalid against the rule. + public static func validate(_ numeric: T, against rule: NumericRule) throws -> T { + var error = ValidationError(kinds: []) + if let minium = rule.minimum { + if !rule.exclusiveMinimum, minium > numeric { + error.kinds.insert(.minimum) + } + if rule.exclusiveMinimum, minium >= numeric { + error.kinds.insert(.minimum) + } + } + if let maximum = rule.maximum { + if !rule.exclusiveMaximum, numeric > maximum { + error.kinds.insert(.maximum) + } + if rule.exclusiveMaximum, numeric >= maximum { + error.kinds.insert(.maximum) + } + } + if let multipleOf = rule.multipleOf, numeric.remainder(dividingBy: multipleOf) != 0 { + error.kinds.insert(.multipleOf) + } + guard error.kinds.isEmpty else { + throw error + } + return numeric + } +} diff --git a/Traq.podspec b/Traq.podspec index 97287d3..cacc7e0 100644 --- a/Traq.podspec +++ b/Traq.podspec @@ -1,9 +1,9 @@ Pod::Spec.new do |s| s.name = 'Traq' - s.ios.deployment_target = '9.0' - s.osx.deployment_target = '10.11' - s.tvos.deployment_target = '9.0' - s.watchos.deployment_target = '3.0' + s.ios.deployment_target = '11.0' + s.osx.deployment_target = '10.13' + s.tvos.deployment_target = '11.0' + s.watchos.deployment_target = '4.0' s.version = '3.0' s.source = { :git => 'git@github.com:OpenAPITools/openapi-generator.git', :tag => 'v3.0' } s.authors = 'OpenAPI Generator' @@ -11,5 +11,5 @@ Pod::Spec.new do |s| s.homepage = 'https://github.com/OpenAPITools/openapi-generator' s.summary = 'Traq Swift SDK' s.source_files = 'Sources/Traq/**/*.swift' - s.dependency 'AnyCodable-FlightSchool', '~> 0.6.1' + s.dependency 'AnyCodable-FlightSchool', '~> 0.6' end diff --git a/project.yml b/project.yml index 2218022..3ed5daf 100644 --- a/project.yml +++ b/project.yml @@ -3,7 +3,7 @@ targets: Traq: type: framework platform: iOS - deploymentTarget: "9.0" + deploymentTarget: "11.0" sources: [Sources] info: path: ./Info.plist