diff --git a/.dotfiles b/.dotfiles index 1e22a870..9d280efb 160000 --- a/.dotfiles +++ b/.dotfiles @@ -1 +1 @@ -Subproject commit 1e22a87058799e7d103b74a02663b37eaf0b85af +Subproject commit 9d280efb3bcec6d4576eb39105539ed13c6b7433 diff --git a/.swiftformat b/.swiftformat new file mode 120000 index 00000000..eb40906c --- /dev/null +++ b/.swiftformat @@ -0,0 +1 @@ +./.dotfiles/.swiftformat-base \ No newline at end of file diff --git a/BuildTools/Empty.swift b/BuildTools/Empty.swift index fecc4ab4..ca543ac3 100644 --- a/BuildTools/Empty.swift +++ b/BuildTools/Empty.swift @@ -1 +1,6 @@ +// Empty.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation diff --git a/Package.swift b/Package.swift index 6d05a000..24bc1e44 100644 --- a/Package.swift +++ b/Package.swift @@ -7,11 +7,11 @@ import PackageDescription // If CommonCrypto is not available, swift-crypto should be used. #if canImport(CommonCrypto) -let dependencies: [Package.Dependency] = [] -let tDependencies: [Target.Dependency] = [] + let dependencies: [Package.Dependency] = [] + let tDependencies: [Target.Dependency] = [] #else // for Linux -let dependencies: [Package.Dependency] = [.package(url: "https://github.com/apple/swift-crypto.git", from: "3.8.0")] -let tDependencies: [Target.Dependency] = [.product(name: "Crypto", package: "swift-crypto")] + let dependencies: [Package.Dependency] = [.package(url: "https://github.com/apple/swift-crypto.git", from: "3.8.0")] + let tDependencies: [Target.Dependency] = [.product(name: "Crypto", package: "swift-crypto")] #endif let package = Package( @@ -20,13 +20,14 @@ let package = Package( .macOS(.v10_14), .iOS(.v12), .tvOS(.v12), - .watchOS(.v6) + .watchOS(.v6), ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( name: "TwitterAPIKit", - targets: ["TwitterAPIKit"]), + targets: ["TwitterAPIKit"] + ), ], dependencies: dependencies, targets: [ @@ -34,9 +35,11 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "TwitterAPIKit", - dependencies: tDependencies), + dependencies: tDependencies + ), .testTarget( name: "TwitterAPIKitTests", - dependencies: ["TwitterAPIKit"]), + dependencies: ["TwitterAPIKit"] + ), ] ) diff --git a/Sources/TwitterAPIKit/APIv1/Account/AccountAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Account/AccountAPIv1.swift index 71f057a9..306edf82 100644 --- a/Sources/TwitterAPIKit/APIv1/Account/AccountAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Account/AccountAPIv1.swift @@ -1,53 +1,75 @@ +// AccountAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class AccountAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-account-settings + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// manage-account-settings/api-reference/get-account-settings public func getAccountSetting( _ request: GetAccountSettingsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-account-verify_credentials + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// manage-account-settings/api-reference/get-account-verify_credentials public func getAccountVerify( _ request: GetAccountVerifyCredentialsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-remove_profile_banner + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// manage-account-settings/api-reference/post-account-remove_profile_banner public func postRemoveProfileBanner( _ request: PostAccountRemoveProfileBannerRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-settings + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// manage-account-settings/api-reference/post-account-settings public func postAccountSettings( _ request: PostAccountSettingsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// manage-account-settings/api-reference/post-account-update_profile public func postAccountProfile( _ request: PostAccountUpdateProfileRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_banner + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// manage-account-settings/api-reference/post-account-update_profile_banner public func postProfileBanner( _ request: PostAccountUpdateProfileBannerRequestV1 ) -> TwitterAPISessionDataTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_image + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// manage-account-settings/api-reference/post-account-update_profile_image public func postProfileImage( _ request: PostAccountUpdateProfileImageRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Account/Requests/GetAccountSettingsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Account/Requests/GetAccountSettingsRequestV1.swift index ee05a441..988ee973 100644 --- a/Sources/TwitterAPIKit/APIv1/Account/Requests/GetAccountSettingsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Account/Requests/GetAccountSettingsRequestV1.swift @@ -1,8 +1,14 @@ +// GetAccountSettingsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-account-settings +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// manage-account-settings/api-reference/get-account-settings open class GetAccountSettingsRequestV1: TwitterAPIRequest { - public var method: HTTPMethod { return .get } @@ -15,6 +21,9 @@ open class GetAccountSettingsRequestV1: TwitterAPIRequest { return [:] } - public init() { + public init() {} + + deinit { + // De-init Logic Here } } diff --git a/Sources/TwitterAPIKit/APIv1/Account/Requests/GetAccountVerifyCredentialsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Account/Requests/GetAccountVerifyCredentialsRequestV1.swift index c6dc146f..babf9f05 100644 --- a/Sources/TwitterAPIKit/APIv1/Account/Requests/GetAccountVerifyCredentialsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Account/Requests/GetAccountVerifyCredentialsRequestV1.swift @@ -1,8 +1,14 @@ +// GetAccountVerifyCredentialsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-account-verify_credentials +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// manage-account-settings/api-reference/get-account-verify_credentials open class GetAccountVerifyCredentialsRequestV1: TwitterAPIRequest { - public let skipStatus: Bool? public let includeEmail: Bool? public let includeEntities: Bool? @@ -16,11 +22,11 @@ open class GetAccountVerifyCredentialsRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - skipStatus.map { p["skip_status"] = $0 } - includeEmail.map { p["include_email"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - return p + var params = [String: Any]() + skipStatus.map { params["skip_status"] = $0 } + includeEmail.map { params["include_email"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + return params } public init( @@ -32,4 +38,8 @@ open class GetAccountVerifyCredentialsRequestV1: TwitterAPIRequest { self.includeEmail = includeEmail self.includeEntities = includeEntities } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountRemoveProfileBannerRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountRemoveProfileBannerRequestV1.swift index 887caffa..66672a2c 100644 --- a/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountRemoveProfileBannerRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountRemoveProfileBannerRequestV1.swift @@ -1,8 +1,14 @@ +// PostAccountRemoveProfileBannerRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-remove_profile_banner +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// manage-account-settings/api-reference/post-account-remove_profile_banner open class PostAccountRemoveProfileBannerRequestV1: TwitterAPIRequest { - public var method: HTTPMethod { return .post } @@ -16,4 +22,8 @@ open class PostAccountRemoveProfileBannerRequestV1: TwitterAPIRequest { } public init() {} + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountSettingsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountSettingsRequestV1.swift index 801e0bae..fec4fc8f 100644 --- a/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountSettingsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountSettingsRequestV1.swift @@ -1,8 +1,14 @@ +// PostAccountSettingsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-settings +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// manage-account-settings/api-reference/post-account-settings open class PostAccountSettingsRequestV1: TwitterAPIRequest { - /// two letter ISO 639-1 public let lang: String? /// RailsTimeZone @@ -24,14 +30,14 @@ open class PostAccountSettingsRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - lang.map { p["lang"] = $0 } - timeZone.map { p["time_zone"] = $0 } - startSleepTime.map { p["start_sleep_time"] = $0 } - endSleepTime.map { p["end_sleep_time"] = $0 } - sleepTimeEnabled.map { p["sleep_time_enabled"] = $0 } - trendLocationWoeid.map { p["trend_location_woeid"] = $0 } - return p + var params = [String: Any]() + lang.map { params["lang"] = $0 } + timeZone.map { params["time_zone"] = $0 } + startSleepTime.map { params["start_sleep_time"] = $0 } + endSleepTime.map { params["end_sleep_time"] = $0 } + sleepTimeEnabled.map { params["sleep_time_enabled"] = $0 } + trendLocationWoeid.map { params["trend_location_woeid"] = $0 } + return params } public init( @@ -49,4 +55,8 @@ open class PostAccountSettingsRequestV1: TwitterAPIRequest { self.sleepTimeEnabled = sleepTimeEnabled self.trendLocationWoeid = trendLocationWoeid } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountUpdateProfileBannerRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountUpdateProfileBannerRequestV1.swift index 63fdf5c8..5cdd1984 100644 --- a/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountUpdateProfileBannerRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountUpdateProfileBannerRequestV1.swift @@ -1,8 +1,14 @@ +// PostAccountUpdateProfileBannerRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_banner +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// manage-account-settings/api-reference/post-account-update_profile_banner open class PostAccountUpdateProfileBannerRequestV1: TwitterAPIRequest { - public let banner: Data public let width: Int? public let height: Int? @@ -18,13 +24,13 @@ open class PostAccountUpdateProfileBannerRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["banner"] = banner.base64EncodedString() - width.map { p["width"] = $0 } - height.map { p["height"] = $0 } - offsetTop.map { p["offset_top"] = $0 } - offsetLeft.map { p["offset_left"] = $0 } - return p + var params = [String: Any]() + params["banner"] = banner.base64EncodedString() + width.map { params["width"] = $0 } + height.map { params["height"] = $0 } + offsetTop.map { params["offset_top"] = $0 } + offsetLeft.map { params["offset_left"] = $0 } + return params } public init( @@ -41,4 +47,7 @@ open class PostAccountUpdateProfileBannerRequestV1: TwitterAPIRequest { self.offsetLeft = offsetLeft } + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountUpdateProfileImageRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountUpdateProfileImageRequestV1.swift index c8adfb7d..960f40fe 100644 --- a/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountUpdateProfileImageRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountUpdateProfileImageRequestV1.swift @@ -1,8 +1,14 @@ +// PostAccountUpdateProfileImageRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_image +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// manage-account-settings/api-reference/post-account-update_profile_image open class PostAccountUpdateProfileImageRequestV1: TwitterAPIRequest { - public let image: Data public let skipStatus: Bool? public let includeEntities: Bool? @@ -16,11 +22,11 @@ open class PostAccountUpdateProfileImageRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["image"] = image.base64EncodedString() - skipStatus.map { p["skip_status"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - return p + var params = [String: Any]() + params["image"] = image.base64EncodedString() + skipStatus.map { params["skip_status"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + return params } public init( @@ -32,4 +38,8 @@ open class PostAccountUpdateProfileImageRequestV1: TwitterAPIRequest { self.skipStatus = skipStatus self.includeEntities = includeEntities } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountUpdateProfileRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountUpdateProfileRequestV1.swift index 35be905c..6b3f16c1 100644 --- a/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountUpdateProfileRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Account/Requests/PostAccountUpdateProfileRequestV1.swift @@ -1,8 +1,14 @@ +// PostAccountUpdateProfileRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// manage-account-settings/api-reference/post-account-update_profile open class PostAccountUpdateProfileRequestV1: TwitterAPIRequest { - public let url: String? public let name: String? public let location: String? @@ -21,15 +27,15 @@ open class PostAccountUpdateProfileRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - url.map { p["url"] = $0 } - name.map { p["name"] = $0 } - location.map { p["location"] = $0 } - skipStatus.map { p["skip_status"] = $0 } - description.map { p["description"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - profileLinkColor.map { p["profile_link_color"] = $0 } - return p + var params = [String: Any]() + url.map { params["url"] = $0 } + name.map { params["name"] = $0 } + location.map { params["location"] = $0 } + skipStatus.map { params["skip_status"] = $0 } + description.map { params["description"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + profileLinkColor.map { params["profile_link_color"] = $0 } + return params } public init( @@ -49,4 +55,8 @@ open class PostAccountUpdateProfileRequestV1: TwitterAPIRequest { self.includeEntities = includeEntities self.profileLinkColor = profileLinkColor } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Application/ApplicationAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Application/ApplicationAPIv1.swift index 9294a7fd..1b5f699d 100644 --- a/Sources/TwitterAPIKit/APIv1/Application/ApplicationAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Application/ApplicationAPIv1.swift @@ -1,11 +1,21 @@ +// ApplicationAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class ApplicationAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/developer-utilities/rate-limit-status/api-reference/get-application-rate_limit_status + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/developer-utilities/ + /// rate-limit-status/api-reference/get-application-rate_limit_status public func getRateLimit( _ request: GetApplicationRateLimitStatusRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Application/Requests/GetApplicationRateLimitStatusRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Application/Requests/GetApplicationRateLimitStatusRequestV1.swift index 19ecdd40..3b6717f2 100644 --- a/Sources/TwitterAPIKit/APIv1/Application/Requests/GetApplicationRateLimitStatusRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Application/Requests/GetApplicationRateLimitStatusRequestV1.swift @@ -1,8 +1,14 @@ +// GetApplicationRateLimitStatusRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/developer-utilities/rate-limit-status/api-reference/get-application-rate_limit_status +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/developer-utilities/ +/// rate-limit-status/api-reference/get-application-rate_limit_status open class GetApplicationRateLimitStatusRequestV1: TwitterAPIRequest { - public let resources: [String]? public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class GetApplicationRateLimitStatusRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - resources.map { p["resources"] = $0.joined(separator: ",") } - return p + var params = [String: Any]() + resources.map { params["resources"] = $0.joined(separator: ",") } + return params } public init( @@ -24,4 +30,7 @@ open class GetApplicationRateLimitStatusRequestV1: TwitterAPIRequest { ) { self.resources = resources } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/BlockAndMute/BlockAndMuteAPIv1.swift b/Sources/TwitterAPIKit/APIv1/BlockAndMute/BlockAndMuteAPIv1.swift index 8fdc8df0..9499b539 100644 --- a/Sources/TwitterAPIKit/APIv1/BlockAndMute/BlockAndMuteAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/BlockAndMute/BlockAndMuteAPIv1.swift @@ -1,67 +1,93 @@ +// BlockAndMuteAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class BlockAndMuteAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/get-blocks-ids + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/ + /// api-reference/get-blocks-ids public func getBlockIDs( _ request: GetBlocksIDsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/get-blocks-list + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/ + /// api-reference/get-blocks-list public func getBlockUsers( _ request: GetBlocksListRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/get-mutes-users-ids + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/ + /// api-reference/get-mutes-users-ids public func getMuteIDs( _ request: GetMutesUsersIDsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/get-mutes-users-list + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/ + /// api-reference/get-mutes-users-list public func getMuteUsers( _ request: GetMutesUsersListRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-blocks-create + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/ + /// api-reference/post-blocks-create public func postBlockUser( _ request: PostBlocksCreateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-blocks-destroy + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/ + /// api-reference/post-blocks-destroy public func postUnblockUser( _ request: PostBlocksDestroyRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-mutes-users-create + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/ + /// api-reference/post-mutes-users-create public func postMuteUser( _ request: PostMutesUsersCreateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-mutes-users-destroy + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/ + /// api-reference/post-mutes-users-destroy public func postUnmuteUser( _ request: PostMutesUsersDestroyRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-users-report_spam + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/ + /// api-reference/post-users-report_spam public func postReportSpam( _ request: PostUsersReportSpamRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetBlocksIDsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetBlocksIDsRequestV1.swift index 83b4bf19..fea6674d 100644 --- a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetBlocksIDsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetBlocksIDsRequestV1.swift @@ -1,24 +1,32 @@ +// GetBlocksIDsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/get-blocks-ids +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// mute-block-report-users/api-reference/get-blocks-ids open class GetBlocksIDsRequestV1: TwitterAPIRequest { - public let stringifyIDs: Bool? public let cursor: String? public var method: HTTPMethod { return .get } + public var path: String { return "/1.1/blocks/ids.json" } open var parameters: [String: Any] { - var p = [String: Any]() - stringifyIDs.map { p["stringify_ids"] = $0 } - cursor.map { p["cursor"] = $0 } - return p + var params = [String: Any]() + stringifyIDs.map { params["stringify_ids"] = $0 } + cursor.map { params["cursor"] = $0 } + return params } + public init( stringifyIDs: Bool? = .none, cursor: String? = .none @@ -26,4 +34,7 @@ open class GetBlocksIDsRequestV1: TwitterAPIRequest { self.stringifyIDs = stringifyIDs self.cursor = cursor } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetBlocksListRequestV1.swift b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetBlocksListRequestV1.swift index 3cf13afe..9acb6051 100644 --- a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetBlocksListRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetBlocksListRequestV1.swift @@ -1,8 +1,14 @@ +// GetBlocksListRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/get-blocks-list +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// mute-block-report-users/api-reference/get-blocks-list open class GetBlocksListRequestV1: TwitterAPIRequest { - public let includeEntities: Bool? public let skipStatus: Bool? public let cursor: String? @@ -16,11 +22,11 @@ open class GetBlocksListRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - includeEntities.map { p["include_entities"] = $0 } - skipStatus.map { p["skip_status"] = $0 } - cursor.map { p["cursor"] = $0 } - return p + var params = [String: Any]() + includeEntities.map { params["include_entities"] = $0 } + skipStatus.map { params["skip_status"] = $0 } + cursor.map { params["cursor"] = $0 } + return params } public init( @@ -32,4 +38,7 @@ open class GetBlocksListRequestV1: TwitterAPIRequest { self.skipStatus = skipStatus self.cursor = cursor } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetMutesUsersIDsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetMutesUsersIDsRequestV1.swift index e490cc6a..055e080f 100644 --- a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetMutesUsersIDsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetMutesUsersIDsRequestV1.swift @@ -1,23 +1,30 @@ +// GetMutesUsersIDsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/get-mutes-users-ids +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// mute-block-report-users/api-reference/get-mutes-users-ids open class GetMutesUsersIDsRequestV1: TwitterAPIRequest { - public let stringifyIDs: Bool? public let cursor: String? public var method: HTTPMethod { return .get } + public var path: String { return "/1.1/mutes/users/ids.json" } open var parameters: [String: Any] { - var p = [String: Any]() - stringifyIDs.map { p["stringify_ids"] = $0 } - cursor.map { p["cursor"] = $0 } - return p + var params = [String: Any]() + stringifyIDs.map { params["stringify_ids"] = $0 } + cursor.map { params["cursor"] = $0 } + return params } public init( @@ -27,4 +34,7 @@ open class GetMutesUsersIDsRequestV1: TwitterAPIRequest { self.stringifyIDs = stringifyIDs self.cursor = cursor } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetMutesUsersListRequestV1.swift b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetMutesUsersListRequestV1.swift index b42a8c6a..29ae1057 100644 --- a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetMutesUsersListRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/GetMutesUsersListRequestV1.swift @@ -1,8 +1,14 @@ +// GetMutesUsersListRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/get-mutes-users-list +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// mute-block-report-users/api-reference/get-mutes-users-list open class GetMutesUsersListRequestV1: TwitterAPIRequest { - public let cursor: String? public let includeEntities: Bool? public let skipStatus: Bool? @@ -10,16 +16,17 @@ open class GetMutesUsersListRequestV1: TwitterAPIRequest { public var method: HTTPMethod { return .get } + public var path: String { return "/1.1/mutes/users/list.json" } open var parameters: [String: Any] { - var p = [String: Any]() - cursor.map { p["cursor"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - skipStatus.map { p["skip_status"] = $0 } - return p + var params = [String: Any]() + cursor.map { params["cursor"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + skipStatus.map { params["skip_status"] = $0 } + return params } public init( @@ -31,4 +38,7 @@ open class GetMutesUsersListRequestV1: TwitterAPIRequest { self.includeEntities = includeEntities self.skipStatus = skipStatus } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostBlocksCreateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostBlocksCreateRequestV1.swift index f06c2986..98c48319 100644 --- a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostBlocksCreateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostBlocksCreateRequestV1.swift @@ -1,8 +1,14 @@ +// PostBlocksCreateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-blocks-create +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// mute-block-report-users/api-reference/post-blocks-create open class PostBlocksCreateRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let includeEntities: Bool? public let skipStatus: Bool? @@ -10,16 +16,17 @@ open class PostBlocksCreateRequestV1: TwitterAPIRequest { public var method: HTTPMethod { return .post } + public var path: String { return "/1.1/blocks/create.json" } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - includeEntities.map { p["include_entities"] = $0 } - skipStatus.map { p["skip_status"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + includeEntities.map { params["include_entities"] = $0 } + skipStatus.map { params["skip_status"] = $0 } + return params } public init( @@ -31,4 +38,7 @@ open class PostBlocksCreateRequestV1: TwitterAPIRequest { self.includeEntities = includeEntities self.skipStatus = skipStatus } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostBlocksDestroyRequestV1.swift b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostBlocksDestroyRequestV1.swift index 936c1a64..4071e3ff 100644 --- a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostBlocksDestroyRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostBlocksDestroyRequestV1.swift @@ -1,8 +1,14 @@ +// PostBlocksDestroyRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-blocks-destroy +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// mute-block-report-users/api-reference/post-blocks-destroy open class PostBlocksDestroyRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let includeEntities: Bool? public let skipStatus: Bool? @@ -10,17 +16,18 @@ open class PostBlocksDestroyRequestV1: TwitterAPIRequest { public var method: HTTPMethod { return .post } + public var path: String { return "/1.1/blocks/destroy.json" } open var parameters: [String: Any] { - var p = [String: Any]() + var params = [String: Any]() - user.bind(param: &p) - includeEntities.map { p["include_entities"] = $0 } - skipStatus.map { p["skip_status"] = $0 } - return p + user.bind(param: ¶ms) + includeEntities.map { params["include_entities"] = $0 } + skipStatus.map { params["skip_status"] = $0 } + return params } public init( @@ -32,4 +39,7 @@ open class PostBlocksDestroyRequestV1: TwitterAPIRequest { self.includeEntities = includeEntities self.skipStatus = skipStatus } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostMutesUsersCreateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostMutesUsersCreateRequestV1.swift index e3e90448..3465bdd1 100644 --- a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostMutesUsersCreateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostMutesUsersCreateRequestV1.swift @@ -1,21 +1,28 @@ +// PostMutesUsersCreateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-mutes-users-create +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// mute-block-report-users/api-reference/post-mutes-users-create open class PostMutesUsersCreateRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public var method: HTTPMethod { return .post } + public var path: String { return "/1.1/mutes/users/create.json" } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - return p + var params = [String: Any]() + user.bind(param: ¶ms) + return params } public init( @@ -23,4 +30,7 @@ open class PostMutesUsersCreateRequestV1: TwitterAPIRequest { ) { self.user = user } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostMutesUsersDestroyRequestV1.swift b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostMutesUsersDestroyRequestV1.swift index 708eb657..01128659 100644 --- a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostMutesUsersDestroyRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostMutesUsersDestroyRequestV1.swift @@ -1,21 +1,28 @@ +// PostMutesUsersDestroyRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-mutes-users-destroy +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/ +/// api-reference/post-mutes-users-destroy open class PostMutesUsersDestroyRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public var method: HTTPMethod { return .post } + public var path: String { return "/1.1/mutes/users/destroy.json" } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - return p + var params = [String: Any]() + user.bind(param: ¶ms) + return params } public init( @@ -23,4 +30,7 @@ open class PostMutesUsersDestroyRequestV1: TwitterAPIRequest { ) { self.user = user } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostUsersReportSpamRequestV1.swift b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostUsersReportSpamRequestV1.swift index 25587a77..bdb2d184 100644 --- a/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostUsersReportSpamRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/BlockAndMute/Requests/PostUsersReportSpamRequestV1.swift @@ -1,21 +1,23 @@ -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-users-report_spam +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// mute-block-report-users/api-reference/post-users-report_spam open class PostUsersReportSpamRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let performBlock: Bool? public var method: HTTPMethod { return .post } + public var path: String { return "/1.1/users/report_spam.json" } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - performBlock.map { p["perform_block"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + performBlock.map { params["perform_block"] = $0 } + return params } public init( @@ -25,4 +27,7 @@ open class PostUsersReportSpamRequestV1: TwitterAPIRequest { self.user = user self.performBlock = performBlock } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Collection/CollectionAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Collection/CollectionAPIv1.swift index 424b17e4..a0376389 100644 --- a/Sources/TwitterAPIKit/APIv1/Collection/CollectionAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Collection/CollectionAPIv1.swift @@ -1,74 +1,102 @@ +// CollectionAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class CollectionAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/get-collections-entries + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/ + /// api-reference/get-collections-entries public func getCollectionEntries( _ request: GetCollectionsEntriesRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/get-collections-list + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/ + /// api-reference/get-collections-list public func getCollections( _ request: GetCollectionsListRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/get-collections-show + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/ + /// api-reference/get-collections-show public func getCollection( _ request: GetCollectionsShowRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-create + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/ + /// api-reference/post-collections-create public func postCreateCollection( _ request: PostCollectionsCreateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-destroy + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/ + /// api-reference/post-collections-destroy public func postDestroyCollection( _ request: PostCollectionsDestroyRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-entries-add + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/ + /// api-reference/post-collections-entries-add public func postCollectionAddEntry( _ request: PostCollectionsEntriesAddRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-entries-curate + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/ + /// api-reference/post-collections-entries-curate public func postCollectionCurate( _ request: PostCollectionsEntriesCurateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-entries-move + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/ + /// api-reference/post-collections-entries-move public func postCollectionMoveEntry( _ request: PostCollectionsEntriesMoveRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-entries-remove + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/ + /// api-reference/post-collections-entries-remove public func postCollectionRemoveEntry( _ request: PostCollectionsEntriesRemoveRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-update + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/ + /// api-reference/post-collections-update public func postCollectionUpdate( _ request: PostCollectionsUpdateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Collection/Requests/GetCollectionsEntriesRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Collection/Requests/GetCollectionsEntriesRequestV1.swift index e5e26bd0..3a6c9c17 100644 --- a/Sources/TwitterAPIKit/APIv1/Collection/Requests/GetCollectionsEntriesRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Collection/Requests/GetCollectionsEntriesRequestV1.swift @@ -1,8 +1,14 @@ +// GetCollectionsEntriesRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/get-collections-entries +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ +/// curate-a-collection/api-reference/get-collections-entries open class GetCollectionsEntriesRequestV1: TwitterAPIRequest { - public let id: String public let count: Int? public let maxPosition: String? @@ -17,12 +23,12 @@ open class GetCollectionsEntriesRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["id"] = id - count.map { p["count"] = $0 } - maxPosition.map { p["max_position"] = $0 } - minPosition.map { p["min_position"] = $0 } - return p + var params = [String: Any]() + params["id"] = id + count.map { params["count"] = $0 } + maxPosition.map { params["max_position"] = $0 } + minPosition.map { params["min_position"] = $0 } + return params } public init( @@ -36,4 +42,7 @@ open class GetCollectionsEntriesRequestV1: TwitterAPIRequest { self.maxPosition = maxPosition self.minPosition = minPosition } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Collection/Requests/GetCollectionsListRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Collection/Requests/GetCollectionsListRequestV1.swift index c9f347bc..f7219b7c 100644 --- a/Sources/TwitterAPIKit/APIv1/Collection/Requests/GetCollectionsListRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Collection/Requests/GetCollectionsListRequestV1.swift @@ -1,8 +1,12 @@ +// GetCollectionsListRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/get-collections-list open class GetCollectionsListRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let count: Int? public let cursor: String? @@ -17,12 +21,12 @@ open class GetCollectionsListRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - count.map { p["count"] = $0 } - cursor.map { p["cursor"] = $0 } - tweetID.map { p["tweet_id"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + count.map { params["count"] = $0 } + cursor.map { params["cursor"] = $0 } + tweetID.map { params["tweet_id"] = $0 } + return params } public init( @@ -36,4 +40,7 @@ open class GetCollectionsListRequestV1: TwitterAPIRequest { self.cursor = cursor self.tweetID = tweetID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Collection/Requests/GetCollectionsShowRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Collection/Requests/GetCollectionsShowRequestV1.swift index 976aef15..b1e9d2ba 100644 --- a/Sources/TwitterAPIKit/APIv1/Collection/Requests/GetCollectionsShowRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Collection/Requests/GetCollectionsShowRequestV1.swift @@ -1,8 +1,12 @@ +// GetCollectionsShowRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/get-collections-show open class GetCollectionsShowRequestV1: TwitterAPIRequest { - public let id: String public var method: HTTPMethod { @@ -14,9 +18,9 @@ open class GetCollectionsShowRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["id"] = id - return p + var params = [String: Any]() + params["id"] = id + return params } public init( @@ -24,4 +28,7 @@ open class GetCollectionsShowRequestV1: TwitterAPIRequest { ) { self.id = id } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsCreateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsCreateRequestV1.swift index 08e007e6..78a5022f 100644 --- a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsCreateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsCreateRequestV1.swift @@ -1,16 +1,24 @@ +// PostCollectionsCreateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-create +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ +/// curate-a-collection/api-reference/post-collections-create open class PostCollectionsCreateRequestV1: TwitterAPIRequest { public enum TimelineOrder: String { case curationReverseChron = "curation_reverse_chron" case tweetChron = "tweet_chron" case tweetReverseChron = "tweet_reverse_chron" - func bind(param: inout [String: Any]) { + public func bind(param: inout [String: Any]) { param["timeline_order"] = rawValue } } + public let name: String public let url: String? public let description: String? @@ -25,12 +33,12 @@ open class PostCollectionsCreateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["name"] = name - url.map { p["url"] = $0 } - description.map { p["description"] = $0 } - timelineOrder?.bind(param: &p) - return p + var params = [String: Any]() + params["name"] = name + url.map { params["url"] = $0 } + description.map { params["description"] = $0 } + timelineOrder?.bind(param: ¶ms) + return params } public init( @@ -44,4 +52,7 @@ open class PostCollectionsCreateRequestV1: TwitterAPIRequest { self.description = description self.timelineOrder = timelineOrder } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsDestroyRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsDestroyRequestV1.swift index e8deffb4..d16307fb 100644 --- a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsDestroyRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsDestroyRequestV1.swift @@ -1,8 +1,14 @@ +// PostCollectionsDestroyRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-destroy +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ +/// curate-a-collection/api-reference/post-collections-destroy open class PostCollectionsDestroyRequestV1: TwitterAPIRequest { - public let id: String public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class PostCollectionsDestroyRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["id"] = id - return p + var params = [String: Any]() + params["id"] = id + return params } public init( @@ -24,4 +30,7 @@ open class PostCollectionsDestroyRequestV1: TwitterAPIRequest { ) { self.id = id } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesAddRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesAddRequestV1.swift index 564f9df4..f5746ce0 100644 --- a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesAddRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesAddRequestV1.swift @@ -1,8 +1,14 @@ +// PostCollectionsEntriesAddRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-entries-add +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ +/// curate-a-collection/api-reference/post-collections-entries-add open class PostCollectionsEntriesAddRequestV1: TwitterAPIRequest { - public let id: String public let tweetID: String public let above: Bool? @@ -17,12 +23,12 @@ open class PostCollectionsEntriesAddRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["id"] = id - p["tweet_id"] = tweetID - above.map { p["above"] = $0 } - relativeTo.map { p["relative_to"] = $0 } - return p + var params = [String: Any]() + params["id"] = id + params["tweet_id"] = tweetID + above.map { params["above"] = $0 } + relativeTo.map { params["relative_to"] = $0 } + return params } public init( @@ -36,4 +42,7 @@ open class PostCollectionsEntriesAddRequestV1: TwitterAPIRequest { self.above = above self.relativeTo = relativeTo } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesCurateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesCurateRequestV1.swift index c0819cec..20235aba 100644 --- a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesCurateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesCurateRequestV1.swift @@ -1,17 +1,23 @@ +// PostCollectionsEntriesCurateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-entries-curate +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ +/// curate-a-collection/api-reference/post-collections-entries-curate open class PostCollectionsEntriesCurateRequestV1: TwitterAPIRequest { - public enum Operation { case add(tweetID: String) case remove(tweetID: String) - var keyValue: [String: String] { + public var keyValue: [String: String] { switch self { - case .add(let tweetID): + case let .add(tweetID): return ["op": "add", "tweet_id": tweetID] - case .remove(let tweetID): + case let .remove(tweetID): return ["op": "remove", "tweet_id": tweetID] } } @@ -33,10 +39,10 @@ open class PostCollectionsEntriesCurateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["id"] = id - p["changes"] = changes.map { $0.keyValue } - return p + var params = [String: Any]() + params["id"] = id + params["changes"] = changes.map(\.keyValue) + return params } public init( @@ -46,4 +52,7 @@ open class PostCollectionsEntriesCurateRequestV1: TwitterAPIRequest { self.id = id self.changes = changes } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesMoveRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesMoveRequestV1.swift index f1892067..0c3372e5 100644 --- a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesMoveRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesMoveRequestV1.swift @@ -1,8 +1,14 @@ +// PostCollectionsEntriesMoveRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-entries-move +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ +/// curate-a-collection/api-reference/post-collections-entries-move open class PostCollectionsEntriesMoveRequestV1: TwitterAPIRequest { - public let id: String public let tweetID: String public let above: Bool? @@ -17,12 +23,12 @@ open class PostCollectionsEntriesMoveRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["id"] = id - p["tweet_id"] = tweetID - above.map { p["above"] = $0 } - p["relative_to"] = relativeTo - return p + var params = [String: Any]() + params["id"] = id + params["tweet_id"] = tweetID + above.map { params["above"] = $0 } + params["relative_to"] = relativeTo + return params } public init( @@ -36,4 +42,7 @@ open class PostCollectionsEntriesMoveRequestV1: TwitterAPIRequest { self.above = above self.relativeTo = relativeTo } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesRemoveRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesRemoveRequestV1.swift index 2c0e8d50..7e245756 100644 --- a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesRemoveRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsEntriesRemoveRequestV1.swift @@ -1,8 +1,14 @@ +// PostCollectionsEntriesRemoveRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-entries-remove +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ +/// curate-a-collection/api-reference/post-collections-entries-remove open class PostCollectionsEntriesRemoveRequestV1: TwitterAPIRequest { - public let id: String public let tweetID: String @@ -15,10 +21,10 @@ open class PostCollectionsEntriesRemoveRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["id"] = id - p["tweet_id"] = tweetID - return p + var params = [String: Any]() + params["id"] = id + params["tweet_id"] = tweetID + return params } public init( @@ -28,4 +34,7 @@ open class PostCollectionsEntriesRemoveRequestV1: TwitterAPIRequest { self.id = id self.tweetID = tweetID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsUpdateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsUpdateRequestV1.swift index d5e5f50c..f598fb86 100644 --- a/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsUpdateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Collection/Requests/PostCollectionsUpdateRequestV1.swift @@ -1,8 +1,14 @@ +// PostCollectionsUpdateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/curate-a-collection/api-reference/post-collections-update +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ +/// curate-a-collection/api-reference/post-collections-update open class PostCollectionsUpdateRequestV1: TwitterAPIRequest { - public let id: String public let url: String? public let name: String? @@ -17,12 +23,12 @@ open class PostCollectionsUpdateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["id"] = id - url.map { p["url"] = $0 } - name.map { p["name"] = $0 } - description.map { p["description"] = $0 } - return p + var params = [String: Any]() + params["id"] = id + url.map { params["url"] = $0 } + name.map { params["name"] = $0 } + description.map { params["description"] = $0 } + return params } public init( @@ -36,4 +42,7 @@ open class PostCollectionsUpdateRequestV1: TwitterAPIRequest { self.name = name self.description = description } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/DirectMessage/DirectMessageAPIv1.swift b/Sources/TwitterAPIKit/APIv1/DirectMessage/DirectMessageAPIv1.swift index 5d584fcd..c1e15685 100644 --- a/Sources/TwitterAPIKit/APIv1/DirectMessage/DirectMessageAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/DirectMessage/DirectMessageAPIv1.swift @@ -1,46 +1,66 @@ +// DirectMessageAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class DirectMessageAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/new-event + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/ + /// sending-and-receiving/api-reference/new-event public func postDirectMessage( _ request: PostDirectMessageRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/delete-message-event + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/ + /// sending-and-receiving/api-reference/delete-message-event public func deleteDirectMessage( _ request: DeleteDirectMessageRequestV1 - ) -> TwitterAPISessionDataTask { // 204 - No Content + ) -> TwitterAPISessionDataTask { // 204 - No Content return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/get-event + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/ + /// sending-and-receiving/api-reference/get-event public func getDirectMessage( _ request: GetDirectMessageRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/list-events + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/ + /// sending-and-receiving/api-reference/list-events public func getDirectMessageList( _ request: GetDirectMessageListRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/typing-indicator-and-read-receipts/api-reference/new-read-receipt + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/ + /// typing-indicator-and-read-receipts/api-reference/new-read-receipt public func postDirectMessageMarkRead( _ request: PostDirectMessagesMarkReadRequestV1 ) -> TwitterAPISessionDataTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/typing-indicator-and-read-receipts/api-reference/new-typing-indicator + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/ + /// typing-indicator-and-read-receipts/api-reference/new-typing-indicator public func postDirectMessageTypingIndicator( _ request: PostDirectMessagesIndicateTypingRequestV1 ) -> TwitterAPISessionDataTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/DeleteDirectMessageRequestV1.swift b/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/DeleteDirectMessageRequestV1.swift index 66f9a83e..2865124c 100644 --- a/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/DeleteDirectMessageRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/DeleteDirectMessageRequestV1.swift @@ -1,8 +1,14 @@ +// DeleteDirectMessageRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/delete-message-event +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/ +/// sending-and-receiving/api-reference/delete-message-event open class DeleteDirectMessageRequestV1: TwitterAPIRequest { - public let id: String public var method: HTTPMethod { @@ -15,11 +21,14 @@ open class DeleteDirectMessageRequestV1: TwitterAPIRequest { open var parameters: [String: Any] { return [ - "id": id + "id": id, ] } public init(id: String) { self.id = id } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/GetDirectMessageListRequestV1.swift b/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/GetDirectMessageListRequestV1.swift index 42815538..499c1315 100644 --- a/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/GetDirectMessageListRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/GetDirectMessageListRequestV1.swift @@ -1,8 +1,12 @@ +// GetDirectMessageListRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/list-events open class GetDirectMessageListRequestV1: TwitterAPIRequest { - /// Max: 50 public let count: Int? public let cursor: String? @@ -16,16 +20,19 @@ open class GetDirectMessageListRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() + var params = [String: Any]() - count.map { p["count"] = $0 } - cursor.map { p["cursor"] = $0 } + count.map { params["count"] = $0 } + cursor.map { params["cursor"] = $0 } - return p + return params } public init(count: Int? = .none, cursor: String? = .none) { self.count = count self.cursor = cursor } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/GetDirectMessageRequestV1.swift b/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/GetDirectMessageRequestV1.swift index f751572e..c70b44f3 100644 --- a/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/GetDirectMessageRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/GetDirectMessageRequestV1.swift @@ -1,9 +1,13 @@ +// GetDirectMessageRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/get-event open class GetDirectMessageRequestV1: TwitterAPIRequest { - public let id: String public var method: HTTPMethod { @@ -21,4 +25,8 @@ open class GetDirectMessageRequestV1: TwitterAPIRequest { public init(id: String) { self.id = id } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/PostDirectMessageRequestV1.swift b/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/PostDirectMessageRequestV1.swift index d56d846f..dd45e4dc 100644 --- a/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/PostDirectMessageRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/PostDirectMessageRequestV1.swift @@ -1,15 +1,19 @@ +// PostDirectMessageRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/new-event open class PostDirectMessageRequestV1: TwitterAPIRequest { - public enum Attachment { public enum Location { case coordinate(TwitterCoordinateV1) - case place(String /* Place ID */) + case place(String /* Place ID */ ) } - case media(String /* Media ID */) + case media(String /* Media ID */ ) /** If you attach a Location, it will probably return the following error for unknown reasons. @@ -26,14 +30,14 @@ open class PostDirectMessageRequestV1: TwitterAPIRequest { */ case location(Location) - var parameter: [String: Any] { + public var parameter: [String: Any] { switch self { - case .media(let mediaID): + case let .media(mediaID): return [ "type": "media", "media": ["id": mediaID], ] - case .location(.coordinate(let coordinate)): + case let .location(.coordinate(coordinate)): return [ "type": "location", "location": [ @@ -42,19 +46,19 @@ open class PostDirectMessageRequestV1: TwitterAPIRequest { "coordinates": [ "type": "Point", "coordinates": [coordinate.lat, coordinate.long], - ] + ], ], ], ] - case .location(.place(let placeID)): + case let .location(.place(placeID)): return [ "type": "location", "location": [ "type": "shared_place", "shared_place": [ "place": [ - "id": placeID - ] + "id": placeID, + ], ], ], ] @@ -77,7 +81,7 @@ open class PostDirectMessageRequestV1: TwitterAPIRequest { self.metadata = metadata } - var parameter: [String: String] { + public var parameter: [String: String] { return [ "label": label, "description": description, @@ -107,14 +111,14 @@ open class PostDirectMessageRequestV1: TwitterAPIRequest { open var parameters: [String: Any] { var messageData: [String: Any] = [ - "text": message + "text": message, ] attachment.map { messageData["attachment"] = $0.parameter } quickReplyOptions.map { messageData["quick_reply"] = [ "type": "options", - "options": $0.map { $0.parameter }, + "options": $0.map(\.parameter), ] } @@ -123,11 +127,11 @@ open class PostDirectMessageRequestV1: TwitterAPIRequest { "type": "message_create", "message_create": [ "target": [ - "recipient_id": targetUserID + "recipient_id": targetUserID, ], "message_data": messageData, ], - ] + ], ] } @@ -142,4 +146,7 @@ open class PostDirectMessageRequestV1: TwitterAPIRequest { self.attachment = attachment self.quickReplyOptions = quickReplyOptions } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/PostDirectMessagesIndicateTypingRequestV1.swift b/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/PostDirectMessagesIndicateTypingRequestV1.swift index b577bd15..23d3a553 100644 --- a/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/PostDirectMessagesIndicateTypingRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/PostDirectMessagesIndicateTypingRequestV1.swift @@ -1,8 +1,14 @@ +// PostDirectMessagesIndicateTypingRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/typing-indicator-and-read-receipts/api-reference/new-typing-indicator +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/ +/// typing-indicator-and-read-receipts/api-reference/new-typing-indicator open class PostDirectMessagesIndicateTypingRequestV1: TwitterAPIRequest { - public let recipientID: String public var method: HTTPMethod { @@ -22,4 +28,7 @@ open class PostDirectMessagesIndicateTypingRequestV1: TwitterAPIRequest { ) { self.recipientID = recipientID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/PostDirectMessagesMarkReadRequestV1.swift b/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/PostDirectMessagesMarkReadRequestV1.swift index 675d84aa..bc023e1a 100644 --- a/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/PostDirectMessagesMarkReadRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/DirectMessage/Requests/PostDirectMessagesMarkReadRequestV1.swift @@ -1,8 +1,14 @@ +// PostDirectMessagesMarkReadRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/typing-indicator-and-read-receipts/api-reference/new-read-receipt +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/ +/// typing-indicator-and-read-receipts/api-reference/new-read-receipt open class PostDirectMessagesMarkReadRequestV1: TwitterAPIRequest { - /// Message ID public let lastReadEventID: String @@ -18,12 +24,12 @@ open class PostDirectMessagesMarkReadRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() + var params = [String: Any]() - p["last_read_event_id"] = lastReadEventID - p["recipient_id"] = recipientID + params["last_read_event_id"] = lastReadEventID + params["recipient_id"] = recipientID - return p + return params } public init( @@ -33,4 +39,7 @@ open class PostDirectMessagesMarkReadRequestV1: TwitterAPIRequest { self.lastReadEventID = lastReadEventID self.recipientID = recipientID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Favorite/FavoriteAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Favorite/FavoriteAPIv1.swift index 8ca109f5..e39d701e 100644 --- a/Sources/TwitterAPIKit/APIv1/Favorite/FavoriteAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Favorite/FavoriteAPIv1.swift @@ -1,7 +1,11 @@ +// FavoriteAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class FavoriteAPIv1: TwitterAPIBase { - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-favorites-create public func postFavorite( _ request: PostFavoriteRequestV1 @@ -22,4 +26,8 @@ open class FavoriteAPIv1: TwitterAPIBase { ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Favorite/Requests/GetFavoritesRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Favorite/Requests/GetFavoritesRequestV1.swift index 88d051a5..3587db2e 100644 --- a/Sources/TwitterAPIKit/APIv1/Favorite/Requests/GetFavoritesRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Favorite/Requests/GetFavoritesRequestV1.swift @@ -1,8 +1,12 @@ +// GetFavoritesRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-favorites-list open class GetFavoritesRequestV1: TwitterAPIRequest { - public let target: TwitterUserIdentifierV1 public let count: Int? public let sinceID: String? @@ -18,15 +22,15 @@ open class GetFavoritesRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() + var params = [String: Any]() - target.bind(param: &p) - count.map { p["count"] = $0 } - sinceID.map { p["since_id"] = $0 } - maxID.map { p["max_id"] = $0 } - includeEntities.map { p["include_entities"] = $0 } + target.bind(param: ¶ms) + count.map { params["count"] = $0 } + sinceID.map { params["since_id"] = $0 } + maxID.map { params["max_id"] = $0 } + includeEntities.map { params["include_entities"] = $0 } - return p + return params } public init( @@ -42,4 +46,7 @@ open class GetFavoritesRequestV1: TwitterAPIRequest { self.maxID = maxID self.includeEntities = includeEntities } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Favorite/Requests/PostFavoriteRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Favorite/Requests/PostFavoriteRequestV1.swift index a0d22eb3..da43a442 100644 --- a/Sources/TwitterAPIKit/APIv1/Favorite/Requests/PostFavoriteRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Favorite/Requests/PostFavoriteRequestV1.swift @@ -1,8 +1,12 @@ +// PostFavoriteRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-favorites-create open class PostFavoriteRequestV1: TwitterAPIRequest { - public let id: String public let includeEntities: Bool? @@ -15,10 +19,10 @@ open class PostFavoriteRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["id"] = id - includeEntities.map { p["include_entities"] = $0 } - return p + var params = [String: Any]() + params["id"] = id + includeEntities.map { params["include_entities"] = $0 } + return params } public init( @@ -28,5 +32,7 @@ open class PostFavoriteRequestV1: TwitterAPIRequest { self.id = id self.includeEntities = includeEntities } - + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Favorite/Requests/PostUnFavoriteRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Favorite/Requests/PostUnFavoriteRequestV1.swift index 0bf1243e..5a499bf2 100644 --- a/Sources/TwitterAPIKit/APIv1/Favorite/Requests/PostUnFavoriteRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Favorite/Requests/PostUnFavoriteRequestV1.swift @@ -1,8 +1,12 @@ +// PostUnFavoriteRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-favorites-destroy open class PostUnFavoriteRequestV1: TwitterAPIRequest { - public let id: String public let includeEntities: Bool? @@ -15,10 +19,10 @@ open class PostUnFavoriteRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["id"] = id - includeEntities.map { p["include_entities"] = $0 } - return p + var params = [String: Any]() + params["id"] = id + includeEntities.map { params["include_entities"] = $0 } + return params } public init( @@ -28,4 +32,7 @@ open class PostUnFavoriteRequestV1: TwitterAPIRequest { self.id = id self.includeEntities = includeEntities } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/FriendshipsAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/FriendshipsAPIv1.swift index c088ce28..a34e03a7 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/FriendshipsAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/FriendshipsAPIv1.swift @@ -1,88 +1,120 @@ +// FriendshipsAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class FriendshipsAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-followers-ids + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/get-followers-ids public func getFollowerIDs( _ request: GetFollowersIDsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-followers-list + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/get-followers-list public func getFollowers( _ request: GetFollowersListRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friends-ids + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/get-friends-ids public func getFriendIDs( _ request: GetFriendsIDsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friends-list + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/get-friends-list public func getFriends( _ request: GetFriendsListRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-incoming + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/get-friendships-incoming public func getFriendshipsIncoming( _ request: GetFriendshipsIncomingRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-lookup + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/get-friendships-lookup public func getFriendshipsLookup( _ request: GetFriendshipsLookupRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-no_retweets-ids + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/get-friendships-no_retweets-ids public func getFriendshipsNoRetweetsIDs( _ request: GetFriendshipsNoRetweetsIDsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-outgoing + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/get-friendships-outgoing public func getFriendshipsOutgoing( _ request: GetFriendshipsOutgoingRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-show + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/get-friendships-show public func getFriendships( _ request: GetFriendshipsShowRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-create + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/post-friendships-create public func postFollowUser( _ request: PostFriendshipsCreateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-destroy + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/post-friendships-destroy public func postUnfollowUser( _ request: PostFriendshipsDestroyRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-update + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/post-friendships-update public func postFriendshipsUpdate( _ request: PostFriendshipsUpdateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFollowersIDsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFollowersIDsRequestV1.swift index 14fc2650..43775a85 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFollowersIDsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFollowersIDsRequestV1.swift @@ -1,8 +1,14 @@ +// GetFollowersIDsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-followers-ids +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/get-followers-ids open class GetFollowersIDsRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let count: Int? public let cursor: String? @@ -17,12 +23,12 @@ open class GetFollowersIDsRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - count.map { p["count"] = $0 } - cursor.map { p["cursor"] = $0 } - stringifyIDs.map { p["stringify_ids"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + count.map { params["count"] = $0 } + cursor.map { params["cursor"] = $0 } + stringifyIDs.map { params["stringify_ids"] = $0 } + return params } public init( @@ -36,4 +42,7 @@ open class GetFollowersIDsRequestV1: TwitterAPIRequest { self.cursor = cursor self.stringifyIDs = stringifyIDs } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFollowersListRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFollowersListRequestV1.swift index 93335d5c..65330ebc 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFollowersListRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFollowersListRequestV1.swift @@ -1,8 +1,14 @@ +// GetFollowersListRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-followers-list +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/get-followers-list open class GetFollowersListRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let count: Int? public let cursor: String? @@ -12,18 +18,19 @@ open class GetFollowersListRequestV1: TwitterAPIRequest { public var method: HTTPMethod { return .get } + public var path: String { return "/1.1/followers/list.json" } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - count.map { p["count"] = $0 } - cursor.map { p["cursor"] = $0 } - skipStatus.map { p["skip_status"] = $0 } - includeUserEntities.map { p["include_user_entities"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + count.map { params["count"] = $0 } + cursor.map { params["cursor"] = $0 } + skipStatus.map { params["skip_status"] = $0 } + includeUserEntities.map { params["include_user_entities"] = $0 } + return params } public init( @@ -39,4 +46,7 @@ open class GetFollowersListRequestV1: TwitterAPIRequest { self.skipStatus = skipStatus self.includeUserEntities = includeUserEntities } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendsIDsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendsIDsRequestV1.swift index 6beea5cf..b2226620 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendsIDsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendsIDsRequestV1.swift @@ -1,8 +1,14 @@ +// GetFriendsIDsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friends-ids +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/get-friends-ids open class GetFriendsIDsRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let count: Int? public let cursor: String? @@ -17,12 +23,12 @@ open class GetFriendsIDsRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - count.map { p["count"] = $0 } - cursor.map { p["cursor"] = $0 } - stringifyIDs.map { p["stringify_ids"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + count.map { params["count"] = $0 } + cursor.map { params["cursor"] = $0 } + stringifyIDs.map { params["stringify_ids"] = $0 } + return params } public init( @@ -36,4 +42,7 @@ open class GetFriendsIDsRequestV1: TwitterAPIRequest { self.cursor = cursor self.stringifyIDs = stringifyIDs } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendsListRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendsListRequestV1.swift index 33d4b46b..e80afc76 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendsListRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendsListRequestV1.swift @@ -1,8 +1,14 @@ +// GetFriendsListRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friends-list +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/get-friends-list open class GetFriendsListRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let count: Int? public let cursor: String? @@ -18,13 +24,13 @@ open class GetFriendsListRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - count.map { p["count"] = $0 } - cursor.map { p["cursor"] = $0 } - skipStatus.map { p["skip_status"] = $0 } - includeUserEntities.map { p["include_user_entities"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + count.map { params["count"] = $0 } + cursor.map { params["cursor"] = $0 } + skipStatus.map { params["skip_status"] = $0 } + includeUserEntities.map { params["include_user_entities"] = $0 } + return params } public init( @@ -40,4 +46,8 @@ open class GetFriendsListRequestV1: TwitterAPIRequest { self.skipStatus = skipStatus self.includeUserEntities = includeUserEntities } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsIncomingRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsIncomingRequestV1.swift index 27f5d7e4..a04a3d07 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsIncomingRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsIncomingRequestV1.swift @@ -1,23 +1,30 @@ +// GetFriendshipsIncomingRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-incoming +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/get-friendships-incoming open class GetFriendshipsIncomingRequestV1: TwitterAPIRequest { - public let cursor: String? public let stringifyIDs: Bool? public var method: HTTPMethod { return .get } + public var path: String { return "/1.1/friendships/incoming.json" } open var parameters: [String: Any] { - var p = [String: Any]() - cursor.map { p["cursor"] = $0 } - stringifyIDs.map { p["stringify_ids"] = $0 } - return p + var params = [String: Any]() + cursor.map { params["cursor"] = $0 } + stringifyIDs.map { params["stringify_ids"] = $0 } + return params } public init( @@ -27,4 +34,7 @@ open class GetFriendshipsIncomingRequestV1: TwitterAPIRequest { self.cursor = cursor self.stringifyIDs = stringifyIDs } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsLookupRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsLookupRequestV1.swift index 8218e00b..3da726d4 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsLookupRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsLookupRequestV1.swift @@ -1,8 +1,14 @@ +// GetFriendshipsLookupRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-lookup +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/get-friendships-lookup open class GetFriendshipsLookupRequestV1: TwitterAPIRequest { - public let users: TwitterUsersIdentifierV1 public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class GetFriendshipsLookupRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - users.bind(param: &p) - return p + var params = [String: Any]() + users.bind(param: ¶ms) + return params } public init( @@ -24,4 +30,7 @@ open class GetFriendshipsLookupRequestV1: TwitterAPIRequest { ) { self.users = users } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsNoRetweetsIDsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsNoRetweetsIDsRequestV1.swift index bf6488cd..b5ef111b 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsNoRetweetsIDsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsNoRetweetsIDsRequestV1.swift @@ -1,8 +1,14 @@ +// GetFriendshipsNoRetweetsIDsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-no_retweets-ids +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/get-friendships-no_retweets-ids open class GetFriendshipsNoRetweetsIDsRequestV1: TwitterAPIRequest { - public let stringifyIDs: Bool? public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class GetFriendshipsNoRetweetsIDsRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - stringifyIDs.map { p["stringify_ids"] = $0 } - return p + var params = [String: Any]() + stringifyIDs.map { params["stringify_ids"] = $0 } + return params } public init( @@ -24,4 +30,7 @@ open class GetFriendshipsNoRetweetsIDsRequestV1: TwitterAPIRequest { ) { self.stringifyIDs = stringifyIDs } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsOutgoingRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsOutgoingRequestV1.swift index 71d76c94..f18b2d97 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsOutgoingRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsOutgoingRequestV1.swift @@ -1,8 +1,14 @@ +// GetFriendshipsOutgoingRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-outgoing +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/get-friendships-outgoing open class GetFriendshipsOutgoingRequestV1: TwitterAPIRequest { - public let cursor: String? public let stringifyIDs: Bool? @@ -15,10 +21,10 @@ open class GetFriendshipsOutgoingRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - cursor.map { p["cursor"] = $0 } - stringifyIDs.map { p["stringify_ids"] = $0 } - return p + var params = [String: Any]() + cursor.map { params["cursor"] = $0 } + stringifyIDs.map { params["stringify_ids"] = $0 } + return params } public init( @@ -28,4 +34,7 @@ open class GetFriendshipsOutgoingRequestV1: TwitterAPIRequest { self.cursor = cursor self.stringifyIDs = stringifyIDs } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsShowRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsShowRequestV1.swift index 54de1c87..edc839be 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsShowRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/GetFriendshipsShowRequestV1.swift @@ -1,8 +1,14 @@ +// GetFriendshipsShowRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-show +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/get-friendships-show open class GetFriendshipsShowRequestV1: TwitterAPIRequest { - public let sourceUser: TwitterUserIdentifierV1 public let targetUser: TwitterUserIdentifierV1 @@ -15,10 +21,10 @@ open class GetFriendshipsShowRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - sourceUser.bind(param: &p, userIDKey: "source_id", screenNameKey: "source_screen_name") - targetUser.bind(param: &p, userIDKey: "target_id", screenNameKey: "target_screen_name") - return p + var params = [String: Any]() + sourceUser.bind(param: ¶ms, userIDKey: "source_id", screenNameKey: "source_screen_name") + targetUser.bind(param: ¶ms, userIDKey: "target_id", screenNameKey: "target_screen_name") + return params } public init( @@ -28,4 +34,7 @@ open class GetFriendshipsShowRequestV1: TwitterAPIRequest { self.sourceUser = sourceUser self.targetUser = targetUser } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/PostFriendshipsCreateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/PostFriendshipsCreateRequestV1.swift index d63febd8..13adbee0 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/PostFriendshipsCreateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/PostFriendshipsCreateRequestV1.swift @@ -1,8 +1,14 @@ +// PostFriendshipsCreateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-create +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/post-friendships-create open class PostFriendshipsCreateRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let follow: Bool? @@ -15,10 +21,10 @@ open class PostFriendshipsCreateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - follow.map { p["follow"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + follow.map { params["follow"] = $0 } + return params } public init( @@ -28,4 +34,7 @@ open class PostFriendshipsCreateRequestV1: TwitterAPIRequest { self.user = user self.follow = follow } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/PostFriendshipsDestroyRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/PostFriendshipsDestroyRequestV1.swift index bd6eb498..d510d4f4 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/PostFriendshipsDestroyRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/PostFriendshipsDestroyRequestV1.swift @@ -1,8 +1,14 @@ +// PostFriendshipsDestroyRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-destroy +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/post-friendships-destroy open class PostFriendshipsDestroyRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class PostFriendshipsDestroyRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - return p + var params = [String: Any]() + user.bind(param: ¶ms) + return params } public init( @@ -24,4 +30,7 @@ open class PostFriendshipsDestroyRequestV1: TwitterAPIRequest { ) { self.user = user } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/PostFriendshipsUpdateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/PostFriendshipsUpdateRequestV1.swift index 3206b1c5..2f3ca39e 100644 --- a/Sources/TwitterAPIKit/APIv1/Friendships/Requests/PostFriendshipsUpdateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Friendships/Requests/PostFriendshipsUpdateRequestV1.swift @@ -1,8 +1,14 @@ +// PostFriendshipsUpdateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-update +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/post-friendships-update open class PostFriendshipsUpdateRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let device: Bool? public let retweets: Bool? @@ -16,11 +22,11 @@ open class PostFriendshipsUpdateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - device.map { p["device"] = $0 } - retweets.map { p["retweets"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + device.map { params["device"] = $0 } + retweets.map { params["retweets"] = $0 } + return params } public init( @@ -32,4 +38,7 @@ open class PostFriendshipsUpdateRequestV1: TwitterAPIRequest { self.device = device self.retweets = retweets } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Geo/GeoAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Geo/GeoAPIv1.swift index d1236cd6..7324c7be 100644 --- a/Sources/TwitterAPIKit/APIv1/Geo/GeoAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Geo/GeoAPIv1.swift @@ -1,25 +1,39 @@ +// GeoAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class GeoAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/geo/places-near-location/api-reference/get-geo-reverse_geocode + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/geo/ + /// places-near-location/api-reference/get-geo-reverse_geocode public func getReverseGeocode( _ request: GetGeoReverseGeocodeRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/geo/place-information/api-reference/get-geo-id-place_id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/geo/ + /// place-information/api-reference/get-geo-id-place_id public func getGeoPlace( _ request: GetGeoPlaceIDRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/geo/places-near-location/api-reference/get-geo-search + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/geo/ + /// places-near-location/api-reference/get-geo-search public func searchGeo( _ request: GetGeoSearchRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Geo/Requests/GetGeoPlaceIDRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Geo/Requests/GetGeoPlaceIDRequestV1.swift index 5f612aa5..0b350dd2 100644 --- a/Sources/TwitterAPIKit/APIv1/Geo/Requests/GetGeoPlaceIDRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Geo/Requests/GetGeoPlaceIDRequestV1.swift @@ -1,8 +1,12 @@ +// GetGeoPlaceIDRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/geo/place-information/api-reference/get-geo-id-place_id open class GetGeoPlaceIDRequestV1: TwitterAPIRequest { - public let placeID: String public var method: HTTPMethod { @@ -22,4 +26,7 @@ open class GetGeoPlaceIDRequestV1: TwitterAPIRequest { ) { self.placeID = placeID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Geo/Requests/GetGeoReverseGeocodeRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Geo/Requests/GetGeoReverseGeocodeRequestV1.swift index 6d35009c..7ea19ab5 100644 --- a/Sources/TwitterAPIKit/APIv1/Geo/Requests/GetGeoReverseGeocodeRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Geo/Requests/GetGeoReverseGeocodeRequestV1.swift @@ -1,8 +1,12 @@ +// GetGeoReverseGeocodeRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/geo/places-near-location/api-reference/get-geo-reverse_geocode open class GetGeoReverseGeocodeRequestV1: TwitterAPIRequest { - public let location: TwitterCoordinateV1 public let accuracy: TwitterAccuracyV1? public let maxResults: Int? @@ -17,12 +21,12 @@ open class GetGeoReverseGeocodeRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - location.bind(param: &p) - accuracy?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - granularity?.bind(param: &p) - return p + var params = [String: Any]() + location.bind(param: ¶ms) + accuracy?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + granularity?.bind(param: ¶ms) + return params } public init( @@ -36,4 +40,7 @@ open class GetGeoReverseGeocodeRequestV1: TwitterAPIRequest { self.maxResults = maxResults self.granularity = granularity } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Geo/Requests/GetGeoSearchRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Geo/Requests/GetGeoSearchRequestV1.swift index ac76f3db..a5a3e2a5 100644 --- a/Sources/TwitterAPIKit/APIv1/Geo/Requests/GetGeoSearchRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Geo/Requests/GetGeoSearchRequestV1.swift @@ -1,19 +1,23 @@ +// GetGeoSearchRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/geo/places-near-location/api-reference/get-geo-search open class GetGeoSearchRequestV1: TwitterAPIRequest { - public enum Location { case coordinate(TwitterCoordinateV1) case query(String) case ip(String) - func bind(param: inout [String: Any]) { + public func bind(param: inout [String: Any]) { switch self { - case .coordinate(let twitterCoordinate): + case let .coordinate(twitterCoordinate): twitterCoordinate.bind(param: ¶m) - case .query(let string): + case let .query(string): param["query"] = string - case .ip(let string): + case let .ip(string): param["ip"] = string } } @@ -32,11 +36,11 @@ open class GetGeoSearchRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - location.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - granularity?.bind(param: &p) - return p + var params = [String: Any]() + location.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + granularity?.bind(param: ¶ms) + return params } public init( @@ -48,5 +52,7 @@ open class GetGeoSearchRequestV1: TwitterAPIRequest { self.maxResults = maxResults self.granularity = granularity } - + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Help/HelpAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Help/HelpAPIv1.swift index 2880ab24..30d8e2f5 100644 --- a/Sources/TwitterAPIKit/APIv1/Help/HelpAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Help/HelpAPIv1.swift @@ -1,11 +1,21 @@ +// HelpAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class HelpAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/developer-utilities/supported-languages/api-reference/get-help-languages + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/developer-utilities/ + /// supported-languages/api-reference/get-help-languages public func getSupportedLanguages( _ request: GetHelpLanguagesRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Help/Requests/GetHelpLanguagesRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Help/Requests/GetHelpLanguagesRequestV1.swift index 8aac306d..45df9053 100644 --- a/Sources/TwitterAPIKit/APIv1/Help/Requests/GetHelpLanguagesRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Help/Requests/GetHelpLanguagesRequestV1.swift @@ -1,8 +1,14 @@ +// GetHelpLanguagesRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/developer-utilities/supported-languages/api-reference/get-help-languages +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/developer-utilities/ +/// supported-languages/api-reference/get-help-languages open class GetHelpLanguagesRequestV1: TwitterAPIRequest { - public var method: HTTPMethod { return .get } @@ -15,6 +21,9 @@ open class GetHelpLanguagesRequestV1: TwitterAPIRequest { return [:] } - public init() { + public init() {} + + deinit { + // De-init Logic Here } } diff --git a/Sources/TwitterAPIKit/APIv1/List/ListAPIv1.swift b/Sources/TwitterAPIKit/APIv1/List/ListAPIv1.swift index 895ad889..80396733 100644 --- a/Sources/TwitterAPIKit/APIv1/List/ListAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/ListAPIv1.swift @@ -1,137 +1,183 @@ +// ListAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class ListAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-list + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/get-lists-list public func getLists( _ request: GetListsListRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-members + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/get-lists-members public func getListMembers( _ request: GetListsMembersRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-members-show + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/get-lists-members-show public func getListMember( _ request: GetListsMembersShowRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-memberships + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/get-lists-memberships public func getListMemberships( _ request: GetListsMembershipsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-ownerships + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/get-lists-ownerships public func getListOwnerships( _ request: GetListsOwnershipsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-show + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/get-lists-show public func getList( _ request: GetListsShowRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-statuses + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/get-lists-statuses public func getListStatuses( _ request: GetListsStatusesRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-subscribers + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/get-lists-subscribers public func getListSubscribers( _ request: GetListsSubscribersRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-subscribers-show + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/get-lists-subscribers-show public func getListSubscriber( _ request: GetListsSubscribersShowRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-subscriptions + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/get-lists-subscriptions public func getListSubscriptions( _ request: GetListsSubscriptionsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-create + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/post-lists-create public func postCreateList( _ request: PostListsCreateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-destroy + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/post-lists-destroy public func postDestroyList( _ request: PostListsDestroyRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/post-lists-members-create public func postAddListMember( _ request: PostListsMembersCreateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create_all + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/post-lists-members-create_all public func postAddListMembers( _ request: PostListsMembersCreateAllRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-destroy + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/post-lists-members-destroy public func postRemoveListMember( _ request: PostListsMembersDestroyRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-destroy_all + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/post-lists-members-destroy_all public func postRemoveListMembers( _ request: PostListsMembersDestroyAllRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-subscribers-create + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/post-lists-subscribers-create public func postSubscribeList( _ request: PostListsSubscribersCreateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-subscribers-destroy + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/post-lists-subscribers-destroy public func postUnsubscribeList( _ request: PostListsSubscribersDestroyRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-update + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// create-manage-lists/api-reference/post-lists-update public func postUpdateList( _ request: PostListsUpdateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsListRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsListRequestV1.swift index f2b4ddeb..e16738a5 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsListRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsListRequestV1.swift @@ -1,8 +1,14 @@ +// GetListsListRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-list +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/get-lists-list open class GetListsListRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let reverse: Bool? @@ -15,10 +21,10 @@ open class GetListsListRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - reverse.map { p["reverse"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + reverse.map { params["reverse"] = $0 } + return params } public init( @@ -28,4 +34,8 @@ open class GetListsListRequestV1: TwitterAPIRequest { self.user = user self.reverse = reverse } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsMembersRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsMembersRequestV1.swift index c9907371..91982880 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsMembersRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsMembersRequestV1.swift @@ -1,8 +1,14 @@ +// GetListsMembersRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-members +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/get-lists-members open class GetListsMembersRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public let count: Int? public let cursor: String? @@ -18,13 +24,13 @@ open class GetListsMembersRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - count.map { p["count"] = $0 } - cursor.map { p["cursor"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - skipStatus.map { p["skip_status"] = $0 } - return p + var params = [String: Any]() + list.bind(param: ¶ms) + count.map { params["count"] = $0 } + cursor.map { params["cursor"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + skipStatus.map { params["skip_status"] = $0 } + return params } public init( @@ -40,4 +46,8 @@ open class GetListsMembersRequestV1: TwitterAPIRequest { self.includeEntities = includeEntities self.skipStatus = skipStatus } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsMembersShowRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsMembersShowRequestV1.swift index 035b4560..f372ff82 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsMembersShowRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsMembersShowRequestV1.swift @@ -1,8 +1,14 @@ +// GetListsMembersShowRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-members-show +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/get-lists-members-show open class GetListsMembersShowRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public let user: TwitterUserIdentifierV1 public let includeEntities: Bool? @@ -17,12 +23,12 @@ open class GetListsMembersShowRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - user.bind(param: &p) - includeEntities.map { p["include_entities"] = $0 } - skipStatus.map { p["skip_status"] = $0 } - return p + var params = [String: Any]() + list.bind(param: ¶ms) + user.bind(param: ¶ms) + includeEntities.map { params["include_entities"] = $0 } + skipStatus.map { params["skip_status"] = $0 } + return params } public init( @@ -36,4 +42,8 @@ open class GetListsMembersShowRequestV1: TwitterAPIRequest { self.includeEntities = includeEntities self.skipStatus = skipStatus } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsMembershipsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsMembershipsRequestV1.swift index 138c59b3..901fcf77 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsMembershipsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsMembershipsRequestV1.swift @@ -1,8 +1,14 @@ +// GetListsMembershipsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-memberships +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/get-lists-memberships open class GetListsMembershipsRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let count: Int? public let cursor: String? @@ -17,13 +23,13 @@ open class GetListsMembershipsRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - count.map { p["count"] = $0 } - cursor.map { p["cursor"] = $0 } - filterToOwnedLists.map { p["filter_to_owned_lists"] = $0 } + var params = [String: Any]() + user.bind(param: ¶ms) + count.map { params["count"] = $0 } + cursor.map { params["cursor"] = $0 } + filterToOwnedLists.map { params["filter_to_owned_lists"] = $0 } - return p + return params } public init( @@ -37,4 +43,8 @@ open class GetListsMembershipsRequestV1: TwitterAPIRequest { self.cursor = cursor self.filterToOwnedLists = filterToOwnedLists } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsOwnershipsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsOwnershipsRequestV1.swift index c0d3d323..926e8ad3 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsOwnershipsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsOwnershipsRequestV1.swift @@ -1,8 +1,14 @@ +// GetListsOwnershipsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-ownerships +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/get-lists-ownerships open class GetListsOwnershipsRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let count: Int? public let cursor: String? @@ -16,11 +22,11 @@ open class GetListsOwnershipsRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - count.map { p["count"] = $0 } - cursor.map { p["cursor"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + count.map { params["count"] = $0 } + cursor.map { params["cursor"] = $0 } + return params } public init( @@ -32,4 +38,8 @@ open class GetListsOwnershipsRequestV1: TwitterAPIRequest { self.count = count self.cursor = cursor } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsShowRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsShowRequestV1.swift index 15bd29ff..7aaaf767 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsShowRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsShowRequestV1.swift @@ -1,8 +1,14 @@ +// GetListsShowRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-show +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/get-lists-show open class GetListsShowRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class GetListsShowRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - return p + var params = [String: Any]() + list.bind(param: ¶ms) + return params } public init( @@ -24,4 +30,8 @@ open class GetListsShowRequestV1: TwitterAPIRequest { ) { self.list = list } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsStatusesRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsStatusesRequestV1.swift index 7dd53886..f429e1f8 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsStatusesRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsStatusesRequestV1.swift @@ -1,8 +1,14 @@ +// GetListsStatusesRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-statuses +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/get-lists-statuses open class GetListsStatusesRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public let count: Int? public let sinceID: String? @@ -19,14 +25,14 @@ open class GetListsStatusesRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - count.map { p["count"] = $0 } - sinceID.map { p["since_id"] = $0 } - maxID.map { p["max_id"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - includeRTs.map { p["include_rts"] = $0 } - return p + var params = [String: Any]() + list.bind(param: ¶ms) + count.map { params["count"] = $0 } + sinceID.map { params["since_id"] = $0 } + maxID.map { params["max_id"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + includeRTs.map { params["include_rts"] = $0 } + return params } public init( @@ -44,4 +50,8 @@ open class GetListsStatusesRequestV1: TwitterAPIRequest { self.includeEntities = includeEntities self.includeRTs = includeRTs } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsSubscribersRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsSubscribersRequestV1.swift index 6426272d..9a4b7ac1 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsSubscribersRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsSubscribersRequestV1.swift @@ -1,8 +1,14 @@ +// GetListsSubscribersRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-subscribers +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/get-lists-subscribers open class GetListsSubscribersRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public let count: Int? public let cursor: String? @@ -18,13 +24,13 @@ open class GetListsSubscribersRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - count.map { p["count"] = $0 } - cursor.map { p["cursor"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - skipStatus.map { p["skip_status"] = $0 } - return p + var params = [String: Any]() + list.bind(param: ¶ms) + count.map { params["count"] = $0 } + cursor.map { params["cursor"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + skipStatus.map { params["skip_status"] = $0 } + return params } public init( @@ -40,4 +46,8 @@ open class GetListsSubscribersRequestV1: TwitterAPIRequest { self.includeEntities = includeEntities self.skipStatus = skipStatus } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsSubscribersShowRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsSubscribersShowRequestV1.swift index c9bd89a3..1f262ac1 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsSubscribersShowRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsSubscribersShowRequestV1.swift @@ -1,8 +1,14 @@ +// GetListsSubscribersShowRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-subscribers-show +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/get-lists-subscribers-show open class GetListsSubscribersShowRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public let user: TwitterUserIdentifierV1 public let includeEntities: Bool? @@ -17,12 +23,12 @@ open class GetListsSubscribersShowRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - user.bind(param: &p) - includeEntities.map { p["include_entities"] = $0 } - skipStatus.map { p["skip_status"] = $0 } - return p + var params = [String: Any]() + list.bind(param: ¶ms) + user.bind(param: ¶ms) + includeEntities.map { params["include_entities"] = $0 } + skipStatus.map { params["skip_status"] = $0 } + return params } public init( @@ -36,4 +42,8 @@ open class GetListsSubscribersShowRequestV1: TwitterAPIRequest { self.includeEntities = includeEntities self.skipStatus = skipStatus } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsSubscriptionsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsSubscriptionsRequestV1.swift index 7522cbac..8d42d63c 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsSubscriptionsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/GetListsSubscriptionsRequestV1.swift @@ -1,11 +1,17 @@ +// GetListsSubscriptionsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-subscriptions +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/get-lists-subscriptions open class GetListsSubscriptionsRequestV1: TwitterAPIRequest { - - let user: TwitterUserIdentifierV1 - let count: Int? - let cursor: String? + internal let user: TwitterUserIdentifierV1 + internal let count: Int? + internal let cursor: String? public var method: HTTPMethod { return .get @@ -16,11 +22,11 @@ open class GetListsSubscriptionsRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - count.map { p["count"] = $0 } - cursor.map { p["cursor"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + count.map { params["count"] = $0 } + cursor.map { params["cursor"] = $0 } + return params } public init( @@ -32,4 +38,8 @@ open class GetListsSubscriptionsRequestV1: TwitterAPIRequest { self.count = count self.cursor = cursor } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsCreateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsCreateRequestV1.swift index da1bccdf..799851ae 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsCreateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsCreateRequestV1.swift @@ -1,8 +1,14 @@ +// PostListsCreateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-create +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/post-lists-create open class PostListsCreateRequestV1: TwitterAPIRequest { - public let name: String public let mode: TwitterListModeV1? public let description: String? @@ -16,11 +22,11 @@ open class PostListsCreateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["name"] = name - mode?.bind(param: &p) - description.map { p["description"] = $0 } - return p + var params = [String: Any]() + params["name"] = name + mode?.bind(param: ¶ms) + description.map { params["description"] = $0 } + return params } public init( @@ -32,4 +38,8 @@ open class PostListsCreateRequestV1: TwitterAPIRequest { self.mode = mode self.description = description } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsDestroyRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsDestroyRequestV1.swift index ad97da0f..e979af40 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsDestroyRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsDestroyRequestV1.swift @@ -1,8 +1,14 @@ +// PostListsDestroyRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-destroy +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/post-lists-destroy open class PostListsDestroyRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class PostListsDestroyRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - return p + var params = [String: Any]() + list.bind(param: ¶ms) + return params } public init( @@ -24,4 +30,8 @@ open class PostListsDestroyRequestV1: TwitterAPIRequest { ) { self.list = list } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersCreateAllRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersCreateAllRequestV1.swift index 37f3d98e..fcbee95c 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersCreateAllRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersCreateAllRequestV1.swift @@ -1,8 +1,14 @@ +// PostListsMembersCreateAllRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create_all +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/post-lists-members-create_all open class PostListsMembersCreateAllRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public let users: TwitterUsersIdentifierV1 @@ -15,10 +21,10 @@ open class PostListsMembersCreateAllRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - users.bind(param: &p) - return p + var params = [String: Any]() + list.bind(param: ¶ms) + users.bind(param: ¶ms) + return params } public init( @@ -28,4 +34,8 @@ open class PostListsMembersCreateAllRequestV1: TwitterAPIRequest { self.list = list self.users = users } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersCreateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersCreateRequestV1.swift index 2313c3ef..cc551a60 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersCreateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersCreateRequestV1.swift @@ -1,8 +1,14 @@ +// PostListsMembersCreateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/post-lists-members-create open class PostListsMembersCreateRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public let user: TwitterUserIdentifierV1 @@ -15,11 +21,12 @@ open class PostListsMembersCreateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - user.bind(param: &p) - return p + var params = [String: Any]() + list.bind(param: ¶ms) + user.bind(param: ¶ms) + return params } + public init( list: TwitterListIdentifierV1, user: TwitterUserIdentifierV1 @@ -27,4 +34,8 @@ open class PostListsMembersCreateRequestV1: TwitterAPIRequest { self.list = list self.user = user } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersDestroyAllRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersDestroyAllRequestV1.swift index 62c57041..420b84a3 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersDestroyAllRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersDestroyAllRequestV1.swift @@ -1,8 +1,14 @@ +// PostListsMembersDestroyAllRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-destroy_all +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/post-lists-members-destroy_all open class PostListsMembersDestroyAllRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public let users: TwitterUsersIdentifierV1 @@ -15,10 +21,10 @@ open class PostListsMembersDestroyAllRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - users.bind(param: &p) - return p + var params = [String: Any]() + list.bind(param: ¶ms) + users.bind(param: ¶ms) + return params } public init( @@ -28,4 +34,8 @@ open class PostListsMembersDestroyAllRequestV1: TwitterAPIRequest { self.list = list self.users = users } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersDestroyRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersDestroyRequestV1.swift index ce4a0c23..57e240a1 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersDestroyRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsMembersDestroyRequestV1.swift @@ -1,8 +1,14 @@ +// PostListsMembersDestroyRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-destroy +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/post-lists-members-destroy open class PostListsMembersDestroyRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public let user: TwitterUserIdentifierV1 @@ -15,10 +21,10 @@ open class PostListsMembersDestroyRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - user.bind(param: &p) - return p + var params = [String: Any]() + list.bind(param: ¶ms) + user.bind(param: ¶ms) + return params } public init( @@ -28,4 +34,8 @@ open class PostListsMembersDestroyRequestV1: TwitterAPIRequest { self.list = list self.user = user } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsSubscribersCreateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsSubscribersCreateRequestV1.swift index ed89a468..7c529b51 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsSubscribersCreateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsSubscribersCreateRequestV1.swift @@ -1,8 +1,14 @@ +// PostListsSubscribersCreateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-subscribers-create +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/post-lists-subscribers-create open class PostListsSubscribersCreateRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class PostListsSubscribersCreateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - return p + var params = [String: Any]() + list.bind(param: ¶ms) + return params } public init( @@ -24,4 +30,8 @@ open class PostListsSubscribersCreateRequestV1: TwitterAPIRequest { ) { self.list = list } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsSubscribersDestroyRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsSubscribersDestroyRequestV1.swift index c11d3147..ba4d6fd6 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsSubscribersDestroyRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsSubscribersDestroyRequestV1.swift @@ -1,8 +1,14 @@ +// PostListsSubscribersDestroyRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-subscribers-destroy +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/post-lists-subscribers-destroy open class PostListsSubscribersDestroyRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class PostListsSubscribersDestroyRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - return p + var params = [String: Any]() + list.bind(param: ¶ms) + return params } public init( @@ -24,4 +30,8 @@ open class PostListsSubscribersDestroyRequestV1: TwitterAPIRequest { ) { self.list = list } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsUpdateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsUpdateRequestV1.swift index 24eebc40..2ccaecb9 100644 --- a/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsUpdateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/List/Requests/PostListsUpdateRequestV1.swift @@ -1,8 +1,14 @@ +// PostListsUpdateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-update +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// create-manage-lists/api-reference/post-lists-update open class PostListsUpdateRequestV1: TwitterAPIRequest { - public let list: TwitterListIdentifierV1 public let name: String? public let mode: TwitterListModeV1? @@ -17,12 +23,12 @@ open class PostListsUpdateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - list.bind(param: &p) - name.map { p["name"] = $0 } - mode?.bind(param: &p) - description.map { p["description"] = $0 } - return p + var params = [String: Any]() + list.bind(param: ¶ms) + name.map { params["name"] = $0 } + mode?.bind(param: ¶ms) + description.map { params["description"] = $0 } + return params } public init( @@ -36,4 +42,8 @@ open class PostListsUpdateRequestV1: TwitterAPIRequest { self.mode = mode self.description = description } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Media/MediaAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Media/MediaAPIv1.swift index d19ab603..500d720a 100644 --- a/Sources/TwitterAPIKit/APIv1/Media/MediaAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Media/MediaAPIv1.swift @@ -1,22 +1,32 @@ +// MediaAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class MediaAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/get-media-upload-status + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/ + /// api-reference/get-media-upload-status public func getUploadMediaStatus( _ request: GetUploadMediaStatusRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload-init + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/ + /// api-reference/post-media-upload-init public func uploadMediaInit( _ request: UploadMediaInitRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload-append + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/ + /// api-reference/post-media-upload-append public func uploadMediaAppend( _ request: UploadMediaAppendRequestV1 ) -> TwitterAPISessionJSONTask { @@ -28,17 +38,17 @@ open class MediaAPIv1: TwitterAPIBase { _ request: UploadMediaAppendRequestV1, maxBytes: Int = 5_242_880 /* 5MB */ ) -> [TwitterAPISessionSpecializedTask] { - - let tasks = request.segments(maxBytes: maxBytes) + return request.segments(maxBytes: maxBytes) .map { req in uploadMediaAppend(req).specialized { _ in req.mediaID } } - return tasks } - /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload-finalize + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/ + /// api-reference/post-media-upload-finalize public func uploadMediaFinalize( _ request: UploadMediaFinalizeRequestV1 ) -> TwitterAPISessionJSONTask { @@ -65,17 +75,17 @@ open class MediaAPIv1: TwitterAPIBase { queue: .processQueue ) { [weak self] response in - guard let self = self else { return } + guard let self else { return } let mediaID: String do { mediaID = try response.result.get().mediaID } catch { - completionHandler(response.map { $0.mediaID }) + completionHandler(response.map(\.mediaID)) return } - self.uploadMediaAppendSplitChunks( + uploadMediaAppendSplitChunks( .init( mediaID: mediaID, filename: parameters.filename, @@ -83,42 +93,45 @@ open class MediaAPIv1: TwitterAPIBase { media: parameters.media, segmentIndex: 0 ), maxBytes: parameters.uploadChunkSize ?? 5_242_880 - ).responseObject(queue: .processQueue) { [weak self] responses in + ) + .responseObject(queue: .processQueue) { [weak self] responses in - guard let self = self else { return } + guard let self else { return } - if let error = responses.first(where: { $0.isError }) { + if let error = responses.first(where: \.isError) { completionHandler(error) return } - self.uploadMediaFinalize(.init(mediaID: mediaID)) - .responseDecodable(type: TwitterAPIClient.UploadMediaFinalizeResponse.self, queue: .processQueue) { - [weak self] response in - guard let self = self else { return } + uploadMediaFinalize(.init(mediaID: mediaID)) + .responseDecodable( + type: TwitterAPIClient.UploadMediaFinalizeResponse.self, + queue: .processQueue + ) { [weak self] response in + guard let self else { return } var finalizeResult: TwitterAPIClient.UploadMediaFinalizeResponse do { finalizeResult = try response.result.get() } catch { - completionHandler(response.map { $0.mediaID }) + completionHandler(response.map(\.mediaID)) return } guard let processingInfo = finalizeResult.processingInfo else { - completionHandler(response.map { $0.mediaID }) + completionHandler(response.map(\.mediaID)) return } - self.waitMediaProcessing( + waitMediaProcessing( mediaID: mediaID, initialWaitSec: processingInfo.checkAfterSecs ?? 0 ) { response in - completionHandler(response.map { $0.mediaID }) + completionHandler(response.map(\.mediaID)) } } } - } + } } public func waitMediaProcessing( @@ -128,10 +141,9 @@ open class MediaAPIv1: TwitterAPIBase { TwitterAPIResponse ) -> Void ) { - DispatchQueue.global(qos: .default).asyncAfter(deadline: .now() + .seconds(initialWaitSec)) { [weak self] in - guard let self = self else { return } - self.waitMediaProcessing(mediaID: mediaID, completionHandler: completionHandler) + guard let self else { return } + waitMediaProcessing(mediaID: mediaID, completionHandler: completionHandler) } } @@ -142,23 +154,24 @@ open class MediaAPIv1: TwitterAPIBase { ) -> Void ) { _ = getUploadMediaStatus(.init(mediaID: mediaID)) - .responseDecodable(type: TwitterAPIClient.UploadMediaStatusResponse.self, queue: .processQueue) { - [weak self] response in - guard let self = self else { return } + .responseDecodable( + type: TwitterAPIClient.UploadMediaStatusResponse.self, + queue: .processQueue + ) { [weak self] response in + guard let self else { return } do { let success = try response.result.get() switch success.state { case let .pending(checkAfterSecs: sec), - let .inProgress(checkAfterSecs: sec, progressPercent: _): + let .inProgress(checkAfterSecs: sec, progressPercent: _): - self.waitMediaProcessing( + waitMediaProcessing( mediaID: mediaID, initialWaitSec: sec, completionHandler: completionHandler ) - case .succeeded: completionHandler(response) case let .failed(error: error): @@ -173,7 +186,7 @@ open class MediaAPIv1: TwitterAPIBase { response.flatMap { _ in .failure(error) } ) return - } catch let error { + } catch { completionHandler( response.flatMap { _ in .failure(.unkonwn(error: error)) } ) @@ -181,24 +194,36 @@ open class MediaAPIv1: TwitterAPIBase { } } - /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-metadata-create + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/ + /// api-reference/post-media-metadata-create public func createMediaMetadata( _ request: PostMediaMetadataCreateRequestV1 ) -> TwitterAPISessionDataTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-subtitles-create + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/ + /// api-reference/ + /// post-media-subtitles-create public func createSubtitle( _ request: PostMediaSubtitlesCreateRequestV1 ) -> TwitterAPISessionDataTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-subtitles-delete + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/ + /// api-reference/ + /// post-media-subtitles-delete public func deleteSubtitle( _ request: PostMediaSubtitlesDeleteRequestV1 ) -> TwitterAPISessionDataTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Media/Requests/GetUploadMediaStatusRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Media/Requests/GetUploadMediaStatusRequestV1.swift index 3bf43824..9dc44035 100644 --- a/Sources/TwitterAPIKit/APIv1/Media/Requests/GetUploadMediaStatusRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Media/Requests/GetUploadMediaStatusRequestV1.swift @@ -1,7 +1,11 @@ +// GetUploadMediaStatusRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class GetUploadMediaStatusRequestV1: TwitterAPIRequest { - public let command: String = "STATUS" public let mediaID: String @@ -27,4 +31,8 @@ open class GetUploadMediaStatusRequestV1: TwitterAPIRequest { public init(mediaID: String) { self.mediaID = mediaID } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Media/Requests/PostMediaMetadataCreateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Media/Requests/PostMediaMetadataCreateRequestV1.swift index 669189f6..fdb94318 100644 --- a/Sources/TwitterAPIKit/APIv1/Media/Requests/PostMediaMetadataCreateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Media/Requests/PostMediaMetadataCreateRequestV1.swift @@ -1,8 +1,12 @@ +// PostMediaMetadataCreateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-metadata-create open class PostMediaMetadataCreateRequestV1: TwitterAPIRequest { - public let mediaID: String public let altText: String @@ -23,12 +27,12 @@ open class PostMediaMetadataCreateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() + var params = [String: Any]() - p["media_id"] = mediaID - p["alt_text"] = ["text": altText] + params["media_id"] = mediaID + params["alt_text"] = ["text": altText] - return p + return params } public init( @@ -38,4 +42,8 @@ open class PostMediaMetadataCreateRequestV1: TwitterAPIRequest { self.mediaID = mediaID self.altText = altText } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Media/Requests/PostMediaSubtitlesCreateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Media/Requests/PostMediaSubtitlesCreateRequestV1.swift index 2229b819..23d22998 100644 --- a/Sources/TwitterAPIKit/APIv1/Media/Requests/PostMediaSubtitlesCreateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Media/Requests/PostMediaSubtitlesCreateRequestV1.swift @@ -1,8 +1,12 @@ +// PostMediaSubtitlesCreateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-subtitles-create open class PostMediaSubtitlesCreateRequestV1: TwitterAPIRequest { - public struct Subtitle { public let mediaID: String /// The language code should be a BCP47 code (e.g. 'en", "sp") @@ -41,20 +45,19 @@ open class PostMediaSubtitlesCreateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - - var p = [String: Any]() - p["media_id"] = mediaID - p["media_category"] = mediaCategory - p["subtitle_info"] = [ + var params = [String: Any]() + params["media_id"] = mediaID + params["media_category"] = mediaCategory + params["subtitle_info"] = [ "subtitles": subtitles.map { - return [ + [ "media_id": $0.mediaID, "language_code": $0.languageCode, "display_name": $0.displayName, ] - } + }, ] - return p + return params } public init( @@ -66,4 +69,8 @@ open class PostMediaSubtitlesCreateRequestV1: TwitterAPIRequest { self.mediaCategory = mediaCategory self.subtitles = subtitles } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Media/Requests/PostMediaSubtitlesDeleteRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Media/Requests/PostMediaSubtitlesDeleteRequestV1.swift index 244152bc..400fc1ab 100644 --- a/Sources/TwitterAPIKit/APIv1/Media/Requests/PostMediaSubtitlesDeleteRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Media/Requests/PostMediaSubtitlesDeleteRequestV1.swift @@ -1,8 +1,12 @@ +// PostMediaSubtitlesDeleteRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-subtitles-delete open class PostMediaSubtitlesDeleteRequestV1: TwitterAPIRequest { - public let mediaID: String public let mediaCategory: String /// //The language code should be a BCP47 code (e.g. 'en", "sp") @@ -25,15 +29,15 @@ open class PostMediaSubtitlesDeleteRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["media_id"] = mediaID - p["media_category"] = mediaCategory - p["subtitle_info"] = [ + var params = [String: Any]() + params["media_id"] = mediaID + params["media_category"] = mediaCategory + params["subtitle_info"] = [ "subtitles": subtitleLanguageCodes.map { - return ["language_code": $0] - } + ["language_code": $0] + }, ] - return p + return params } public init( @@ -45,4 +49,8 @@ open class PostMediaSubtitlesDeleteRequestV1: TwitterAPIRequest { self.mediaCategory = mediaCategory self.subtitleLanguageCodes = subtitleLanguageCodes } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Media/Requests/UploadMediaAppendRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Media/Requests/UploadMediaAppendRequestV1.swift index c001aaf9..40eaf3ea 100644 --- a/Sources/TwitterAPIKit/APIv1/Media/Requests/UploadMediaAppendRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Media/Requests/UploadMediaAppendRequestV1.swift @@ -1,8 +1,12 @@ +// UploadMediaAppendRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload-append open class UploadMediaAppendRequestV1: TwitterAPIRequest { - public let command: String = "APPEND" public let mediaID: String @@ -31,18 +35,17 @@ open class UploadMediaAppendRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - - let p: [String: MultipartFormDataPart] = [ - "command": .value(name: "command", value: command), - "media_id": .value(name: "media_id", value: mediaID), - "media": .data(name: "media", value: media, filename: filename, mimeType: mimeType), - "segment_index": .value(name: "segment_index", value: segmentIndex), + return [ + "command": command, + "media_id": mediaID, + "media": media, + "segment_index": segmentIndex, + "filename": filename, + "mime_type": mimeType ] - - return p } - public init( + public required init( mediaID: String, filename: String, mimeType: String, @@ -57,19 +60,18 @@ open class UploadMediaAppendRequestV1: TwitterAPIRequest { } open func segments(maxBytes: Int) -> [UploadMediaAppendRequestV1] { - - var requests = [UploadMediaAppendRequestV1]() + var requests = [Self]() let totalDataSize = media.count var currentSegmentIndex = 0 repeat { currentSegmentIndex = segmentIndex + requests.count let start = currentSegmentIndex * maxBytes let len = min(totalDataSize - start, maxBytes) - let req = UploadMediaAppendRequestV1( + let req = Self( mediaID: mediaID, filename: filename, mimeType: mimeType, - media: media.subdata(in: start..<(start + len)), + media: media.subdata(in: start ..< (start + len)), segmentIndex: currentSegmentIndex ) requests.append(req) @@ -77,4 +79,8 @@ open class UploadMediaAppendRequestV1: TwitterAPIRequest { return requests } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Media/Requests/UploadMediaFinalizeRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Media/Requests/UploadMediaFinalizeRequestV1.swift index c9fd6432..0e981445 100644 --- a/Sources/TwitterAPIKit/APIv1/Media/Requests/UploadMediaFinalizeRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Media/Requests/UploadMediaFinalizeRequestV1.swift @@ -1,8 +1,12 @@ +// UploadMediaFinalizeRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload-finalize open class UploadMediaFinalizeRequestV1: TwitterAPIRequest { - public let command: String = "FINALIZE" public let mediaID: String @@ -28,4 +32,8 @@ open class UploadMediaFinalizeRequestV1: TwitterAPIRequest { public init(mediaID: String) { self.mediaID = mediaID } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Media/Requests/UploadMediaInitRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Media/Requests/UploadMediaInitRequestV1.swift index 2336d7d0..100519bb 100644 --- a/Sources/TwitterAPIKit/APIv1/Media/Requests/UploadMediaInitRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Media/Requests/UploadMediaInitRequestV1.swift @@ -1,8 +1,12 @@ +// UploadMediaInitRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload-init open class UploadMediaInitRequestV1: TwitterAPIRequest { - public let command: String = "INIT" public let totalBytes: Int public let mediaType: String @@ -22,13 +26,13 @@ open class UploadMediaInitRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["command"] = command - p["total_bytes"] = totalBytes - p["media_type"] = mediaType - mediaCategory.map { p["media_category"] = $0 } - additionalOwners.map { p["additional_owners"] = $0.joined(separator: ",") } - return p + var params = [String: Any]() + params["command"] = command + params["total_bytes"] = totalBytes + params["media_type"] = mediaType + mediaCategory.map { params["media_category"] = $0 } + additionalOwners.map { params["additional_owners"] = $0.joined(separator: ",") } + return params } public init( @@ -42,4 +46,8 @@ open class UploadMediaInitRequestV1: TwitterAPIRequest { self.mediaCategory = mediaCategory self.additionalOwners = additionalOwners } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Media/UploadMediaEntity.swift b/Sources/TwitterAPIKit/APIv1/Media/UploadMediaRequestParameters.swift similarity index 63% rename from Sources/TwitterAPIKit/APIv1/Media/UploadMediaEntity.swift rename to Sources/TwitterAPIKit/APIv1/Media/UploadMediaRequestParameters.swift index d13a125e..3f9a3e61 100644 --- a/Sources/TwitterAPIKit/APIv1/Media/UploadMediaEntity.swift +++ b/Sources/TwitterAPIKit/APIv1/Media/UploadMediaRequestParameters.swift @@ -1,15 +1,38 @@ +// UploadMediaEntity.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// Parameters for uploading media to Twitter's API. public struct UploadMediaRequestParameters { + /// The raw media data to upload. public let media: Data + + /// The MIME type of the media (e.g., "image/jpeg", "video/mp4"). public let mediaType: String + + /// The filename to use for the uploaded media. public let filename: String + + /// The category of media being uploaded (e.g., "tweet_image", "tweet_video"). public let mediaCategory: String? + + /// Additional Twitter user IDs that should have permission to use this media. public let additionalOwners: [String]? - /// Byte + + /// The size of each chunk when uploading large media files, in bytes. public let uploadChunkSize: Int? - /// filename can be any value. ex) hoge.mp4 + /// Creates parameters for a media upload request. + /// - Parameters: + /// - media: The raw media data to upload. + /// - mediaType: The MIME type of the media. + /// - filename: The filename to use (can be any value, e.g., "photo.jpg"). + /// - mediaCategory: The category of media being uploaded (optional). + /// - additionalOwners: Additional user IDs that can use this media (optional). + /// - uploadChunkSize: Size of each chunk for chunked uploads, in bytes (optional). public init( media: Data, mediaType: String, @@ -27,9 +50,8 @@ public struct UploadMediaRequestParameters { } } -extension TwitterAPIClient { - - public struct UploadMediaInitResponse: Decodable { +public extension TwitterAPIClient { + struct UploadMediaInitResponse: Decodable { public let mediaID: String public let expiresAfterSecs: Int @@ -39,12 +61,11 @@ extension TwitterAPIClient { } } - public struct UploadMediaVideo: Decodable { + struct UploadMediaVideo: Decodable { public let videoType: String } - public struct UploadMediaProcessingInfo: Decodable { - + struct UploadMediaProcessingInfo: Decodable { public enum State { case pending(checkAfterSecs: Int) case inProgress(checkAfterSecs: Int, progressPercent: Int) @@ -55,15 +76,15 @@ extension TwitterAPIClient { } public var enumState: State { - if state == "pending", let checkAfterSecs = checkAfterSecs { + if state == "pending", let checkAfterSecs { return .pending(checkAfterSecs: checkAfterSecs) } - if state == "in_progress", let checkAfterSecs = checkAfterSecs, let progressPercent = progressPercent { + if state == "in_progress", let checkAfterSecs, let progressPercent { return .inProgress(checkAfterSecs: checkAfterSecs, progressPercent: progressPercent) } - if state == "failed", let error = error { + if state == "failed", let error { return .failed(error: error) } @@ -82,8 +103,7 @@ extension TwitterAPIClient { public let error: TwitterAPIKitError.UploadMediaError? } - public struct UploadMediaFinalizeResponse: Decodable { - + struct UploadMediaFinalizeResponse: Decodable { public let mediaID: String public let size: Int public let expiresAfterSecs: Int @@ -96,8 +116,7 @@ extension TwitterAPIClient { } } - public struct UploadMediaStatusResponse: Decodable { - + struct UploadMediaStatusResponse: Decodable { public var state: UploadMediaProcessingInfo.State { return processingInfo.enumState } @@ -112,5 +131,4 @@ extension TwitterAPIClient { case expiresAfterSecs, video, processingInfo } } - } diff --git a/Sources/TwitterAPIKit/APIv1/Retweet/Requests/GetRetweetersRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Retweet/Requests/GetRetweetersRequestV1.swift index c7cd45b3..7b27edbf 100644 --- a/Sources/TwitterAPIKit/APIv1/Retweet/Requests/GetRetweetersRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Retweet/Requests/GetRetweetersRequestV1.swift @@ -1,44 +1,45 @@ +// GetRetweetersRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-retweeters-ids +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ +/// post-and-engage/api-reference/get-statuses-retweeters-ids open class GetRetweetersRequestV1: TwitterAPIRequest { - - // Status ID - let id: String - let count: Int? - let cursor: String? - let stringifyIDs: Bool? + public let tweetID: String + public let cursor: String? + public let stringifyIDs: Bool? public var method: HTTPMethod { return .get } public var path: String { - return "/1.1/statuses/retweeters/ids.json" } open var parameters: [String: Any] { - - var p = [String: Any]() - - p["id"] = id - count.map { p["count"] = $0 } - cursor.map { p["cursor"] = $0 } - stringifyIDs.map { p["stringify_ids"] = $0 } - - return p + var parameters = [String: Any]() + parameters["id"] = tweetID + cursor.map { parameters["cursor"] = $0 } + stringifyIDs.map { parameters["stringify_ids"] = $0 } + return parameters } public init( - id: String, - count: Int? = .none, + tweetID: String, cursor: String? = .none, stringifyIDs: Bool? = .none ) { - self.id = id - self.count = count + self.tweetID = tweetID self.cursor = cursor self.stringifyIDs = stringifyIDs } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Retweet/Requests/GetRetweetsOfMeRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Retweet/Requests/GetRetweetsOfMeRequestV1.swift index b3642eb9..3cf07541 100644 --- a/Sources/TwitterAPIKit/APIv1/Retweet/Requests/GetRetweetsOfMeRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Retweet/Requests/GetRetweetsOfMeRequestV1.swift @@ -1,8 +1,14 @@ +// GetRetweetsOfMeRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-retweets_of_me +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ +/// post-and-engage/api-reference/get-statuses-retweets_of_me open class GetRetweetsOfMeRequestV1: TwitterAPIRequest { - public let count: Int? public let sinceID: String? public let maxID: String? @@ -19,16 +25,16 @@ open class GetRetweetsOfMeRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() + var params = [String: Any]() - count.map { p["count"] = $0 } - sinceID.map { p["since_id"] = $0 } - maxID.map { p["max_id"] = $0 } - trimUser.map { p["trim_user"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - includeUserEntities.map { p["include_user_entities"] = $0 } + count.map { params["count"] = $0 } + sinceID.map { params["since_id"] = $0 } + maxID.map { params["max_id"] = $0 } + trimUser.map { params["trim_user"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + includeUserEntities.map { params["include_user_entities"] = $0 } - return p + return params } public init( @@ -46,5 +52,7 @@ open class GetRetweetsOfMeRequestV1: TwitterAPIRequest { self.includeEntities = includeEntities self.includeUserEntities = includeUserEntities } - + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Retweet/Requests/GetRetweetsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Retweet/Requests/GetRetweetsRequestV1.swift index 64f8a3cd..2af04528 100644 --- a/Sources/TwitterAPIKit/APIv1/Retweet/Requests/GetRetweetsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Retweet/Requests/GetRetweetsRequestV1.swift @@ -1,8 +1,12 @@ +// GetRetweetsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-retweets-id open class GetRetweetsRequestV1: TwitterAPIRequest { - /// Status ID public let id: String /// max: 100 @@ -18,10 +22,10 @@ open class GetRetweetsRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - count.map { p["count"] = $0 } - trimUser.map { p["trim_user"] = $0 } - return p + var params = [String: Any]() + count.map { params["count"] = $0 } + trimUser.map { params["trim_user"] = $0 } + return params } public init( @@ -33,4 +37,7 @@ open class GetRetweetsRequestV1: TwitterAPIRequest { self.count = count self.trimUser = trimUser } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Retweet/Requests/PostRetweetRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Retweet/Requests/PostRetweetRequestV1.swift index 226fb404..458acdcd 100644 --- a/Sources/TwitterAPIKit/APIv1/Retweet/Requests/PostRetweetRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Retweet/Requests/PostRetweetRequestV1.swift @@ -1,3 +1,8 @@ +// PostRetweetRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-retweet-id @@ -14,9 +19,9 @@ open class PostRetweetRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - trimUser.map { p["trim_user"] = $0 } - return p + var params = [String: Any]() + trimUser.map { params["trim_user"] = $0 } + return params } public init( @@ -26,4 +31,7 @@ open class PostRetweetRequestV1: TwitterAPIRequest { self.id = id self.trimUser = trimUser } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Retweet/Requests/PostUnRetweetRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Retweet/Requests/PostUnRetweetRequestV1.swift index 55121f37..741a4ae4 100644 --- a/Sources/TwitterAPIKit/APIv1/Retweet/Requests/PostUnRetweetRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Retweet/Requests/PostUnRetweetRequestV1.swift @@ -1,3 +1,8 @@ +// PostUnRetweetRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-unretweet-id @@ -14,9 +19,9 @@ open class PostUnRetweetRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - trimUser.map { p["trim_user"] = $0 } - return p + var params = [String: Any]() + trimUser.map { params["trim_user"] = $0 } + return params } public init( @@ -26,4 +31,7 @@ open class PostUnRetweetRequestV1: TwitterAPIRequest { self.id = id self.trimUser = trimUser } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Retweet/RetweetAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Retweet/RetweetAPIv1.swift index 28523da1..dfcd29c8 100644 --- a/Sources/TwitterAPIKit/APIv1/Retweet/RetweetAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Retweet/RetweetAPIv1.swift @@ -1,39 +1,57 @@ +// RetweetAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class RetweetAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-retweet-id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/ + /// api-reference/post-statuses-retweet-id public func postRetweet( _ request: PostRetweetRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-unretweet-id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/ + /// api-reference/post-statuses-unretweet-id public func postUnRetweet( _ request: PostUnRetweetRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-retweets-id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/ + /// api-reference/get-statuses-retweets-id public func getRetweets( _ request: GetRetweetsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-retweets_of_me + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/ + /// api-reference/get-statuses-retweets_of_me public func getRetweetsOfMe( _ request: GetRetweetsOfMeRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-retweeters-ids + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/ + /// api-reference/get-statuses-retweeters-ids public func getRetweeters( _ request: GetRetweetersRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Search/Requests/GetSavedSearchesListRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Search/Requests/GetSavedSearchesListRequestV1.swift index aa80f61c..d33b5e9f 100644 --- a/Sources/TwitterAPIKit/APIv1/Search/Requests/GetSavedSearchesListRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Search/Requests/GetSavedSearchesListRequestV1.swift @@ -1,8 +1,14 @@ +// GetSavedSearchesListRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-saved_searches-list +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// manage-account-settings/api-reference/get-saved_searches-list open class GetSavedSearchesListRequestV1: TwitterAPIRequest { - public var method: HTTPMethod { return .get } @@ -17,4 +23,7 @@ open class GetSavedSearchesListRequestV1: TwitterAPIRequest { public init() {} + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Search/Requests/GetSearchTweetsRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Search/Requests/GetSearchTweetsRequestV1.swift index 77f5b258..d4cf7a17 100644 --- a/Sources/TwitterAPIKit/APIv1/Search/Requests/GetSearchTweetsRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Search/Requests/GetSearchTweetsRequestV1.swift @@ -1,15 +1,19 @@ +// GetSearchTweetsRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/api-reference/get-search-tweets open class GetSearchTweetsRequestV1: TwitterAPIRequest { - public enum ResultType: String { case mixed case recent case popular } - public let q: String + public let query: String public let lang: String? public let count: Int? public let until: String? @@ -29,22 +33,22 @@ open class GetSearchTweetsRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["q"] = q - lang.map { p["lang"] = $0 } - count.map { p["count"] = $0 } - until.map { p["until"] = $0 } - maxID.map { p["max_id"] = $0 } - locale.map { p["locale"] = $0 } - geocode.map { p["geocode"] = $0 } - sinceID.map { p["since_id"] = $0 } - resultType.map { p["result_type"] = $0.rawValue } - includeEntities.map { p["include_entities"] = $0 } - return p + var params = [String: Any]() + params["q"] = query + lang.map { params["lang"] = $0 } + count.map { params["count"] = $0 } + until.map { params["until"] = $0 } + maxID.map { params["max_id"] = $0 } + locale.map { params["locale"] = $0 } + geocode.map { params["geocode"] = $0 } + sinceID.map { params["since_id"] = $0 } + resultType.map { params["result_type"] = $0.rawValue } + includeEntities.map { params["include_entities"] = $0 } + return params } public init( - q: String, + query: String, lang: String? = .none, count: Int? = .none, until: String? = .none, @@ -55,7 +59,7 @@ open class GetSearchTweetsRequestV1: TwitterAPIRequest { resultType: ResultType? = .none, includeEntities: Bool? = .none ) { - self.q = q + self.query = query self.lang = lang self.count = count self.until = until @@ -66,4 +70,7 @@ open class GetSearchTweetsRequestV1: TwitterAPIRequest { self.resultType = resultType self.includeEntities = includeEntities } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Search/Requests/PostSavedSearchesCreateRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Search/Requests/PostSavedSearchesCreateRequestV1.swift index dbd37516..d2f33b57 100644 --- a/Sources/TwitterAPIKit/APIv1/Search/Requests/PostSavedSearchesCreateRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Search/Requests/PostSavedSearchesCreateRequestV1.swift @@ -1,8 +1,14 @@ +// PostSavedSearchesCreateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-saved_searches-create +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// manage-account-settings/api-reference/post-saved_searches-create open class PostSavedSearchesCreateRequestV1: TwitterAPIRequest { - public let query: String public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class PostSavedSearchesCreateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["query"] = query - return p + var params = [String: Any]() + params["query"] = query + return params } public init( @@ -24,4 +30,8 @@ open class PostSavedSearchesCreateRequestV1: TwitterAPIRequest { ) { self.query = query } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Search/Requests/PostSavedSearchesDestroyRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Search/Requests/PostSavedSearchesDestroyRequestV1.swift index 130cb60d..02eb7972 100644 --- a/Sources/TwitterAPIKit/APIv1/Search/Requests/PostSavedSearchesDestroyRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Search/Requests/PostSavedSearchesDestroyRequestV1.swift @@ -1,8 +1,14 @@ +// PostSavedSearchesDestroyRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-saved_searches-destroy-id +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// manage-account-settings/api-reference/post-saved_searches-destroy-id open class PostSavedSearchesDestroyRequestV1: TwitterAPIRequest { - public let id: String public var method: HTTPMethod { @@ -22,4 +28,7 @@ open class PostSavedSearchesDestroyRequestV1: TwitterAPIRequest { ) { self.id = id } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Search/SearchAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Search/SearchAPIv1.swift index acc09f06..a9c81889 100644 --- a/Sources/TwitterAPIKit/APIv1/Search/SearchAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Search/SearchAPIv1.swift @@ -1,32 +1,48 @@ +// SearchAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class SearchAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/api-reference/get-search-tweets + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/ + /// api-reference/get-search-tweets public func searchTweets( _ request: GetSearchTweetsRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-saved_searches-list + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// manage-account-settings/api-reference/get-saved_searches-list public func getSavedSearches( _ request: GetSavedSearchesListRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-saved_searches-create + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// manage-account-settings/api-reference/post-saved_searches-create public func postCreateSavedSearch( _ request: PostSavedSearchesCreateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-saved_searches-destroy-id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ + /// manage-account-settings/api-reference/post-saved_searches-destroy-id public func postDestroySavedSearch( _ request: PostSavedSearchesCreateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Timelines/Requests/GetStatusesHomeTimelineRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Timelines/Requests/GetStatusesHomeTimelineRequestV1.swift index 3ad9fc85..351402cd 100644 --- a/Sources/TwitterAPIKit/APIv1/Timelines/Requests/GetStatusesHomeTimelineRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Timelines/Requests/GetStatusesHomeTimelineRequestV1.swift @@ -1,8 +1,14 @@ +// GetStatusesHomeTimelineRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/api-reference/get-statuses-home_timeline +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/ +/// api-reference/get-statuses-home_timeline open class GetStatusesHomeTimelineRequestV1: TwitterAPIRequest { - public let count: Int? public let maxID: String? public let sinceID: String? @@ -19,14 +25,14 @@ open class GetStatusesHomeTimelineRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - count.map { p["count"] = $0 } - maxID.map { p["max_id"] = $0 } - sinceID.map { p["since_id"] = $0 } - trimUser.map { p["trim_user"] = $0 } - excludeReplies.map { p["exclude_replies"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - return p + var params = [String: Any]() + count.map { params["count"] = $0 } + maxID.map { params["max_id"] = $0 } + sinceID.map { params["since_id"] = $0 } + trimUser.map { params["trim_user"] = $0 } + excludeReplies.map { params["exclude_replies"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + return params } public init( @@ -44,4 +50,7 @@ open class GetStatusesHomeTimelineRequestV1: TwitterAPIRequest { self.excludeReplies = excludeReplies self.includeEntities = includeEntities } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Timelines/Requests/GetStatusesMentionsTimelineRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Timelines/Requests/GetStatusesMentionsTimelineRequestV1.swift index 49486e18..4839ad2e 100644 --- a/Sources/TwitterAPIKit/APIv1/Timelines/Requests/GetStatusesMentionsTimelineRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Timelines/Requests/GetStatusesMentionsTimelineRequestV1.swift @@ -1,8 +1,12 @@ +// GetStatusesMentionsTimelineRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/api-reference/get-statuses-mentions_timeline open class GetStatusesMentionsTimelineRequestV1: TwitterAPIRequest { - public let count: Int? public let maxID: String? public let sinceID: String? @@ -18,13 +22,13 @@ open class GetStatusesMentionsTimelineRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - count.map { p["count"] = $0 } - maxID.map { p["max_id"] = $0 } - sinceID.map { p["since_id"] = $0 } - trimUser.map { p["trim_user"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - return p + var params = [String: Any]() + count.map { params["count"] = $0 } + maxID.map { params["max_id"] = $0 } + sinceID.map { params["since_id"] = $0 } + trimUser.map { params["trim_user"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + return params } public init( @@ -40,4 +44,7 @@ open class GetStatusesMentionsTimelineRequestV1: TwitterAPIRequest { self.trimUser = trimUser self.includeEntities = includeEntities } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Timelines/Requests/GetStatusesUserTimelineRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Timelines/Requests/GetStatusesUserTimelineRequestV1.swift index 722c2999..95732a5e 100644 --- a/Sources/TwitterAPIKit/APIv1/Timelines/Requests/GetStatusesUserTimelineRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Timelines/Requests/GetStatusesUserTimelineRequestV1.swift @@ -1,8 +1,12 @@ +// GetStatusesUserTimelineRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/api-reference/get-statuses-user_timeline open class GetStatusesUserTimelineRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let count: Int? public let maxID: String? @@ -20,15 +24,15 @@ open class GetStatusesUserTimelineRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - count.map { p["count"] = $0 } - maxID.map { p["max_id"] = $0 } - sinceID.map { p["since_id"] = $0 } - trimUser.map { p["trim_user"] = $0 } - includeRTs.map { p["include_rts"] = $0 } - excludeReplies.map { p["exclude_replies"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + count.map { params["count"] = $0 } + maxID.map { params["max_id"] = $0 } + sinceID.map { params["since_id"] = $0 } + trimUser.map { params["trim_user"] = $0 } + includeRTs.map { params["include_rts"] = $0 } + excludeReplies.map { params["exclude_replies"] = $0 } + return params } public init( @@ -48,4 +52,7 @@ open class GetStatusesUserTimelineRequestV1: TwitterAPIRequest { self.includeRTs = includeRTs self.excludeReplies = excludeReplies } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Timelines/TimelineAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Timelines/TimelineAPIv1.swift index e477a2c7..200b4132 100644 --- a/Sources/TwitterAPIKit/APIv1/Timelines/TimelineAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Timelines/TimelineAPIv1.swift @@ -1,26 +1,45 @@ +// TimelineAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/overview +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/ +/// overview open class TimelineAPIv1: TwitterAPIBase { - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/api-reference/get-statuses-home_timeline + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/ + /// api-reference/get-statuses-home_timeline public func getHomeTimeline( _ request: GetStatusesHomeTimelineRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/api-reference/get-statuses-mentions_timeline + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/ + /// overview + /// api-reference/get-statuses-mentions_timeline public func getMentionsTimeline( _ request: GetStatusesMentionsTimelineRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/api-reference/get-statuses-user_timeline + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/ + /// api-reference/get-statuses-user_timeline public func getUserTimeline( _ request: GetStatusesUserTimelineRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Trend/Requests/GetTrendsAvailableRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Trend/Requests/GetTrendsAvailableRequestV1.swift index 89b645c9..bf2d3021 100644 --- a/Sources/TwitterAPIKit/APIv1/Trend/Requests/GetTrendsAvailableRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Trend/Requests/GetTrendsAvailableRequestV1.swift @@ -1,8 +1,14 @@ +// GetTrendsAvailableRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/trends/locations-with-trending-topics/api-reference/get-trends-available +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/trends/trends-for-location/ +/// api-reference/get-trends-available open class GetTrendsAvailableRequestV1: TwitterAPIRequest { - public var method: HTTPMethod { return .get } @@ -16,5 +22,7 @@ open class GetTrendsAvailableRequestV1: TwitterAPIRequest { } public init() {} - + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Trend/Requests/GetTrendsClosestRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Trend/Requests/GetTrendsClosestRequestV1.swift index 7ec24ce7..895adf2c 100644 --- a/Sources/TwitterAPIKit/APIv1/Trend/Requests/GetTrendsClosestRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Trend/Requests/GetTrendsClosestRequestV1.swift @@ -1,8 +1,14 @@ +// GetTrendsClosestRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/trends/locations-with-trending-topics/api-reference/get-trends-closest +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/trends/trends-for-location/ +/// api-reference/get-trends-closest open class GetTrendsClosestRequestV1: TwitterAPIRequest { - public let location: TwitterCoordinateV1 public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class GetTrendsClosestRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - location.bind(param: &p) - return p + var params = [String: Any]() + location.bind(param: ¶ms) + return params } public init( @@ -24,4 +30,7 @@ open class GetTrendsClosestRequestV1: TwitterAPIRequest { ) { self.location = location } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Trend/Requests/GetTrendsPlaceRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Trend/Requests/GetTrendsPlaceRequestV1.swift index 5e98e24b..7100d8db 100644 --- a/Sources/TwitterAPIKit/APIv1/Trend/Requests/GetTrendsPlaceRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Trend/Requests/GetTrendsPlaceRequestV1.swift @@ -1,8 +1,12 @@ +// GetTrendsPlaceRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/trends/trends-for-location/api-reference/get-trends-place open class GetTrendsPlaceRequestV1: TwitterAPIRequest { - /// Where On Earth ID Global public let woeid: String @@ -18,10 +22,10 @@ open class GetTrendsPlaceRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["woeid"] = woeid - exclude.map { p["exclude"] = $0 } - return p + var params = [String: Any]() + params["woeid"] = woeid + exclude.map { params["exclude"] = $0 } + return params } public init( @@ -31,4 +35,7 @@ open class GetTrendsPlaceRequestV1: TwitterAPIRequest { self.woeid = woeid self.exclude = exclude } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Trend/TrendAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Trend/TrendAPIv1.swift index 14e3fa0b..c7890371 100644 --- a/Sources/TwitterAPIKit/APIv1/Trend/TrendAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Trend/TrendAPIv1.swift @@ -1,25 +1,39 @@ +// TrendAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class TrendAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/trends/locations-with-trending-topics/api-reference/get-trends-available + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/trends/ + /// trends-for-location/api-reference/get-trends-available public func getTrendsAvailable( _ request: GetTrendsAvailableRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/trends/locations-with-trending-topics/api-reference/get-trends-closest + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/trends/ + /// locations-with-trending-topics/api-reference/get-trends-closest public func getTrendsClosest( _ request: GetTrendsClosestRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/trends/trends-for-location/api-reference/get-trends-place + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/trends/ + /// trends-for-location/api-reference/get-trends-place public func getTrends( _ request: GetTrendsPlaceRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Tweet/Requests/GetStatusesLookupRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Tweet/Requests/GetStatusesLookupRequestV1.swift index 0796e663..30316349 100644 --- a/Sources/TwitterAPIKit/APIv1/Tweet/Requests/GetStatusesLookupRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Tweet/Requests/GetStatusesLookupRequestV1.swift @@ -1,8 +1,12 @@ +// GetStatusesLookupRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-lookup open class GetStatusesLookupRequestV1: TwitterAPIRequest { - public let ids: [String] public let map: Bool? public let trimUser: Bool? @@ -19,14 +23,14 @@ open class GetStatusesLookupRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["id"] = ids.joined(separator: ",") - map.map { p["map"] = $0 } - trimUser.map { p["trim_user"] = $0 } - includeCardUri.map { p["include_card_uri"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - includeExtAltText.map { p["include_ext_alt_text"] = $0 } - return p + var params = [String: Any]() + params["id"] = ids.joined(separator: ",") + map.map { params["map"] = $0 } + trimUser.map { params["trim_user"] = $0 } + includeCardUri.map { params["include_card_uri"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + includeExtAltText.map { params["include_ext_alt_text"] = $0 } + return params } public init( @@ -44,4 +48,7 @@ open class GetStatusesLookupRequestV1: TwitterAPIRequest { self.includeEntities = includeEntities self.includeExtAltText = includeExtAltText } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Tweet/Requests/GetStatusesShowRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Tweet/Requests/GetStatusesShowRequestV1.swift index 1eff520d..c99a72b7 100644 --- a/Sources/TwitterAPIKit/APIv1/Tweet/Requests/GetStatusesShowRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Tweet/Requests/GetStatusesShowRequestV1.swift @@ -1,8 +1,12 @@ +// GetStatusesShowRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-show-id open class GetStatusesShowRequestV1: TwitterAPIRequest { - public let id: String public let trimUser: Bool? public let includeCardUri: Bool? @@ -19,14 +23,14 @@ open class GetStatusesShowRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["id"] = id - trimUser.map { p["trim_user"] = $0 } - includeCardUri.map { p["include_card_uri"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - includeMyRetweet.map { p["include_my_retweet"] = $0 } - includeExtAltText.map { p["include_ext_alt_text"] = $0 } - return p + var params = [String: Any]() + params["id"] = id + trimUser.map { params["trim_user"] = $0 } + includeCardUri.map { params["include_card_uri"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + includeMyRetweet.map { params["include_my_retweet"] = $0 } + includeExtAltText.map { params["include_ext_alt_text"] = $0 } + return params } public init( @@ -44,5 +48,7 @@ open class GetStatusesShowRequestV1: TwitterAPIRequest { self.includeMyRetweet = includeMyRetweet self.includeExtAltText = includeExtAltText } - + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Tweet/Requests/PostStatusesDestroyRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Tweet/Requests/PostStatusesDestroyRequestV1.swift index 30108d2e..faa5666a 100644 --- a/Sources/TwitterAPIKit/APIv1/Tweet/Requests/PostStatusesDestroyRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Tweet/Requests/PostStatusesDestroyRequestV1.swift @@ -1,8 +1,12 @@ +// PostStatusesDestroyRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-destroy-id open class PostStatusesDestroyRequestV1: TwitterAPIRequest { - public let id: String public let trimUser: Bool? @@ -13,10 +17,11 @@ open class PostStatusesDestroyRequestV1: TwitterAPIRequest { public var path: String { return "/1.1/statuses/destroy/\(id).json" } + open var parameters: [String: Any] { - var p = [String: Any]() - trimUser.map { p["trim_user"] = $0 } - return p + var params = [String: Any]() + trimUser.map { params["trim_user"] = $0 } + return params } public init( @@ -26,4 +31,7 @@ open class PostStatusesDestroyRequestV1: TwitterAPIRequest { self.id = id self.trimUser = trimUser } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Tweet/Requests/PostUpdateStatusRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Tweet/Requests/PostStatusesUpdateRequestV1.swift similarity index 64% rename from Sources/TwitterAPIKit/APIv1/Tweet/Requests/PostUpdateStatusRequestV1.swift rename to Sources/TwitterAPIKit/APIv1/Tweet/Requests/PostStatusesUpdateRequestV1.swift index b86a52c9..a761ad01 100644 --- a/Sources/TwitterAPIKit/APIv1/Tweet/Requests/PostUpdateStatusRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Tweet/Requests/PostStatusesUpdateRequestV1.swift @@ -1,8 +1,12 @@ +// PostUpdateStatusRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-update open class PostStatusesUpdateRequestV1: TwitterAPIRequest { - public let status: String public let inReplyToStatusID: String? public let autoPopulateReplyMetadata: Bool? @@ -27,22 +31,22 @@ open class PostStatusesUpdateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["status"] = status - inReplyToStatusID.map { p["in_reply_to_status_id"] = $0 } - autoPopulateReplyMetadata.map { p["auto_populate_reply_metadata"] = $0 } - excludeReplyUserIDs.map { p["exclude_reply_user_ids"] = $0.joined(separator: ",") } - attachmentUrl.map { p["attachment_url"] = $0 } - mediaIDs.map { p["media_ids"] = $0.joined(separator: ",") } - possiblySensitive.map { p["possibly_sensitive"] = $0 } - location?.bind(param: &p) - placeID.map { p["place_id"] = $0 } - displayCoordinates.map { p["display_coordinates"] = $0 } - trimUser.map { p["trim_user"] = $0 } - enableDMcommands.map { p["enable_dmcommands"] = $0 } - failDMcommands.map { p["fail_dmcommands"] = $0 } - cardUri.map { p["card_uri"] = $0 } - return p + var params = [String: Any]() + params["status"] = status + inReplyToStatusID.map { params["in_reply_to_status_id"] = $0 } + autoPopulateReplyMetadata.map { params["auto_populate_reply_metadata"] = $0 } + excludeReplyUserIDs.map { params["exclude_reply_user_ids"] = $0.joined(separator: ",") } + attachmentUrl.map { params["attachment_url"] = $0 } + mediaIDs.map { params["media_ids"] = $0.joined(separator: ",") } + possiblySensitive.map { params["possibly_sensitive"] = $0 } + location?.bind(param: ¶ms) + placeID.map { params["place_id"] = $0 } + displayCoordinates.map { params["display_coordinates"] = $0 } + trimUser.map { params["trim_user"] = $0 } + enableDMcommands.map { params["enable_dmcommands"] = $0 } + failDMcommands.map { params["fail_dmcommands"] = $0 } + cardUri.map { params["card_uri"] = $0 } + return params } public init( @@ -76,5 +80,7 @@ open class PostStatusesUpdateRequestV1: TwitterAPIRequest { self.failDMcommands = failDMcommands self.cardUri = cardUri } - + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Tweet/TweetAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Tweet/TweetAPIv1.swift index 94d06540..ad826192 100644 --- a/Sources/TwitterAPIKit/APIv1/Tweet/TweetAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Tweet/TweetAPIv1.swift @@ -1,35 +1,48 @@ +// TweetAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class TweetAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-update + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ + /// post-and-engage/api-reference/post-statuses-update public func postUpdateStatus( _ request: PostStatusesUpdateRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-destroy-id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ + /// post-and-engage/api-reference/post-statuses-destroy-id public func postDestroyStatus( _ request: PostStatusesDestroyRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-show-id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ + /// post-and-engage/api-reference/get-statuses-show-id public func getShowStatus( _ request: GetStatusesShowRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-lookup + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/ + /// post-and-engage/api-reference/get-statuses-lookup public func getLookupStatuses( _ request: GetStatusesLookupRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-oembed - // TODO↑ + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/TwitterAPIv1.swift b/Sources/TwitterAPIKit/APIv1/TwitterAPIv1.swift index dd47ea0d..5e917a38 100644 --- a/Sources/TwitterAPIKit/APIv1/TwitterAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/TwitterAPIv1.swift @@ -1,22 +1,70 @@ -open class TwitterAPIv1 { +// TwitterAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + +/// A protocol that represents a Twitter API. +public protocol TwitterAPI { + // No Logic Here +} + +/// Main class for accessing Twitter API v1.1 endpoints. +/// This class provides access to all Twitter API v1.1 functionality through specialized API clients. +/// Each property represents a group of related API endpoints. +open class TwitterAPIv1: TwitterAPI { + /// API client for managing Twitter account settings and profile information. public let account: AccountAPIv1 + + /// API client for accessing application-level information and rate limits. public let application: ApplicationAPIv1 + + /// API client for managing blocked and muted users. public let blockAndMute: BlockAndMuteAPIv1 + + /// API client for managing Twitter collections (curated groups of tweets). public let collection: CollectionAPIv1 + + /// API client for sending and receiving direct messages. public let directMessage: DirectMessageAPIv1 + + /// API client for managing tweet favorites (likes). public let favorite: FavoriteAPIv1 + + /// API client for managing user relationships (following/followers). public let friendships: FriendshipsAPIv1 + + /// API client for accessing Twitter's geo-location features. public let geo: GeoAPIv1 + + /// API client for accessing Twitter platform information and supported features. public let help: HelpAPIv1 + + /// API client for managing Twitter lists. public let list: ListAPIv1 + + /// API client for uploading and managing media attachments. public let media: MediaAPIv1 + + /// API client for managing retweets. public let retweet: RetweetAPIv1 + + /// API client for searching tweets and managing saved searches. public let search: SearchAPIv1 + + /// API client for accessing user timelines. public let timeline: TimelineAPIv1 + + /// API client for accessing trending topics. public let trend: TrendAPIv1 + + /// API client for creating, deleting, and retrieving tweets. public let tweet: TweetAPIv1 + + /// API client for managing and retrieving user information. public let user: UserAPIv1 + /// Creates a new Twitter API v1.1 client. + /// - Parameter session: The Twitter API session to use for making requests. public init(session: TwitterAPISession) { account = .init(session: session) application = .init(session: session) @@ -36,4 +84,8 @@ open class TwitterAPIv1 { tweet = .init(session: session) user = .init(session: session) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/TwitterListIdentifierV1.swift b/Sources/TwitterAPIKit/APIv1/TwitterListIdentifierV1.swift index faeee8e3..3c8c8468 100644 --- a/Sources/TwitterAPIKit/APIv1/TwitterListIdentifierV1.swift +++ b/Sources/TwitterAPIKit/APIv1/TwitterListIdentifierV1.swift @@ -1,21 +1,38 @@ +// TwitterListIdentifierV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// Represents different ways to identify a Twitter list in API v1.1. +/// Lists can be identified either by their unique ID or by a combination of slug and owner. public enum TwitterListIdentifierV1 { + /// Identifies a list by its unique numeric ID. + /// - Parameter listID: The unique identifier of the list. case listID(String) + + /// Identifies a list by its slug (URL-friendly name) and owner. + /// - Parameters: + /// - slug: The URL-friendly name of the list. + /// - owner: The identifier of the list's owner. case slug(slug: String, owner: TwitterUserIdentifierV1) } extension TwitterListIdentifierV1 { - func bind(param: inout [String: Any]) { + /// Binds the list identifier to the request parameters. + /// - Parameters: + /// - param: The parameters dictionary to bind to. + public func bind(param: inout [String: Any]) { switch self { - case .listID(let string): + case let .listID(string): param["list_id"] = string - case .slug(let slug, let owner): + case let .slug(slug, owner): param["slug"] = slug switch owner { - case .userID(let string): + case let .userID(string): param["owner_id"] = string - case .screenName(let string): + case let .screenName(string): param["owner_screen_name"] = string } } diff --git a/Sources/TwitterAPIKit/APIv1/TwitterListModeV1.swift b/Sources/TwitterAPIKit/APIv1/TwitterListModeV1.swift index 524f5783..8f80286e 100644 --- a/Sources/TwitterAPIKit/APIv1/TwitterListModeV1.swift +++ b/Sources/TwitterAPIKit/APIv1/TwitterListModeV1.swift @@ -1,11 +1,24 @@ +// TwitterListModeV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// Represents the visibility mode of a Twitter list in API v1.1. +/// Lists can be either public (visible to all users) or private (visible only to the owner). public enum TwitterListModeV1 { - case `public` + /// The list is private and only visible to its owner. case `private` + + /// The list is publicly visible to all Twitter users. + case `public` } -extension TwitterListModeV1 { +public extension TwitterListModeV1 { + /// Binds the list mode to the request parameters. + /// - Parameters: + /// - param: The parameters dictionary to bind to. func bind(param: inout [String: Any]) { switch self { case .public: diff --git a/Sources/TwitterAPIKit/APIv1/TwitterLocations.swift b/Sources/TwitterAPIKit/APIv1/TwitterLocations.swift index 96de0a18..f930aa3f 100644 --- a/Sources/TwitterAPIKit/APIv1/TwitterLocations.swift +++ b/Sources/TwitterAPIKit/APIv1/TwitterLocations.swift @@ -1,43 +1,68 @@ +// TwitterLocations.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -public struct TwitterCoordinateV1 { - var lat: Double - var long: Double +/// A protocol that represents a location in the Twitter API v1 +public protocol TwitterLocations { + // No Logic Here +} + +/// Represents geographical coordinates in the Twitter API v1 +public struct TwitterCoordinateV1: TwitterLocations { + /// The latitude coordinate + public var lat: Double + /// The longitude coordinate + public var long: Double + /// Creates a new coordinate with the specified latitude and longitude public init(lat: Double, long: Double) { self.lat = lat self.long = long } - func bind(param: inout [String: Any]) { + /// Binds the coordinate values to the provided parameters dictionary + public func bind(param: inout [String: Any]) { param["lat"] = lat param["long"] = long } } -public enum TwitterAccuracyV1 { - /// meter - case m(Int) - /// feet +/// Represents accuracy levels for geographical locations +public enum TwitterAccuracyV1: TwitterLocations { +// swiftlint:disable identifier_name + /// Accuracy in feet case ft(Int) + /// Accuracy in meters + case m(Int) - func bind(param: inout [String: Any]) { + /// Binds the accuracy value to the provided parameters dictionary + public func bind(param: inout [String: Any]) { switch self { - case .m(let int): + case let .m(int): param["accuracy"] = "\(int)m" - case .ft(let int): + case let .ft(int): param["accuracy"] = "\(int)ft" } } } +// swiftlint:enable identifier_name +/// Represents the granularity level for geographical locations public enum TwitterGranularityV1: String { - case neighborhood - case city + /// Administrative level granularity case admin + /// City level granularity + case city + /// Country levelk granularity case country + /// Neighborhood level granularity + case neighborhood - func bind(param: inout [String: Any]) { + /// Binds the granularity value to the provided parameters dictionary + public func bind(param: inout [String: Any]) { param["granularity"] = rawValue } } diff --git a/Sources/TwitterAPIKit/APIv1/TwitterUserIdentifierV1.swift b/Sources/TwitterAPIKit/APIv1/TwitterUserIdentifierV1.swift index f49b14ff..0be63a50 100644 --- a/Sources/TwitterAPIKit/APIv1/TwitterUserIdentifierV1.swift +++ b/Sources/TwitterAPIKit/APIv1/TwitterUserIdentifierV1.swift @@ -1,34 +1,61 @@ +// TwitterUserIdentifierV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// Represents a way to identify a single Twitter user in the v1.1 API. public enum TwitterUserIdentifierV1 { - case userID(String) + /// Identifies a user by their screen name (username). + /// - Parameter String: The user's screen name without the @ symbol. case screenName(String) + + /// Identifies a user by their numeric user ID. + /// - Parameter String: The user's unique numeric ID. + case userID(String) } -public enum TwitterUsersIdentifierV1 { - case userIDs([String]) +/// Represents a way to identify multiple Twitter users in the v1.1 API. +public enum TwitterUsersIdentifierV1 { + /// Identifies multiple users by their screen names (usernames). + /// - Parameter [String]: An array of screen names without the @ symbol. case screenNames([String]) + + /// Identifies multiple users by their numeric user IDs. + /// - Parameter [String]: An array of user IDs. + case userIDs([String]) } // MARK: - extensions +/// Extension to bind user identifier to request parameters extension TwitterUserIdentifierV1 { - func bind(param: inout [String: Any], userIDKey: String = "user_id", screenNameKey: String = "screen_name") { + /// Binds the user identifier to the request parameters + /// - Parameters: + /// - param: The parameters dictionary to bind to + /// - userIDKey: The key to use for the user ID + /// - screenNameKey: The key to use for the screen name + public func bind(param: inout [String: Any], userIDKey: String = "user_id", screenNameKey: String = "screen_name") { switch self { - case .userID(let string): + case let .userID(string): param[userIDKey] = string - case .screenName(let string): + case let .screenName(string): param[screenNameKey] = string } } } +/// Extension to bind multiple user identifiers to request parameters extension TwitterUsersIdentifierV1 { - func bind(param: inout [String: Any]) { + /// Binds the multiple user identifiers to the request parameters + /// - Parameters: + /// - param: The parameters dictionary to bind to + public func bind(param: inout [String: Any]) { switch self { - case .userIDs(let array): + case let .userIDs(array): param["user_id"] = array.joined(separator: ",") - case .screenNames(let array): + case let .screenNames(array): param["screen_name"] = array.joined(separator: ",") } } diff --git a/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersLookupRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersLookupRequestV1.swift index f5acc19b..04471a91 100644 --- a/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersLookupRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersLookupRequestV1.swift @@ -1,8 +1,14 @@ +// GetUsersLookupRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-users-lookup +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/get-users-lookup open class GetUsersLookupRequestV1: TwitterAPIRequest { - public let users: TwitterUsersIdentifierV1 public let tweetMode: Bool? public let includeEntities: Bool? @@ -16,11 +22,11 @@ open class GetUsersLookupRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - users.bind(param: &p) - tweetMode.map { p["tweet_mode"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - return p + var params = [String: Any]() + users.bind(param: ¶ms) + tweetMode.map { params["tweet_mode"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + return params } public init( @@ -32,4 +38,8 @@ open class GetUsersLookupRequestV1: TwitterAPIRequest { self.tweetMode = tweetMode self.includeEntities = includeEntities } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersProfileBannerRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersProfileBannerRequestV1.swift index 7268e94b..3ca0314e 100644 --- a/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersProfileBannerRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersProfileBannerRequestV1.swift @@ -1,8 +1,14 @@ +// GetUsersProfileBannerRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-users-profile_banner +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// manage-account-settings/api-reference/get-users-profile_banner open class GetUsersProfileBannerRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class GetUsersProfileBannerRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - return p + var params = [String: Any]() + user.bind(param: ¶ms) + return params } public init( @@ -24,4 +30,8 @@ open class GetUsersProfileBannerRequestV1: TwitterAPIRequest { ) { self.user = user } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersSearchRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersSearchRequestV1.swift index f7945cb2..6df02c90 100644 --- a/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersSearchRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersSearchRequestV1.swift @@ -1,9 +1,15 @@ +// GetUsersSearchRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-users-search +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/get-users-search open class GetUsersSearchRequestV1: TwitterAPIRequest { - - public let q: String + public let query: String public let page: Int? public let count: Int? public let includeEntities: Bool? @@ -17,23 +23,27 @@ open class GetUsersSearchRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["q"] = q - page.map { p["page"] = $0 } - count.map { p["count"] = $0 } - includeEntities.map { p["include_entities"] = $0 } - return p + var params = [String: Any]() + params["q"] = query + page.map { params["page"] = $0 } + count.map { params["count"] = $0 } + includeEntities.map { params["include_entities"] = $0 } + return params } public init( - q: String, + query: String, page: Int? = .none, count: Int? = .none, includeEntities: Bool? = .none ) { - self.q = q + self.query = query self.page = page self.count = count self.includeEntities = includeEntities } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersShowRequestV1.swift b/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersShowRequestV1.swift index 650cde93..ca6dad1e 100644 --- a/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersShowRequestV1.swift +++ b/Sources/TwitterAPIKit/APIv1/Users/Requests/GetUsersShowRequestV1.swift @@ -1,8 +1,14 @@ +// GetUsersShowRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-users-show +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/ +/// follow-search-get-users/api-reference/get-users-show open class GetUsersShowRequestV1: TwitterAPIRequest { - public let user: TwitterUserIdentifierV1 public let includeEntities: Bool? @@ -15,10 +21,10 @@ open class GetUsersShowRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - user.bind(param: &p) - includeEntities.map { p["include_entities"] = $0 } - return p + var params = [String: Any]() + user.bind(param: ¶ms) + includeEntities.map { params["include_entities"] = $0 } + return params } public init( @@ -28,4 +34,8 @@ open class GetUsersShowRequestV1: TwitterAPIRequest { self.user = user self.includeEntities = includeEntities } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv1/Users/UserAPIv1.swift b/Sources/TwitterAPIKit/APIv1/Users/UserAPIv1.swift index 1f144164..f6fae092 100644 --- a/Sources/TwitterAPIKit/APIv1/Users/UserAPIv1.swift +++ b/Sources/TwitterAPIKit/APIv1/Users/UserAPIv1.swift @@ -1,32 +1,48 @@ +// UserAPIv1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class UserAPIv1: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-users-lookup + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/get-users-lookup public func getUsers( _ request: GetUsersLookupRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-users-show + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/get-users-show public func getUser( _ request: GetUsersShowRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-users-search + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/ + /// api-reference/get-users-search public func searchUser( _ request: GetUsersShowRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-users-profile_banner + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/ + /// api-reference/get-users-profile_banner public func getUserProfileBanner( _ request: GetUsersProfileBannerRequestV1 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/BlockAndMute/BlockAndMuteAPIv2.swift b/Sources/TwitterAPIKit/APIv2/BlockAndMute/BlockAndMuteAPIv2.swift index bd595b09..df1ed4b8 100644 --- a/Sources/TwitterAPIKit/APIv2/BlockAndMute/BlockAndMuteAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/BlockAndMute/BlockAndMuteAPIv2.swift @@ -1,7 +1,11 @@ +// BlockAndMuteAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class BlockAndMuteAPIv2: TwitterAPIBase { - /// https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/get-users-blocking public func getBlockUsers( _ request: GetUsersBlockingRequestV2 @@ -43,4 +47,8 @@ open class BlockAndMuteAPIv2: TwitterAPIBase { ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/DeleteUsersBlockingRequestV2.swift b/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/DeleteUsersBlockingRequestV2.swift index 220607cc..2310fe0d 100644 --- a/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/DeleteUsersBlockingRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/DeleteUsersBlockingRequestV2.swift @@ -1,8 +1,12 @@ +// DeleteUsersBlockingRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/delete-users-user_id-blocking open class DeleteUsersBlockingRequestV2: TwitterAPIRequest { - public let sourceUserID: String public let targetUserID: String @@ -25,4 +29,7 @@ open class DeleteUsersBlockingRequestV2: TwitterAPIRequest { self.sourceUserID = sourceUserID self.targetUserID = targetUserID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/DeleteUsersMutingRequestV2.swift b/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/DeleteUsersMutingRequestV2.swift index 7fd0e23d..4784824d 100644 --- a/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/DeleteUsersMutingRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/DeleteUsersMutingRequestV2.swift @@ -1,8 +1,12 @@ +// DeleteUsersMutingRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/delete-users-user_id-muting open class DeleteUsersMutingRequestV2: TwitterAPIRequest { - public let sourceUserID: String public let targetUserID: String @@ -25,4 +29,7 @@ open class DeleteUsersMutingRequestV2: TwitterAPIRequest { self.sourceUserID = sourceUserID self.targetUserID = targetUserID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/GetUsersBlockingRequestV2.swift b/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/GetUsersBlockingRequestV2.swift index 67bb76e2..9de9812b 100644 --- a/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/GetUsersBlockingRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/GetUsersBlockingRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersBlockingRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/get-users-blocking open class GetUsersBlockingRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let maxResults: Int? @@ -19,13 +23,13 @@ open class GetUsersBlockingRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -43,4 +47,7 @@ open class GetUsersBlockingRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/GetUsersMutingRequestV2.swift b/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/GetUsersMutingRequestV2.swift index 6dca6307..839fa9a2 100644 --- a/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/GetUsersMutingRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/GetUsersMutingRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersMutingRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/get-users-muting open class GetUsersMutingRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let maxResults: Int? @@ -19,13 +23,13 @@ open class GetUsersMutingRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -43,4 +47,7 @@ open class GetUsersMutingRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/PostUsersBlockingRequestV2.swift b/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/PostUsersBlockingRequestV2.swift index 3c864ff5..784ff6c2 100644 --- a/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/PostUsersBlockingRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/PostUsersBlockingRequestV2.swift @@ -1,8 +1,12 @@ +// PostUsersBlockingRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/post-users-user_id-blocking open class PostUsersBlockingRequestV2: TwitterAPIRequest { - public let id: String public let targetUserID: String @@ -19,9 +23,9 @@ open class PostUsersBlockingRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["target_user_id"] = targetUserID - return p + var params = [String: Any]() + params["target_user_id"] = targetUserID + return params } public init( @@ -31,4 +35,7 @@ open class PostUsersBlockingRequestV2: TwitterAPIRequest { self.id = id self.targetUserID = targetUserID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/PostUsersMutingRequestV2.swift b/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/PostUsersMutingRequestV2.swift index 0de67654..e5bbc93b 100644 --- a/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/PostUsersMutingRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/BlockAndMute/Requests/PostUsersMutingRequestV2.swift @@ -1,8 +1,12 @@ +// PostUsersMutingRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/post-users-user_id-muting open class PostUsersMutingRequestV2: TwitterAPIRequest { - public let id: String public let targetUserID: String @@ -19,9 +23,9 @@ open class PostUsersMutingRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["target_user_id"] = targetUserID - return p + var params = [String: Any]() + params["target_user_id"] = targetUserID + return params } public init( @@ -31,4 +35,7 @@ open class PostUsersMutingRequestV2: TwitterAPIRequest { self.id = id self.targetUserID = targetUserID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Bookmarks/BookmarksAPIv2.swift b/Sources/TwitterAPIKit/APIv2/Bookmarks/BookmarksAPIv2.swift index 13e94fa2..74d118fd 100644 --- a/Sources/TwitterAPIKit/APIv2/Bookmarks/BookmarksAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/Bookmarks/BookmarksAPIv2.swift @@ -1,25 +1,39 @@ +// BookmarksAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class BookmarksAPIv2: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/get-users-id-bookmarks + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/ + /// api-reference/get-users-id-bookmarks public func getBookmarks( _ request: GetUsersBookmarksRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/post-users-id-bookmarks + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/ + /// api-reference/post-users-id-bookmarks public func createBookmark( _ request: PostUsersBookmarksRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/delete-users-id-bookmarks-tweet_id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/ + /// api-reference/delete-users-id-bookmarks-tweet_id public func deleteBookmark( _ request: DeleteUsersBookmarksRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Bookmarks/Requests/DeleteUsersBookmarksRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Bookmarks/Requests/DeleteUsersBookmarksRequestV2.swift index ce9904a4..cd5ed1c0 100644 --- a/Sources/TwitterAPIKit/APIv2/Bookmarks/Requests/DeleteUsersBookmarksRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Bookmarks/Requests/DeleteUsersBookmarksRequestV2.swift @@ -1,9 +1,15 @@ +// DeleteUsersBookmarksRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/delete-users-id-bookmarks-tweet_id open class DeleteUsersBookmarksRequestV2: TwitterAPIRequest { - - /// The user ID of an authenticated user who you are removing a Bookmark of a Tweet on behalf of. It must match your own user ID or that of an authenticating user, meaning that you must pass the Access Tokens associated with the user ID when authenticating your request. + /// The user ID of an authenticated user who you are removing a Bookmark of a Tweet on behalf of. It must match your + /// own user ID or that of an authenticating user, meaning that you must pass the Access Tokens associated with the + /// user ID when authenticating your request. public let id: String public let tweetID: String @@ -26,4 +32,7 @@ open class DeleteUsersBookmarksRequestV2: TwitterAPIRequest { self.id = id self.tweetID = tweetID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Bookmarks/Requests/GetUsersBookmarksRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Bookmarks/Requests/GetUsersBookmarksRequestV2.swift index f05e12f4..2eeca539 100644 --- a/Sources/TwitterAPIKit/APIv2/Bookmarks/Requests/GetUsersBookmarksRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Bookmarks/Requests/GetUsersBookmarksRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersBookmarksRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/get-users-id-bookmarks open class GetUsersBookmarksRequestV2: TwitterAPIRequest { - /// User ID of an authenticated user to request bookmarked Tweets for. public let id: String public let expansions: Set? @@ -23,16 +27,16 @@ open class GetUsersBookmarksRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - mediaFields?.bind(param: &p) - paginationToken.map { p["pagination_token"] = $0 } - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + mediaFields?.bind(param: ¶ms) + paginationToken.map { params["pagination_token"] = $0 } + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -56,4 +60,7 @@ open class GetUsersBookmarksRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Bookmarks/Requests/PostUsersBookmarksRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Bookmarks/Requests/PostUsersBookmarksRequestV2.swift index ea3d4059..bc66520d 100644 --- a/Sources/TwitterAPIKit/APIv2/Bookmarks/Requests/PostUsersBookmarksRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Bookmarks/Requests/PostUsersBookmarksRequestV2.swift @@ -1,9 +1,15 @@ +// PostUsersBookmarksRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/post-users-id-bookmarks open class PostUsersBookmarksRequestV2: TwitterAPIRequest { - - /// The user ID who you are bookmarking a Tweet on behalf of. It must match your own user ID or that of an authenticating user, meaning that you must pass the Access Token associated with the user ID when authenticating your request. + /// The user ID who you are bookmarking a Tweet on behalf of. It must match your own user ID or that of an + /// authenticating user, meaning that you must pass the Access Token associated with the user ID when authenticating + /// your request. public let id: String public let tweetID: String @@ -20,9 +26,9 @@ open class PostUsersBookmarksRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["tweet_id"] = tweetID - return p + var params = [String: Any]() + params["tweet_id"] = tweetID + return params } public init( @@ -32,4 +38,7 @@ open class PostUsersBookmarksRequestV2: TwitterAPIRequest { self.id = id self.tweetID = tweetID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Compliance/ComplianceAPIv2.swift b/Sources/TwitterAPIKit/APIv2/Compliance/ComplianceAPIv2.swift index 514c47d9..05431f8f 100644 --- a/Sources/TwitterAPIKit/APIv2/Compliance/ComplianceAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/Compliance/ComplianceAPIv2.swift @@ -1,25 +1,39 @@ +// ComplianceAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class ComplianceAPIv2: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/get-compliance-jobs-id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/ + /// api-reference/get-compliance-jobs-id public func getComplianceJob( _ request: GetComplianceJobRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/get-compliance-jobs + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/ + /// api-reference/get-compliance-jobs public func getComplianceJobj( _ request: GetComplianceJobsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/post-compliance-jobs + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/ + /// api-reference/post-compliance-jobs public func createComplianceJob( _ request: PostComplianceJobsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Compliance/Requests/GetComplianceJobRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Compliance/Requests/GetComplianceJobRequestV2.swift index 970ac81c..519c33cb 100644 --- a/Sources/TwitterAPIKit/APIv2/Compliance/Requests/GetComplianceJobRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Compliance/Requests/GetComplianceJobRequestV2.swift @@ -1,8 +1,12 @@ +// GetComplianceJobRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/get-compliance-jobs-id open class GetComplianceJobRequestV2: TwitterAPIRequest { - public let id: Int public var method: HTTPMethod { @@ -22,4 +26,7 @@ open class GetComplianceJobRequestV2: TwitterAPIRequest { ) { self.id = id } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Compliance/Requests/GetComplianceJobsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Compliance/Requests/GetComplianceJobsRequestV2.swift index 3155fc59..a2c11690 100644 --- a/Sources/TwitterAPIKit/APIv2/Compliance/Requests/GetComplianceJobsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Compliance/Requests/GetComplianceJobsRequestV2.swift @@ -1,14 +1,18 @@ +// GetComplianceJobsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/get-compliance-jobs open class GetComplianceJobsRequestV2: TwitterAPIRequest { - public enum Status: String { case created case inProgress = "in_progress" case failed case complete - func bind(param: inout [String: Any]) { + public func bind(param: inout [String: Any]) { param["status"] = rawValue } } @@ -25,10 +29,10 @@ open class GetComplianceJobsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - type.bind(param: &p) - status?.bind(param: &p) - return p + var params = [String: Any]() + type.bind(param: ¶ms) + status?.bind(param: ¶ms) + return params } public init( @@ -38,4 +42,7 @@ open class GetComplianceJobsRequestV2: TwitterAPIRequest { self.type = type self.status = status } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Compliance/Requests/PostComplianceJobsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Compliance/Requests/PostComplianceJobsRequestV2.swift index 9691a0bf..b729964b 100644 --- a/Sources/TwitterAPIKit/APIv2/Compliance/Requests/PostComplianceJobsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Compliance/Requests/PostComplianceJobsRequestV2.swift @@ -1,8 +1,12 @@ +// PostComplianceJobsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/post-compliance-jobs open class PostComplianceJobsRequestV2: TwitterAPIRequest { - public let type: TwitterComplianceJobTypeV2 public let name: String? public let resumable: Bool? @@ -20,11 +24,11 @@ open class PostComplianceJobsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - type.bind(param: &p) - name.map { p["name"] = $0 } - resumable.map { p["resumable"] = $0 } - return p + var params = [String: Any]() + type.bind(param: ¶ms) + name.map { params["name"] = $0 } + resumable.map { params["resumable"] = $0 } + return params } public init( @@ -36,4 +40,7 @@ open class PostComplianceJobsRequestV2: TwitterAPIRequest { self.name = name self.resumable = resumable } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Compliance/TwitterComplianceJobTypeV2.swift b/Sources/TwitterAPIKit/APIv2/Compliance/TwitterComplianceJobTypeV2.swift index 2bc380e5..8e78d2cf 100644 --- a/Sources/TwitterAPIKit/APIv2/Compliance/TwitterComplianceJobTypeV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Compliance/TwitterComplianceJobTypeV2.swift @@ -1,10 +1,15 @@ +// TwitterComplianceJobTypeV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation public enum TwitterComplianceJobTypeV2: String { case tweets case users - func bind(param: inout [String: Any]) { + public func bind(param: inout [String: Any]) { param["type"] = rawValue } } diff --git a/Sources/TwitterAPIKit/APIv2/DirectMessage/DirectMessageAPIv2.swift b/Sources/TwitterAPIKit/APIv2/DirectMessage/DirectMessageAPIv2.swift index 20d8b5d3..9caef205 100644 --- a/Sources/TwitterAPIKit/APIv2/DirectMessage/DirectMessageAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/DirectMessage/DirectMessageAPIv2.swift @@ -1,45 +1,66 @@ +// DirectMessageAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class DirectMessageAPIv2: TwitterAPIBase { - /// https://developer.twitter.com/en/docs/twitter-api/direct-messages/lookup/api-reference/get-dm_events + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/direct-messages/lookup/ + /// api-reference/get-dm_events public func getDmEvents( _ request: GetDmEventsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/direct-messages/lookup/api-reference/get-dm_conversations-with-participant_id-dm_events + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/direct-messages/lookup/ + /// api-reference/get-dm_conversations-with-participant_id-dm_events public func getDmEventsWithParticipantId( _ request: GetDmConversationsWithParticipantIdDmEventsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/direct-messages/lookup/api-reference/get-dm_conversations-dm_conversation_id-dm_events + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/direct-messages/lookup/ + /// api-reference/get-dm_conversations-dm_conversation_id-dm_events public func getDmEventsByConversationsId( _ request: GetDmConversationsIdDmEventsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/direct-messages/manage/api-reference/post-dm_conversations-dm_conversation_id-messages + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/direct-messages/manage/ + /// api-reference/post-dm_conversations-dm_conversation_id-messages public func postDmConversationById( _ request: PostDmConversationByIdRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/direct-messages/manage/api-reference/post-dm_conversations-with-participant_id-messages + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/direct-messages/manage/ + /// api-reference/post-dm_conversations-with-participant_id-messages public func postDmConversationWithUser( _ request: PostDmConversationWithUserRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/direct-messages/manage/api-reference/post-dm_conversations + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/direct-messages/manage/ + /// api-reference/post-dm_conversations public func postDmConversation( _ request: PostDmConversationRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/GetDmConversationsIdDmEventsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/GetDmConversationsIdDmEventsRequestV2.swift index 46de57f5..dea85e90 100644 --- a/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/GetDmConversationsIdDmEventsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/GetDmConversationsIdDmEventsRequestV2.swift @@ -1,9 +1,13 @@ +// GetDmConversationsIdDmEventsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// Returns DM Events for a DM Conversation /// Required OAuth 2.0 scopes: dm.read, tweet.read, users.read open class GetDmConversationsIdDmEventsRequestV2: TwitterAPIRequest { - /// The DM Conversation ID. public let id: String /// The maximum number of results. @@ -32,16 +36,16 @@ open class GetDmConversationsIdDmEventsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - eventTypes?.bind(param: &p) - dmEventFields?.bind(param: &p) - expansions?.bind(param: &p) - mediaFields?.bind(param: &p) - userFields?.bind(param: &p) - tweetFields?.bind(param: &p) - return p + var params = [String: Any]() + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + eventTypes?.bind(param: ¶ms) + dmEventFields?.bind(param: ¶ms) + expansions?.bind(param: ¶ms) + mediaFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + return params } public init( @@ -65,4 +69,8 @@ open class GetDmConversationsIdDmEventsRequestV2: TwitterAPIRequest { self.userFields = userFields self.tweetFields = tweetFields } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/GetDmConversationsWithParticipantIdDmEventsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/GetDmConversationsWithParticipantIdDmEventsRequestV2.swift index f494d995..fac4833e 100644 --- a/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/GetDmConversationsWithParticipantIdDmEventsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/GetDmConversationsWithParticipantIdDmEventsRequestV2.swift @@ -1,9 +1,14 @@ +// GetDmConversationsWithParticipantIdDmEventsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + +// swiftlint:disable type_name import Foundation /// Returns DM Events for a DM Conversation /// Required OAuth 2.0 scopes: dm.read, tweet.read, users.read open class GetDmConversationsWithParticipantIdDmEventsRequestV2: TwitterAPIRequest { - /// The ID of the participant user for the One to One DM conversation. public let participantID: String /// The maximum number of results. @@ -32,16 +37,16 @@ open class GetDmConversationsWithParticipantIdDmEventsRequestV2: TwitterAPIReque } open var parameters: [String: Any] { - var p = [String: Any]() - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - eventTypes?.bind(param: &p) - dmEventFields?.bind(param: &p) - expansions?.bind(param: &p) - mediaFields?.bind(param: &p) - userFields?.bind(param: &p) - tweetFields?.bind(param: &p) - return p + var params = [String: Any]() + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + eventTypes?.bind(param: ¶ms) + dmEventFields?.bind(param: ¶ms) + expansions?.bind(param: ¶ms) + mediaFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + return params } public init( @@ -65,4 +70,9 @@ open class GetDmConversationsWithParticipantIdDmEventsRequestV2: TwitterAPIReque self.userFields = userFields self.tweetFields = tweetFields } + + deinit { + // De-init Logic Here + } } +// swiftlint:enable type_name diff --git a/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/GetDmEventsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/GetDmEventsRequestV2.swift index c2bbdcc4..6100ab38 100644 --- a/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/GetDmEventsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/GetDmEventsRequestV2.swift @@ -1,9 +1,13 @@ +// GetDmEventsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// Returns recent DM Events across DM conversations /// Required OAuth 2.0 scopes: dm.read, tweet.read, users.read open class GetDmEventsRequestV2: TwitterAPIRequest { - /// The maximum number of results. public let maxResults: Int? /// This parameter is used to get a specified 'page' of results. @@ -30,16 +34,16 @@ open class GetDmEventsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - eventTypes?.bind(param: &p) - dmEventFields?.bind(param: &p) - expansions?.bind(param: &p) - mediaFields?.bind(param: &p) - userFields?.bind(param: &p) - tweetFields?.bind(param: &p) - return p + var params = [String: Any]() + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + eventTypes?.bind(param: ¶ms) + dmEventFields?.bind(param: ¶ms) + expansions?.bind(param: ¶ms) + mediaFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + return params } public init( @@ -61,4 +65,8 @@ open class GetDmEventsRequestV2: TwitterAPIRequest { self.userFields = userFields self.tweetFields = tweetFields } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/PostDmConversationByIdRequestV2.swift b/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/PostDmConversationByIdRequestV2.swift index 8c4e984d..65a14f8a 100644 --- a/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/PostDmConversationByIdRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/PostDmConversationByIdRequestV2.swift @@ -1,9 +1,13 @@ +// PostDmConversationByIdRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// Creates a new message for a DM Conversation specified by DM Conversation ID /// Required OAuth 2.0 scopes: dm.write, tweet.read, users.read open class PostDmConversationByIdRequestV2: TwitterAPIRequest { - /// The DM Conversation ID. public let dmConversationID: String /// Attachments to a DM Event. @@ -24,12 +28,12 @@ open class PostDmConversationByIdRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - if let attachments = attachments { - p["attachments"] = attachments.map { ["media_id": $0] } + var params = [String: Any]() + if let attachments { + params["attachments"] = attachments.map { ["media_id": $0] } } - text.map { p["text"] = $0 } - return p + text.map { params["text"] = $0 } + return params } public init( @@ -41,4 +45,8 @@ open class PostDmConversationByIdRequestV2: TwitterAPIRequest { self.attachments = attachments self.text = text } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/PostDmConversationRequestV2.swift b/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/PostDmConversationRequestV2.swift index cd7bb508..eb80bee2 100644 --- a/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/PostDmConversationRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/PostDmConversationRequestV2.swift @@ -1,9 +1,13 @@ +// PostDmConversationRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// Creates a new DM Conversation. /// Required OAuth 2.0 scopes: dm.write, tweet.read, users.read open class PostDmConversationRequestV2: TwitterAPIRequest { - /// The conversation type that is being created. public enum ConversationType: String { case group = "Group" @@ -31,16 +35,16 @@ open class PostDmConversationRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["conversation_type"] = conversationType.rawValue - p["participant_ids"] = participantIDs + var params = [String: Any]() + params["conversation_type"] = conversationType.rawValue + params["participant_ids"] = participantIDs var message = [String: Any]() text.map { message["text"] = $0 } - if let attachments = attachments { + if let attachments { message["attachments"] = attachments.map { ["media_id": $0] } } - p["message"] = message - return p + params["message"] = message + return params } public init( @@ -54,4 +58,8 @@ open class PostDmConversationRequestV2: TwitterAPIRequest { self.attachments = attachments self.text = text } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/PostDmConversationWithUserRequestV2.swift b/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/PostDmConversationWithUserRequestV2.swift index fe79dafb..4a091567 100644 --- a/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/PostDmConversationWithUserRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/DirectMessage/Requests/PostDmConversationWithUserRequestV2.swift @@ -1,9 +1,13 @@ +// PostDmConversationWithUserRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// Creates a new message for a DM Conversation with a participant user by ID /// Required OAuth 2.0 scopes: dm.write, tweet.read, users.read open class PostDmConversationWithUserRequestV2: TwitterAPIRequest { - /// The ID of the recipient user that will receive the DM. public let participantID: String /// Attachments to a DM Event. @@ -24,12 +28,12 @@ open class PostDmConversationWithUserRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - if let attachments = attachments { - p["attachments"] = attachments.map { ["media_id": $0] } + var params = [String: Any]() + if let attachments { + params["attachments"] = attachments.map { ["media_id": $0] } } - text.map { p["text"] = $0 } - return p + text.map { params["text"] = $0 } + return params } public init( @@ -41,4 +45,8 @@ open class PostDmConversationWithUserRequestV2: TwitterAPIRequest { self.attachments = attachments self.text = text } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/DirectMessage/TwitterDirectMessageEventTypeV2.swift b/Sources/TwitterAPIKit/APIv2/DirectMessage/TwitterDirectMessageEventTypeV2.swift index cc5ee326..72d37ff6 100644 --- a/Sources/TwitterAPIKit/APIv2/DirectMessage/TwitterDirectMessageEventTypeV2.swift +++ b/Sources/TwitterAPIKit/APIv2/DirectMessage/TwitterDirectMessageEventTypeV2.swift @@ -1,3 +1,8 @@ +// TwitterDirectMessageEventTypeV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// The set of event_types to include in the results. @@ -11,8 +16,10 @@ extension TwitterDirectMessageEventTypeV2: TwitterAPIv2RequestParameter { public var stringValue: String { return rawValue } } +/// Binds the event_types to the request parameters. extension Set where Element == TwitterDirectMessageEventTypeV2 { - func bind(param: inout [String: Any]) { + /// Binds the event_types to the request parameters. + public func bind(param: inout [String: Any]) { param["event_types"] = commaSeparatedString } } diff --git a/Sources/TwitterAPIKit/APIv2/Friendships/FriendshipsAPIv2.swift b/Sources/TwitterAPIKit/APIv2/Friendships/FriendshipsAPIv2.swift index 68ff906e..7acb0947 100644 --- a/Sources/TwitterAPIKit/APIv2/Friendships/FriendshipsAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/Friendships/FriendshipsAPIv2.swift @@ -1,31 +1,48 @@ +// FriendshipsAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class FriendshipsAPIv2: TwitterAPIBase { - /// https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-following + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/users/follows/ + /// api-reference/get-users-id-following public func getFollowing( _ request: GetUsersFollowingRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-followers + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/users/follows/ + /// api-reference/get-users-id-followers public func getFollowers( _ request: GetUsersFollowersRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/post-users-source_user_id-following + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/users/follows/ + /// api-reference/post-users-source_user_id-following public func follow( _ request: PostUsersFollowingRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/delete-users-source_id-following + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/users/follows/ + /// api-reference/delete-users-source_id-following public func unfollow( _ request: DeleteUsersFollowingRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Friendships/Requests/DeleteUsersFollowingRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Friendships/Requests/DeleteUsersFollowingRequestV2.swift index a09b8ee3..0d9a640d 100644 --- a/Sources/TwitterAPIKit/APIv2/Friendships/Requests/DeleteUsersFollowingRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Friendships/Requests/DeleteUsersFollowingRequestV2.swift @@ -1,8 +1,12 @@ +// DeleteUsersFollowingRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/delete-users-source_id-following open class DeleteUsersFollowingRequestV2: TwitterAPIRequest { - public let sourceUserID: String public let targetUserID: String @@ -25,4 +29,7 @@ open class DeleteUsersFollowingRequestV2: TwitterAPIRequest { self.sourceUserID = sourceUserID self.targetUserID = targetUserID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Friendships/Requests/GetUsersFollowersRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Friendships/Requests/GetUsersFollowersRequestV2.swift index d83e62bc..d5c41fd2 100644 --- a/Sources/TwitterAPIKit/APIv2/Friendships/Requests/GetUsersFollowersRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Friendships/Requests/GetUsersFollowersRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersFollowersRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-followers open class GetUsersFollowersRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let maxResults: Int? @@ -19,13 +23,13 @@ open class GetUsersFollowersRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -43,4 +47,7 @@ open class GetUsersFollowersRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Friendships/Requests/GetUsersFollowingRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Friendships/Requests/GetUsersFollowingRequestV2.swift index 696d37ec..ada8e080 100644 --- a/Sources/TwitterAPIKit/APIv2/Friendships/Requests/GetUsersFollowingRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Friendships/Requests/GetUsersFollowingRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersFollowingRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-following open class GetUsersFollowingRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let maxResults: Int? @@ -19,13 +23,13 @@ open class GetUsersFollowingRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -43,4 +47,7 @@ open class GetUsersFollowingRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Friendships/Requests/PostUsersFollowingRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Friendships/Requests/PostUsersFollowingRequestV2.swift index a2398a08..b0ce7f67 100644 --- a/Sources/TwitterAPIKit/APIv2/Friendships/Requests/PostUsersFollowingRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Friendships/Requests/PostUsersFollowingRequestV2.swift @@ -1,8 +1,12 @@ +// PostUsersFollowingRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/post-users-source_user_id-following open class PostUsersFollowingRequestV2: TwitterAPIRequest { - public let id: String public let targetUserID: String @@ -19,9 +23,9 @@ open class PostUsersFollowingRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["target_user_id"] = targetUserID - return p + var params = [String: Any]() + params["target_user_id"] = targetUserID + return params } public init( @@ -31,4 +35,7 @@ open class PostUsersFollowingRequestV2: TwitterAPIRequest { self.id = id self.targetUserID = targetUserID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Like/LikeAPIv2.swift b/Sources/TwitterAPIKit/APIv2/Like/LikeAPIv2.swift index 7daf5b20..9798445c 100644 --- a/Sources/TwitterAPIKit/APIv2/Like/LikeAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/Like/LikeAPIv2.swift @@ -1,7 +1,11 @@ +// LikeAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class LikeAPIv2: TwitterAPIBase { - /// https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-tweets-id-liking_users public func getLikingUsers( _ request: GetTweetsLikingUsersRequestV2 @@ -29,4 +33,8 @@ open class LikeAPIv2: TwitterAPIBase { ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Like/Requests/DeleteUsersLikesRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Like/Requests/DeleteUsersLikesRequestV2.swift index 4b20f4f7..8f48b861 100644 --- a/Sources/TwitterAPIKit/APIv2/Like/Requests/DeleteUsersLikesRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Like/Requests/DeleteUsersLikesRequestV2.swift @@ -1,8 +1,12 @@ +// DeleteUsersLikesRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/delete-users-id-likes-tweet_id open class DeleteUsersLikesRequestV2: TwitterAPIRequest { - /// user ID public let id: String public let tweetID: String @@ -26,4 +30,7 @@ open class DeleteUsersLikesRequestV2: TwitterAPIRequest { self.id = id self.tweetID = tweetID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Like/Requests/GetTweetsLikingUsersRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Like/Requests/GetTweetsLikingUsersRequestV2.swift index 68ffdfa4..50f8c833 100644 --- a/Sources/TwitterAPIKit/APIv2/Like/Requests/GetTweetsLikingUsersRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Like/Requests/GetTweetsLikingUsersRequestV2.swift @@ -1,8 +1,12 @@ +// GetTweetsLikingUsersRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-tweets-id-liking_users open class GetTweetsLikingUsersRequestV2: TwitterAPIRequest { - /// Tweet ID public let id: String public let expansions: Set? @@ -23,16 +27,16 @@ open class GetTweetsLikingUsersRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - mediaFields?.bind(param: &p) - paginationToken.map { p["pagination_token"] = $0 } - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + mediaFields?.bind(param: ¶ms) + paginationToken.map { params["pagination_token"] = $0 } + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -56,4 +60,7 @@ open class GetTweetsLikingUsersRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Like/Requests/GetUsersLikedTweetsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Like/Requests/GetUsersLikedTweetsRequestV2.swift index d0569bdb..028fd553 100644 --- a/Sources/TwitterAPIKit/APIv2/Like/Requests/GetUsersLikedTweetsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Like/Requests/GetUsersLikedTweetsRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersLikedTweetsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-users-id-liked_tweets open class GetUsersLikedTweetsRequestV2: TwitterAPIRequest { - /// User ID public let id: String public let expansions: Set? @@ -23,16 +27,16 @@ open class GetUsersLikedTweetsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - mediaFields?.bind(param: &p) - paginationToken.map { p["pagination_token"] = $0 } - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + mediaFields?.bind(param: ¶ms) + paginationToken.map { params["pagination_token"] = $0 } + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -56,4 +60,7 @@ open class GetUsersLikedTweetsRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Like/Requests/PostUsersLikesRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Like/Requests/PostUsersLikesRequestV2.swift index c28d7035..db24cc7b 100644 --- a/Sources/TwitterAPIKit/APIv2/Like/Requests/PostUsersLikesRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Like/Requests/PostUsersLikesRequestV2.swift @@ -1,8 +1,12 @@ +// PostUsersLikesRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/post-users-id-likes open class PostUsersLikesRequestV2: TwitterAPIRequest { - /// user ID public let id: String public let tweetID: String @@ -20,9 +24,9 @@ open class PostUsersLikesRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["tweet_id"] = tweetID - return p + var params = [String: Any]() + params["tweet_id"] = tweetID + return params } public init( @@ -32,4 +36,7 @@ open class PostUsersLikesRequestV2: TwitterAPIRequest { self.id = id self.tweetID = tweetID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/ListAPIv2.swift b/Sources/TwitterAPIKit/APIv2/List/ListAPIv2.swift index e762cc3d..e55e5d54 100644 --- a/Sources/TwitterAPIKit/APIv2/List/ListAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/ListAPIv2.swift @@ -1,123 +1,165 @@ +// ListAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class ListAPIv2: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/lists/list-tweets/api-reference/get-lists-id-tweets + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/list-tweets/ + /// api-reference/get-lists-id-tweets public func getListTweets( _ request: GetListsTweetsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-lists-id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/ + /// api-reference/get-lists-id public func getList( _ request: GetListRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-users-id-owned_lists + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/ + /// api-reference/get-users-id-owned_lists public func getLists( _ request: GetUsersOwnedListsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/post-users-id-followed-lists + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/ + /// api-reference/post-users-id-followed-lists public func followList( _ request: PostUsersFollowedListsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/delete-users-id-followed-lists-list_id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/ + /// api-reference/delete-users-id-followed-lists-list_id public func unfollowList( _ request: DeleteUsersFollowedListsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/get-lists-id-followers + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/ + /// api-reference/get-lists-id-followers public func listFollowers( _ request: GetListsFollowersRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/get-users-id-followed_lists + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/ + /// api-reference/get-users-id-followed_lists public func followedLists( _ request: GetUsersFollowedListsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/post-lists-id-members + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/list-members/ + /// api-reference/post-lists-id-members public func addListMember( _ request: PostListsMembersRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/delete-lists-id-members-user_id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/list-members/ + /// api-reference/delete-lists-id-members-user_id public func removeListMember( _ request: DeleteListsMembersRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/get-users-id-list_memberships + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/list-members/ + /// api-reference/get-users-id-list_memberships public func getListMemberships( _ request: GetUsersListMembershipsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/get-lists-id-members + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/list-members/ + /// api-reference/get-lists-id-members public func getListMembers( _ request: GetListsMembersRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/post-lists + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/ + /// api-reference/post-lists public func createList( _ request: PostListsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/put-lists-id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/ + /// api-reference/put-lists-id public func updateList( _ request: PutListRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/delete-lists-id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/ + /// api-reference/delete-lists-id public func deleteList( _ request: DeleteListRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/pinned-lists/api-reference/get-users-id-pinned_lists + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/pinned-lists/ + /// api-reference/get-users-id-pinned_lists public func pinnedList( _ request: GetUsersPinnedListsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/pinned-lists/api-reference/post-users-id-pinned-lists + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/pinned-lists/ + /// api-reference/post-users-id-pinned-lists public func pinList( _ request: PostUsersPinnedListsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/lists/pinned-lists/api-reference/delete-users-id-pinned-lists-list_id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/lists/pinned-lists/ + /// api-reference/delete-users-id-pinned-lists-list_id public func unpinList( _ request: DeleteUsersPinnedListsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteListRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteListRequestV2.swift index 984582d0..71337123 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteListRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteListRequestV2.swift @@ -1,8 +1,12 @@ +// DeleteListRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/delete-lists-id open class DeleteListRequestV2: TwitterAPIRequest { - public let id: String public var method: HTTPMethod { @@ -22,4 +26,7 @@ open class DeleteListRequestV2: TwitterAPIRequest { ) { self.id = id } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteListsMembersRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteListsMembersRequestV2.swift index 641d71c8..d18f7814 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteListsMembersRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteListsMembersRequestV2.swift @@ -1,8 +1,12 @@ +// DeleteListsMembersRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/delete-lists-id-members-user_id open class DeleteListsMembersRequestV2: TwitterAPIRequest { - public let id: String public let userID: String @@ -25,4 +29,7 @@ open class DeleteListsMembersRequestV2: TwitterAPIRequest { self.id = id self.userID = userID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteUsersFollowedListsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteUsersFollowedListsRequestV2.swift index 60bbf743..f8904a32 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteUsersFollowedListsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteUsersFollowedListsRequestV2.swift @@ -1,8 +1,14 @@ +// DeleteUsersFollowedListsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/delete-users-id-followed-lists-list_id +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/ +/// api-reference/delete-users-id-followed-lists-list_id open class DeleteUsersFollowedListsRequestV2: TwitterAPIRequest { - public let id: String public let listID: String @@ -25,4 +31,7 @@ open class DeleteUsersFollowedListsRequestV2: TwitterAPIRequest { self.id = id self.listID = listID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteUsersPinnedListsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteUsersPinnedListsRequestV2.swift index b33ce1e5..c35ab979 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteUsersPinnedListsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/DeleteUsersPinnedListsRequestV2.swift @@ -1,8 +1,14 @@ +// DeleteUsersPinnedListsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/lists/pinned-lists/api-reference/delete-users-id-pinned-lists-list_id +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/lists/pinned-lists/ +/// api-reference/delete-users-id-pinned-lists-list_id open class DeleteUsersPinnedListsRequestV2: TwitterAPIRequest { - public let id: String public let listID: String @@ -25,4 +31,7 @@ open class DeleteUsersPinnedListsRequestV2: TwitterAPIRequest { self.id = id self.listID = listID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/GetListRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/GetListRequestV2.swift index a5579170..78b6cb57 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/GetListRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/GetListRequestV2.swift @@ -1,8 +1,12 @@ +// GetListRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-lists-id open class GetListRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let listFields: Set? @@ -17,11 +21,11 @@ open class GetListRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - listFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + listFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -35,4 +39,7 @@ open class GetListRequestV2: TwitterAPIRequest { self.listFields = listFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/GetListsFollowersRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/GetListsFollowersRequestV2.swift index f1640b8d..087a4efd 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/GetListsFollowersRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/GetListsFollowersRequestV2.swift @@ -1,8 +1,12 @@ +// GetListsFollowersRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/get-lists-id-followers open class GetListsFollowersRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let maxResults: Int? @@ -19,13 +23,13 @@ open class GetListsFollowersRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -43,4 +47,7 @@ open class GetListsFollowersRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/GetListsMembersRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/GetListsMembersRequestV2.swift index 8a34a974..36adf8ff 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/GetListsMembersRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/GetListsMembersRequestV2.swift @@ -1,8 +1,12 @@ +// GetListsMembersRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/get-lists-id-members open class GetListsMembersRequestV2: TwitterAPIRequest { - /// List ID public let id: String public let expansions: Set? @@ -20,13 +24,13 @@ open class GetListsMembersRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -44,4 +48,7 @@ open class GetListsMembersRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/GetListsTweetsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/GetListsTweetsRequestV2.swift index aa72e1a3..5778b00e 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/GetListsTweetsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/GetListsTweetsRequestV2.swift @@ -1,8 +1,12 @@ +// GetListsTweetsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/list-tweets/api-reference/get-lists-id-tweets open class GetListsTweetsRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let maxResults: Int? @@ -19,13 +23,13 @@ open class GetListsTweetsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -43,4 +47,7 @@ open class GetListsTweetsRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersFollowedListsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersFollowedListsRequestV2.swift index 299a69d9..24105f9d 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersFollowedListsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersFollowedListsRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersFollowedListsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/get-users-id-followed_lists open class GetUsersFollowedListsRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let listFields: Set? @@ -19,13 +23,13 @@ open class GetUsersFollowedListsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - listFields?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + listFields?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + userFields?.bind(param: ¶ms) + return params } public init( @@ -43,4 +47,7 @@ open class GetUsersFollowedListsRequestV2: TwitterAPIRequest { self.paginationToken = paginationToken self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersListMembershipsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersListMembershipsRequestV2.swift index 7eba6e46..bdde1cc6 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersListMembershipsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersListMembershipsRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersListMembershipsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/get-users-id-list_memberships open class GetUsersListMembershipsRequestV2: TwitterAPIRequest { - /// User ID public let id: String public let expansions: Set? @@ -20,13 +24,13 @@ open class GetUsersListMembershipsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - listFields?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + listFields?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + userFields?.bind(param: ¶ms) + return params } public init( @@ -44,4 +48,7 @@ open class GetUsersListMembershipsRequestV2: TwitterAPIRequest { self.paginationToken = paginationToken self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersOwnedListsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersOwnedListsRequestV2.swift index 5ca55a51..f060db0d 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersOwnedListsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersOwnedListsRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersOwnedListsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-users-id-owned_lists open class GetUsersOwnedListsRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let listFields: Set? @@ -19,13 +23,13 @@ open class GetUsersOwnedListsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - listFields?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - paginationToken.map { p["pagination_token"] = $0 } - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + listFields?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + paginationToken.map { params["pagination_token"] = $0 } + userFields?.bind(param: ¶ms) + return params } public init( @@ -43,4 +47,7 @@ open class GetUsersOwnedListsRequestV2: TwitterAPIRequest { self.paginationToken = paginationToken self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersPinnedListsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersPinnedListsRequestV2.swift index d15a4e6a..c0b38f1a 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersPinnedListsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/GetUsersPinnedListsRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersPinnedListsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/pinned-lists/api-reference/get-users-id-pinned_lists open class GetUsersPinnedListsRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let listFields: Set? @@ -17,11 +21,11 @@ open class GetUsersPinnedListsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - listFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + listFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -35,4 +39,7 @@ open class GetUsersPinnedListsRequestV2: TwitterAPIRequest { self.listFields = listFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/PostListsMembersRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/PostListsMembersRequestV2.swift index ac423acc..c7651cd3 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/PostListsMembersRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/PostListsMembersRequestV2.swift @@ -1,8 +1,12 @@ +// PostListsMembersRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/post-lists-id-members open class PostListsMembersRequestV2: TwitterAPIRequest { - public let id: String public let userID: String @@ -19,9 +23,9 @@ open class PostListsMembersRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["user_id"] = userID - return p + var params = [String: Any]() + params["user_id"] = userID + return params } public init( @@ -31,4 +35,7 @@ open class PostListsMembersRequestV2: TwitterAPIRequest { self.id = id self.userID = userID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/PostListsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/PostListsRequestV2.swift index 512bf11e..ef824be3 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/PostListsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/PostListsRequestV2.swift @@ -1,8 +1,12 @@ +// PostListsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/post-lists open class PostListsRequestV2: TwitterAPIRequest { - public let name: String public let description: String? public let `private`: Bool? @@ -20,11 +24,11 @@ open class PostListsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["name"] = name - description.map { p["description"] = $0 } - `private`.map { p["private"] = $0 } - return p + var params = [String: Any]() + params["name"] = name + description.map { params["description"] = $0 } + `private`.map { params["private"] = $0 } + return params } public init( @@ -36,4 +40,7 @@ open class PostListsRequestV2: TwitterAPIRequest { self.description = description self.private = `private` } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/PostUsersFollowedListsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/PostUsersFollowedListsRequestV2.swift index b7aaa556..24858ce9 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/PostUsersFollowedListsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/PostUsersFollowedListsRequestV2.swift @@ -1,8 +1,12 @@ +// PostUsersFollowedListsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/post-users-id-followed-lists open class PostUsersFollowedListsRequestV2: TwitterAPIRequest { - public let id: String public let listID: String @@ -19,9 +23,9 @@ open class PostUsersFollowedListsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["list_id"] = listID - return p + var params = [String: Any]() + params["list_id"] = listID + return params } public init( @@ -31,4 +35,7 @@ open class PostUsersFollowedListsRequestV2: TwitterAPIRequest { self.id = id self.listID = listID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/PostUsersPinnedListsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/PostUsersPinnedListsRequestV2.swift index 626d1e77..9c5be1bd 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/PostUsersPinnedListsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/PostUsersPinnedListsRequestV2.swift @@ -1,8 +1,12 @@ +// PostUsersPinnedListsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/pinned-lists/api-reference/post-users-id-pinned-lists open class PostUsersPinnedListsRequestV2: TwitterAPIRequest { - public let id: String public let listID: String @@ -19,9 +23,9 @@ open class PostUsersPinnedListsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["list_id"] = listID - return p + var params = [String: Any]() + params["list_id"] = listID + return params } public init( @@ -31,4 +35,7 @@ open class PostUsersPinnedListsRequestV2: TwitterAPIRequest { self.id = id self.listID = listID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/List/Requests/PutListRequestV2.swift b/Sources/TwitterAPIKit/APIv2/List/Requests/PutListRequestV2.swift index 49c610da..375f9d40 100644 --- a/Sources/TwitterAPIKit/APIv2/List/Requests/PutListRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/List/Requests/PutListRequestV2.swift @@ -1,8 +1,12 @@ +// PutListRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/put-lists-id open class PutListRequestV2: TwitterAPIRequest { - public let id: String public let description: String? public let name: String? @@ -21,11 +25,11 @@ open class PutListRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - description.map { p["description"] = $0 } - name.map { p["name"] = $0 } - `private`.map { p["private"] = $0 } - return p + var params = [String: Any]() + description.map { params["description"] = $0 } + name.map { params["name"] = $0 } + `private`.map { params["private"] = $0 } + return params } public init( @@ -39,4 +43,7 @@ open class PutListRequestV2: TwitterAPIRequest { self.name = name self.private = `private` } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Retweet/Requests/DeleteUsersRetweetsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Retweet/Requests/DeleteUsersRetweetsRequestV2.swift index 8a1d21c3..9baed0cd 100644 --- a/Sources/TwitterAPIKit/APIv2/Retweet/Requests/DeleteUsersRetweetsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Retweet/Requests/DeleteUsersRetweetsRequestV2.swift @@ -1,8 +1,12 @@ +// DeleteUsersRetweetsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/delete-users-id-retweets-tweet_id open class DeleteUsersRetweetsRequestV2: TwitterAPIRequest { - public let id: String public let sourceTweetID: String @@ -25,4 +29,7 @@ open class DeleteUsersRetweetsRequestV2: TwitterAPIRequest { self.id = id self.sourceTweetID = sourceTweetID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Retweet/Requests/GetTweetsRetweetedByRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Retweet/Requests/GetTweetsRetweetedByRequestV2.swift index 84c05741..b9b37ca2 100644 --- a/Sources/TwitterAPIKit/APIv2/Retweet/Requests/GetTweetsRetweetedByRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Retweet/Requests/GetTweetsRetweetedByRequestV2.swift @@ -1,8 +1,12 @@ +// GetTweetsRetweetedByRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/get-tweets-id-retweeted_by open class GetTweetsRetweetedByRequestV2: TwitterAPIRequest { - /// Tweet ID public let id: String public let expansions: Set? @@ -23,16 +27,16 @@ open class GetTweetsRetweetedByRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - mediaFields?.bind(param: &p) - paginationToken.map { p["pagination_token"] = $0 } - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + mediaFields?.bind(param: ¶ms) + paginationToken.map { params["pagination_token"] = $0 } + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -56,4 +60,7 @@ open class GetTweetsRetweetedByRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Retweet/Requests/PostUsersRetweetsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Retweet/Requests/PostUsersRetweetsRequestV2.swift index edf40647..1b5e77d7 100644 --- a/Sources/TwitterAPIKit/APIv2/Retweet/Requests/PostUsersRetweetsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Retweet/Requests/PostUsersRetweetsRequestV2.swift @@ -1,8 +1,12 @@ +// PostUsersRetweetsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/post-users-id-retweets open class PostUsersRetweetsRequestV2: TwitterAPIRequest { - public let id: String public let tweetID: String @@ -19,9 +23,9 @@ open class PostUsersRetweetsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["tweet_id"] = tweetID - return p + var params = [String: Any]() + params["tweet_id"] = tweetID + return params } public init( @@ -31,4 +35,7 @@ open class PostUsersRetweetsRequestV2: TwitterAPIRequest { self.id = id self.tweetID = tweetID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Retweet/RetweetAPIv2.swift b/Sources/TwitterAPIKit/APIv2/Retweet/RetweetAPIv2.swift index 568f8265..47666a01 100644 --- a/Sources/TwitterAPIKit/APIv2/Retweet/RetweetAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/Retweet/RetweetAPIv2.swift @@ -1,25 +1,39 @@ +// RetweetAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class RetweetAPIv2: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/get-tweets-id-retweeted_by + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/ + /// api-reference/get-tweets-id-retweeted_by public func getRetweetedBy( _ request: GetTweetsRetweetedByRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/post-users-id-retweets + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/ + /// api-reference/post-users-id-retweets public func postRetweet( _ request: PostUsersRetweetsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/delete-users-id-retweets-tweet_id + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/ + /// api-reference/delete-users-id-retweets-tweet_id public func deleteRetweet( _ request: DeleteUsersRetweetsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Search/Requests/GetTweetsSearchAllRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Search/Requests/GetTweetsSearchAllRequestV2.swift index cedb8f8f..17f4a11d 100644 --- a/Sources/TwitterAPIKit/APIv2/Search/Requests/GetTweetsSearchAllRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Search/Requests/GetTweetsSearchAllRequestV2.swift @@ -1,9 +1,13 @@ +// GetTweetsSearchAllRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// This endpoint is only available to those users who have been approved for Academic Research access. /// https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-all open class GetTweetsSearchAllRequestV2: TwitterAPIRequest { - public let query: String public let endTime: Date? public let expansions: Set? @@ -28,22 +32,22 @@ open class GetTweetsSearchAllRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["query"] = query - endTime?.bind(param: &p, for: "end_time") - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - mediaFields?.bind(param: &p) - nextToken.map { p["next_token"] = $0 } - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - sinceID.map { p["since_id"] = $0 } - sortOrder?.bind(param: &p) - startTime?.bind(param: &p, for: "start_time") - tweetFields?.bind(param: &p) - untilID.map { p["until_id"] = $0 } - userFields?.bind(param: &p) - return p + var params = [String: Any]() + params["query"] = query + endTime?.bind(param: ¶ms, for: "end_time") + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + mediaFields?.bind(param: ¶ms) + nextToken.map { params["next_token"] = $0 } + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + sinceID.map { params["since_id"] = $0 } + sortOrder?.bind(param: ¶ms) + startTime?.bind(param: ¶ms, for: "start_time") + tweetFields?.bind(param: ¶ms) + untilID.map { params["until_id"] = $0 } + userFields?.bind(param: ¶ms) + return params } public init( @@ -77,4 +81,8 @@ open class GetTweetsSearchAllRequestV2: TwitterAPIRequest { self.untilID = untilID self.userFields = userFields } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Search/Requests/GetTweetsSearchRecentRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Search/Requests/GetTweetsSearchRecentRequestV2.swift index f282c332..5cfc7ab9 100644 --- a/Sources/TwitterAPIKit/APIv2/Search/Requests/GetTweetsSearchRecentRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Search/Requests/GetTweetsSearchRecentRequestV2.swift @@ -1,13 +1,17 @@ +// GetTweetsSearchRecentRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent open class GetTweetsSearchRecentRequestV2: TwitterAPIRequest { - public enum TwitterSearchTweetsSortOrderV2: String { case recency case relevancy - func bind(param: inout [String: Any]) { + public func bind(param: inout [String: Any]) { param["sort_order"] = rawValue } } @@ -36,22 +40,22 @@ open class GetTweetsSearchRecentRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["query"] = query - endTime?.bind(param: &p, for: "end_time") - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - mediaFields?.bind(param: &p) - nextToken.map { p["next_token"] = $0 } - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - sinceID.map { p["since_id"] = $0 } - sortOrder?.bind(param: &p) - startTime?.bind(param: &p, for: "start_time") - tweetFields?.bind(param: &p) - untilID.map { p["until_id"] = $0 } - userFields?.bind(param: &p) - return p + var params = [String: Any]() + params["query"] = query + endTime?.bind(param: ¶ms, for: "end_time") + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + mediaFields?.bind(param: ¶ms) + nextToken.map { params["next_token"] = $0 } + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + sinceID.map { params["since_id"] = $0 } + sortOrder?.bind(param: ¶ms) + startTime?.bind(param: ¶ms, for: "start_time") + tweetFields?.bind(param: ¶ms) + untilID.map { params["until_id"] = $0 } + userFields?.bind(param: ¶ms) + return params } public init( @@ -85,4 +89,7 @@ open class GetTweetsSearchRecentRequestV2: TwitterAPIRequest { self.untilID = untilID self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Search/SearchAPIv2.swift b/Sources/TwitterAPIKit/APIv2/Search/SearchAPIv2.swift index feaad5f8..1788bdad 100644 --- a/Sources/TwitterAPIKit/APIv2/Search/SearchAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/Search/SearchAPIv2.swift @@ -1,7 +1,11 @@ +// SearchAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class SearchAPIv2: TwitterAPIBase { - /// https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent public func searchTweetsRecent( _ request: GetTweetsSearchRecentRequestV2 @@ -16,4 +20,8 @@ open class SearchAPIv2: TwitterAPIBase { ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Search/TwitterSearchTweetsSortOrderV2.swift b/Sources/TwitterAPIKit/APIv2/Search/TwitterSearchTweetsSortOrderV2.swift index 3d006612..b9ecd377 100644 --- a/Sources/TwitterAPIKit/APIv2/Search/TwitterSearchTweetsSortOrderV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Search/TwitterSearchTweetsSortOrderV2.swift @@ -1,11 +1,15 @@ +// TwitterSearchTweetsSortOrderV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation public enum TwitterSearchTweetsSortOrderV2: String { - case recency case relevancy - func bind(param: inout [String: Any]) { + public func bind(param: inout [String: Any]) { param["sort_order"] = rawValue } } diff --git a/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpaceRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpaceRequestV2.swift index 0fe85f6d..03e05782 100644 --- a/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpaceRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpaceRequestV2.swift @@ -1,8 +1,12 @@ +// GetSpaceRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id open class GetSpaceRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let spaceFields: Set? @@ -18,12 +22,12 @@ open class GetSpaceRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - spaceFields?.bind(param: &p) - topicFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + spaceFields?.bind(param: ¶ms) + topicFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -39,4 +43,7 @@ open class GetSpaceRequestV2: TwitterAPIRequest { self.topicFields = topicFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesBuyersRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesBuyersRequestV2.swift index d5a5bdfc..0e3f5f65 100644 --- a/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesBuyersRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesBuyersRequestV2.swift @@ -1,8 +1,12 @@ +// GetSpacesBuyersRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id-buyers open class GetSpacesBuyersRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let mediaFields: Set? @@ -20,14 +24,14 @@ open class GetSpacesBuyersRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - mediaFields?.bind(param: &p) - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + mediaFields?.bind(param: ¶ms) + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -47,4 +51,7 @@ open class GetSpacesBuyersRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesByCreatorIDsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesByCreatorIDsRequestV2.swift index d75289d3..da1c2608 100644 --- a/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesByCreatorIDsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesByCreatorIDsRequestV2.swift @@ -1,8 +1,12 @@ +// GetSpacesByCreatorIDsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-by-creator-ids open class GetSpacesByCreatorIDsRequestV2: TwitterAPIRequest { - public let userIDs: [String] public let expansions: Set? public let spaceFields: Set? @@ -18,13 +22,13 @@ open class GetSpacesByCreatorIDsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["user_ids"] = userIDs.joined(separator: ",") - expansions?.bind(param: &p) - spaceFields?.bind(param: &p) - topicFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + params["user_ids"] = userIDs.joined(separator: ",") + expansions?.bind(param: ¶ms) + spaceFields?.bind(param: ¶ms) + topicFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -40,4 +44,7 @@ open class GetSpacesByCreatorIDsRequestV2: TwitterAPIRequest { self.topicFields = topicFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesRequestV2.swift index fdf4aefc..57064267 100644 --- a/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesRequestV2.swift @@ -1,8 +1,12 @@ +// GetSpacesRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces open class GetSpacesRequestV2: TwitterAPIRequest { - public let ids: [String] public let expansions: Set? public let spaceFields: Set? @@ -18,13 +22,13 @@ open class GetSpacesRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["ids"] = ids.joined(separator: ",") - expansions?.bind(param: &p) - spaceFields?.bind(param: &p) - topicFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + params["ids"] = ids.joined(separator: ",") + expansions?.bind(param: ¶ms) + spaceFields?.bind(param: ¶ms) + topicFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -40,4 +44,7 @@ open class GetSpacesRequestV2: TwitterAPIRequest { self.topicFields = topicFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesSearchRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesSearchRequestV2.swift index f831fa41..406431ed 100644 --- a/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesSearchRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesSearchRequestV2.swift @@ -1,13 +1,17 @@ +// GetSpacesSearchRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/spaces/search/api-reference/get-spaces-search open class GetSpacesSearchRequestV2: TwitterAPIRequest { - public enum State: String { case all case live case scheduled - func bind(param: inout [String: Any]) { + public func bind(param: inout [String: Any]) { param["state"] = rawValue } } @@ -28,14 +32,14 @@ open class GetSpacesSearchRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["query"] = query - expansions?.bind(param: &p) - spaceFields?.bind(param: &p) - state?.bind(param: &p) - topicFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + params["query"] = query + expansions?.bind(param: ¶ms) + spaceFields?.bind(param: ¶ms) + state?.bind(param: ¶ms) + topicFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -53,4 +57,7 @@ open class GetSpacesSearchRequestV2: TwitterAPIRequest { self.topicFields = topicFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesTweetsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesTweetsRequestV2.swift index b677c362..01e897f3 100644 --- a/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesTweetsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Spaces/Requests/GetSpacesTweetsRequestV2.swift @@ -1,8 +1,12 @@ +// GetSpacesTweetsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id-tweets open class GetSpacesTweetsRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let mediaFields: Set? @@ -20,14 +24,14 @@ open class GetSpacesTweetsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - mediaFields?.bind(param: &p) - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + mediaFields?.bind(param: ¶ms) + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -47,4 +51,7 @@ open class GetSpacesTweetsRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Spaces/SpacesAPIv2.swift b/Sources/TwitterAPIKit/APIv2/Spaces/SpacesAPIv2.swift index fa80a1b6..9b88fc23 100644 --- a/Sources/TwitterAPIKit/APIv2/Spaces/SpacesAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/Spaces/SpacesAPIv2.swift @@ -1,7 +1,11 @@ +// SpacesAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class SpacesAPIv2: TwitterAPIBase { - /// https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id public func getSpace( _ request: GetSpaceRequestV2 @@ -43,4 +47,8 @@ open class SpacesAPIv2: TwitterAPIBase { ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Stream/Requests/GetTweetsSampleStreamRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Stream/Requests/GetTweetsSampleStreamRequestV2.swift index dda31764..9ef0d2fe 100644 --- a/Sources/TwitterAPIKit/APIv2/Stream/Requests/GetTweetsSampleStreamRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Stream/Requests/GetTweetsSampleStreamRequestV2.swift @@ -1,8 +1,12 @@ +// GetTweetsSampleStreamRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/volume-streams/api-reference/get-tweets-sample-stream open class GetTweetsSampleStreamRequestV2: TwitterAPIRequest { - public let backfillMinutes: Int? public let expansions: Set? public let mediaFields: Set? @@ -20,15 +24,15 @@ open class GetTweetsSampleStreamRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - backfillMinutes.map { p["backfill_minutes"] = $0 } - expansions?.bind(param: &p) - mediaFields?.bind(param: &p) - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + backfillMinutes.map { params["backfill_minutes"] = $0 } + expansions?.bind(param: ¶ms) + mediaFields?.bind(param: ¶ms) + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -48,4 +52,7 @@ open class GetTweetsSampleStreamRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Stream/Requests/GetTweetsSearchStreamRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Stream/Requests/GetTweetsSearchStreamRequestV2.swift index f298717a..07d4f0f3 100644 --- a/Sources/TwitterAPIKit/APIv2/Stream/Requests/GetTweetsSearchStreamRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Stream/Requests/GetTweetsSearchStreamRequestV2.swift @@ -1,8 +1,12 @@ +// GetTweetsSearchStreamRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream open class GetTweetsSearchStreamRequestV2: TwitterAPIRequest { - public let backfillMinutes: Int? public let expansions: Set? public let mediaFields: Set? @@ -20,15 +24,15 @@ open class GetTweetsSearchStreamRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - backfillMinutes.map { p["backfill_minutes"] = $0 } - expansions?.bind(param: &p) - mediaFields?.bind(param: &p) - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + backfillMinutes.map { params["backfill_minutes"] = $0 } + expansions?.bind(param: ¶ms) + mediaFields?.bind(param: ¶ms) + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -48,4 +52,7 @@ open class GetTweetsSearchStreamRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Stream/Requests/GetTweetsSearchStreamRulesRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Stream/Requests/GetTweetsSearchStreamRulesRequestV2.swift index 27fbf2fd..52e220fc 100644 --- a/Sources/TwitterAPIKit/APIv2/Stream/Requests/GetTweetsSearchStreamRulesRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Stream/Requests/GetTweetsSearchStreamRulesRequestV2.swift @@ -1,8 +1,14 @@ +// GetTweetsSearchStreamRulesRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream-rules +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream +/// /api-reference/get-tweets-search-stream-rules open class GetTweetsSearchStreamRulesRequestV2: TwitterAPIRequest { - public let ids: [String]? public var method: HTTPMethod { @@ -14,9 +20,9 @@ open class GetTweetsSearchStreamRulesRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - ids.map { p["ids"] = $0.joined(separator: ",") } - return p + var params = [String: Any]() + ids.map { params["ids"] = $0.joined(separator: ",") } + return params } public init( @@ -24,4 +30,7 @@ open class GetTweetsSearchStreamRulesRequestV2: TwitterAPIRequest { ) { self.ids = ids } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Stream/Requests/PostTweetsSearchStreamRulesRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Stream/Requests/PostTweetsSearchStreamRulesRequestV2.swift index 682efdf8..fd07646b 100644 --- a/Sources/TwitterAPIKit/APIv2/Stream/Requests/PostTweetsSearchStreamRulesRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Stream/Requests/PostTweetsSearchStreamRulesRequestV2.swift @@ -1,8 +1,14 @@ +// PostTweetsSearchStreamRulesRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/post-tweets-search-stream-rules#Validate +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/ +/// api-reference/post-tweets-search-stream-rules#Validate open class PostTweetsSearchStreamRulesRequestV2: TwitterAPIRequest { - public struct Rule { public let value: String public let tag: String? @@ -14,7 +20,7 @@ open class PostTweetsSearchStreamRulesRequestV2: TwitterAPIRequest { public enum Operation { case add([Rule]) - case delete([String] /* rule IDs */) + case delete([String] /* rule IDs */ ) } public let dryRun: Bool? @@ -33,27 +39,27 @@ open class PostTweetsSearchStreamRulesRequestV2: TwitterAPIRequest { } open var queryParameters: [String: Any] { - var p = [String: Any]() - dryRun.map { p["dry_run"] = $0 } - return p + var params = [String: Any]() + dryRun.map { params["dry_run"] = $0 } + return params } open var bodyParameters: [String: Any] { - var p = [String: Any]() + var params = [String: Any]() switch operation { - case .add(let rules): - p["add"] = rules.map { - return [ + case let .add(rules): + params["add"] = rules.map { + [ "value": $0.value, "tag": $0.tag, ].compactMapValues { $0 } } - case .delete(let ids): - p["delete"] = ["ids": ids] + case let .delete(ids): + params["delete"] = ["ids": ids] } - return p + return params } public init( @@ -63,4 +69,7 @@ open class PostTweetsSearchStreamRulesRequestV2: TwitterAPIRequest { self.operation = operation self.dryRun = dryRun } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Stream/StreamAPIv2.swift b/Sources/TwitterAPIKit/APIv2/Stream/StreamAPIv2.swift index 8d3ec0c7..3a20e8c3 100644 --- a/Sources/TwitterAPIKit/APIv2/Stream/StreamAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/Stream/StreamAPIv2.swift @@ -1,32 +1,48 @@ +// StreamAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class StreamAPIv2: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/tweets/volume-streams/api-reference/get-tweets-sample-stream + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/volume-streams/ + /// api-reference/get-tweets-sample-stream public func sampleStream( _ request: GetTweetsSampleStreamRequestV2 ) -> TwitterAPISessionStreamTask { return session.send(streamRequest: request) } - /// https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream-rules + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/ + /// api-reference/get-tweets-search-stream-rules public func getSearchStreamRules( _ request: GetTweetsSearchStreamRulesRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/post-tweets-search-stream-rules#Validate + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/ + /// api-reference/post-tweets-search-stream-rules#Validate public func postSearchStreamRules( _ request: PostTweetsSearchStreamRulesRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/ + /// api-reference/get-tweets-search-stream public func searchStream( _ request: GetTweetsSearchStreamRequestV2 ) -> TwitterAPISessionStreamTask { return session.send(streamRequest: request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Timeline/Requests/GetUsersMentionsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Timeline/Requests/GetUsersMentionsRequestV2.swift index 342a0390..0cce0f10 100644 --- a/Sources/TwitterAPIKit/APIv2/Timeline/Requests/GetUsersMentionsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Timeline/Requests/GetUsersMentionsRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersMentionsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-mentions open class GetUsersMentionsRequestV2: TwitterAPIRequest { - public let id: String public let endTime: Date? public let expansions: Set? @@ -26,20 +30,20 @@ open class GetUsersMentionsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - endTime?.bind(param: &p, for: "end_time") - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - mediaFields?.bind(param: &p) - paginationToken.map { p["pagination_token"] = $0 } - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - sinceID.map { p["since_id"] = $0 } - startTime?.bind(param: &p, for: "start_time") - tweetFields?.bind(param: &p) - untilID.map { p["until_id"] = $0 } - userFields?.bind(param: &p) - return p + var params = [String: Any]() + endTime?.bind(param: ¶ms, for: "end_time") + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + mediaFields?.bind(param: ¶ms) + paginationToken.map { params["pagination_token"] = $0 } + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + sinceID.map { params["since_id"] = $0 } + startTime?.bind(param: ¶ms, for: "start_time") + tweetFields?.bind(param: ¶ms) + untilID.map { params["until_id"] = $0 } + userFields?.bind(param: ¶ms) + return params } public init( @@ -71,4 +75,7 @@ open class GetUsersMentionsRequestV2: TwitterAPIRequest { self.untilID = untilID self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Timeline/Requests/GetUsersTimelinesReverseChronologicalRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Timeline/Requests/GetUsersTimelinesReverseChronologicalRequestV2.swift index 405abab9..fbe697bc 100644 --- a/Sources/TwitterAPIKit/APIv2/Timeline/Requests/GetUsersTimelinesReverseChronologicalRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Timeline/Requests/GetUsersTimelinesReverseChronologicalRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersTimelinesReverseChronologicalRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-reverse-chronological open class GetUsersTimelinesReverseChronologicalRequestV2: TwitterAPIRequest { - public let id: String public let endTime: Date? public let exclude: Set? @@ -27,21 +31,21 @@ open class GetUsersTimelinesReverseChronologicalRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - endTime?.bind(param: &p, for: "end_time") - exclude?.bind(param: &p) - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - mediaFields?.bind(param: &p) - paginationToken.map { p["pagination_token"] = $0 } - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - sinceID.map { p["since_id"] = $0 } - startTime?.bind(param: &p, for: "start_time") - tweetFields?.bind(param: &p) - untilID.map { p["until_id"] = $0 } - userFields?.bind(param: &p) - return p + var params = [String: Any]() + endTime?.bind(param: ¶ms, for: "end_time") + exclude?.bind(param: ¶ms) + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + mediaFields?.bind(param: ¶ms) + paginationToken.map { params["pagination_token"] = $0 } + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + sinceID.map { params["since_id"] = $0 } + startTime?.bind(param: ¶ms, for: "start_time") + tweetFields?.bind(param: ¶ms) + untilID.map { params["until_id"] = $0 } + userFields?.bind(param: ¶ms) + return params } public init( @@ -75,4 +79,7 @@ open class GetUsersTimelinesReverseChronologicalRequestV2: TwitterAPIRequest { self.untilID = untilID self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Timeline/Requests/GetUsersTweetsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Timeline/Requests/GetUsersTweetsRequestV2.swift index 62b49d71..22da8e49 100644 --- a/Sources/TwitterAPIKit/APIv2/Timeline/Requests/GetUsersTweetsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Timeline/Requests/GetUsersTweetsRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersTweetsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-tweets open class GetUsersTweetsRequestV2: TwitterAPIRequest { - public let id: String public let endTime: Date? public let exclude: Set? @@ -27,21 +31,21 @@ open class GetUsersTweetsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - endTime?.bind(param: &p, for: "end_time") - exclude?.bind(param: &p) - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - mediaFields?.bind(param: &p) - paginationToken.map { p["pagination_token"] = $0 } - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - sinceID.map { p["since_id"] = $0 } - startTime?.bind(param: &p, for: "start_time") - tweetFields?.bind(param: &p) - untilID.map { p["until_id"] = $0 } - userFields?.bind(param: &p) - return p + var params = [String: Any]() + endTime?.bind(param: ¶ms, for: "end_time") + exclude?.bind(param: ¶ms) + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + mediaFields?.bind(param: ¶ms) + paginationToken.map { params["pagination_token"] = $0 } + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + sinceID.map { params["since_id"] = $0 } + startTime?.bind(param: ¶ms, for: "start_time") + tweetFields?.bind(param: ¶ms) + untilID.map { params["until_id"] = $0 } + userFields?.bind(param: ¶ms) + return params } public init( @@ -75,4 +79,7 @@ open class GetUsersTweetsRequestV2: TwitterAPIRequest { self.untilID = untilID self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Timeline/TimelineAPIv2.swift b/Sources/TwitterAPIKit/APIv2/Timeline/TimelineAPIv2.swift index ae73719e..772dcebe 100644 --- a/Sources/TwitterAPIKit/APIv2/Timeline/TimelineAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/Timeline/TimelineAPIv2.swift @@ -1,15 +1,23 @@ +// TimelineAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class TimelineAPIv2: TwitterAPIBase { - - /// https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-tweets + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/ + /// api-reference/get-users-id-tweets public func getUserTweets( _ request: GetUsersTweetsRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } - /// https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-mentions + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/ + /// api-reference/get-users-id-mentions public func getUserMensions( _ request: GetUsersMentionsRequestV2 ) -> TwitterAPISessionJSONTask { @@ -17,10 +25,16 @@ open class TimelineAPIv2: TwitterAPIBase { } /// a.k.a Home Timeline - /// https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-reverse-chronological + /// For more details, see: + /// https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/ + /// api-reference/get-users-id-reverse-chronological public func getUserReverseChronological( _ request: GetUsersTimelinesReverseChronologicalRequestV2 ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Timeline/TwitterTimelineExcludeV2.swift b/Sources/TwitterAPIKit/APIv2/Timeline/TwitterTimelineExcludeV2.swift index 53866e1a..63d9dc47 100644 --- a/Sources/TwitterAPIKit/APIv2/Timeline/TwitterTimelineExcludeV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Timeline/TwitterTimelineExcludeV2.swift @@ -1,16 +1,29 @@ +// TwitterTimelineExcludeV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// The types of items to exclude from the timeline. public enum TwitterTimelineExcludeV2: String, TwitterAPIv2RequestParameter { - case retweets + /// Exclude replies from the timeline. case replies + /// Exclude retweets from the timeline. + case retweets + /// The string value of the exclude type. public var stringValue: String { return rawValue } } +/// Extension to bind the exclude types to the request parameters. extension Set where Element == TwitterTimelineExcludeV2 { - func bind(param: inout [String: Any]) { + /// Binds the exclude types to the request parameters. + /// - Parameters: + /// - param: The parameters dictionary to bind to. + public func bind(param: inout [String: Any]) { param["exclude"] = commaSeparatedString } } diff --git a/Sources/TwitterAPIKit/APIv2/Tweet/Requests/DeleteTweetRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Tweet/Requests/DeleteTweetRequestV2.swift index 16b977b5..497353a4 100644 --- a/Sources/TwitterAPIKit/APIv2/Tweet/Requests/DeleteTweetRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Tweet/Requests/DeleteTweetRequestV2.swift @@ -1,8 +1,12 @@ +// DeleteTweetRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/delete-tweets-id open class DeleteTweetRequestV2: TwitterAPIRequest { - public let id: String public var method: HTTPMethod { @@ -22,4 +26,7 @@ open class DeleteTweetRequestV2: TwitterAPIRequest { ) { self.id = id } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetRequestV2.swift index 6e048e6e..92eea865 100644 --- a/Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetRequestV2.swift @@ -1,8 +1,12 @@ +// GetTweetRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id open class GetTweetRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let mediaFields: Set? @@ -20,14 +24,14 @@ open class GetTweetRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - mediaFields?.bind(param: &p) - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + mediaFields?.bind(param: ¶ms) + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -47,4 +51,8 @@ open class GetTweetRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetsQuoteTweetsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetsQuoteTweetsRequestV2.swift index ef110382..9e589b41 100644 --- a/Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetsQuoteTweetsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetsQuoteTweetsRequestV2.swift @@ -1,8 +1,12 @@ +// GetTweetsQuoteTweetsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/quote-tweets/api-reference/get-tweets-id-quote_tweets open class GetTweetsQuoteTweetsRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let maxResults: Int? @@ -22,16 +26,16 @@ open class GetTweetsQuoteTweetsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - maxResults.map { p["max_results"] = $0 } - mediaFields?.bind(param: &p) - paginationToken.map { p["pagination_token"] = $0 } - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + maxResults.map { params["max_results"] = $0 } + mediaFields?.bind(param: ¶ms) + paginationToken.map { params["pagination_token"] = $0 } + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -55,4 +59,7 @@ open class GetTweetsQuoteTweetsRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetsRequestV2.swift index 319997e5..8998d988 100644 --- a/Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetsRequestV2.swift @@ -1,8 +1,12 @@ +// GetTweetsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets open class GetTweetsRequestV2: TwitterAPIRequest { - public let ids: [String] public let expansions: Set? public let mediaFields: Set? @@ -20,15 +24,15 @@ open class GetTweetsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["ids"] = ids.joined(separator: ",") - expansions?.bind(param: &p) - mediaFields?.bind(param: &p) - placeFields?.bind(param: &p) - pollFields?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + params["ids"] = ids.joined(separator: ",") + expansions?.bind(param: ¶ms) + mediaFields?.bind(param: ¶ms) + placeFields?.bind(param: ¶ms) + pollFields?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -46,6 +50,10 @@ open class GetTweetsRequestV2: TwitterAPIRequest { self.placeFields = placeFields self.pollFields = pollFields self.tweetFields = tweetFields - self.userFields = userFields + self.userFields = userFields + } + + deinit { + // De-init Logic Here } } diff --git a/Sources/TwitterAPIKit/APIv2/Tweet/Requests/PostTweetsRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Tweet/Requests/PostTweetsRequestV2.swift index 7c6e3adc..c8420d25 100644 --- a/Sources/TwitterAPIKit/APIv2/Tweet/Requests/PostTweetsRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Tweet/Requests/PostTweetsRequestV2.swift @@ -1,8 +1,12 @@ +// PostTweetsRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets open class PostTweetsRequestV2: TwitterAPIRequest { - public struct Geo { public let placeID: String @@ -10,12 +14,12 @@ open class PostTweetsRequestV2: TwitterAPIRequest { self.placeID = placeID } - func bind(param: inout [String: Any]) { - var p = [String: Any]() + public func bind(param: inout [String: Any]) { + var params = [String: Any]() - p["place_id"] = placeID + params["place_id"] = placeID - param["geo"] = p + param["geo"] = params } } @@ -31,13 +35,13 @@ open class PostTweetsRequestV2: TwitterAPIRequest { self.taggedUserIDs = taggedUserIDs } - func bind(param: inout [String: Any]) { - var p = [String: Any]() + public func bind(param: inout [String: Any]) { + var params = [String: Any]() - p["media_ids"] = mediaIDs - taggedUserIDs.map { p["tagged_user_ids"] = $0 } + params["media_ids"] = mediaIDs + taggedUserIDs.map { params["tagged_user_ids"] = $0 } - param["media"] = p + param["media"] = params } } @@ -53,13 +57,13 @@ open class PostTweetsRequestV2: TwitterAPIRequest { self.options = options } - func bind(param: inout [String: Any]) { - var p = [String: Any]() + public func bind(param: inout [String: Any]) { + var params = [String: Any]() - p["duration_minutes"] = durationMinutes - p["options"] = options + params["duration_minutes"] = durationMinutes + params["options"] = options - param["poll"] = p + param["poll"] = params } } @@ -75,13 +79,13 @@ open class PostTweetsRequestV2: TwitterAPIRequest { self.inReplyToTweetID = inReplyToTweetID } - func bind(param: inout [String: Any]) { - var p = [String: Any]() + public func bind(param: inout [String: Any]) { + var params = [String: Any]() - excludeReplyUserIDs.map { p["exclude_reply_user_ids"] = $0 } - p["in_reply_to_tweet_id"] = inReplyToTweetID + excludeReplyUserIDs.map { params["exclude_reply_user_ids"] = $0 } + params["in_reply_to_tweet_id"] = inReplyToTweetID - param["reply"] = p + param["reply"] = params } } @@ -90,7 +94,7 @@ open class PostTweetsRequestV2: TwitterAPIRequest { case following case everyone - func bind(param: inout [String: Any]) { + public func bind(param: inout [String: Any]) { param["reply_settings"] = rawValue } } @@ -118,17 +122,17 @@ open class PostTweetsRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - directMessageDeepLink.map { p["direct_message_deep_link"] = $0 } - forSuperFollowersOnly.map { p["for_super_followers_only"] = $0 } - geo?.bind(param: &p) - media?.bind(param: &p) - poll?.bind(param: &p) - quoteTweetID.map { p["quote_tweet_id"] = $0 } - reply?.bind(param: &p) - replySettings?.bind(param: &p) - text.map { p["text"] = $0 } - return p + var params = [String: Any]() + directMessageDeepLink.map { params["direct_message_deep_link"] = $0 } + forSuperFollowersOnly.map { params["for_super_followers_only"] = $0 } + geo?.bind(param: ¶ms) + media?.bind(param: ¶ms) + poll?.bind(param: ¶ms) + quoteTweetID.map { params["quote_tweet_id"] = $0 } + reply?.bind(param: ¶ms) + replySettings?.bind(param: ¶ms) + text.map { params["text"] = $0 } + return params } public init( @@ -152,4 +156,8 @@ open class PostTweetsRequestV2: TwitterAPIRequest { self.replySettings = replySettings self.text = text } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Tweet/Requests/PutTweetsHiddenRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Tweet/Requests/PutTweetsHiddenRequestV2.swift index 8639c6a2..6e467e86 100644 --- a/Sources/TwitterAPIKit/APIv2/Tweet/Requests/PutTweetsHiddenRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Tweet/Requests/PutTweetsHiddenRequestV2.swift @@ -1,8 +1,12 @@ +// PutTweetsHiddenRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/hide-replies/api-reference/put-tweets-id-hidden open class PutTweetsHiddenRequestV2: TwitterAPIRequest { - /// Tweet ID public let id: String public let hidden: Bool @@ -20,9 +24,9 @@ open class PutTweetsHiddenRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["hidden"] = hidden - return p + var params = [String: Any]() + params["hidden"] = hidden + return params } public init( @@ -32,4 +36,8 @@ open class PutTweetsHiddenRequestV2: TwitterAPIRequest { self.id = id self.hidden = hidden } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Tweet/TweetAPIv2.swift b/Sources/TwitterAPIKit/APIv2/Tweet/TweetAPIv2.swift index d6b10036..a6480dc1 100644 --- a/Sources/TwitterAPIKit/APIv2/Tweet/TweetAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/Tweet/TweetAPIv2.swift @@ -1,3 +1,8 @@ +// TweetAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class TweetAPIv2: TwitterAPIBase { @@ -42,4 +47,8 @@ open class TweetAPIv2: TwitterAPIBase { ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/GetTweetsCountsAllRequestV2.swift b/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/GetTweetsCountsAllRequestV2.swift index 94b5faef..ac2f4678 100644 --- a/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/GetTweetsCountsAllRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/GetTweetsCountsAllRequestV2.swift @@ -1,8 +1,12 @@ +// GetTweetsCountsAllRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/counts/api-reference/get-tweets-counts-all open class GetTweetsCountsAllRequestV2: TwitterAPIRequest { - public let query: String public let endTime: Date? public let granularity: TweetCountGranularityV2? @@ -20,15 +24,15 @@ open class GetTweetsCountsAllRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["query"] = query - endTime?.bind(param: &p, for: "end_time") - granularity?.bind(param: &p) - nextToken.map { p["next_token"] = $0 } - sinceID.map { p["since_id"] = $0 } - startTime?.bind(param: &p, for: "start_time") - untilID.map { p["until_id"] = $0 } - return p + var params = [String: Any]() + params["query"] = query + endTime?.bind(param: ¶ms, for: "end_time") + granularity?.bind(param: ¶ms) + nextToken.map { params["next_token"] = $0 } + sinceID.map { params["since_id"] = $0 } + startTime?.bind(param: ¶ms, for: "start_time") + untilID.map { params["until_id"] = $0 } + return params } public init( @@ -48,4 +52,7 @@ open class GetTweetsCountsAllRequestV2: TwitterAPIRequest { self.startTime = startTime self.untilID = untilID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/GetTweetsCountsRecentRequestV2.swift b/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/GetTweetsCountsRecentRequestV2.swift index 7ff28e8a..1058ea02 100644 --- a/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/GetTweetsCountsRecentRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/GetTweetsCountsRecentRequestV2.swift @@ -1,8 +1,12 @@ +// GetTweetsCountsRecentRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/tweets/counts/api-reference/get-tweets-counts-recent open class GetTweetsCountsRecentRequestV2: TwitterAPIRequest { - public let query: String public let endTime: Date? public let granularity: TweetCountGranularityV2? @@ -19,14 +23,14 @@ open class GetTweetsCountsRecentRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["query"] = query - endTime?.bind(param: &p, for: "end_time") - granularity?.bind(param: &p) - sinceID.map { p["since_id"] = $0 } - startTime?.bind(param: &p, for: "start_time") - untilID.map { p["until_id"] = $0 } - return p + var params = [String: Any]() + params["query"] = query + endTime?.bind(param: ¶ms, for: "end_time") + granularity?.bind(param: ¶ms) + sinceID.map { params["since_id"] = $0 } + startTime?.bind(param: ¶ms, for: "start_time") + untilID.map { params["until_id"] = $0 } + return params } public init( @@ -44,4 +48,7 @@ open class GetTweetsCountsRecentRequestV2: TwitterAPIRequest { self.startTime = startTime self.untilID = untilID } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/TweetCountGranularity.swift b/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/TweetCountGranularity.swift deleted file mode 100644 index 9b4d0d6e..00000000 --- a/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/TweetCountGranularity.swift +++ /dev/null @@ -1,12 +0,0 @@ -import Foundation - -public enum TweetCountGranularityV2: String { - - case minute - case hour - case day - - func bind(param: inout [String: Any]) { - param["granularity"] = rawValue - } -} diff --git a/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/TweetCountGranularityV2.swift b/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/TweetCountGranularityV2.swift new file mode 100644 index 00000000..454edc23 --- /dev/null +++ b/Sources/TwitterAPIKit/APIv2/TweetCount/Requests/TweetCountGranularityV2.swift @@ -0,0 +1,16 @@ +// TweetCountGranularity.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + +import Foundation + +public enum TweetCountGranularityV2: String { + case day + case hour + case minute + + public func bind(param: inout [String: Any]) { + param["granularity"] = rawValue + } +} diff --git a/Sources/TwitterAPIKit/APIv2/TweetCount/TweetCountAPIv2.swift b/Sources/TwitterAPIKit/APIv2/TweetCount/TweetCountAPIv2.swift index 6ed53156..e95200bc 100644 --- a/Sources/TwitterAPIKit/APIv2/TweetCount/TweetCountAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/TweetCount/TweetCountAPIv2.swift @@ -1,3 +1,8 @@ +// TweetCountAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class TweetCountAPIv2: TwitterAPIBase { @@ -15,4 +20,8 @@ open class TweetCountAPIv2: TwitterAPIBase { ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/APIv2/TwitterAPIv2.swift b/Sources/TwitterAPIKit/APIv2/TwitterAPIv2.swift index a3fc5170..e9f83d95 100644 --- a/Sources/TwitterAPIKit/APIv2/TwitterAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/TwitterAPIv2.swift @@ -1,24 +1,63 @@ +// TwitterAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation // https://developer.twitter.com/en/docs/api-reference-index +/// Main class for interacting with Twitter API v2 endpoints. +/// This class provides access to various API modules for different Twitter functionalities. +/// Each property represents a specialized API client for specific Twitter features. open class TwitterAPIv2 { + /// Client for managing block and mute relationships between users. public let blockAndMute: BlockAndMuteAPIv2 + + /// Client for managing tweet bookmarks. public let bookmarks: BookmarksAPIv2 + + /// Client for accessing Twitter's compliance and data management endpoints. public let compliance: ComplianceAPIv2 + + /// Client for managing follow relationships between users. public let friendships: FriendshipsAPIv2 + + /// Client for managing tweet likes (favorites). public let like: LikeAPIv2 + + /// Client for managing Twitter lists. public let list: ListAPIv2 + + /// Client for managing retweets. public let retweet: RetweetAPIv2 + + /// Client for searching tweets. public let search: SearchAPIv2 + + /// Client for managing Twitter Spaces. public let spaces: SpacesAPIv2 + + /// Client for accessing Twitter's streaming endpoints. public let stream: StreamAPIv2 + + /// Client for accessing user timelines. public let timeline: TimelineAPIv2 + + /// Client for managing tweets. public let tweet: TweetAPIv2 + + /// Client for retrieving tweet counts and metrics. public let tweetCount: TweetCountAPIv2 + + /// Client for managing user profiles and information. public let user: UserAPIv2 + + /// Client for managing direct messages. public let dm: DirectMessageAPIv2 + /// Initializes a new TwitterAPIv2 instance. + /// - Parameter session: The session to use for making API requests. public init(session: TwitterAPISession) { blockAndMute = .init(session: session) bookmarks = .init(session: session) @@ -36,14 +75,21 @@ open class TwitterAPIv2 { user = .init(session: session) dm = .init(session: session) } + + deinit { + // De-init Logic Here + } } +/// Protocol defining parameters that can be used in Twitter API v2 requests. public protocol TwitterAPIv2RequestParameter { + /// The string representation of the parameter value. var stringValue: String { get } } extension Collection where Element: TwitterAPIv2RequestParameter { - var commaSeparatedString: String { - return map { $0.stringValue }.sorted().joined(separator: ",") + /// Joins multiple parameter values into a comma-separated string. + public var commaSeparatedString: String { + return map(\.stringValue).sorted().joined(separator: ",") } } diff --git a/Sources/TwitterAPIKit/APIv2/ExpansionsV2.swift b/Sources/TwitterAPIKit/APIv2/TwitterDmEventExpansionsV2.swift similarity index 81% rename from Sources/TwitterAPIKit/APIv2/ExpansionsV2.swift rename to Sources/TwitterAPIKit/APIv2/TwitterDmEventExpansionsV2.swift index a7213ff8..5b520d09 100644 --- a/Sources/TwitterAPIKit/APIv2/ExpansionsV2.swift +++ b/Sources/TwitterAPIKit/APIv2/TwitterDmEventExpansionsV2.swift @@ -1,44 +1,50 @@ -import Foundation +// ExpansionsV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. -// https://developer.twitter.com/en/docs/twitter-api/expansions +import Foundation -protocol TwitterExpansionsParameterV2: TwitterAPIv2RequestParameter {} +/// For more details, see: +/// https://developer.twitter.com/en/docs/twitter-api/expansions +public protocol TwitterExpansionsParameterV2: TwitterAPIv2RequestParameter {} +/// Binds the expansions to the request parameters. extension Set where Element: TwitterExpansionsParameterV2 { - func bind(param: inout [String: Any]) { + /// Binds the expansions to the request parameters. + public func bind(param: inout [String: Any]) { param["expansions"] = commaSeparatedString } } public enum TwitterTweetExpansionsV2: TwitterExpansionsParameterV2, Hashable { - - case attachmentsPollIDs case attachmentsMediaKeys + case attachmentsPollIDs case authorID case entitiesMentionsUsername case geoPlaceID case inReplyToUserID + case other(String) case referencedTweetsID case referencedTweetsIDAuthorID - case other(String) public var stringValue: String { switch self { - case .attachmentsPollIDs: return "attachments.poll_ids" case .attachmentsMediaKeys: return "attachments.media_keys" + case .attachmentsPollIDs: return "attachments.poll_ids" case .authorID: return "author_id" case .entitiesMentionsUsername: return "entities.mentions.username" case .geoPlaceID: return "geo.place_id" case .inReplyToUserID: return "in_reply_to_user_id" + case let .other(string): return string case .referencedTweetsID: return "referenced_tweets.id" case .referencedTweetsIDAuthorID: return "referenced_tweets.id.author_id" - case .other(let string): return string } } public static let all: Set = [ - .attachmentsPollIDs, .attachmentsMediaKeys, + .attachmentsPollIDs, .authorID, .entitiesMentionsUsername, .geoPlaceID, @@ -49,63 +55,62 @@ public enum TwitterTweetExpansionsV2: TwitterExpansionsParameterV2, Hashable { } public enum TwitterUserExpansionsV2: TwitterExpansionsParameterV2, Hashable { - case pinnedTweetID case other(String) + case pinnedTweetID public var stringValue: String { switch self { + case let .other(string): return string case .pinnedTweetID: return "pinned_tweet_id" - case .other(let string): return string } } public static let all: Set = [ - .pinnedTweetID + .pinnedTweetID, ] } public enum TwitterListExpansionsV2: TwitterExpansionsParameterV2, Hashable { - case ownerID case other(String) + case ownerID public var stringValue: String { switch self { + case let .other(string): return string case .ownerID: return "owner_id" - case .other(let string): return string } } public static let all: Set = [ - .ownerID + .ownerID, ] } public enum TwitterSpaceExpansionsV2: TwitterExpansionsParameterV2, Hashable { - - case invitedUserIDs - case speakerIDs case creatorID case hostIDs - case topicIDs + case invitedUserIDs case other(String) + case speakerIDs + case topicIDs public var stringValue: String { switch self { - case .invitedUserIDs: return "invited_user_ids" - case .speakerIDs: return "speaker_ids" case .creatorID: return "creator_id" case .hostIDs: return "host_ids" + case .invitedUserIDs: return "invited_user_ids" + case let .other(string): return string + case .speakerIDs: return "speaker_ids" case .topicIDs: return "topic_ids" - case .other(let string): return string } } public static let all: Set = [ + .creatorID, + .hostIDs, .invitedUserIDs, .speakerIDs, - .creatorID, .topicIDs, - .hostIDs, ] } @@ -113,18 +118,18 @@ public enum TwitterSpaceExpansionsV2: TwitterExpansionsParameterV2, Hashable { /// expansions public enum TwitterDmEventExpansionsV2: TwitterExpansionsParameterV2, Hashable { case attachmentsMediaKeys + case other(String) case participantIDs case referencedTweetsID case senderID - case other(String) public var stringValue: String { switch self { case .attachmentsMediaKeys: return "attachments.media_keys" + case let .other(string): return string case .participantIDs: return "participant_ids" case .referencedTweetsID: return "referenced_tweets.id" case .senderID: return "sender_id" - case .other(let string): return string } } diff --git a/Sources/TwitterAPIKit/APIv2/FieldsV2.swift b/Sources/TwitterAPIKit/APIv2/TwitterTweetFieldsV2.swift similarity index 80% rename from Sources/TwitterAPIKit/APIv2/FieldsV2.swift rename to Sources/TwitterAPIKit/APIv2/TwitterTweetFieldsV2.swift index 5ed79d61..fc0faac3 100644 --- a/Sources/TwitterAPIKit/APIv2/FieldsV2.swift +++ b/Sources/TwitterAPIKit/APIv2/TwitterTweetFieldsV2.swift @@ -1,10 +1,14 @@ +// TwitterAPIv2Fields.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation // https://developer.twitter.com/en/docs/twitter-api/fields /// tweet.fields public enum TwitterTweetFieldsV2: TwitterAPIv2RequestParameter, Hashable { - case attachments case authorID case contextAnnotations @@ -16,19 +20,18 @@ public enum TwitterTweetFieldsV2: TwitterAPIv2RequestParameter, Hashable { case inReplyToUserID case lang case nonPublicMetrics - case publicMetrics case organicMetrics - case promotedMetrics + case other(String) case possiblySensitive + case promotedMetrics + case publicMetrics case referencedTweets case replySettings case source case text case withheld - case other(String) public var stringValue: String { - switch self { case .attachments: return "attachments" @@ -52,14 +55,16 @@ public enum TwitterTweetFieldsV2: TwitterAPIv2RequestParameter, Hashable { return "lang" case .nonPublicMetrics: return "non_public_metrics" - case .publicMetrics: - return "public_metrics" case .organicMetrics: return "organic_metrics" - case .promotedMetrics: - return "promoted_metrics" + case let .other(other): + return other case .possiblySensitive: return "possibly_sensitive" + case .promotedMetrics: + return "promoted_metrics" + case .publicMetrics: + return "public_metrics" case .referencedTweets: return "referenced_tweets" case .replySettings: @@ -70,8 +75,6 @@ public enum TwitterTweetFieldsV2: TwitterAPIv2RequestParameter, Hashable { return "text" case .withheld: return "withheld" - case .other(let other): - return other } } @@ -87,10 +90,10 @@ public enum TwitterTweetFieldsV2: TwitterAPIv2RequestParameter, Hashable { .inReplyToUserID, .lang, .nonPublicMetrics, - .publicMetrics, .organicMetrics, - .promotedMetrics, .possiblySensitive, + .promotedMetrics, + .publicMetrics, .referencedTweets, .replySettings, .source, @@ -99,7 +102,10 @@ public enum TwitterTweetFieldsV2: TwitterAPIv2RequestParameter, Hashable { ] } -extension Set where Element == TwitterTweetFieldsV2 { +/// Extension to bind tweet fields to request parameters +public extension Set where Element == TwitterTweetFieldsV2 { + /// Binds the tweet fields to the request parameters + /// - Parameter param: The parameters dictionary to bind to func bind(param: inout [String: Any]) { param["tweet.fields"] = commaSeparatedString } @@ -113,6 +119,7 @@ public enum TwitterUserFieldsV2: TwitterAPIv2RequestParameter, Hashable { case id case location case name + case other(String) case pinnedTweetID case profileImageUrl case protected @@ -121,7 +128,6 @@ public enum TwitterUserFieldsV2: TwitterAPIv2RequestParameter, Hashable { case username case verified case withheld - case other(String) public var stringValue: String { switch self { @@ -137,6 +143,8 @@ public enum TwitterUserFieldsV2: TwitterAPIv2RequestParameter, Hashable { return "location" case .name: return "name" + case let .other(other): + return other case .pinnedTweetID: return "pinned_tweet_id" case .profileImageUrl: @@ -153,8 +161,6 @@ public enum TwitterUserFieldsV2: TwitterAPIv2RequestParameter, Hashable { return "verified" case .withheld: return "withheld" - case .other(let other): - return other } } @@ -176,7 +182,10 @@ public enum TwitterUserFieldsV2: TwitterAPIv2RequestParameter, Hashable { ] } -extension Set where Element == TwitterUserFieldsV2 { +/// Extension to bind user fields to request parameters +public extension Set where Element == TwitterUserFieldsV2 { + /// Binds the user fields to the request parameters + /// - Parameter param: The parameters dictionary to bind to func bind(param: inout [String: Any]) { param["user.fields"] = commaSeparatedString } @@ -184,7 +193,6 @@ extension Set where Element == TwitterUserFieldsV2 { /// place.fields public enum TwitterPlaceFieldsV2: TwitterAPIv2RequestParameter, Hashable { - case containedWithin case country case countryCode @@ -192,8 +200,8 @@ public enum TwitterPlaceFieldsV2: TwitterAPIv2RequestParameter, Hashable { case geo case id case name - case placeType case other(String) + case placeType public var stringValue: String { switch self { @@ -211,10 +219,10 @@ public enum TwitterPlaceFieldsV2: TwitterAPIv2RequestParameter, Hashable { return "id" case .name: return "name" + case let .other(other): + return other case .placeType: return "place_type" - case .other(let other): - return other } } @@ -230,7 +238,10 @@ public enum TwitterPlaceFieldsV2: TwitterAPIv2RequestParameter, Hashable { ] } -extension Set where Element == TwitterPlaceFieldsV2 { +/// Extension to bind place fields to request parameters +public extension Set where Element == TwitterPlaceFieldsV2 { + /// Binds the place fields to the request parameters + /// - Parameter param: The parameters dictionary to bind to func bind(param: inout [String: Any]) { param["place.fields"] = commaSeparatedString } @@ -242,8 +253,8 @@ public enum TwitterPollFieldsV2: TwitterAPIv2RequestParameter, Hashable { case endDatetime case id case options - case votingStatus case other(String) + case votingStatus public var stringValue: String { switch self { @@ -255,10 +266,10 @@ public enum TwitterPollFieldsV2: TwitterAPIv2RequestParameter, Hashable { return "id" case .options: return "options" + case let .other(other): + return other case .votingStatus: return "voting_status" - case .other(let other): - return other } } @@ -271,7 +282,10 @@ public enum TwitterPollFieldsV2: TwitterAPIv2RequestParameter, Hashable { ] } -extension Set where Element == TwitterPollFieldsV2 { +/// Extension to bind poll fields to request parameters +public extension Set where Element == TwitterPollFieldsV2 { + /// Binds the poll fields to the request parameters + /// - Parameter param: The parameters dictionary to bind to func bind(param: inout [String: Any]) { param["poll.fields"] = commaSeparatedString } @@ -279,58 +293,61 @@ extension Set where Element == TwitterPollFieldsV2 { /// media.fields public enum TwitterMediaFieldsV2: TwitterAPIv2RequestParameter, Hashable { + case altText case durationMs case height case mediaKey - case previewImageUrl - case type - case url - case width - case publicMetrics case nonPublicMetrics case organicMetrics + case other(String) + case previewImageUrl case promotedMetrics - case altText + case publicMetrics + case type + case url case variants - case other(String) + case width public var stringValue: String { switch self { + case .altText: return "alt_text" case .durationMs: return "duration_ms" case .height: return "height" case .mediaKey: return "media_key" - case .previewImageUrl: return "preview_image_url" - case .type: return "type" - case .url: return "url" - case .width: return "width" - case .publicMetrics: return "public_metrics" case .nonPublicMetrics: return "non_public_metrics" case .organicMetrics: return "organic_metrics" + case let .other(string): return string + case .previewImageUrl: return "preview_image_url" case .promotedMetrics: return "promoted_metrics" - case .altText: return "alt_text" + case .publicMetrics: return "public_metrics" + case .type: return "type" + case .url: return "url" case .variants: return "variants" - case .other(let string): return string + case .width: return "width" } } public static let all: Set = [ + .altText, .durationMs, .height, .mediaKey, - .previewImageUrl, - .type, - .url, - .width, - .publicMetrics, .nonPublicMetrics, .organicMetrics, + .previewImageUrl, .promotedMetrics, - .altText, + .publicMetrics, + .type, + .url, .variants, + .width, ] } -extension Set where Element == TwitterMediaFieldsV2 { +/// Extension to bind media fields to request parameters +public extension Set where Element == TwitterMediaFieldsV2 { + /// Binds the media fields to the request parameters + /// - Parameter param: The parameters dictionary to bind to func bind(param: inout [String: Any]) { param["media.fields"] = commaSeparatedString } @@ -338,44 +355,48 @@ extension Set where Element == TwitterMediaFieldsV2 { /// list.fields public enum TwitterListFieldsV2: TwitterAPIv2RequestParameter, Hashable { - + // swiftlint:disable sorted_enum_cases case createdAt - case followerCount - case memberCount - case `private` case description + case followerCount case id + case memberCount case name - case ownerID case other(String) + case ownerID + case `private` public var stringValue: String { switch self { case .createdAt: return "created_at" - case .followerCount: return "follower_count" - case .memberCount: return "member_count" - case .private: return "private" case .description: return "description" + case .followerCount: return "follower_count" case .id: return "id" + case .memberCount: return "member_count" case .name: return "name" + case let .other(string): return string case .ownerID: return "owner_id" - case .other(let string): return string + case .private: return "private" } } public static let all: Set = [ .createdAt, - .followerCount, - .memberCount, - .private, .description, + .followerCount, .id, + .memberCount, .name, .ownerID, + .private, ] + // swiftlint:enable sorted_enum_cases } -extension Set where Element == TwitterListFieldsV2 { +/// Extension to bind list fields to request parameters +public extension Set where Element == TwitterListFieldsV2 { + /// Binds the list fields to the request parameters + /// - Parameter param: The parameters dictionary to bind to func bind(param: inout [String: Any]) { param["list.fields"] = commaSeparatedString } @@ -383,71 +404,73 @@ extension Set where Element == TwitterListFieldsV2 { /// space.fields public enum TwitterSpaceFieldsV2: TwitterAPIv2RequestParameter, Hashable { - - case id - case state - case hostIDs case createdAt case creatorID - case lang + case endedAt + case hostIDs + case id case invitedUserIDs + case isTicketed + case lang + case other(String) case participantCount + case scheduledStart case speakerIDs case startedAt - case endedAt + case state case subscriberCount - case topicIDs case title + case topicIDs case updatedAt - case scheduledStart - case isTicketed - case other(String) public var stringValue: String { switch self { - case .id: return "id" - case .state: return "state" - case .hostIDs: return "host_ids" case .createdAt: return "created_at" case .creatorID: return "creator_id" - case .lang: return "lang" + case .endedAt: return "ended_at" + case .hostIDs: return "host_ids" + case .id: return "id" case .invitedUserIDs: return "invited_user_ids" + case .isTicketed: return "is_ticketed" + case .lang: return "lang" + case let .other(string): return string case .participantCount: return "participant_count" + case .scheduledStart: return "scheduled_start" case .speakerIDs: return "speaker_ids" case .startedAt: return "started_at" - case .endedAt: return "ended_at" + case .state: return "state" case .subscriberCount: return "subscriber_count" - case .topicIDs: return "topic_ids" case .title: return "title" + case .topicIDs: return "topic_ids" case .updatedAt: return "updated_at" - case .scheduledStart: return "scheduled_start" - case .isTicketed: return "is_ticketed" - case .other(let string): return string } } public static let all: Set = [ - .id, - .state, - .hostIDs, .createdAt, .creatorID, - .lang, + .endedAt, + .hostIDs, + .id, .invitedUserIDs, + .isTicketed, + .lang, .participantCount, + .scheduledStart, .speakerIDs, .startedAt, - .endedAt, + .state, .subscriberCount, - .topicIDs, .title, + .topicIDs, .updatedAt, - .scheduledStart, - .isTicketed, ] } -extension Set where Element == TwitterSpaceFieldsV2 { +/// Extension to bind space fields to request parameters +public extension Set where Element == TwitterSpaceFieldsV2 { + /// Binds the space fields to the request parameters + /// - Parameter param: The parameters dictionary to bind to func bind(param: inout [String: Any]) { param["space.fields"] = commaSeparatedString } @@ -455,29 +478,31 @@ extension Set where Element == TwitterSpaceFieldsV2 { /// topic.fields public enum TwitterTopicFieldsV2: TwitterAPIv2RequestParameter, Hashable { - + case description case id case name - case description case other(String) public var stringValue: String { switch self { + case .description: return "description" case .id: return "id" case .name: return "name" - case .description: return "description" - case .other(let string): return string + case let .other(string): return string } } public static let all: Set = [ + .description, .id, .name, - .description, ] } -extension Set where Element == TwitterTopicFieldsV2 { +/// Extension to bind topic fields to request parameters +public extension Set where Element == TwitterTopicFieldsV2 { + /// Binds the topic fields to the request parameters + /// - Parameter param: The parameters dictionary to bind to func bind(param: inout [String: Any]) { param["topic.fields"] = commaSeparatedString } @@ -491,11 +516,11 @@ public enum TwitterDmEventFieldsV2: TwitterAPIv2RequestParameter, Hashable { case dmConversationID case eventType case id + case other(String) case participantIDs case referencedTweets case senderID case text - case other(String) public var stringValue: String { switch self { @@ -504,11 +529,11 @@ public enum TwitterDmEventFieldsV2: TwitterAPIv2RequestParameter, Hashable { case .dmConversationID: return "dm_conversation_id" case .eventType: return "event_type" case .id: return "id" + case let .other(string): return string case .participantIDs: return "participant_ids" case .referencedTweets: return "referenced_tweets" case .senderID: return "sender_id" case .text: return "text" - case .other(let string): return string } } @@ -525,7 +550,10 @@ public enum TwitterDmEventFieldsV2: TwitterAPIv2RequestParameter, Hashable { ] } -extension Set where Element == TwitterDmEventFieldsV2 { +/// Extension to bind DM event fields to request parameters +public extension Set where Element == TwitterDmEventFieldsV2 { + /// Binds the DM event fields to the request parameters + /// - Parameter param: The parameters dictionary to bind to func bind(param: inout [String: Any]) { param["dm_event.fields"] = commaSeparatedString } @@ -540,16 +568,19 @@ public enum TwitterDmConversationFieldsV2: TwitterAPIv2RequestParameter, Hashabl public var stringValue: String { switch self { case .id: return "id" - case .other(let string): return string + case let .other(string): return string } } public static let all: Set = [ - .id + .id, ] } -extension Set where Element == TwitterDmConversationFieldsV2 { +/// Extension to bind DM conversation fields to request parameters +public extension Set where Element == TwitterDmConversationFieldsV2 { + /// Binds the DM conversation fields to the request parameters + /// - Parameter param: The parameters dictionary to bind to func bind(param: inout [String: Any]) { param["dm_conversation.fields"] = commaSeparatedString } diff --git a/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUserRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUserRequestV2.swift index 199cc709..a907ecec 100644 --- a/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUserRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUserRequestV2.swift @@ -1,8 +1,12 @@ +// GetUserRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-id open class GetUserRequestV2: TwitterAPIRequest { - public let id: String public let expansions: Set? public let tweetFields: Set? @@ -17,11 +21,11 @@ open class GetUserRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -35,4 +39,7 @@ open class GetUserRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersByRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersByRequestV2.swift index 90c9a7c8..8e88dfa2 100644 --- a/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersByRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersByRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersByRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by open class GetUsersByRequestV2: TwitterAPIRequest { - public let usernames: [String] public let expansions: Set? public let tweetFields: Set? @@ -17,12 +21,12 @@ open class GetUsersByRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["usernames"] = usernames.joined(separator: ",") - expansions?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + params["usernames"] = usernames.joined(separator: ",") + expansions?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -36,4 +40,7 @@ open class GetUsersByRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersByUsernameRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersByUsernameRequestV2.swift index 7633e850..e8b4f472 100644 --- a/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersByUsernameRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersByUsernameRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersByUsernameRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by-username-username open class GetUsersByUsernameRequestV2: TwitterAPIRequest { - public let username: String public let expansions: Set? public let tweetFields: Set? @@ -17,11 +21,11 @@ open class GetUsersByUsernameRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -35,4 +39,7 @@ open class GetUsersByUsernameRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersMeRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersMeRequestV2.swift index a1b10250..6d193126 100644 --- a/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersMeRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersMeRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersMeRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-me open class GetUsersMeRequestV2: TwitterAPIRequest { - public let expansions: Set? public let tweetFields: Set? public let userFields: Set? @@ -16,11 +20,11 @@ open class GetUsersMeRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - expansions?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + expansions?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -32,4 +36,7 @@ open class GetUsersMeRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersRequestV2.swift b/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersRequestV2.swift index 24835625..0ce1ff11 100644 --- a/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersRequestV2.swift +++ b/Sources/TwitterAPIKit/APIv2/Users/Requests/GetUsersRequestV2.swift @@ -1,8 +1,12 @@ +// GetUsersRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users open class GetUsersRequestV2: TwitterAPIRequest { - public let ids: [String] public let expansions: Set? public let tweetFields: Set? @@ -17,12 +21,12 @@ open class GetUsersRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["ids"] = ids.joined(separator: ",") - expansions?.bind(param: &p) - tweetFields?.bind(param: &p) - userFields?.bind(param: &p) - return p + var params = [String: Any]() + params["ids"] = ids.joined(separator: ",") + expansions?.bind(param: ¶ms) + tweetFields?.bind(param: ¶ms) + userFields?.bind(param: ¶ms) + return params } public init( @@ -36,4 +40,7 @@ open class GetUsersRequestV2: TwitterAPIRequest { self.tweetFields = tweetFields self.userFields = userFields } + deinit { + // de-init logic here + } } diff --git a/Sources/TwitterAPIKit/APIv2/Users/UserAPIv2.swift b/Sources/TwitterAPIKit/APIv2/Users/UserAPIv2.swift index 08e424dc..041264ef 100644 --- a/Sources/TwitterAPIKit/APIv2/Users/UserAPIv2.swift +++ b/Sources/TwitterAPIKit/APIv2/Users/UserAPIv2.swift @@ -1,3 +1,8 @@ +// UserAPIv2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class UserAPIv2: TwitterAPIBase { @@ -35,4 +40,8 @@ open class UserAPIv2: TwitterAPIBase { ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/AuthAPI.swift b/Sources/TwitterAPIKit/AuthAPI/AuthAPI.swift deleted file mode 100644 index 1ec7993b..00000000 --- a/Sources/TwitterAPIKit/AuthAPI/AuthAPI.swift +++ /dev/null @@ -1,10 +0,0 @@ -open class TwitterAuthAPI { - - public let oauth10a: OAuth10aAPI - public let oauth20: OAuth20API - - public init(session: TwitterAPISession) { - oauth10a = .init(session: session) - oauth20 = .init(session: session) - } -} diff --git a/Sources/TwitterAPIKit/AuthAPI/OAuth10aAPI.swift b/Sources/TwitterAPIKit/AuthAPI/OAuth10aAPI.swift index cb9f4f34..15b8422f 100644 --- a/Sources/TwitterAPIKit/AuthAPI/OAuth10aAPI.swift +++ b/Sources/TwitterAPIKit/AuthAPI/OAuth10aAPI.swift @@ -1,7 +1,11 @@ +// OAuth10aAPI.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class OAuth10aAPI: TwitterAPIBase { - /// https://developer.twitter.com/en/docs/authentication/api-reference/request_token public func postOAuthRequestTokenData( _ request: PostOAuthRequestTokenRequestV1 @@ -64,4 +68,8 @@ open class OAuth10aAPI: TwitterAPIBase { ) -> TwitterAPISessionJSONTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/OAuth20API.swift b/Sources/TwitterAPIKit/AuthAPI/OAuth20API.swift index 30b547ff..91345411 100644 --- a/Sources/TwitterAPIKit/AuthAPI/OAuth20API.swift +++ b/Sources/TwitterAPIKit/AuthAPI/OAuth20API.swift @@ -1,7 +1,11 @@ +// OAuth20API.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class OAuth20API: TwitterAPIBase { - // MARK: - OAuth 2.0 Bearer Token /// https://developer.twitter.com/en/docs/authentication/api-reference/token @@ -24,7 +28,7 @@ open class OAuth20API: TwitterAPIBase { ) } return token - } catch let error { + } catch { throw TwitterAPIKitError.responseSerializeFailed( reason: .jsonSerializationFailed(error: error) ) @@ -34,7 +38,8 @@ open class OAuth20API: TwitterAPIBase { /// https://developer.twitter.com/en/docs/authentication/api-reference/invalidate_bearer_token /// - ///May not work. {"errors":[{"code":348,"message":"Client application is not permitted to to invalidate this token."}]} + /// May not work. + /// {"errors":[{"code":348,"message":"Client application is not permitted to to invalidate this token."}]} /// https://twittercommunity.com/t/oauth2-invalidate-token-not-working-for-app-only-authentication-tokens/133108 /// https://twittercommunity.com/t/invalidate-bearer-client-application-not-permitted/162761 public func postInvalidateOAuth2BearerToken( @@ -74,7 +79,6 @@ open class OAuth20API: TwitterAPIBase { ) -> TwitterAPISessionSpecializedTask { return postOAuth2RefreshTokenData(request) .specialized { try TwitterOAuth2AccessToken.fromResponse(data: $0) } - } public func postOAuth2RevokeToken( @@ -82,4 +86,8 @@ open class OAuth20API: TwitterAPIBase { ) -> TwitterAPISessionDataTask { return session.send(request) } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/Requests/GetOAuth2AuthorizeRequestV1.swift b/Sources/TwitterAPIKit/AuthAPI/Requests/GetOAuth2AuthorizeRequestV1.swift index aa6070de..b2c4821d 100644 --- a/Sources/TwitterAPIKit/AuthAPI/Requests/GetOAuth2AuthorizeRequestV1.swift +++ b/Sources/TwitterAPIKit/AuthAPI/Requests/GetOAuth2AuthorizeRequestV1.swift @@ -1,3 +1,8 @@ +// GetOAuth2AuthorizeRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/authentication/oauth-2-0/authorization-code @@ -24,16 +29,16 @@ open class GetOAuth2AuthorizeRequestV1: TwitterAPIRequest { } public var parameters: [String: Any] { - var p = [String: String]() - - p["response_type"] = responseType - p["client_id"] = clientID - p["redirect_uri"] = redirectURI - p["state"] = state - p["code_challenge"] = codeChallenge - p["code_challenge_method"] = codeChallengeMethod - p["scope"] = scopes.joined(separator: " ") - return p + var params = [String: String]() + + params["response_type"] = responseType + params["client_id"] = clientID + params["redirect_uri"] = redirectURI + params["state"] = state + params["code_challenge"] = codeChallenge + params["code_challenge_method"] = codeChallengeMethod + params["scope"] = scopes.joined(separator: " ") + return params } public init( @@ -53,4 +58,8 @@ open class GetOAuth2AuthorizeRequestV1: TwitterAPIRequest { self.codeChallengeMethod = codeChallengeMethod self.scopes = scopes } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/Requests/GetOAuthAuthenticateRequestV1.swift b/Sources/TwitterAPIKit/AuthAPI/Requests/GetOAuthAuthenticateRequestV1.swift index df581ec9..0dddc25d 100644 --- a/Sources/TwitterAPIKit/AuthAPI/Requests/GetOAuthAuthenticateRequestV1.swift +++ b/Sources/TwitterAPIKit/AuthAPI/Requests/GetOAuthAuthenticateRequestV1.swift @@ -1,8 +1,12 @@ +// GetOAuthAuthenticateRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/authentication/api-reference/authenticate open class GetOAuthAuthenticateRequestV1: TwitterAPIRequest { - public let oauthToken: String public let forceLogin: Bool? public let screenName: String? @@ -16,11 +20,11 @@ open class GetOAuthAuthenticateRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["oauth_token"] = oauthToken - forceLogin.map { p["force_login"] = $0 } - screenName.map { p["screen_name"] = $0 } - return p + var params = [String: Any]() + params["oauth_token"] = oauthToken + forceLogin.map { params["force_login"] = $0 } + screenName.map { params["screen_name"] = $0 } + return params } public init( @@ -32,4 +36,8 @@ open class GetOAuthAuthenticateRequestV1: TwitterAPIRequest { self.forceLogin = forceLogin self.screenName = screenName } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/Requests/GetOAuthAuthorizeRequestV1.swift b/Sources/TwitterAPIKit/AuthAPI/Requests/GetOAuthAuthorizeRequestV1.swift index c5e95c52..5246044b 100644 --- a/Sources/TwitterAPIKit/AuthAPI/Requests/GetOAuthAuthorizeRequestV1.swift +++ b/Sources/TwitterAPIKit/AuthAPI/Requests/GetOAuthAuthorizeRequestV1.swift @@ -1,8 +1,12 @@ +// GetOAuthAuthorizeRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/authentication/api-reference/authorize open class GetOAuthAuthorizeRequestV1: TwitterAPIRequest { - public let oauthToken: String public let forceLogin: Bool? public let screenName: String? @@ -16,11 +20,11 @@ open class GetOAuthAuthorizeRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["oauth_token"] = oauthToken - forceLogin.map { p["force_login"] = $0 } - screenName.map { p["screen_name"] = $0 } - return p + var params = [String: Any]() + params["oauth_token"] = oauthToken + forceLogin.map { params["force_login"] = $0 } + screenName.map { params["screen_name"] = $0 } + return params } public init( @@ -32,4 +36,8 @@ open class GetOAuthAuthorizeRequestV1: TwitterAPIRequest { self.forceLogin = forceLogin self.screenName = screenName } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2AccessTokenRequestV2.swift b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2AccessTokenRequestV2.swift index 37b67d3d..e2475dc6 100644 --- a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2AccessTokenRequestV2.swift +++ b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2AccessTokenRequestV2.swift @@ -1,7 +1,11 @@ +// PostOAuth2AccessTokenRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation open class PostOAuth2AccessTokenRequestV2: TwitterAPIRequest { - public let code: String public let grantType: String /// Required for Public Client. @@ -18,13 +22,13 @@ open class PostOAuth2AccessTokenRequestV2: TwitterAPIRequest { } public var parameters: [String: Any] { - var p = [String: String]() - p["code"] = code - p["grant_type"] = grantType - clientID.map { p["client_id"] = $0 } - p["redirect_uri"] = redirectURI - p["code_verifier"] = codeVerifier - return p + var params = [String: String]() + params["code"] = code + params["grant_type"] = grantType + clientID.map { params["client_id"] = $0 } + params["redirect_uri"] = redirectURI + params["code_verifier"] = codeVerifier + return params } public init( @@ -40,4 +44,8 @@ open class PostOAuth2AccessTokenRequestV2: TwitterAPIRequest { self.redirectURI = redirectURI self.codeVerifier = codeVerifier } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2InvalidateTokenRequestV1.swift b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2InvalidateTokenRequestV1.swift index c706a212..b94ab6de 100644 --- a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2InvalidateTokenRequestV1.swift +++ b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2InvalidateTokenRequestV1.swift @@ -1,8 +1,12 @@ +// PostOAuth2InvalidateTokenRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/authentication/api-reference/invalidate_bearer_token open class PostOAuth2InvalidateTokenRequestV1: TwitterAPIRequest { - public let accessToken: String public var method: HTTPMethod { @@ -14,9 +18,9 @@ open class PostOAuth2InvalidateTokenRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["access_token"] = accessToken - return p + var params = [String: Any]() + params["access_token"] = accessToken + return params } public init( @@ -24,4 +28,8 @@ open class PostOAuth2InvalidateTokenRequestV1: TwitterAPIRequest { ) { self.accessToken = accessToken } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2RefreshTokenRequestV2.swift b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2RefreshTokenRequestV2.swift index c8072b48..b5e2536d 100644 --- a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2RefreshTokenRequestV2.swift +++ b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2RefreshTokenRequestV2.swift @@ -1,8 +1,12 @@ +// PostOAuth2RefreshTokenRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/authentication/oauth-2-0/user-access-token open class PostOAuth2RefreshTokenRequestV2: TwitterAPIRequest { - public let refreshToken: String public let grantType: String /// Required for Public Client. @@ -17,13 +21,13 @@ open class PostOAuth2RefreshTokenRequestV2: TwitterAPIRequest { } public var parameters: [String: Any] { - var p = [String: String]() + var params = [String: String]() - p["refresh_token"] = refreshToken - p["grant_type"] = grantType - clientID.map { p["client_id"] = $0 } + params["refresh_token"] = refreshToken + params["grant_type"] = grantType + clientID.map { params["client_id"] = $0 } - return p + return params } public init( @@ -35,4 +39,8 @@ open class PostOAuth2RefreshTokenRequestV2: TwitterAPIRequest { self.grantType = grantType self.clientID = clientID } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2RevokeTokenRequestV2.swift b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2RevokeTokenRequestV2.swift index c35fd780..c0f251e2 100644 --- a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2RevokeTokenRequestV2.swift +++ b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2RevokeTokenRequestV2.swift @@ -1,12 +1,17 @@ +// PostOAuth2RevokeTokenRequestV2.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/authentication/oauth-2-0/user-access-token open class PostOAuth2RevokeTokenRequestV2: TwitterAPIRequest { - public let token: String /// Required for Public Client. public let clientID: String? - /// Maybe need this parameter when you got {"error":"invalid_request","error_description":"Missing required parameter [token_type_hint]."} + /// Maybe need this parameter when you got + /// {"error":"invalid_request","error_description":"Missing required parameter [token_type_hint]."} /// access_token or refresh_token /// > https://datatracker.ietf.org/doc/html/rfc7009#section-2.1 public let tokenTypeHint: String? @@ -20,12 +25,12 @@ open class PostOAuth2RevokeTokenRequestV2: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: String]() - p["token"] = token - tokenTypeHint.map { p["token_type_hint"] = $0 } - clientID.map { p["client_id"] = $0 } + var params = [String: String]() + params["token"] = token + tokenTypeHint.map { params["token_type_hint"] = $0 } + clientID.map { params["client_id"] = $0 } - return p + return params } public init( @@ -37,4 +42,8 @@ open class PostOAuth2RevokeTokenRequestV2: TwitterAPIRequest { self.clientID = clientID self.tokenTypeHint = tokenTypeHint } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2TokenRequestV1.swift b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2TokenRequestV1.swift index 5bb12169..fd008256 100644 --- a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2TokenRequestV1.swift +++ b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuth2TokenRequestV1.swift @@ -1,8 +1,12 @@ +// PostOAuth2TokenRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/authentication/api-reference/token open class PostOAuth2TokenRequestV1: TwitterAPIRequest { - public let grantType: String public var method: HTTPMethod { @@ -12,10 +16,11 @@ open class PostOAuth2TokenRequestV1: TwitterAPIRequest { public var path: String { return "/oauth2/token" } + open var parameters: [String: Any] { - var p = [String: Any]() - p["grant_type"] = grantType - return p + var params = [String: Any]() + params["grant_type"] = grantType + return params } public init( @@ -23,4 +28,8 @@ open class PostOAuth2TokenRequestV1: TwitterAPIRequest { ) { self.grantType = grantType } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuthAccessTokenRequestV1.swift b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuthAccessTokenRequestV1.swift index bb275b8f..37e1f31f 100644 --- a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuthAccessTokenRequestV1.swift +++ b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuthAccessTokenRequestV1.swift @@ -1,8 +1,12 @@ +// PostOAuthAccessTokenRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/authentication/api-reference/access_token open class PostOAuthAccessTokenRequestV1: TwitterAPIRequest { - public let oauthToken: String public let oauthVerifier: String @@ -15,10 +19,10 @@ open class PostOAuthAccessTokenRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["oauth_token"] = oauthToken - p["oauth_verifier"] = oauthVerifier - return p + var params = [String: Any]() + params["oauth_token"] = oauthToken + params["oauth_verifier"] = oauthVerifier + return params } public init( @@ -28,4 +32,8 @@ open class PostOAuthAccessTokenRequestV1: TwitterAPIRequest { self.oauthToken = oauthToken self.oauthVerifier = oauthVerifier } + + deinit { + // De-init logic here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuthInvalidateTokenRequestV1.swift b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuthInvalidateTokenRequestV1.swift index cebfdf1d..3bf2efa3 100644 --- a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuthInvalidateTokenRequestV1.swift +++ b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuthInvalidateTokenRequestV1.swift @@ -1,8 +1,12 @@ +// PostOAuthInvalidateTokenRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/authentication/api-reference/invalidate_access_token open class PostOAuthInvalidateTokenRequestV1: TwitterAPIRequest { - public var method: HTTPMethod { return .post } @@ -16,4 +20,8 @@ open class PostOAuthInvalidateTokenRequestV1: TwitterAPIRequest { } public init() {} + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuthRequestTokenRequestV1.swift b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuthRequestTokenRequestV1.swift index 62bdb83f..5e338b0e 100644 --- a/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuthRequestTokenRequestV1.swift +++ b/Sources/TwitterAPIKit/AuthAPI/Requests/PostOAuthRequestTokenRequestV1.swift @@ -1,8 +1,12 @@ +// PostOAuthRequestTokenRequestV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation /// https://developer.twitter.com/en/docs/authentication/api-reference/request_token open class PostOAuthRequestTokenRequestV1: TwitterAPIRequest { - /// If you are using pin-based authorization, you will need to set this to oob public let oauthCallback: String @@ -18,10 +22,10 @@ open class PostOAuthRequestTokenRequestV1: TwitterAPIRequest { } open var parameters: [String: Any] { - var p = [String: Any]() - p["oauth_callback"] = oauthCallback - xAuthAccessType.map { p["x_auth_access_type"] = $0 } - return p + var params = [String: Any]() + params["oauth_callback"] = oauthCallback + xAuthAccessType.map { params["x_auth_access_type"] = $0 } + return params } public init( @@ -31,4 +35,8 @@ open class PostOAuthRequestTokenRequestV1: TwitterAPIRequest { self.oauthCallback = oauthCallback self.xAuthAccessType = xAuthAccessType } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/AuthAPI/TwitterAuthAPI.swift b/Sources/TwitterAPIKit/AuthAPI/TwitterAuthAPI.swift new file mode 100644 index 00000000..b1c13817 --- /dev/null +++ b/Sources/TwitterAPIKit/AuthAPI/TwitterAuthAPI.swift @@ -0,0 +1,25 @@ +// TwitterAuthAPI.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + +/// A class that provides access to Twitter's authentication APIs. +/// This class supports both OAuth 1.0a and OAuth 2.0 authentication methods. +open class TwitterAuthAPI { + /// The OAuth 1.0a API client for legacy authentication. + public let oauth10a: OAuth10aAPI + + /// The OAuth 2.0 API client for modern authentication. + public let oauth20: OAuth20API + + /// Creates a new TwitterAuthAPI instance. + /// - Parameter session: The Twitter API session to use for making requests. + public init(session: TwitterAPISession) { + oauth10a = .init(session: session) + oauth20 = .init(session: session) + } + + deinit { + // De-init Logic Here + } +} diff --git a/Sources/TwitterAPIKit/AuthAPI/TwitterOAuth2AccessToken.swift b/Sources/TwitterAPIKit/AuthAPI/TwitterOAuth2AccessToken.swift index ef6d154d..205c7e6f 100644 --- a/Sources/TwitterAPIKit/AuthAPI/TwitterOAuth2AccessToken.swift +++ b/Sources/TwitterAPIKit/AuthAPI/TwitterOAuth2AccessToken.swift @@ -1,7 +1,12 @@ +// TwitterOAuth2AccessToken.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/* ex - confidential client +/* Example responses: + Confidential client: { "scope" : "tweet.write tweet.read", "token_type" : "bearer", @@ -9,7 +14,7 @@ import Foundation "access_token" : "" } - public client + Public client: { "refresh_token" : "", "scope" : "tweet.write tweet.read offline.access", @@ -19,35 +24,52 @@ import Foundation } */ +/// Represents an OAuth 2.0 access token response from Twitter's API. +/// Contains the access token and associated metadata for both confidential and public clients. public struct TwitterOAuth2AccessToken { - + /// The scopes granted to this access token, as an array of permission strings. public let scope: [String] + + /// The type of token, typically "bearer". public let tokenType: String + + /// The number of seconds until the token expires. public let expiresIn: Int + + /// The access token string used for API authentication. public let accessToken: String - /// Only Public Client + /// The refresh token for obtaining new access tokens without re-authentication. + /// Only available for public clients using PKCE flow. public let refreshToken: String? + /// Creates an OAuth 2.0 access token from JSON response data. + /// - Parameter jsonData: The raw JSON data from Twitter's OAuth 2.0 token endpoint. + /// - Throws: An error if JSON parsing fails. + /// - Returns: An initialized access token if the JSON contains valid data, nil otherwise. public init?(jsonData: Data) throws { let json = try JSONSerialization.jsonObject(with: jsonData, options: []) guard let obj = json as? [String: Any], - let scope = obj["scope"] as? String, - let tokenType = obj["token_type"] as? String, - let expiresIn = obj["expires_in"] as? Int, - let accessToken = obj["access_token"] as? String + let scope = obj["scope"] as? String, + let tokenType = obj["token_type"] as? String, + let expiresIn = obj["expires_in"] as? Int, + let accessToken = obj["access_token"] as? String else { return nil } self.scope = scope.components(separatedBy: " ") self.tokenType = tokenType self.expiresIn = expiresIn self.accessToken = accessToken - self.refreshToken = obj["refresh_token"] as? String + refreshToken = obj["refresh_token"] as? String } } -extension TwitterOAuth2AccessToken { +public extension TwitterOAuth2AccessToken { + /// Creates an OAuth 2.0 access token from a Twitter API response. + /// - Parameter data: The raw response data from Twitter's OAuth 2.0 token endpoint. + /// - Throws: A `TwitterAPIKitError` if parsing fails. + /// - Returns: An initialized access token. static func fromResponse(data: Data) throws -> Self { do { guard let token = try TwitterOAuth2AccessToken(jsonData: data) else { @@ -56,7 +78,7 @@ extension TwitterOAuth2AccessToken { ) } return token - } catch let error { + } catch { throw TwitterAPIKitError.responseSerializeFailed( reason: .jsonSerializationFailed(error: error) ) diff --git a/Sources/TwitterAPIKit/AuthAPI/TwitterOAuth2BearerToken.swift b/Sources/TwitterAPIKit/AuthAPI/TwitterOAuth2BearerToken.swift index 7f51a27f..37d0eef6 100644 --- a/Sources/TwitterAPIKit/AuthAPI/TwitterOAuth2BearerToken.swift +++ b/Sources/TwitterAPIKit/AuthAPI/TwitterOAuth2BearerToken.swift @@ -1,17 +1,30 @@ +// TwitterOAuth2BearerToken.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// Represents an OAuth 2.0 bearer token response from Twitter's API. +/// This token type is used for application-only authentication. public struct TwitterOAuth2BearerToken { + /// The type of token, typically "bearer". public let tokenType: String + + /// The bearer token string used for API authentication. public let accessToken: String + /// Creates a bearer token from JSON response data. + /// - Parameter jsonData: The raw JSON data from Twitter's OAuth 2.0 token endpoint. + /// Expected format: `{"token_type":"bearer","access_token":"ACCESS_TOKEN"}` + /// - Throws: An error if JSON parsing fails. + /// - Returns: An initialized bearer token if the JSON contains valid data, nil otherwise. public init?(jsonData: Data) throws { - // {"token_type":"bearer","access_token":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA%2FAAAAAAAAAAAAAAAAAAAA%3DAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"} - let json = try JSONSerialization.jsonObject(with: jsonData, options: []) guard let obj = json as? [String: Any], - let tokenType = obj["token_type"] as? String, - let accessToken = obj["access_token"] as? String + let tokenType = obj["token_type"] as? String, + let accessToken = obj["access_token"] as? String else { return nil } diff --git a/Sources/TwitterAPIKit/AuthAPI/TwitterOAuthAccessTokenV1.swift b/Sources/TwitterAPIKit/AuthAPI/TwitterOAuthAccessTokenV1.swift index a606a50c..82666c35 100644 --- a/Sources/TwitterAPIKit/AuthAPI/TwitterOAuthAccessTokenV1.swift +++ b/Sources/TwitterAPIKit/AuthAPI/TwitterOAuthAccessTokenV1.swift @@ -1,37 +1,58 @@ +// TwitterOAuthAccessTokenV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// Represents an OAuth 1.0a access token for Twitter API v1 authentication. public struct TwitterOAuthAccessTokenV1 { - + /// The OAuth token string used for authentication. public let oauthToken: String + + /// The OAuth token secret used for signing requests. public let oauthTokenSecret: String - // According to RFC5849, there is no mention of the user_id and screen_name parameters, but TwitterAPI does include them in its response. + // According to RFC5849, there is no mention of the user_id and screen_name parameters, + // but TwitterAPI does include them in its response. + /// The unique identifier of the authenticated user. public let userID: String? + + /// The screen name (username) of the authenticated user. public let screenName: String? - /// From: - /// oauth_token=your_oauth_token - /// &oauth_token_secret=your_oauth_token_secret - /// &user_id=numeric_user_id - /// &screen_name=your_screen_name + /// Creates an OAuth access token from a query string response. + /// - Parameter queryStringData: The raw data containing the OAuth response in query string format. + /// The expected format is: + /// ``` + /// oauth_token=your_oauth_token&oauth_token_secret=your_oauth_token_secret \ + /// &user_id=numeric_user_id&screen_name=your_screen_name + /// ``` + /// - Returns: An initialized access token if the query string contains valid OAuth token and secret, nil otherwise. public init?(queryStringData: Data) { let query = String(data: queryStringData, encoding: .utf8) var comp = URLComponents() comp.query = query guard let oauthToken = comp.queryItems?.first(where: { $0.name == "oauth_token" })?.value, - let oauthTokenSecret = comp.queryItems?.first(where: { $0.name == "oauth_token_secret" })?.value + let oauthTokenSecret = comp.queryItems?.first(where: { $0.name == "oauth_token_secret" })?.value else { return nil } self.oauthToken = oauthToken self.oauthTokenSecret = oauthTokenSecret - self.userID = comp.queryItems?.first(where: { $0.name == "user_id" })?.value - self.screenName = comp.queryItems?.first(where: { $0.name == "screen_name" })?.value + userID = comp.queryItems?.first { $0.name == "user_id" }?.value + screenName = comp.queryItems?.first { $0.name == "screen_name" }?.value } + /// Creates an OAuth access token with the specified values. + /// - Parameters: + /// - oauthToken: The OAuth token string. + /// - oauthTokenSecret: The OAuth token secret. + /// - userID: The unique identifier of the authenticated user (optional). + /// - screenName: The screen name of the authenticated user (optional). public init( oauthToken: String, oauthTokenSecret: String, @@ -43,5 +64,4 @@ public struct TwitterOAuthAccessTokenV1 { self.userID = userID self.screenName = screenName } - } diff --git a/Sources/TwitterAPIKit/AuthAPI/TwitterOAuthTokenV1.swift b/Sources/TwitterAPIKit/AuthAPI/TwitterOAuthTokenV1.swift index 727513ce..7d1af635 100644 --- a/Sources/TwitterAPIKit/AuthAPI/TwitterOAuthTokenV1.swift +++ b/Sources/TwitterAPIKit/AuthAPI/TwitterOAuthTokenV1.swift @@ -1,26 +1,41 @@ +// TwitterOAuthTokenV1.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// Represents an OAuth 1.0a request token response from Twitter's API. +/// This token is used in the first step of the OAuth 1.0a authentication flow. public struct TwitterOAuthTokenV1 { + /// The OAuth token string used for authentication. public let oauthToken: String + + /// The OAuth token secret used for signing requests. public let oauthTokenSecret: String + + /// Indicates whether the OAuth callback was confirmed by Twitter. + /// This is typically true for OAuth 1.0a requests with a callback URL. public let oauthCallbackConfirmed: Bool? - /// from: oauth_token=zlgW3QAAAAAA2_NZAAABfxxxxxxk&oauth_token_secret=pBYEQzdbyMqIcyDzyn0X7LDxxxxxxxxx&oauth_callback_confirmed=true + /// Creates an OAuth token from a query string response. + /// - Parameter queryStringData: The raw data containing the OAuth response in query string format. + /// Expected format: `oauth_token=TOKEN&oauth_token_secret=SECRET&oauth_callback_confirmed=true` + /// - Returns: An initialized token if the query string contains valid OAuth token and secret, nil otherwise. public init?(queryStringData: Data) { - let query = String(data: queryStringData, encoding: .utf8) var comp = URLComponents() comp.query = query guard let oauthToken = comp.queryItems?.first(where: { $0.name == "oauth_token" })?.value, - let oauthTokenSecret = comp.queryItems?.first(where: { $0.name == "oauth_token_secret" })?.value + let oauthTokenSecret = comp.queryItems?.first(where: { $0.name == "oauth_token_secret" })?.value else { return nil } let oauthCallbackConfirmed = comp.queryItems? - .first(where: { $0.name == "oauth_callback_confirmed" }) + .first { $0.name == "oauth_callback_confirmed" } .map { $0.value == "true" } self.oauthToken = oauthToken @@ -28,6 +43,11 @@ public struct TwitterOAuthTokenV1 { self.oauthCallbackConfirmed = oauthCallbackConfirmed } + /// Creates an OAuth token with the specified values. + /// - Parameters: + /// - oauthToken: The OAuth token string. + /// - oauthTokenSecret: The OAuth token secret. + /// - oauthCallbackConfirmed: Whether the OAuth callback was confirmed (optional). public init( oauthToken: String, oauthTokenSecret: String, diff --git a/Sources/TwitterAPIKit/Extensions/Concurrency.swift b/Sources/TwitterAPIKit/Extensions/Concurrency.swift index a344d614..46daabbc 100644 --- a/Sources/TwitterAPIKit/Extensions/Concurrency.swift +++ b/Sources/TwitterAPIKit/Extensions/Concurrency.swift @@ -1,112 +1,153 @@ -// swift-format-ignore-file +// Concurrency.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. import Foundation -#if compiler(>=5.5.2) && canImport(_Concurrency) +/// A protocol that represents a concurrency. +public protocol Concurrency { + // No Logic Here +} -// I'm not that familiar with Swift Concurrency, so please report any problems. +#if compiler(>=5.5.2) && canImport(_Concurrency) -@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -extension TwitterAPISessionDataTask { + // I'm not that familiar with Swift Concurrency, so please report any problems. - public var responseData: TwitterAPIResponse { - get async { - return await withTaskCancellationHandler( - operation: { - return await withCheckedContinuation { c in - responseData { response in - c.resume(returning: response) + /// Adds async/await support to TwitterAPISessionDataTask. + @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) + public extension TwitterAPISessionDataTask { + /// Asynchronously retrieves the response data from the API request. + /// This property provides an async interface to the completion handler-based API. + /// - Returns: A TwitterAPIResponse containing the raw data response. + var responseData: TwitterAPIResponse { + get async { + await withTaskCancellationHandler( + operation: { + await withCheckedContinuation { continuation in + responseData { response in + continuation.resume(returning: response) + } } + }, + onCancel: { + cancel() } - }, - onCancel: { - cancel() - }) + ) + } } } -} -@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -extension TwitterAPISessionJSONTask { + /// Adds async/await support to TwitterAPISessionJSONTask. + @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) + public extension TwitterAPISessionJSONTask { + /// Asynchronously retrieves the JSON response as a generic object. + /// This property provides an async interface to the completion handler-based API. + /// - Returns: A TwitterAPIResponse containing the parsed JSON object. + var responseObject: TwitterAPIResponse { + get async { + await withTaskCancellationHandler( + operation: { + await withCheckedContinuation { continuation in + responseObject { response in + continuation.resume(returning: response) + } + } + }, + onCancel: { + cancel() + } + ) + } + } - public var responseObject: TwitterAPIResponse { - get async { + /// Asynchronously decodes the JSON response into a specified Decodable type. + /// - Parameters: + /// - type: The Decodable type to decode the response into. + /// - decoder: The JSONDecoder to use for decoding. Defaults to TwitterAPIClient.defaultJSONDecoder. + /// - Returns: A TwitterAPIResponse containing the decoded object. + func responseDecodable( + type: T.Type, + decoder _: JSONDecoder = TwitterAPIClient.defaultJSONDecoder + ) async -> TwitterAPIResponse { return await withTaskCancellationHandler( operation: { - return await withCheckedContinuation { c in - responseObject { response in - c.resume(returning: response) + await withCheckedContinuation { continuation in + responseDecodable(type: type) { response in + continuation.resume(returning: response) } } }, onCancel: { cancel() - }) - } - } - - public func responseDecodable(type: T.Type, decoder: JSONDecoder = TwitterAPIClient.defaultJSONDecoder) async -> TwitterAPIResponse { - return await withTaskCancellationHandler( - operation: { - return await withCheckedContinuation { c in - responseDecodable(type: type) { response in - c.resume(returning: response) - } } - }, - onCancel: { - cancel() - }) + ) + } } -} - -@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -extension TwitterAPISessionSpecializedTask { - public var responseObject: TwitterAPIResponse { - get async { - return await withTaskCancellationHandler( - operation: { - return await withCheckedContinuation { c in - responseObject { response in - c.resume(returning: response) + /// Adds async/await support to TwitterAPISessionSpecializedTask. + @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) + public extension TwitterAPISessionSpecializedTask { + /// Asynchronously retrieves the specialized response object. + /// This property provides an async interface to the completion handler-based API. + /// - Returns: A TwitterAPIResponse containing the specialized success type. + var responseObject: TwitterAPIResponse { + get async { + await withTaskCancellationHandler( + operation: { + await withCheckedContinuation { continuation in + responseObject { response in + continuation.resume(returning: response) + } } + }, onCancel: { + cancel() } - }, onCancel: { - cancel() - }) + ) + } } } -} - -@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -extension TwitterAPISessionStreamTask { - public func streamResponse(queue: DispatchQueue = .main) -> AsyncStream> { - return AsyncStream { continuation in - streamResponse(queue: queue) { response in - continuation.yield(response) - if response.isError { - continuation.finish() + /// Adds async/await support to TwitterAPISessionStreamTask. + @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) + public extension TwitterAPISessionStreamTask { + /// Creates an AsyncStream for receiving streaming responses from the API. + /// - Parameter queue: The dispatch queue on which to receive responses. Defaults to the main queue. + /// - Returns: An AsyncStream that yields TwitterAPIResponse values. + func streamResponse(queue: DispatchQueue = .main) -> AsyncStream> { + return AsyncStream { continuation in + streamResponse(queue: queue) { response in + continuation.yield(response) + if response.isError { + continuation.finish() + } + } + continuation.onTermination = { @Sendable _ in + cancel() } - } - continuation.onTermination = { @Sendable _ in - cancel() } } } -} - -@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -extension TwitterAPIClient { - public func refreshOAuth20Token(type: TwitterAuthenticationMethod.OAuth20WithPKCEClientType, forceRefresh: Bool = false) async throws -> RefreshOAuth20TokenResultValue { - return try await withCheckedThrowingContinuation { c in - refreshOAuth20Token(type: type, forceRefresh: forceRefresh) { result in - c.resume(with: result) + /// Adds async/await support to TwitterAPIClient. + @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) + public extension TwitterAPIClient { + /// Asynchronously refreshes the OAuth 2.0 token. + /// - Parameters: + /// - type: The type of OAuth 2.0 client to use for token refresh. + /// - forceRefresh: Whether to force a token refresh even if the current token is still valid. + /// - Returns: The result of the token refresh operation. + /// - Throws: A TwitterAPIKitError if the token refresh fails. + func refreshOAuth20Token( + type: TwitterAuthenticationMethod.OAuth20WithPKCEClientType, + forceRefresh: Bool = false + ) async throws -> RefreshOAuth20TokenResultValue { + return try await withCheckedThrowingContinuation { continuation in + refreshOAuth20Token(type: type, forceRefresh: forceRefresh) { result in + continuation.resume(with: result) + } } } } -} #endif diff --git a/Sources/TwitterAPIKit/Extensions/Data.swift b/Sources/TwitterAPIKit/Extensions/Data.swift index 8366fa36..0edca14f 100644 --- a/Sources/TwitterAPIKit/Extensions/Data.swift +++ b/Sources/TwitterAPIKit/Extensions/Data.swift @@ -1,32 +1,42 @@ +// Data.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation extension Data { - - func split(separator: Data, omittingEmptySubsequences: Bool = true) -> [Data] { + /// Splits the data into chunks using the specified separator + /// - Parameters: + /// - separator: The data to use as a separator + /// - omittingEmptySubsequences: Whether to omit empty subsequences + /// - Returns: An array of data chunks + public func split(separator: Data, omittingEmptySubsequences: Bool = true) -> [Data] { var current = startIndex var chunks = [Data]() while let range = self[current...].range(of: separator) { - if !omittingEmptySubsequences { - chunks.append(self[current.. current { - chunks.append(self[current.. Result { + /// Attempts to serialize the data as JSON + /// - Returns: A Result containing either the serialized JSON object or an error + public func serialize() -> Result { do { let jsonObj = try JSONSerialization.jsonObject(with: self, options: []) return .success(jsonObj) - } catch let error { + } catch { return .failure( .responseSerializeFailed( reason: .jsonSerializationFailed(error: error) @@ -35,15 +45,20 @@ extension Data { } } - func decode( + /// Attempts to decode the data into a specified Decodable type + /// - Parameters: + /// - type: The type to decode into + /// - decoder: The JSON decoder to use + /// - Returns: A Result containing either the decoded object or an error + public func decode( _ type: T.Type, decoder: JSONDecoder ) -> Result { let result: Result = .init { - return try decoder.decode(type, from: self) + try decoder.decode(type, from: self) } return result.mapError { error in - return .responseSerializeFailed( + .responseSerializeFailed( reason: .jsonDecodeFailed(error: error) ) } diff --git a/Sources/TwitterAPIKit/Extensions/Date.swift b/Sources/TwitterAPIKit/Extensions/Date.swift index 0706e71f..e8f7b125 100644 --- a/Sources/TwitterAPIKit/Extensions/Date.swift +++ b/Sources/TwitterAPIKit/Extensions/Date.swift @@ -1,12 +1,23 @@ +// Date.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation private let formatter = ISO8601DateFormatter() extension Date { - func toISO8601String() -> String { + /// Converts the date to an ISO8601 formatted string + /// - Returns: The date formatted as an ISO8601 string + public func toISO8601String() -> String { return formatter.string(from: self) } - func bind(param: inout [String: Any], for key: String) { + /// Binds the date as an ISO8601 string to the provided parameters dictionary + /// - Parameters: + /// - param: The parameters dictionary to bind to + /// - key: The key to use for the date value + public func bind(param: inout [String: Any], for key: String) { param[key] = toISO8601String() } } diff --git a/Sources/TwitterAPIKit/Extensions/Dictionary.swift b/Sources/TwitterAPIKit/Extensions/Dictionary.swift index 3e3bd9ac..16d6d907 100644 --- a/Sources/TwitterAPIKit/Extensions/Dictionary.swift +++ b/Sources/TwitterAPIKit/Extensions/Dictionary.swift @@ -1,14 +1,20 @@ +// Dictionary.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation extension Dictionary { - - var urlEncodedQueryString: String { + /// Converts the dictionary into a URL-encoded query string + /// Format: key1=value1&key2=value2 + public var urlEncodedQueryString: String { var parts = [String]() for (key, value) in self { let keyString = "\(key)".urlEncodedString let valueString = "\(value)".urlEncodedString - let query: String = "\(keyString)=\(valueString)" + let query = "\(keyString)=\(valueString)" parts.append(query) } diff --git a/Sources/TwitterAPIKit/Extensions/DispatchQueue.swift b/Sources/TwitterAPIKit/Extensions/DispatchQueue.swift index 5c497942..f8b5a563 100644 --- a/Sources/TwitterAPIKit/Extensions/DispatchQueue.swift +++ b/Sources/TwitterAPIKit/Extensions/DispatchQueue.swift @@ -1,7 +1,13 @@ +// DispatchQueue.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation extension DispatchQueue { - static var processQueue: DispatchQueue { + /// A global queue used for processing Twitter API tasks with default QoS + public static var processQueue: DispatchQueue { return .global(qos: .default) } } diff --git a/Sources/TwitterAPIKit/Extensions/HMAC.swift b/Sources/TwitterAPIKit/Extensions/HMAC.swift index fa2ab416..aa5345c5 100644 --- a/Sources/TwitterAPIKit/Extensions/HMAC.swift +++ b/Sources/TwitterAPIKit/Extensions/HMAC.swift @@ -1,11 +1,20 @@ +// HMAC.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// A protocol that represents a HMAC. +public protocol HMAC { + // No Logic Here +} + #if canImport(CommonCrypto) import CommonCrypto - extension Data { - fileprivate func hmac(key: Data) -> Data { - + fileprivate extension Data { + func hmac(key: Data) -> Data { // Thanks: https://github.com/jernejstrasner/SwiftCrypto let digestLen = Int(CC_SHA1_DIGEST_LENGTH) @@ -19,7 +28,8 @@ import Foundation CCHmac( CCHmacAlgorithm(kCCHmacAlgSHA1), body.baseAddress, - key.count, bytes.baseAddress, + key.count, + bytes.baseAddress, count, result ) @@ -30,13 +40,24 @@ import Foundation } } - func createHMACSHA1(key: Data, message: Data) -> Data { + /// Creates an HMAC-SHA1 signature for the given message using the provided key + /// - Parameters: + /// - key: The key to use for signing + /// - message: The message to sign + /// - Returns: The HMAC-SHA1 signature as Data + public func createHMACSHA1(key: Data, message: Data) -> Data { return message.hmac(key: key) } -#elseif canImport(Crypto) // for Linux +#elseif canImport(Crypto) // for Linux import Crypto - func createHMACSHA1(key: Data, message: Data) -> Data { + + /// Creates an HMAC-SHA1 signature for the given message using the provided key + /// - Parameters: + /// - key: The key to use for signing + /// - message: The message to sign + /// - Returns: The HMAC-SHA1 signature as Data + public func createHMACSHA1(key: Data, message: Data) -> Data { return Data(HMAC.authenticationCode(for: message, using: SymmetricKey(data: key))) } #else diff --git a/Sources/TwitterAPIKit/Extensions/Result.swift b/Sources/TwitterAPIKit/Extensions/Result.swift index a51f2739..eb4a26cf 100644 --- a/Sources/TwitterAPIKit/Extensions/Result.swift +++ b/Sources/TwitterAPIKit/Extensions/Result.swift @@ -1,12 +1,20 @@ +// Result.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation extension Result where Failure == TwitterAPIKitError { - var success: Success? { - guard case .success(let value) = self else { return nil } + /// Returns the success value if the result is a success, nil otherwise + public var success: Success? { + guard case let .success(value) = self else { return nil } return value } - var error: Failure? { - guard case .failure(let error) = self else { return nil } + + /// Returns the error if the result is a failure, nil otherwise + public var error: Failure? { + guard case let .failure(error) = self else { return nil } return error } } diff --git a/Sources/TwitterAPIKit/Extensions/String.swift b/Sources/TwitterAPIKit/Extensions/String.swift index 3c38f00c..35ec14ce 100644 --- a/Sources/TwitterAPIKit/Extensions/String.swift +++ b/Sources/TwitterAPIKit/Extensions/String.swift @@ -1,9 +1,15 @@ +// String.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation extension String { - var urlEncodedString: String { + /// Returns a URL-safe encoded version of the string + public var urlEncodedString: String { let allowedCharacterSet = NSMutableCharacterSet.alphanumeric() allowedCharacterSet.addCharacters(in: "-._~") - return addingPercentEncoding(withAllowedCharacters: allowedCharacterSet as CharacterSet)! + return addingPercentEncoding(withAllowedCharacters: allowedCharacterSet as CharacterSet) ?? "" } } diff --git a/Sources/TwitterAPIKit/OAuthHelper.swift b/Sources/TwitterAPIKit/OAuthHelper.swift index 669ec119..1fe52bfd 100644 --- a/Sources/TwitterAPIKit/OAuthHelper.swift +++ b/Sources/TwitterAPIKit/OAuthHelper.swift @@ -1,9 +1,27 @@ +// OAuthHelper.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation private let oauthVersion = "1.0" private let oauthSignatureMethod = "HMAC-SHA1" -func authorizationHeader( +// swiftlint:disable function_parameter_count +/// Generates an OAuth authorization header for a given HTTP method, URL, and parameters. +/// - Parameters: +/// - method: The HTTP method to use. +/// - url: The URL to use. +/// - parameters: The parameters to use. +/// - consumerKey: The consumer key to use. +/// - consumerSecret: The consumer secret to use. +/// - oauthToken: The OAuth token to use. +/// - oauthTokenSecret: The OAuth token secret to use. +/// - oauthTimestamp: The OAuth timestamp to use. +/// - oauthNonce: The OAuth nonce to use. +/// - Returns: The OAuth authorization header. +public func authorizationHeader( for method: HTTPMethod, url: URL, parameters: [String: Any], @@ -14,6 +32,7 @@ func authorizationHeader( oauthTimestamp: String? = .none, oauthNonce: String? = .none ) -> String { +// swiftlint:enable function_parameter_count var authorizationParameters = [String: Any]() authorizationParameters["oauth_version"] = oauthVersion authorizationParameters["oauth_signature_method"] = oauthSignatureMethod @@ -21,7 +40,7 @@ func authorizationHeader( authorizationParameters["oauth_timestamp"] = oauthTimestamp ?? String(Int(Date().timeIntervalSince1970)) authorizationParameters["oauth_nonce"] = oauthNonce ?? UUID().uuidString - if let oauthToken = oauthToken { + if let oauthToken { authorizationParameters["oauth_token"] = oauthToken } @@ -32,12 +51,17 @@ func authorizationHeader( let combinedParameters = authorizationParameters.merging(parameters) { $1 } authorizationParameters["oauth_signature"] = oauthSignature( - for: method, url: url, parameters: combinedParameters, consumerSecret: consumerSecret, - oauthTokenSecret: oauthTokenSecret) + for: method, + url: url, + parameters: combinedParameters, + consumerSecret: consumerSecret, + oauthTokenSecret: oauthTokenSecret + ) - let authorizationParameterComponents = authorizationParameters.urlEncodedQueryString.components( - separatedBy: "&" - ).sorted() + let authorizationParameterComponents = authorizationParameters + .urlEncodedQueryString + .components(separatedBy: "&") + .sorted() var headerComponents = [String]() for component in authorizationParameterComponents { @@ -58,7 +82,7 @@ private func oauthSignature( oauthTokenSecret: String? ) -> String { let tokenSecret = oauthTokenSecret?.urlEncodedString ?? "" - let encodedConsumerSecret = consumerSecret.urlEncodedString + let encodedConsumerSecret = consumerSecret.urlEncodedString let signingKey = "\(encodedConsumerSecret)&\(tokenSecret)" let parameterComponents = parameters.urlEncodedQueryString.components(separatedBy: "&").sorted() let parameterString = parameterComponents.joined(separator: "&") @@ -66,8 +90,8 @@ private func oauthSignature( let encodedURL = url.absoluteString.urlEncodedString let signatureBaseString = "\(method.rawValue)&\(encodedURL)&\(encodedParameterString)" - let key = signingKey.data(using: .utf8)! - let msg = signatureBaseString.data(using: .utf8)! + let key = signingKey.data(using: .utf8) ?? Data() + let msg = signatureBaseString.data(using: .utf8) ?? Data() let sha1 = createHMACSHA1(key: key, message: msg) return sha1.base64EncodedString(options: []) } diff --git a/Sources/TwitterAPIKit/SessionTask/TwitterAPIFailedTask.swift b/Sources/TwitterAPIKit/SessionTask/TwitterAPIFailedTask.swift index 83de5695..45096327 100644 --- a/Sources/TwitterAPIKit/SessionTask/TwitterAPIFailedTask.swift +++ b/Sources/TwitterAPIKit/SessionTask/TwitterAPIFailedTask.swift @@ -1,7 +1,11 @@ +// TwitterAPIFailedTask.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation public struct TwitterAPIFailedTask: TwitterAPISessionJSONTask, TwitterAPISessionStreamTask { - public let error: TwitterAPIKitError public init(_ error: TwitterAPIKitError) { @@ -16,7 +20,7 @@ public struct TwitterAPIFailedTask: TwitterAPISessionJSONTask, TwitterAPISession public func responseData( queue: DispatchQueue, _ block: @escaping (TwitterAPIResponse) -> Void - ) -> TwitterAPIFailedTask { + ) -> Self { queue.async { block( TwitterAPIResponse( @@ -24,7 +28,8 @@ public struct TwitterAPIFailedTask: TwitterAPISessionJSONTask, TwitterAPISession response: nil, data: nil, result: .failure(error), - rateLimit: nil) + rateLimit: nil + ) ) } return self @@ -33,7 +38,7 @@ public struct TwitterAPIFailedTask: TwitterAPISessionJSONTask, TwitterAPISession @discardableResult public func responseData( _ block: @escaping (TwitterAPIResponse) -> Void - ) -> TwitterAPIFailedTask { + ) -> Self { return responseData(queue: .main, block) } @@ -41,7 +46,7 @@ public struct TwitterAPIFailedTask: TwitterAPISessionJSONTask, TwitterAPISession public func responseObject( queue: DispatchQueue, _ block: @escaping (TwitterAPIResponse) -> Void - ) -> TwitterAPIFailedTask { + ) -> Self { queue.async { block( TwitterAPIResponse( @@ -49,9 +54,9 @@ public struct TwitterAPIFailedTask: TwitterAPISessionJSONTask, TwitterAPISession response: nil, data: nil, result: .failure(error), - rateLimit: nil) + rateLimit: nil + ) ) - } return self } @@ -59,17 +64,17 @@ public struct TwitterAPIFailedTask: TwitterAPISessionJSONTask, TwitterAPISession @discardableResult public func responseObject( _ block: @escaping (TwitterAPIResponse) -> Void - ) -> TwitterAPIFailedTask { + ) -> Self { return responseObject(queue: .main, block) } @discardableResult public func responseDecodable( - type: T.Type, - decoder: JSONDecoder, + type _: T.Type, + decoder _: JSONDecoder, queue: DispatchQueue, _ block: @escaping (TwitterAPIResponse) -> Void - ) -> TwitterAPIFailedTask where T: Decodable { + ) -> Self where T: Decodable { queue.async { block( TwitterAPIResponse( @@ -77,9 +82,9 @@ public struct TwitterAPIFailedTask: TwitterAPISessionJSONTask, TwitterAPISession response: nil, data: nil, result: .failure(error), - rateLimit: nil) + rateLimit: nil + ) ) - } return self } @@ -89,7 +94,7 @@ public struct TwitterAPIFailedTask: TwitterAPISessionJSONTask, TwitterAPISession type: T.Type, decoder: JSONDecoder, _ block: @escaping (TwitterAPIResponse) -> Void - ) -> TwitterAPIFailedTask where T: Decodable { + ) -> Self where T: Decodable { return responseDecodable( type: type, decoder: decoder, @@ -103,7 +108,7 @@ public struct TwitterAPIFailedTask: TwitterAPISessionJSONTask, TwitterAPISession type: T.Type, queue: DispatchQueue, _ block: @escaping (TwitterAPIResponse) -> Void - ) -> TwitterAPIFailedTask where T: Decodable { + ) -> Self where T: Decodable { return responseDecodable( type: type, decoder: TwitterAPIClient.defaultJSONDecoder, @@ -116,7 +121,7 @@ public struct TwitterAPIFailedTask: TwitterAPISessionJSONTask, TwitterAPISession public func responseDecodable( type: T.Type, _ block: @escaping (TwitterAPIResponse) -> Void - ) -> TwitterAPIFailedTask where T: Decodable { + ) -> Self where T: Decodable { return responseDecodable( type: type, decoder: TwitterAPIClient.defaultJSONDecoder, @@ -129,22 +134,24 @@ public struct TwitterAPIFailedTask: TwitterAPISessionJSONTask, TwitterAPISession public func streamResponse( queue: DispatchQueue, _ block: @escaping (TwitterAPIResponse) -> Void - ) -> TwitterAPIFailedTask { + ) -> Self { queue.async { let response = TwitterAPIResponse( request: nil, response: nil, data: nil, result: .failure(error), - rateLimit: nil) + rateLimit: nil + ) block(response) } return self } + @discardableResult public func streamResponse( _ block: @escaping (TwitterAPIResponse) -> Void - ) -> TwitterAPIFailedTask { + ) -> Self { return streamResponse(queue: .main, block) } diff --git a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionDataTask.swift b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionDataTask.swift index ca6c4a53..763635be 100644 --- a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionDataTask.swift +++ b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionDataTask.swift @@ -1,7 +1,11 @@ +// TwitterAPISessionDataTask.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation public protocol TwitterAPISessionDataTask: TwitterAPISessionTask { - @discardableResult func responseData( queue: DispatchQueue, @@ -17,7 +21,11 @@ public protocol TwitterAPISessionDataTask: TwitterAPISessionTask { // MARK: - internal extension TwitterAPISessionDataTask { - func specialized( + /// Specializes the task to return a new type. + /// - Parameters: + /// - transform: The transform to apply to the data. + /// - Returns: A new specialized task. + public func specialized( _ transform: @escaping (Data) throws -> NewSuccess ) -> TwitterAPISessionSpecializedTask diff --git a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionDelegatedJSONTask.swift b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionDelegatedJSONTask.swift index 4874e0af..8ed00f38 100644 --- a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionDelegatedJSONTask.swift +++ b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionDelegatedJSONTask.swift @@ -1,11 +1,15 @@ +// TwitterAPISessionDelegatedJSONTask.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -protocol TwitterAPISessionDelegatedJSONTaskDelegate: AnyObject { +internal protocol TwitterAPISessionDelegatedJSONTaskDelegate: AnyObject { func didFinishQueueInJsonTask(task: TwitterAPISessionDelegatedJSONTask) } public class TwitterAPISessionDelegatedJSONTask: TwitterAPISessionJSONTask, TwitterAPISessionDelegatedTask { - public var taskIdentifier: Int { return task.taskIdentifier } @@ -22,19 +26,20 @@ public class TwitterAPISessionDelegatedJSONTask: TwitterAPISessionJSONTask, Twit return task.httpResponse } - weak var delegate: TwitterAPISessionDelegatedJSONTaskDelegate? + internal weak var delegate: TwitterAPISessionDelegatedJSONTaskDelegate? public private(set) var error: Error? public var data: Data? { guard completed else { return nil } return dataChunk } + public private(set) var completed = false - let task: TwitterAPISessionTask + internal let task: TwitterAPISessionTask private let taskQueue: DispatchQueue - private var dataChunk: Data = Data() + private var dataChunk: Data = .init() private let group = DispatchGroup() public init(task: TwitterAPISessionTask) { @@ -52,28 +57,27 @@ public class TwitterAPISessionDelegatedJSONTask: TwitterAPISessionJSONTask, Twit } } - func append(chunk: Data) { + public func append(chunk: Data) { dataChunk.append(chunk) } - func complete(error: Error?) { + public func complete(error: Error?) { self.error = error - self.completed = true + completed = true group.notify(queue: taskQueue) { [weak self] in - guard let self = self else { return } - self.delegate?.didFinishQueueInJsonTask(task: self) + guard let self else { return } + delegate?.didFinishQueueInJsonTask(task: self) } taskQueue.resume() } private func getResponse() -> TwitterAPIResponse { - - guard completed, let data = self.data else { + guard completed, let data else { fatalError("Request not completed yet.") } - guard error == nil, let httpResponse = httpResponse else { + guard error == nil, let httpResponse else { return TwitterAPIResponse( request: currentRequest, response: httpResponse, @@ -85,8 +89,7 @@ public class TwitterAPISessionDelegatedJSONTask: TwitterAPISessionJSONTask, Twit let rateLimit = TwitterRateLimit(header: httpResponse.allHeaderFields) - guard 200..<300 ~= httpResponse.statusCode else { - + guard 200 ..< 300 ~= httpResponse.statusCode else { return TwitterAPIResponse( request: currentRequest, response: httpResponse, @@ -94,7 +97,10 @@ public class TwitterAPISessionDelegatedJSONTask: TwitterAPISessionJSONTask, Twit result: .failure( .responseFailed( reason: .unacceptableStatusCode( - statusCode: httpResponse.statusCode, error: .init(data: data), rateLimit: rateLimit))), + statusCode: httpResponse.statusCode, error: .init(data: data), rateLimit: rateLimit + ) + ) + ), rateLimit: rateLimit ) } @@ -113,17 +119,16 @@ public class TwitterAPISessionDelegatedJSONTask: TwitterAPISessionJSONTask, Twit flatMap transform: @escaping (Data) -> Result, response block: @escaping ((TwitterAPIResponse) -> Void) ) -> Self { - group.enter() taskQueue.async { [weak self] in - guard let self = self else { return } + guard let self else { return } - let response = self.getResponse().flatMap(transform) + let response = getResponse().flatMap(transform) queue.async { [weak self] in - guard let self = self else { return } + guard let self else { return } block(response) - self.group.leave() + group.leave() } } @@ -134,6 +139,7 @@ public class TwitterAPISessionDelegatedJSONTask: TwitterAPISessionJSONTask, Twit return registerResponseBlock(queue: queue, flatMap: { .success($0) }, response: block) } + @discardableResult public func responseData(_ block: @escaping (TwitterAPIResponse) -> Void) -> Self { return responseData(queue: .main, block) } diff --git a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionDelegatedStreamTask.swift b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionDelegatedStreamTask.swift index 20b75096..997a6827 100644 --- a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionDelegatedStreamTask.swift +++ b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionDelegatedStreamTask.swift @@ -1,19 +1,24 @@ +// TwitterAPISessionDelegatedStreamTask.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -private let chunkSeparator = "\r\n".data(using: .utf8)! +private let chunkSeparator = Data("\r\n".utf8) public class TwitterAPISessionDelegatedStreamTask: TwitterAPISessionStreamTask, TwitterAPISessionDelegatedTask { - public var taskIdentifier: Int { return task.taskIdentifier } public var currentRequest: URLRequest? { return task.currentRequest } public var originalRequest: URLRequest? { return task.originalRequest } public var httpResponse: HTTPURLResponse? { return task.httpResponse } + private let task: TwitterAPISessionTask private var dataBlocks = [(queue: DispatchQueue, block: (TwitterAPIResponse) -> Void)]() private lazy var taskQueue = DispatchQueue(label: "TwitterAPISessionDelegatedStreamTask_\(taskIdentifier)") - init(task: TwitterAPISessionTask) { + public init(task: TwitterAPISessionTask) { self.task = task } @@ -38,21 +43,20 @@ public class TwitterAPISessionDelegatedStreamTask: TwitterAPISessionStreamTask, task.cancel() } - func append(chunk: Data) { + public func append(chunk: Data) { taskQueue.async { [weak self] in - guard let self = self else { return } + guard let self else { return } - guard let httpResponse = self.httpResponse else { - self.notify(result: .failure(.responseFailed(reason: .invalidResponse(error: nil))), rateLimit: nil) + guard let httpResponse else { + notify(result: .failure(.responseFailed(reason: .invalidResponse(error: nil))), rateLimit: nil) return } let rateLimit = TwitterRateLimit(header: httpResponse.allHeaderFields) guard httpResponse.statusCode < 300 else { - let error = TwitterAPIErrorResponse(data: chunk) - self.notify( + notify( result: .failure( .responseFailed( reason: .unacceptableStatusCode( @@ -60,22 +64,24 @@ public class TwitterAPISessionDelegatedStreamTask: TwitterAPISessionStreamTask, error: error, rateLimit: rateLimit ) - )), rateLimit: rateLimit) + ) + ), rateLimit: rateLimit + ) return } for data in chunk.split(separator: chunkSeparator) { - self.notify(result: .success(data), rateLimit: rateLimit) + notify(result: .success(data), rateLimit: rateLimit) } } } - func complete(error: Error?) { - if let error = error { + public func complete(error: Error?) { + if let error { taskQueue.async { [weak self] in - guard let self = self else { return } - self.notify(result: .failure(.responseFailed(reason: .invalidResponse(error: error))), rateLimit: nil) + guard let self else { return } + notify(result: .failure(.responseFailed(reason: .invalidResponse(error: error))), rateLimit: nil) } } } @@ -89,10 +95,14 @@ public class TwitterAPISessionDelegatedStreamTask: TwitterAPISessionStreamTask, rateLimit: rateLimit ) - dataBlocks.forEach { (queue, block) in + for (queue, block) in dataBlocks { queue.async { block(response) } } } + + deinit { + // De-init Logic Here + } } diff --git a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionJSONTask.swift b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionJSONTask.swift index 8825f377..cf098b0a 100644 --- a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionJSONTask.swift +++ b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionJSONTask.swift @@ -1,7 +1,11 @@ +// TwitterAPISessionJSONTask.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation public protocol TwitterAPISessionJSONTask: TwitterAPISessionDataTask { - @discardableResult func responseObject( queue: DispatchQueue, diff --git a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionSpecializedTask.swift b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionSpecializedTask.swift index 9d2b95f0..e84dcc6e 100644 --- a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionSpecializedTask.swift +++ b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionSpecializedTask.swift @@ -1,6 +1,11 @@ +// TwitterAPISessionSpecializedTask.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -protocol TwitterAPISessionSpecializedTask_: TwitterAPISessionDataTask { +public protocol TwitterAPISessionSpecializedTaskProtocol: TwitterAPISessionDataTask { associatedtype Success @discardableResult func responseObject( @@ -9,14 +14,15 @@ protocol TwitterAPISessionSpecializedTask_: TwitterAPISessionDataTask { ) -> TwitterAPISessionSpecializedTask } -public struct TwitterAPISessionSpecializedTask: TwitterAPISessionSpecializedTask_ { - +public struct TwitterAPISessionSpecializedTask: TwitterAPISessionSpecializedTaskProtocol { public var taskIdentifier: Int { return innerTask.taskIdentifier } + public var currentRequest: URLRequest? { return innerTask.currentRequest } + public var originalRequest: URLRequest? { return innerTask.originalRequest } @@ -32,7 +38,7 @@ public struct TwitterAPISessionSpecializedTask: TwitterAPISessionSpecia task: TwitterAPISessionDataTask, transform: @escaping (Data) throws -> Success ) { - self.innerTask = task + innerTask = task self.transform = transform } @@ -71,19 +77,22 @@ public struct TwitterAPISessionSpecializedTask: TwitterAPISessionSpecia } } -extension Array where Element: TwitterAPISessionSpecializedTask_ { - +public extension Array where Element: TwitterAPISessionSpecializedTaskProtocol { + /// Specializes the task to return an array of responses. + /// - Parameters: + /// - queue: The queue to run the response on. + /// - block: The block to call with the responses. func responseObject( - queue: DispatchQueue = .main, _ block: @escaping ([TwitterAPIResponse]) -> Void + queue: DispatchQueue = .main, + _ block: @escaping ([TwitterAPIResponse]) -> Void ) { - let group = DispatchGroup() var responses = [TwitterAPIResponse]() let innerQueue = DispatchQueue(label: "TwitterAPISessionSpecializedTask.array") innerQueue.suspend() - self.forEach { task in + for task in self { group.enter() innerQueue.async { task.responseObject(queue: innerQueue) { diff --git a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionStreamTask.swift b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionStreamTask.swift index daf1e6a2..58184676 100644 --- a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionStreamTask.swift +++ b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionStreamTask.swift @@ -1,7 +1,11 @@ +// TwitterAPISessionStreamTask.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation public protocol TwitterAPISessionStreamTask: TwitterAPISessionTask { - @discardableResult func streamResponse( queue: DispatchQueue, diff --git a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionTask.swift b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionTask.swift index dfaa0564..eef07340 100644 --- a/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionTask.swift +++ b/Sources/TwitterAPIKit/SessionTask/TwitterAPISessionTask.swift @@ -1,15 +1,27 @@ +// TwitterAPISessionTask.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// A protocol that defines the properties and methods for a session task. public protocol TwitterAPISessionTask { + /// The unique identifier for the task. var taskIdentifier: Int { get } + /// The current request being processed. var currentRequest: URLRequest? { get } + /// The original request that was used to create the task. var originalRequest: URLRequest? { get } + /// The HTTP response received from the server. var httpResponse: HTTPURLResponse? { get } - + /// Cancels the task. func cancel() } +/// A default implementation of the TwitterAPISessionTask protocol. extension URLSessionTask: TwitterAPISessionTask { + /// The HTTP response received from the server. public var httpResponse: HTTPURLResponse? { return response as? HTTPURLResponse } diff --git a/Sources/TwitterAPIKit/TwitterAPI+Flat.generated.swift b/Sources/TwitterAPIKit/TwitterAPI+Flat.generated.swift deleted file mode 100644 index 6272406d..00000000 --- a/Sources/TwitterAPIKit/TwitterAPI+Flat.generated.swift +++ /dev/null @@ -1,701 +0,0 @@ -// Generated using Sourcery 1.9.0 — https://github.com/krzysztofzablocki/Sourcery -// DO NOT EDIT - -// swift-format-ignore-file -import Foundation - -extension TwitterAuthAPI { - - // MARK: - OAuth10aAPI - - public func postOAuthRequestTokenData(_ request: PostOAuthRequestTokenRequestV1) -> TwitterAPISessionDataTask { - return oauth10a.postOAuthRequestTokenData(request) - } - public func postOAuthRequestToken(_ request: PostOAuthRequestTokenRequestV1) -> TwitterAPISessionSpecializedTask { - return oauth10a.postOAuthRequestToken(request) - } - public func makeOAuthAuthorizeURL(_ request: GetOAuthAuthorizeRequestV1) -> URL? { - return oauth10a.makeOAuthAuthorizeURL(request) - } - public func makeOAuthAuthenticateURL(_ request: GetOAuthAuthenticateRequestV1) -> URL? { - return oauth10a.makeOAuthAuthenticateURL(request) - } - public func postOAuthAccessTokenData(_ request: PostOAuthAccessTokenRequestV1) -> TwitterAPISessionDataTask { - return oauth10a.postOAuthAccessTokenData(request) - } - public func postOAuthAccessToken(_ request: PostOAuthAccessTokenRequestV1) -> TwitterAPISessionSpecializedTask { - return oauth10a.postOAuthAccessToken(request) - } - public func postInvalidateAccessToken(_ request: PostOAuthInvalidateTokenRequestV1) -> TwitterAPISessionJSONTask { - return oauth10a.postInvalidateAccessToken(request) - } - - // MARK: - OAuth20API - - public func postOAuth2BearerTokenData(_ request: PostOAuth2TokenRequestV1) -> TwitterAPISessionDataTask { - return oauth20.postOAuth2BearerTokenData(request) - } - public func postOAuth2BearerToken(_ request: PostOAuth2TokenRequestV1) -> TwitterAPISessionSpecializedTask { - return oauth20.postOAuth2BearerToken(request) - } - public func postInvalidateOAuth2BearerToken(_ request: PostOAuth2InvalidateTokenRequestV1) -> TwitterAPISessionJSONTask { - return oauth20.postInvalidateOAuth2BearerToken(request) - } - public func makeOAuth2AuthorizeURL(_ request: GetOAuth2AuthorizeRequestV1) -> URL? { - return oauth20.makeOAuth2AuthorizeURL(request) - } - public func postOAuth2AccessTokenData(_ request: PostOAuth2AccessTokenRequestV2) -> TwitterAPISessionDataTask { - return oauth20.postOAuth2AccessTokenData(request) - } - public func postOAuth2AccessToken(_ request: PostOAuth2AccessTokenRequestV2) -> TwitterAPISessionSpecializedTask { - return oauth20.postOAuth2AccessToken(request) - } - public func postOAuth2RefreshTokenData(_ request: PostOAuth2RefreshTokenRequestV2) -> TwitterAPISessionDataTask { - return oauth20.postOAuth2RefreshTokenData(request) - } - public func postOAuth2RefreshToken(_ request: PostOAuth2RefreshTokenRequestV2) -> TwitterAPISessionSpecializedTask { - return oauth20.postOAuth2RefreshToken(request) - } - public func postOAuth2RevokeToken(_ request: PostOAuth2RevokeTokenRequestV2) -> TwitterAPISessionDataTask { - return oauth20.postOAuth2RevokeToken(request) - } -} - -extension TwitterAPIv1 { - - // MARK: - AccountAPIv1 - - public func getAccountSetting(_ request: GetAccountSettingsRequestV1) -> TwitterAPISessionJSONTask { - return account.getAccountSetting(request) - } - public func getAccountVerify(_ request: GetAccountVerifyCredentialsRequestV1) -> TwitterAPISessionJSONTask { - return account.getAccountVerify(request) - } - public func postRemoveProfileBanner(_ request: PostAccountRemoveProfileBannerRequestV1) -> TwitterAPISessionJSONTask { - return account.postRemoveProfileBanner(request) - } - public func postAccountSettings(_ request: PostAccountSettingsRequestV1) -> TwitterAPISessionJSONTask { - return account.postAccountSettings(request) - } - public func postAccountProfile(_ request: PostAccountUpdateProfileRequestV1) -> TwitterAPISessionJSONTask { - return account.postAccountProfile(request) - } - public func postProfileBanner(_ request: PostAccountUpdateProfileBannerRequestV1) -> TwitterAPISessionDataTask { - return account.postProfileBanner(request) - } - public func postProfileImage(_ request: PostAccountUpdateProfileImageRequestV1) -> TwitterAPISessionJSONTask { - return account.postProfileImage(request) - } - - // MARK: - ApplicationAPIv1 - - public func getRateLimit(_ request: GetApplicationRateLimitStatusRequestV1) -> TwitterAPISessionJSONTask { - return application.getRateLimit(request) - } - - // MARK: - BlockAndMuteAPIv1 - - public func getBlockIDs(_ request: GetBlocksIDsRequestV1) -> TwitterAPISessionJSONTask { - return blockAndMute.getBlockIDs(request) - } - public func getBlockUsers(_ request: GetBlocksListRequestV1) -> TwitterAPISessionJSONTask { - return blockAndMute.getBlockUsers(request) - } - public func getMuteIDs(_ request: GetMutesUsersIDsRequestV1) -> TwitterAPISessionJSONTask { - return blockAndMute.getMuteIDs(request) - } - public func getMuteUsers(_ request: GetMutesUsersListRequestV1) -> TwitterAPISessionJSONTask { - return blockAndMute.getMuteUsers(request) - } - public func postBlockUser(_ request: PostBlocksCreateRequestV1) -> TwitterAPISessionJSONTask { - return blockAndMute.postBlockUser(request) - } - public func postUnblockUser(_ request: PostBlocksDestroyRequestV1) -> TwitterAPISessionJSONTask { - return blockAndMute.postUnblockUser(request) - } - public func postMuteUser(_ request: PostMutesUsersCreateRequestV1) -> TwitterAPISessionJSONTask { - return blockAndMute.postMuteUser(request) - } - public func postUnmuteUser(_ request: PostMutesUsersDestroyRequestV1) -> TwitterAPISessionJSONTask { - return blockAndMute.postUnmuteUser(request) - } - public func postReportSpam(_ request: PostUsersReportSpamRequestV1) -> TwitterAPISessionJSONTask { - return blockAndMute.postReportSpam(request) - } - - // MARK: - CollectionAPIv1 - - public func getCollectionEntries(_ request: GetCollectionsEntriesRequestV1) -> TwitterAPISessionJSONTask { - return collection.getCollectionEntries(request) - } - public func getCollections(_ request: GetCollectionsListRequestV1) -> TwitterAPISessionJSONTask { - return collection.getCollections(request) - } - public func getCollection(_ request: GetCollectionsShowRequestV1) -> TwitterAPISessionJSONTask { - return collection.getCollection(request) - } - public func postCreateCollection(_ request: PostCollectionsCreateRequestV1) -> TwitterAPISessionJSONTask { - return collection.postCreateCollection(request) - } - public func postDestroyCollection(_ request: PostCollectionsDestroyRequestV1) -> TwitterAPISessionJSONTask { - return collection.postDestroyCollection(request) - } - public func postCollectionAddEntry(_ request: PostCollectionsEntriesAddRequestV1) -> TwitterAPISessionJSONTask { - return collection.postCollectionAddEntry(request) - } - public func postCollectionCurate(_ request: PostCollectionsEntriesCurateRequestV1) -> TwitterAPISessionJSONTask { - return collection.postCollectionCurate(request) - } - public func postCollectionMoveEntry(_ request: PostCollectionsEntriesMoveRequestV1) -> TwitterAPISessionJSONTask { - return collection.postCollectionMoveEntry(request) - } - public func postCollectionRemoveEntry(_ request: PostCollectionsEntriesRemoveRequestV1) -> TwitterAPISessionJSONTask { - return collection.postCollectionRemoveEntry(request) - } - public func postCollectionUpdate(_ request: PostCollectionsUpdateRequestV1) -> TwitterAPISessionJSONTask { - return collection.postCollectionUpdate(request) - } - - // MARK: - DirectMessageAPIv1 - - public func postDirectMessage(_ request: PostDirectMessageRequestV1) -> TwitterAPISessionJSONTask { - return directMessage.postDirectMessage(request) - } - public func deleteDirectMessage(_ request: DeleteDirectMessageRequestV1) -> TwitterAPISessionDataTask { - return directMessage.deleteDirectMessage(request) - } - public func getDirectMessage(_ request: GetDirectMessageRequestV1) -> TwitterAPISessionJSONTask { - return directMessage.getDirectMessage(request) - } - public func getDirectMessageList(_ request: GetDirectMessageListRequestV1) -> TwitterAPISessionJSONTask { - return directMessage.getDirectMessageList(request) - } - public func postDirectMessageMarkRead(_ request: PostDirectMessagesMarkReadRequestV1) -> TwitterAPISessionDataTask { - return directMessage.postDirectMessageMarkRead(request) - } - public func postDirectMessageTypingIndicator(_ request: PostDirectMessagesIndicateTypingRequestV1) -> TwitterAPISessionDataTask { - return directMessage.postDirectMessageTypingIndicator(request) - } - - // MARK: - FavoriteAPIv1 - - public func postFavorite(_ request: PostFavoriteRequestV1) -> TwitterAPISessionJSONTask { - return favorite.postFavorite(request) - } - public func postUnFavorite(_ request: PostUnFavoriteRequestV1) -> TwitterAPISessionJSONTask { - return favorite.postUnFavorite(request) - } - public func getFavorites(_ request: GetFavoritesRequestV1) -> TwitterAPISessionJSONTask { - return favorite.getFavorites(request) - } - - // MARK: - FriendshipsAPIv1 - - public func getFollowerIDs(_ request: GetFollowersIDsRequestV1) -> TwitterAPISessionJSONTask { - return friendships.getFollowerIDs(request) - } - public func getFollowers(_ request: GetFollowersListRequestV1) -> TwitterAPISessionJSONTask { - return friendships.getFollowers(request) - } - public func getFriendIDs(_ request: GetFriendsIDsRequestV1) -> TwitterAPISessionJSONTask { - return friendships.getFriendIDs(request) - } - public func getFriends(_ request: GetFriendsListRequestV1) -> TwitterAPISessionJSONTask { - return friendships.getFriends(request) - } - public func getFriendshipsIncoming(_ request: GetFriendshipsIncomingRequestV1) -> TwitterAPISessionJSONTask { - return friendships.getFriendshipsIncoming(request) - } - public func getFriendshipsLookup(_ request: GetFriendshipsLookupRequestV1) -> TwitterAPISessionJSONTask { - return friendships.getFriendshipsLookup(request) - } - public func getFriendshipsNoRetweetsIDs(_ request: GetFriendshipsNoRetweetsIDsRequestV1) -> TwitterAPISessionJSONTask { - return friendships.getFriendshipsNoRetweetsIDs(request) - } - public func getFriendshipsOutgoing(_ request: GetFriendshipsOutgoingRequestV1) -> TwitterAPISessionJSONTask { - return friendships.getFriendshipsOutgoing(request) - } - public func getFriendships(_ request: GetFriendshipsShowRequestV1) -> TwitterAPISessionJSONTask { - return friendships.getFriendships(request) - } - public func postFollowUser(_ request: PostFriendshipsCreateRequestV1) -> TwitterAPISessionJSONTask { - return friendships.postFollowUser(request) - } - public func postUnfollowUser(_ request: PostFriendshipsDestroyRequestV1) -> TwitterAPISessionJSONTask { - return friendships.postUnfollowUser(request) - } - public func postFriendshipsUpdate(_ request: PostFriendshipsUpdateRequestV1) -> TwitterAPISessionJSONTask { - return friendships.postFriendshipsUpdate(request) - } - - // MARK: - GeoAPIv1 - - public func getReverseGeocode(_ request: GetGeoReverseGeocodeRequestV1) -> TwitterAPISessionJSONTask { - return geo.getReverseGeocode(request) - } - public func getGeoPlace(_ request: GetGeoPlaceIDRequestV1) -> TwitterAPISessionJSONTask { - return geo.getGeoPlace(request) - } - public func searchGeo(_ request: GetGeoSearchRequestV1) -> TwitterAPISessionJSONTask { - return geo.searchGeo(request) - } - - // MARK: - HelpAPIv1 - - public func getSupportedLanguages(_ request: GetHelpLanguagesRequestV1) -> TwitterAPISessionJSONTask { - return help.getSupportedLanguages(request) - } - - // MARK: - ListAPIv1 - - public func getLists(_ request: GetListsListRequestV1) -> TwitterAPISessionJSONTask { - return list.getLists(request) - } - public func getListMembers(_ request: GetListsMembersRequestV1) -> TwitterAPISessionJSONTask { - return list.getListMembers(request) - } - public func getListMember(_ request: GetListsMembersShowRequestV1) -> TwitterAPISessionJSONTask { - return list.getListMember(request) - } - public func getListMemberships(_ request: GetListsMembershipsRequestV1) -> TwitterAPISessionJSONTask { - return list.getListMemberships(request) - } - public func getListOwnerships(_ request: GetListsOwnershipsRequestV1) -> TwitterAPISessionJSONTask { - return list.getListOwnerships(request) - } - public func getList(_ request: GetListsShowRequestV1) -> TwitterAPISessionJSONTask { - return list.getList(request) - } - public func getListStatuses(_ request: GetListsStatusesRequestV1) -> TwitterAPISessionJSONTask { - return list.getListStatuses(request) - } - public func getListSubscribers(_ request: GetListsSubscribersRequestV1) -> TwitterAPISessionJSONTask { - return list.getListSubscribers(request) - } - public func getListSubscriber(_ request: GetListsSubscribersShowRequestV1) -> TwitterAPISessionJSONTask { - return list.getListSubscriber(request) - } - public func getListSubscriptions(_ request: GetListsSubscriptionsRequestV1) -> TwitterAPISessionJSONTask { - return list.getListSubscriptions(request) - } - public func postCreateList(_ request: PostListsCreateRequestV1) -> TwitterAPISessionJSONTask { - return list.postCreateList(request) - } - public func postDestroyList(_ request: PostListsDestroyRequestV1) -> TwitterAPISessionJSONTask { - return list.postDestroyList(request) - } - public func postAddListMember(_ request: PostListsMembersCreateRequestV1) -> TwitterAPISessionJSONTask { - return list.postAddListMember(request) - } - public func postAddListMembers(_ request: PostListsMembersCreateAllRequestV1) -> TwitterAPISessionJSONTask { - return list.postAddListMembers(request) - } - public func postRemoveListMember(_ request: PostListsMembersDestroyRequestV1) -> TwitterAPISessionJSONTask { - return list.postRemoveListMember(request) - } - public func postRemoveListMembers(_ request: PostListsMembersDestroyAllRequestV1) -> TwitterAPISessionJSONTask { - return list.postRemoveListMembers(request) - } - public func postSubscribeList(_ request: PostListsSubscribersCreateRequestV1) -> TwitterAPISessionJSONTask { - return list.postSubscribeList(request) - } - public func postUnsubscribeList(_ request: PostListsSubscribersDestroyRequestV1) -> TwitterAPISessionJSONTask { - return list.postUnsubscribeList(request) - } - public func postUpdateList(_ request: PostListsUpdateRequestV1) -> TwitterAPISessionJSONTask { - return list.postUpdateList(request) - } - - // MARK: - MediaAPIv1 - - public func getUploadMediaStatus(_ request: GetUploadMediaStatusRequestV1) -> TwitterAPISessionJSONTask { - return media.getUploadMediaStatus(request) - } - public func uploadMediaInit(_ request: UploadMediaInitRequestV1) -> TwitterAPISessionJSONTask { - return media.uploadMediaInit(request) - } - public func uploadMediaAppend(_ request: UploadMediaAppendRequestV1) -> TwitterAPISessionJSONTask { - return media.uploadMediaAppend(request) - } - public func uploadMediaAppendSplitChunks(_ request: UploadMediaAppendRequestV1, maxBytes: Int = 5_242_880) -> [TwitterAPISessionSpecializedTask] { - return media.uploadMediaAppendSplitChunks(request, maxBytes: maxBytes) - } - public func uploadMediaFinalize(_ request: UploadMediaFinalizeRequestV1) -> TwitterAPISessionJSONTask { - return media.uploadMediaFinalize(request) - } - public func uploadMedia(_ parameters: UploadMediaRequestParameters, completionHandler: @escaping (TwitterAPIResponse) -> Void) { - media.uploadMedia(parameters, completionHandler: completionHandler) - } - public func waitMediaProcessing(mediaID: String, initialWaitSec: Int, completionHandler: @escaping (TwitterAPIResponse) -> Void) { - media.waitMediaProcessing(mediaID: mediaID, initialWaitSec: initialWaitSec, completionHandler: completionHandler) - } - public func waitMediaProcessing(mediaID: String, completionHandler: @escaping (TwitterAPIResponse) -> Void) { - media.waitMediaProcessing(mediaID: mediaID, completionHandler: completionHandler) - } - public func createMediaMetadata(_ request: PostMediaMetadataCreateRequestV1) -> TwitterAPISessionDataTask { - return media.createMediaMetadata(request) - } - public func createSubtitle(_ request: PostMediaSubtitlesCreateRequestV1) -> TwitterAPISessionDataTask { - return media.createSubtitle(request) - } - public func deleteSubtitle(_ request: PostMediaSubtitlesDeleteRequestV1) -> TwitterAPISessionDataTask { - return media.deleteSubtitle(request) - } - - // MARK: - RetweetAPIv1 - - public func postRetweet(_ request: PostRetweetRequestV1) -> TwitterAPISessionJSONTask { - return retweet.postRetweet(request) - } - public func postUnRetweet(_ request: PostUnRetweetRequestV1) -> TwitterAPISessionJSONTask { - return retweet.postUnRetweet(request) - } - public func getRetweets(_ request: GetRetweetsRequestV1) -> TwitterAPISessionJSONTask { - return retweet.getRetweets(request) - } - public func getRetweetsOfMe(_ request: GetRetweetsOfMeRequestV1) -> TwitterAPISessionJSONTask { - return retweet.getRetweetsOfMe(request) - } - public func getRetweeters(_ request: GetRetweetersRequestV1) -> TwitterAPISessionJSONTask { - return retweet.getRetweeters(request) - } - - // MARK: - SearchAPIv1 - - public func searchTweets(_ request: GetSearchTweetsRequestV1) -> TwitterAPISessionJSONTask { - return search.searchTweets(request) - } - public func getSavedSearches(_ request: GetSavedSearchesListRequestV1) -> TwitterAPISessionJSONTask { - return search.getSavedSearches(request) - } - public func postCreateSavedSearch(_ request: PostSavedSearchesCreateRequestV1) -> TwitterAPISessionJSONTask { - return search.postCreateSavedSearch(request) - } - public func postDestroySavedSearch(_ request: PostSavedSearchesCreateRequestV1) -> TwitterAPISessionJSONTask { - return search.postDestroySavedSearch(request) - } - - // MARK: - TimelineAPIv1 - - public func getHomeTimeline(_ request: GetStatusesHomeTimelineRequestV1) -> TwitterAPISessionJSONTask { - return timeline.getHomeTimeline(request) - } - public func getMentionsTimeline(_ request: GetStatusesMentionsTimelineRequestV1) -> TwitterAPISessionJSONTask { - return timeline.getMentionsTimeline(request) - } - public func getUserTimeline(_ request: GetStatusesUserTimelineRequestV1) -> TwitterAPISessionJSONTask { - return timeline.getUserTimeline(request) - } - - // MARK: - TrendAPIv1 - - public func getTrendsAvailable(_ request: GetTrendsAvailableRequestV1) -> TwitterAPISessionJSONTask { - return trend.getTrendsAvailable(request) - } - public func getTrendsClosest(_ request: GetTrendsClosestRequestV1) -> TwitterAPISessionJSONTask { - return trend.getTrendsClosest(request) - } - public func getTrends(_ request: GetTrendsPlaceRequestV1) -> TwitterAPISessionJSONTask { - return trend.getTrends(request) - } - - // MARK: - TweetAPIv1 - - public func postUpdateStatus(_ request: PostStatusesUpdateRequestV1) -> TwitterAPISessionJSONTask { - return tweet.postUpdateStatus(request) - } - public func postDestroyStatus(_ request: PostStatusesDestroyRequestV1) -> TwitterAPISessionJSONTask { - return tweet.postDestroyStatus(request) - } - public func getShowStatus(_ request: GetStatusesShowRequestV1) -> TwitterAPISessionJSONTask { - return tweet.getShowStatus(request) - } - public func getLookupStatuses(_ request: GetStatusesLookupRequestV1) -> TwitterAPISessionJSONTask { - return tweet.getLookupStatuses(request) - } - - // MARK: - UserAPIv1 - - public func getUsers(_ request: GetUsersLookupRequestV1) -> TwitterAPISessionJSONTask { - return user.getUsers(request) - } - public func getUser(_ request: GetUsersShowRequestV1) -> TwitterAPISessionJSONTask { - return user.getUser(request) - } - public func searchUser(_ request: GetUsersShowRequestV1) -> TwitterAPISessionJSONTask { - return user.searchUser(request) - } - public func getUserProfileBanner(_ request: GetUsersProfileBannerRequestV1) -> TwitterAPISessionJSONTask { - return user.getUserProfileBanner(request) - } -} - -extension TwitterAPIv2 { - - // MARK: - BlockAndMuteAPIv2 - - public func getBlockUsers(_ request: GetUsersBlockingRequestV2) -> TwitterAPISessionJSONTask { - return blockAndMute.getBlockUsers(request) - } - public func blockUser(_ request: PostUsersBlockingRequestV2) -> TwitterAPISessionJSONTask { - return blockAndMute.blockUser(request) - } - public func unblockUser(_ request: DeleteUsersBlockingRequestV2) -> TwitterAPISessionJSONTask { - return blockAndMute.unblockUser(request) - } - public func getMuteUsers(_ request: GetUsersMutingRequestV2) -> TwitterAPISessionJSONTask { - return blockAndMute.getMuteUsers(request) - } - public func muteUser(_ request: PostUsersMutingRequestV2) -> TwitterAPISessionJSONTask { - return blockAndMute.muteUser(request) - } - public func unmuteUser(_ request: DeleteUsersMutingRequestV2) -> TwitterAPISessionJSONTask { - return blockAndMute.unmuteUser(request) - } - - // MARK: - BookmarksAPIv2 - - public func getBookmarks(_ request: GetUsersBookmarksRequestV2) -> TwitterAPISessionJSONTask { - return bookmarks.getBookmarks(request) - } - public func createBookmark(_ request: PostUsersBookmarksRequestV2) -> TwitterAPISessionJSONTask { - return bookmarks.createBookmark(request) - } - public func deleteBookmark(_ request: DeleteUsersBookmarksRequestV2) -> TwitterAPISessionJSONTask { - return bookmarks.deleteBookmark(request) - } - - // MARK: - ComplianceAPIv2 - - public func getComplianceJob(_ request: GetComplianceJobRequestV2) -> TwitterAPISessionJSONTask { - return compliance.getComplianceJob(request) - } - public func getComplianceJobj(_ request: GetComplianceJobsRequestV2) -> TwitterAPISessionJSONTask { - return compliance.getComplianceJobj(request) - } - public func createComplianceJob(_ request: PostComplianceJobsRequestV2) -> TwitterAPISessionJSONTask { - return compliance.createComplianceJob(request) - } - - // MARK: - FriendshipsAPIv2 - - public func getFollowing(_ request: GetUsersFollowingRequestV2) -> TwitterAPISessionJSONTask { - return friendships.getFollowing(request) - } - public func getFollowers(_ request: GetUsersFollowersRequestV2) -> TwitterAPISessionJSONTask { - return friendships.getFollowers(request) - } - public func follow(_ request: PostUsersFollowingRequestV2) -> TwitterAPISessionJSONTask { - return friendships.follow(request) - } - public func unfollow(_ request: DeleteUsersFollowingRequestV2) -> TwitterAPISessionJSONTask { - return friendships.unfollow(request) - } - - // MARK: - LikeAPIv2 - - public func getLikingUsers(_ request: GetTweetsLikingUsersRequestV2) -> TwitterAPISessionJSONTask { - return like.getLikingUsers(request) - } - public func getLikedTweets(_ request: GetUsersLikedTweetsRequestV2) -> TwitterAPISessionJSONTask { - return like.getLikedTweets(request) - } - public func postLike(_ request: PostUsersLikesRequestV2) -> TwitterAPISessionJSONTask { - return like.postLike(request) - } - public func deleteLike(_ request: DeleteUsersLikesRequestV2) -> TwitterAPISessionJSONTask { - return like.deleteLike(request) - } - - // MARK: - ListAPIv2 - - public func getListTweets(_ request: GetListsTweetsRequestV2) -> TwitterAPISessionJSONTask { - return list.getListTweets(request) - } - public func getList(_ request: GetListRequestV2) -> TwitterAPISessionJSONTask { - return list.getList(request) - } - public func getLists(_ request: GetUsersOwnedListsRequestV2) -> TwitterAPISessionJSONTask { - return list.getLists(request) - } - public func followList(_ request: PostUsersFollowedListsRequestV2) -> TwitterAPISessionJSONTask { - return list.followList(request) - } - public func unfollowList(_ request: DeleteUsersFollowedListsRequestV2) -> TwitterAPISessionJSONTask { - return list.unfollowList(request) - } - public func listFollowers(_ request: GetListsFollowersRequestV2) -> TwitterAPISessionJSONTask { - return list.listFollowers(request) - } - public func followedLists(_ request: GetUsersFollowedListsRequestV2) -> TwitterAPISessionJSONTask { - return list.followedLists(request) - } - public func addListMember(_ request: PostListsMembersRequestV2) -> TwitterAPISessionJSONTask { - return list.addListMember(request) - } - public func removeListMember(_ request: DeleteListsMembersRequestV2) -> TwitterAPISessionJSONTask { - return list.removeListMember(request) - } - public func getListMemberships(_ request: GetUsersListMembershipsRequestV2) -> TwitterAPISessionJSONTask { - return list.getListMemberships(request) - } - public func getListMembers(_ request: GetListsMembersRequestV2) -> TwitterAPISessionJSONTask { - return list.getListMembers(request) - } - public func createList(_ request: PostListsRequestV2) -> TwitterAPISessionJSONTask { - return list.createList(request) - } - public func updateList(_ request: PutListRequestV2) -> TwitterAPISessionJSONTask { - return list.updateList(request) - } - public func deleteList(_ request: DeleteListRequestV2) -> TwitterAPISessionJSONTask { - return list.deleteList(request) - } - public func pinnedList(_ request: GetUsersPinnedListsRequestV2) -> TwitterAPISessionJSONTask { - return list.pinnedList(request) - } - public func pinList(_ request: PostUsersPinnedListsRequestV2) -> TwitterAPISessionJSONTask { - return list.pinList(request) - } - public func unpinList(_ request: DeleteUsersPinnedListsRequestV2) -> TwitterAPISessionJSONTask { - return list.unpinList(request) - } - - // MARK: - RetweetAPIv2 - - public func getRetweetedBy(_ request: GetTweetsRetweetedByRequestV2) -> TwitterAPISessionJSONTask { - return retweet.getRetweetedBy(request) - } - public func postRetweet(_ request: PostUsersRetweetsRequestV2) -> TwitterAPISessionJSONTask { - return retweet.postRetweet(request) - } - public func deleteRetweet(_ request: DeleteUsersRetweetsRequestV2) -> TwitterAPISessionJSONTask { - return retweet.deleteRetweet(request) - } - - // MARK: - SearchAPIv2 - - public func searchTweetsRecent(_ request: GetTweetsSearchRecentRequestV2) -> TwitterAPISessionJSONTask { - return search.searchTweetsRecent(request) - } - public func searchTweetsAll(_ request: GetTweetsSearchAllRequestV2) -> TwitterAPISessionJSONTask { - return search.searchTweetsAll(request) - } - - // MARK: - SpacesAPIv2 - - public func getSpace(_ request: GetSpaceRequestV2) -> TwitterAPISessionJSONTask { - return spaces.getSpace(request) - } - public func getSpaces(_ request: GetSpacesRequestV2) -> TwitterAPISessionJSONTask { - return spaces.getSpaces(request) - } - public func getSpacesByCreators(_ request: GetSpacesByCreatorIDsRequestV2) -> TwitterAPISessionJSONTask { - return spaces.getSpacesByCreators(request) - } - public func getSpacesBuyers(_ request: GetSpacesBuyersRequestV2) -> TwitterAPISessionJSONTask { - return spaces.getSpacesBuyers(request) - } - public func getSPacesTweets(_ request: GetSpacesTweetsRequestV2) -> TwitterAPISessionJSONTask { - return spaces.getSPacesTweets(request) - } - public func searchSpaces(_ request: GetSpacesSearchRequestV2) -> TwitterAPISessionJSONTask { - return spaces.searchSpaces(request) - } - - // MARK: - StreamAPIv2 - - public func sampleStream(_ request: GetTweetsSampleStreamRequestV2) -> TwitterAPISessionStreamTask { - return stream.sampleStream(request) - } - public func getSearchStreamRules(_ request: GetTweetsSearchStreamRulesRequestV2) -> TwitterAPISessionJSONTask { - return stream.getSearchStreamRules(request) - } - public func postSearchStreamRules(_ request: PostTweetsSearchStreamRulesRequestV2) -> TwitterAPISessionJSONTask { - return stream.postSearchStreamRules(request) - } - public func searchStream(_ request: GetTweetsSearchStreamRequestV2) -> TwitterAPISessionStreamTask { - return stream.searchStream(request) - } - - // MARK: - TimelineAPIv2 - - public func getUserTweets(_ request: GetUsersTweetsRequestV2) -> TwitterAPISessionJSONTask { - return timeline.getUserTweets(request) - } - public func getUserMensions(_ request: GetUsersMentionsRequestV2) -> TwitterAPISessionJSONTask { - return timeline.getUserMensions(request) - } - public func getUserReverseChronological(_ request: GetUsersTimelinesReverseChronologicalRequestV2) -> TwitterAPISessionJSONTask { - return timeline.getUserReverseChronological(request) - } - - // MARK: - TweetAPIv2 - - public func getTweets(_ request: GetTweetsRequestV2) -> TwitterAPISessionJSONTask { - return tweet.getTweets(request) - } - public func getTweet(_ request: GetTweetRequestV2) -> TwitterAPISessionJSONTask { - return tweet.getTweet(request) - } - public func getQuoteTweets(_ request: GetTweetsQuoteTweetsRequestV2) -> TwitterAPISessionJSONTask { - return tweet.getQuoteTweets(request) - } - public func deleteTweet(_ request: DeleteTweetRequestV2) -> TwitterAPISessionJSONTask { - return tweet.deleteTweet(request) - } - public func postTweet(_ request: PostTweetsRequestV2) -> TwitterAPISessionJSONTask { - return tweet.postTweet(request) - } - public func hideReply(_ request: PutTweetsHiddenRequestV2) -> TwitterAPISessionJSONTask { - return tweet.hideReply(request) - } - - // MARK: - TweetCountAPIv2 - - public func getTweetCountRecent(_ request: GetTweetsCountsRecentRequestV2) -> TwitterAPISessionJSONTask { - return tweetCount.getTweetCountRecent(request) - } - public func getTweetCountAll(_ request: GetTweetsCountsAllRequestV2) -> TwitterAPISessionJSONTask { - return tweetCount.getTweetCountAll(request) - } - - // MARK: - UserAPIv2 - - public func getUser(_ request: GetUserRequestV2) -> TwitterAPISessionJSONTask { - return user.getUser(request) - } - public func getUsers(_ request: GetUsersRequestV2) -> TwitterAPISessionJSONTask { - return user.getUsers(request) - } - public func getUserByUsername(_ request: GetUsersByUsernameRequestV2) -> TwitterAPISessionJSONTask { - return user.getUserByUsername(request) - } - public func getUsersByUsernames(_ request: GetUsersByRequestV2) -> TwitterAPISessionJSONTask { - return user.getUsersByUsernames(request) - } - public func getMe(_ request: GetUsersMeRequestV2) -> TwitterAPISessionJSONTask { - return user.getMe(request) - } - - // MARK: - DirectMessageAPIv2 - - public func getDmEvents(_ request: GetDmEventsRequestV2) -> TwitterAPISessionJSONTask { - return dm.getDmEvents(request) - } - public func getDmEventsWithParticipantId(_ request: GetDmConversationsWithParticipantIdDmEventsRequestV2) -> TwitterAPISessionJSONTask { - return dm.getDmEventsWithParticipantId(request) - } - public func getDmEventsByConversationsId(_ request: GetDmConversationsIdDmEventsRequestV2) -> TwitterAPISessionJSONTask { - return dm.getDmEventsByConversationsId(request) - } - public func postDmConversationById(_ request: PostDmConversationByIdRequestV2) -> TwitterAPISessionJSONTask { - return dm.postDmConversationById(request) - } - public func postDmConversationWithUser(_ request: PostDmConversationWithUserRequestV2) -> TwitterAPISessionJSONTask { - return dm.postDmConversationWithUser(request) - } - public func postDmConversation(_ request: PostDmConversationRequestV2) -> TwitterAPISessionJSONTask { - return dm.postDmConversation(request) - } -} diff --git a/Sources/TwitterAPIKit/TwitterAPI.swift b/Sources/TwitterAPIKit/TwitterAPI.swift new file mode 100644 index 00000000..65aac2d8 --- /dev/null +++ b/Sources/TwitterAPIKit/TwitterAPI.swift @@ -0,0 +1,1492 @@ +// TwitterAPI+Flat.generated.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + +// swift-format-ignore-file +import Foundation + +/// A protocol that represents a Twitter API. +public protocol TwitterAPI { + // No Logic Here +} + +/// Extension providing OAuth authentication methods for the Twitter API. +public extension TwitterAuthAPI: TwitterAPI { + // MARK: - OAuth10aAPI + + /// Requests an OAuth request token from Twitter. + /// - Parameter request: The request parameters for obtaining a request token. + /// - Returns: A data task that will return the raw response data. + func postOAuthRequestTokenData(_ request: PostOAuthRequestTokenRequestV1) -> TwitterAPISessionDataTask { + return oauth10a.postOAuthRequestTokenData(request) + } + + /// Requests an OAuth request token from Twitter and parses the response. + /// - Parameter request: The request parameters for obtaining a request token. + /// - Returns: A specialized task that will return a parsed OAuth token. + func postOAuthRequestToken(_ request: PostOAuthRequestTokenRequestV1) + -> TwitterAPISessionSpecializedTask + { + return oauth10a.postOAuthRequestToken(request) + } + + /// Creates a URL for authorizing the application with OAuth. + /// - Parameter request: The request parameters for creating the authorization URL. + /// - Returns: The authorization URL if it can be created, nil otherwise. + func makeOAuthAuthorizeURL(_ request: GetOAuthAuthorizeRequestV1) -> URL? { + return oauth10a.makeOAuthAuthorizeURL(request) + } + + /// Creates a URL for authenticating with OAuth. + /// - Parameter request: The request parameters for creating the authentication URL. + /// - Returns: The authentication URL if it can be created, nil otherwise. + func makeOAuthAuthenticateURL(_ request: GetOAuthAuthenticateRequestV1) -> URL? { + return oauth10a.makeOAuthAuthenticateURL(request) + } + + /// Requests an OAuth access token from Twitter. + /// - Parameter request: The request parameters for obtaining an access token. + /// - Returns: A data task that will return the raw response data. + func postOAuthAccessTokenData(_ request: PostOAuthAccessTokenRequestV1) -> TwitterAPISessionDataTask { + return oauth10a.postOAuthAccessTokenData(request) + } + + /// Requests an OAuth access token from Twitter and parses the response. + /// - Parameter request: The request parameters for obtaining an access token. + /// - Returns: A specialized task that will return a parsed OAuth access token. + func postOAuthAccessToken(_ request: PostOAuthAccessTokenRequestV1) + -> TwitterAPISessionSpecializedTask + { + return oauth10a.postOAuthAccessToken(request) + } + + /// Invalidates the current OAuth access token. + /// - Parameter request: The request parameters for invalidating the token. + /// - Returns: A JSON task that will return the response. + func postInvalidateAccessToken(_ request: PostOAuthInvalidateTokenRequestV1) -> TwitterAPISessionJSONTask { + return oauth10a.postInvalidateAccessToken(request) + } + + // MARK: - OAuth20API + + /// Requests an OAuth 2.0 bearer token from Twitter. + /// - Parameter request: The request parameters for obtaining a bearer token. + /// - Returns: A data task that will return the raw response data. + func postOAuth2BearerTokenData(_ request: PostOAuth2TokenRequestV1) -> TwitterAPISessionDataTask { + return oauth20.postOAuth2BearerTokenData(request) + } + + /// Requests an OAuth 2.0 bearer token from Twitter and parses the response. + /// - Parameter request: The request parameters for obtaining a bearer token. + /// - Returns: A specialized task that will return a parsed OAuth 2.0 bearer token. + func postOAuth2BearerToken(_ request: PostOAuth2TokenRequestV1) + -> TwitterAPISessionSpecializedTask + { + return oauth20.postOAuth2BearerToken(request) + } + + /// Invalidates the current OAuth 2.0 bearer token. + /// - Parameter request: The request parameters for invalidating the token. + /// - Returns: A JSON task that will return the response. + func postInvalidateOAuth2BearerToken(_ request: PostOAuth2InvalidateTokenRequestV1) -> TwitterAPISessionJSONTask { + return oauth20.postInvalidateOAuth2BearerToken(request) + } + + /// Creates a URL for OAuth 2.0 authorization. + /// - Parameter request: The request parameters for creating the authorization URL. + /// - Returns: The authorization URL if it can be created, nil otherwise. + func makeOAuth2AuthorizeURL(_ request: GetOAuth2AuthorizeRequestV1) -> URL? { + return oauth20.makeOAuth2AuthorizeURL(request) + } + + /// Requests an OAuth 2.0 access token from Twitter. + /// - Parameter request: The request parameters for obtaining an access token. + /// - Returns: A data task that will return the raw response data. + func postOAuth2AccessTokenData(_ request: PostOAuth2AccessTokenRequestV2) -> TwitterAPISessionDataTask { + return oauth20.postOAuth2AccessTokenData(request) + } + + /// Requests an OAuth 2.0 access token from Twitter and parses the response. + /// - Parameter request: The request parameters for obtaining an access token. + /// - Returns: A specialized task that will return a parsed OAuth 2.0 access token. + func postOAuth2AccessToken(_ request: PostOAuth2AccessTokenRequestV2) + -> TwitterAPISessionSpecializedTask + { + return oauth20.postOAuth2AccessToken(request) + } + + /// Requests a refresh of the OAuth 2.0 access token. + /// - Parameter request: The request parameters for refreshing the token. + /// - Returns: A data task that will return the raw response data. + func postOAuth2RefreshTokenData(_ request: PostOAuth2RefreshTokenRequestV2) -> TwitterAPISessionDataTask { + return oauth20.postOAuth2RefreshTokenData(request) + } + + /// Requests a refresh of the OAuth 2.0 access token and parses the response. + /// - Parameter request: The request parameters for refreshing the token. + /// - Returns: A specialized task that will return a parsed OAuth 2.0 access token. + func postOAuth2RefreshToken(_ request: PostOAuth2RefreshTokenRequestV2) + -> TwitterAPISessionSpecializedTask + { + return oauth20.postOAuth2RefreshToken(request) + } + + /// Revokes an OAuth 2.0 token. + /// - Parameter request: The request parameters for revoking the token. + /// - Returns: A data task that will return the response. + func postOAuth2RevokeToken(_ request: PostOAuth2RevokeTokenRequestV2) -> TwitterAPISessionDataTask { + return oauth20.postOAuth2RevokeToken(request) + } +} + +/// Extension providing Twitter API v1 endpoints. +public extension TwitterAPIv1: TwitterAPI { + // MARK: - AccountAPIv1 + + /// Retrieves the current account settings. + /// - Parameter request: The request parameters for retrieving account settings. + /// - Returns: A JSON task that will return the account settings. + func getAccountSetting(_ request: GetAccountSettingsRequestV1) -> TwitterAPISessionJSONTask { + return account.getAccountSetting(request) + } + + /// Verifies the credentials of the current user. + /// - Parameter request: The request parameters for verifying credentials. + /// - Returns: A JSON task that will return the verification result. + func getAccountVerify(_ request: GetAccountVerifyCredentialsRequestV1) -> TwitterAPISessionJSONTask { + return account.getAccountVerify(request) + } + + /// Removes the profile banner for the authenticated user. + /// - Parameter request: The request parameters for removing the profile banner. + /// - Returns: A JSON task that will return the response. + func postRemoveProfileBanner(_ request: PostAccountRemoveProfileBannerRequestV1) -> TwitterAPISessionJSONTask { + return account.postRemoveProfileBanner(request) + } + + /// Updates the account settings for the authenticated user. + /// - Parameter request: The request parameters containing the new settings. + /// - Returns: A JSON task that will return the updated settings. + func postAccountSettings(_ request: PostAccountSettingsRequestV1) -> TwitterAPISessionJSONTask { + return account.postAccountSettings(request) + } + + /// Updates the profile information for the authenticated user. + /// - Parameter request: The request parameters containing the new profile information. + /// - Returns: A JSON task that will return the updated profile. + func postAccountProfile(_ request: PostAccountUpdateProfileRequestV1) -> TwitterAPISessionJSONTask { + return account.postAccountProfile(request) + } + + /// Updates the profile banner for the authenticated user. + /// - Parameter request: The request parameters containing the new banner image. + /// - Returns: A data task that will return the response. + func postProfileBanner(_ request: PostAccountUpdateProfileBannerRequestV1) -> TwitterAPISessionDataTask { + return account.postProfileBanner(request) + } + + /// Updates the profile image for the authenticated user. + /// - Parameter request: The request parameters containing the new profile image. + /// - Returns: A JSON task that will return the response. + func postProfileImage(_ request: PostAccountUpdateProfileImageRequestV1) -> TwitterAPISessionJSONTask { + return account.postProfileImage(request) + } + + // MARK: - ApplicationAPIv1 + + /// Retrieves the current rate limit status for the application. + /// - Parameter request: The request parameters for retrieving rate limit status. + /// - Returns: A JSON task that will return the rate limit information. + func getRateLimit(_ request: GetApplicationRateLimitStatusRequestV1) -> TwitterAPISessionJSONTask { + return application.getRateLimit(request) + } + + // MARK: - BlockAndMuteAPIv1 + + /// Retrieves the IDs of users blocked by the authenticated user. + /// - Parameter request: The request parameters for retrieving blocked user IDs. + /// - Returns: A JSON task that will return the list of blocked user IDs. + func getBlockIDs(_ request: GetBlocksIDsRequestV1) -> TwitterAPISessionJSONTask { + return blockAndMute.getBlockIDs(request) + } + + /// Retrieves detailed information about users blocked by the authenticated user. + /// - Parameter request: The request parameters for retrieving blocked users. + /// - Returns: A JSON task that will return the list of blocked users. + func getBlockUsers(_ request: GetBlocksListRequestV1) -> TwitterAPISessionJSONTask { + return blockAndMute.getBlockUsers(request) + } + + /// Retrieves the IDs of users muted by the authenticated user. + /// - Parameter request: The request parameters for retrieving muted user IDs. + /// - Returns: A JSON task that will return the list of muted user IDs. + func getMuteIDs(_ request: GetMutesUsersIDsRequestV1) -> TwitterAPISessionJSONTask { + return blockAndMute.getMuteIDs(request) + } + + /// Retrieves detailed information about users muted by the authenticated user. + /// - Parameter request: The request parameters for retrieving muted users. + /// - Returns: A JSON task that will return the list of muted users. + func getMuteUsers(_ request: GetMutesUsersListRequestV1) -> TwitterAPISessionJSONTask { + return blockAndMute.getMuteUsers(request) + } + + /// Blocks a user. + /// - Parameter request: The request parameters containing the user to block. + /// - Returns: A JSON task that will return the blocked user information. + func postBlockUser(_ request: PostBlocksCreateRequestV1) -> TwitterAPISessionJSONTask { + return blockAndMute.postBlockUser(request) + } + + /// Unblocks a user. + /// - Parameter request: The request parameters containing the user to unblock. + /// - Returns: A JSON task that will return the unblocked user information. + func postUnblockUser(_ request: PostBlocksDestroyRequestV1) -> TwitterAPISessionJSONTask { + return blockAndMute.postUnblockUser(request) + } + + /// Mutes a user. + /// - Parameter request: The request parameters containing the user to mute. + /// - Returns: A JSON task that will return the muted user information. + func postMuteUser(_ request: PostMutesUsersCreateRequestV1) -> TwitterAPISessionJSONTask { + return blockAndMute.postMuteUser(request) + } + + /// Unmutes a user. + /// - Parameter request: The request parameters containing the user to unmute. + /// - Returns: A JSON task that will return the unmuted user information. + func postUnmuteUser(_ request: PostMutesUsersDestroyRequestV1) -> TwitterAPISessionJSONTask { + return blockAndMute.postUnmuteUser(request) + } + + /// Reports a user as spam. + /// - Parameter request: The request parameters containing the user to report. + /// - Returns: A JSON task that will return the response. + func postReportSpam(_ request: PostUsersReportSpamRequestV1) -> TwitterAPISessionJSONTask { + return blockAndMute.postReportSpam(request) + } + + // MARK: - CollectionAPIv1 + + /// Retrieves entries from a collection. + /// - Parameter request: The request parameters for retrieving collection entries. + /// - Returns: A JSON task that will return the collection entries. + func getCollectionEntries(_ request: GetCollectionsEntriesRequestV1) -> TwitterAPISessionJSONTask { + return collection.getCollectionEntries(request) + } + + /// Retrieves a list of collections owned by a user. + /// - Parameter request: The request parameters for retrieving collections. + /// - Returns: A JSON task that will return the list of collections. + func getCollections(_ request: GetCollectionsListRequestV1) -> TwitterAPISessionJSONTask { + return collection.getCollections(request) + } + + /// Retrieves information about a specific collection. + /// - Parameter request: The request parameters for retrieving the collection. + /// - Returns: A JSON task that will return the collection information. + func getCollection(_ request: GetCollectionsShowRequestV1) -> TwitterAPISessionJSONTask { + return collection.getCollection(request) + } + + /// Creates a new collection. + /// - Parameter request: The request parameters for creating the collection. + /// - Returns: A JSON task that will return the created collection. + func postCreateCollection(_ request: PostCollectionsCreateRequestV1) -> TwitterAPISessionJSONTask { + return collection.postCreateCollection(request) + } + + /// Deletes a collection. + /// - Parameter request: The request parameters for deleting the collection. + /// - Returns: A JSON task that will return the response. + func postDestroyCollection(_ request: PostCollectionsDestroyRequestV1) -> TwitterAPISessionJSONTask { + return collection.postDestroyCollection(request) + } + + /// Adds a tweet to a collection. + /// - Parameter request: The request parameters for adding the tweet. + /// - Returns: A JSON task that will return the response. + func postCollectionAddEntry(_ request: PostCollectionsEntriesAddRequestV1) -> TwitterAPISessionJSONTask { + return collection.postCollectionAddEntry(request) + } + + /// Curates tweets in a collection. + /// - Parameter request: The request parameters for curating the collection. + /// - Returns: A JSON task that will return the response. + func postCollectionCurate(_ request: PostCollectionsEntriesCurateRequestV1) -> TwitterAPISessionJSONTask { + return collection.postCollectionCurate(request) + } + + /// Moves a tweet to a different position in a collection. + /// - Parameter request: The request parameters for moving the tweet. + /// - Returns: A JSON task that will return the response. + func postCollectionMoveEntry(_ request: PostCollectionsEntriesMoveRequestV1) -> TwitterAPISessionJSONTask { + return collection.postCollectionMoveEntry(request) + } + + /// Removes a tweet from a collection. + /// - Parameter request: The request parameters for removing the tweet. + /// - Returns: A JSON task that will return the response. + func postCollectionRemoveEntry(_ request: PostCollectionsEntriesRemoveRequestV1) -> TwitterAPISessionJSONTask { + return collection.postCollectionRemoveEntry(request) + } + + /// Updates a collection's metadata. + /// - Parameter request: The request parameters containing the updated metadata. + /// - Returns: A JSON task that will return the updated collection. + func postCollectionUpdate(_ request: PostCollectionsUpdateRequestV1) -> TwitterAPISessionJSONTask { + return collection.postCollectionUpdate(request) + } + + // MARK: - DirectMessageAPIv1 + + /// Sends a new direct message. + /// - Parameter request: The request parameters containing the message content. + /// - Returns: A JSON task that will return the sent message. + func postDirectMessage(_ request: PostDirectMessageRequestV1) -> TwitterAPISessionJSONTask { + return directMessage.postDirectMessage(request) + } + + /// Deletes a direct message. + /// - Parameter request: The request parameters containing the message to delete. + /// - Returns: A data task that will return the response. + func deleteDirectMessage(_ request: DeleteDirectMessageRequestV1) -> TwitterAPISessionDataTask { + return directMessage.deleteDirectMessage(request) + } + + /// Retrieves a specific direct message. + /// - Parameter request: The request parameters for retrieving the message. + /// - Returns: A JSON task that will return the message. + func getDirectMessage(_ request: GetDirectMessageRequestV1) -> TwitterAPISessionJSONTask { + return directMessage.getDirectMessage(request) + } + + /// Retrieves a list of direct messages. + /// - Parameter request: The request parameters for retrieving messages. + /// - Returns: A JSON task that will return the list of messages. + func getDirectMessageList(_ request: GetDirectMessageListRequestV1) -> TwitterAPISessionJSONTask { + return directMessage.getDirectMessageList(request) + } + + /// Marks a direct message as read. + /// - Parameter request: The request parameters containing the message to mark. + /// - Returns: A data task that will return the response. + func postDirectMessageMarkRead(_ request: PostDirectMessagesMarkReadRequestV1) -> TwitterAPISessionDataTask { + return directMessage.postDirectMessageMarkRead(request) + } + + /// Indicates that the user is typing a direct message. + /// - Parameter request: The request parameters for the typing indicator. + /// - Returns: A data task that will return the response. + func postDirectMessageTypingIndicator(_ request: PostDirectMessagesIndicateTypingRequestV1) + -> TwitterAPISessionDataTask + { + return directMessage.postDirectMessageTypingIndicator(request) + } + + // MARK: - FavoriteAPIv1 + + /// Favorites (likes) a tweet. + /// - Parameter request: The request parameters containing the tweet to favorite. + /// - Returns: A JSON task that will return the favorited tweet. + func postFavorite(_ request: PostFavoriteRequestV1) -> TwitterAPISessionJSONTask { + return favorite.postFavorite(request) + } + + /// Removes a favorite (unlike) from a tweet. + /// - Parameter request: The request parameters containing the tweet to unfavorite. + /// - Returns: A JSON task that will return the unfavorited tweet. + func postUnFavorite(_ request: PostUnFavoriteRequestV1) -> TwitterAPISessionJSONTask { + return favorite.postUnFavorite(request) + } + + /// Retrieves tweets favorited by a user. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the list of favorited tweets. + func getFavorites(_ request: GetFavoritesRequestV1) -> TwitterAPISessionJSONTask { + return favorite.getFavorites(request) + } + + // MARK: - FriendshipsAPIv1 + + /// Retrieves IDs of users following a specified user. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the list of follower IDs. + func getFollowerIDs(_ request: GetFollowersIDsRequestV1) -> TwitterAPISessionJSONTask { + return friendships.getFollowerIDs(request) + } + + /// Retrieves detailed information about users following a specified user. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the list of followers. + func getFollowers(_ request: GetFollowersListRequestV1) -> TwitterAPISessionJSONTask { + return friendships.getFollowers(request) + } + + /// Retrieves IDs of users a specified user is following. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the list of friend IDs. + func getFriendIDs(_ request: GetFriendsIDsRequestV1) -> TwitterAPISessionJSONTask { + return friendships.getFriendIDs(request) + } + + /// Retrieves detailed information about users a specified user is following. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the list of friends. + func getFriends(_ request: GetFriendsListRequestV1) -> TwitterAPISessionJSONTask { + return friendships.getFriends(request) + } + + /// Retrieves incoming follow requests for the authenticated user. + /// - Parameter request: The request parameters for retrieving incoming requests. + /// - Returns: A JSON task that will return the list of pending followers. + func getFriendshipsIncoming(_ request: GetFriendshipsIncomingRequestV1) -> TwitterAPISessionJSONTask { + return friendships.getFriendshipsIncoming(request) + } + + /// Retrieves detailed friendship information between users. + /// - Parameter request: The request parameters containing the user identifiers. + /// - Returns: A JSON task that will return the friendship details. + func getFriendshipsLookup(_ request: GetFriendshipsLookupRequestV1) -> TwitterAPISessionJSONTask { + return friendships.getFriendshipsLookup(request) + } + + /// Retrieves IDs of users whose retweets are disabled. + /// - Parameter request: The request parameters for retrieving no-retweet IDs. + /// - Returns: A JSON task that will return the list of user IDs. + func getFriendshipsNoRetweetsIDs(_ request: GetFriendshipsNoRetweetsIDsRequestV1) -> TwitterAPISessionJSONTask { + return friendships.getFriendshipsNoRetweetsIDs(request) + } + + /// Retrieves outgoing follow requests from the authenticated user. + /// - Parameter request: The request parameters for retrieving outgoing requests. + /// - Returns: A JSON task that will return the list of pending friends. + func getFriendshipsOutgoing(_ request: GetFriendshipsOutgoingRequestV1) -> TwitterAPISessionJSONTask { + return friendships.getFriendshipsOutgoing(request) + } + + /// Retrieves detailed friendship information between two users. + /// - Parameter request: The request parameters containing the user identifiers. + /// - Returns: A JSON task that will return the friendship details. + func getFriendships(_ request: GetFriendshipsShowRequestV1) -> TwitterAPISessionJSONTask { + return friendships.getFriendships(request) + } + + /// Follows a user. + /// - Parameter request: The request parameters containing the user to follow. + /// - Returns: A JSON task that will return the followed user information. + func postFollowUser(_ request: PostFriendshipsCreateRequestV1) -> TwitterAPISessionJSONTask { + return friendships.postFollowUser(request) + } + + /// Unfollows a user. + /// - Parameter request: The request parameters containing the user to unfollow. + /// - Returns: A JSON task that will return the unfollowed user information. + func postUnfollowUser(_ request: PostFriendshipsDestroyRequestV1) -> TwitterAPISessionJSONTask { + return friendships.postUnfollowUser(request) + } + + /// Updates friendship settings with a user. + /// - Parameter request: The request parameters containing the settings to update. + /// - Returns: A JSON task that will return the updated friendship information. + func postFriendshipsUpdate(_ request: PostFriendshipsUpdateRequestV1) -> TwitterAPISessionJSONTask { + return friendships.postFriendshipsUpdate(request) + } + + // MARK: - GeoAPIv1 + + /// Retrieves location information for given coordinates. + /// - Parameter request: The request parameters containing the coordinates. + /// - Returns: A JSON task that will return the location information. + func getReverseGeocode(_ request: GetGeoReverseGeocodeRequestV1) -> TwitterAPISessionJSONTask { + return geo.getReverseGeocode(request) + } + + /// Retrieves information about a specific place. + /// - Parameter request: The request parameters containing the place ID. + /// - Returns: A JSON task that will return the place information. + func getGeoPlace(_ request: GetGeoPlaceIDRequestV1) -> TwitterAPISessionJSONTask { + return geo.getGeoPlace(request) + } + + /// Searches for places matching specified criteria. + /// - Parameter request: The request parameters containing the search criteria. + /// - Returns: A JSON task that will return the matching places. + func searchGeo(_ request: GetGeoSearchRequestV1) -> TwitterAPISessionJSONTask { + return geo.searchGeo(request) + } + + // MARK: - HelpAPIv1 + + /// Retrieves the list of languages supported by Twitter. + /// - Parameter request: The request parameters for retrieving languages. + /// - Returns: A JSON task that will return the supported languages. + func getSupportedLanguages(_ request: GetHelpLanguagesRequestV1) -> TwitterAPISessionJSONTask { + return help.getSupportedLanguages(request) + } + + // MARK: - ListAPIv1 + + /// Retrieves lists owned by a user. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the owned lists. + func getLists(_ request: GetListsListRequestV1) -> TwitterAPISessionJSONTask { + return list.getLists(request) + } + + /// Retrieves members of a list. + /// - Parameter request: The request parameters containing the list ID. + /// - Returns: A JSON task that will return the list members. + func getListMembers(_ request: GetListsMembersRequestV1) -> TwitterAPISessionJSONTask { + return list.getListMembers(request) + } + + /// Checks if a user is a member of a list. + /// - Parameter request: The request parameters containing the user and list identifiers. + /// - Returns: A JSON task that will return the membership status. + func getListMember(_ request: GetListsMembersShowRequestV1) -> TwitterAPISessionJSONTask { + return list.getListMember(request) + } + + /// Retrieves lists that a user is a member of. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the list memberships. + func getListMemberships(_ request: GetListsMembershipsRequestV1) -> TwitterAPISessionJSONTask { + return list.getListMemberships(request) + } + + /// Retrieves lists owned by a user. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the owned lists. + func getListOwnerships(_ request: GetListsOwnershipsRequestV1) -> TwitterAPISessionJSONTask { + return list.getListOwnerships(request) + } + + /// Retrieves information about a specific list. + /// - Parameter request: The request parameters containing the list ID. + /// - Returns: A JSON task that will return the list information. + func getList(_ request: GetListsShowRequestV1) -> TwitterAPISessionJSONTask { + return list.getList(request) + } + + /// Retrieves tweets from a list. + /// - Parameter request: The request parameters containing the list ID. + /// - Returns: A JSON task that will return the list tweets. + func getListStatuses(_ request: GetListsStatusesRequestV1) -> TwitterAPISessionJSONTask { + return list.getListStatuses(request) + } + + /// Retrieves subscribers of a list. + /// - Parameter request: The request parameters containing the list ID. + /// - Returns: A JSON task that will return the list subscribers. + func getListSubscribers(_ request: GetListsSubscribersRequestV1) -> TwitterAPISessionJSONTask { + return list.getListSubscribers(request) + } + + /// Checks if a user is subscribed to a list. + /// - Parameter request: The request parameters containing the user and list identifiers. + /// - Returns: A JSON task that will return the subscription status. + func getListSubscriber(_ request: GetListsSubscribersShowRequestV1) -> TwitterAPISessionJSONTask { + return list.getListSubscriber(request) + } + + /// Retrieves lists that a user is subscribed to. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the subscribed lists. + func getListSubscriptions(_ request: GetListsSubscriptionsRequestV1) -> TwitterAPISessionJSONTask { + return list.getListSubscriptions(request) + } + + /// Creates a new list. + /// - Parameter request: The request parameters for creating the list. + /// - Returns: A JSON task that will return the created list. + func postCreateList(_ request: PostListsCreateRequestV1) -> TwitterAPISessionJSONTask { + return list.postCreateList(request) + } + + /// Deletes a list. + /// - Parameter request: The request parameters containing the list to delete. + /// - Returns: A JSON task that will return the response. + func postDestroyList(_ request: PostListsDestroyRequestV1) -> TwitterAPISessionJSONTask { + return list.postDestroyList(request) + } + + /// Adds a member to a list. + /// - Parameter request: The request parameters containing the user and list. + /// - Returns: A JSON task that will return the response. + func postAddListMember(_ request: PostListsMembersCreateRequestV1) -> TwitterAPISessionJSONTask { + return list.postAddListMember(request) + } + + /// Adds multiple members to a list. + /// - Parameter request: The request parameters containing the users and list. + /// - Returns: A JSON task that will return the response. + func postAddListMembers(_ request: PostListsMembersCreateAllRequestV1) -> TwitterAPISessionJSONTask { + return list.postAddListMembers(request) + } + + /// Removes a member from a list. + /// - Parameter request: The request parameters containing the user and list. + /// - Returns: A JSON task that will return the response. + func postRemoveListMember(_ request: PostListsMembersDestroyRequestV1) -> TwitterAPISessionJSONTask { + return list.postRemoveListMember(request) + } + + /// Removes multiple members from a list. + /// - Parameter request: The request parameters containing the users and list. + /// - Returns: A JSON task that will return the response. + func postRemoveListMembers(_ request: PostListsMembersDestroyAllRequestV1) -> TwitterAPISessionJSONTask { + return list.postRemoveListMembers(request) + } + + /// Subscribes the authenticated user to a list. + /// - Parameter request: The request parameters containing the list to subscribe to. + /// - Returns: A JSON task that will return the response. + func postSubscribeList(_ request: PostListsSubscribersCreateRequestV1) -> TwitterAPISessionJSONTask { + return list.postSubscribeList(request) + } + + /// Unsubscribes the authenticated user from a list. + /// - Parameter request: The request parameters containing the list to unsubscribe from. + /// - Returns: A JSON task that will return the response. + func postUnsubscribeList(_ request: PostListsSubscribersDestroyRequestV1) -> TwitterAPISessionJSONTask { + return list.postUnsubscribeList(request) + } + + /// Updates a list's metadata. + /// - Parameter request: The request parameters containing the updated information. + /// - Returns: A JSON task that will return the updated list. + func postUpdateList(_ request: PostListsUpdateRequestV1) -> TwitterAPISessionJSONTask { + return list.postUpdateList(request) + } + + // MARK: - MediaAPIv1 + + /// Retrieves the status of a media upload. + /// - Parameter request: The request parameters for checking upload status. + /// - Returns: A JSON task that will return the upload status. + func getUploadMediaStatus(_ request: GetUploadMediaStatusRequestV1) -> TwitterAPISessionJSONTask { + return media.getUploadMediaStatus(request) + } + + /// Initializes a media upload. + /// - Parameter request: The request parameters for initializing the upload. + /// - Returns: A JSON task that will return the initialization response. + func uploadMediaInit(_ request: UploadMediaInitRequestV1) -> TwitterAPISessionJSONTask { + return media.uploadMediaInit(request) + } + + /// Appends media data to an initialized upload. + /// - Parameter request: The request parameters containing the media chunk. + /// - Returns: A JSON task that will return the append response. + func uploadMediaAppend(_ request: UploadMediaAppendRequestV1) -> TwitterAPISessionJSONTask { + return media.uploadMediaAppend(request) + } + + /// Appends media data in chunks to an initialized upload. + /// - Parameters: + /// - request: The request parameters containing the media data. + /// - maxBytes: The maximum size of each chunk in bytes (default: 5MB). + /// - Returns: An array of tasks that will return the media ID for each chunk. + func uploadMediaAppendSplitChunks( + _ request: UploadMediaAppendRequestV1, + maxBytes: Int = 5_242_880 + ) -> [TwitterAPISessionSpecializedTask] { + return media.uploadMediaAppendSplitChunks(request, maxBytes: maxBytes) + } + + /// Finalizes a media upload. + /// - Parameter request: The request parameters for finalizing the upload. + /// - Returns: A JSON task that will return the finalization response. + func uploadMediaFinalize(_ request: UploadMediaFinalizeRequestV1) -> TwitterAPISessionJSONTask { + return media.uploadMediaFinalize(request) + } + + /// Uploads media in a single operation. + /// - Parameters: + /// - parameters: The parameters for the media upload. + /// - completionHandler: A closure to be called with the upload response. + func uploadMedia( + _ parameters: UploadMediaRequestParameters, + completionHandler: @escaping (TwitterAPIResponse) -> Void + ) { + media.uploadMedia(parameters, completionHandler: completionHandler) + } + + /// Waits for media processing to complete with a specified initial wait time. + /// - Parameters: + /// - mediaID: The ID of the media to wait for. + /// - initialWaitSec: The number of seconds to wait initially. + /// - completionHandler: A closure to be called with the processing status. + func waitMediaProcessing( + mediaID: String, + initialWaitSec: Int, + completionHandler: @escaping (TwitterAPIResponse) -> Void + ) { + media.waitMediaProcessing( + mediaID: mediaID, + initialWaitSec: initialWaitSec, + completionHandler: completionHandler + ) + } + + /// Waits for media processing to complete with default wait time. + /// - Parameters: + /// - mediaID: The ID of the media to wait for. + /// - completionHandler: A closure to be called with the processing status. + func waitMediaProcessing( + mediaID: String, + completionHandler: @escaping (TwitterAPIResponse) -> Void + ) { + media.waitMediaProcessing(mediaID: mediaID, completionHandler: completionHandler) + } + + /// Creates metadata for uploaded media. + /// - Parameter request: The request parameters containing the metadata. + /// - Returns: A data task that will return the response. + func createMediaMetadata(_ request: PostMediaMetadataCreateRequestV1) -> TwitterAPISessionDataTask { + return media.createMediaMetadata(request) + } + + /// Creates subtitles for media. + /// - Parameter request: The request parameters containing the subtitle data. + /// - Returns: A data task that will return the response. + func createSubtitle(_ request: PostMediaSubtitlesCreateRequestV1) -> TwitterAPISessionDataTask { + return media.createSubtitle(request) + } + + /// Deletes subtitles from media. + /// - Parameter request: The request parameters identifying the subtitles to delete. + /// - Returns: A data task that will return the response. + func deleteSubtitle(_ request: PostMediaSubtitlesDeleteRequestV1) -> TwitterAPISessionDataTask { + return media.deleteSubtitle(request) + } + + // MARK: - RetweetAPIv1 + + /// Creates a retweet of a tweet. + /// - Parameter request: The request parameters containing the tweet to retweet. + /// - Returns: A JSON task that will return the retweet. + func postRetweet(_ request: PostRetweetRequestV1) -> TwitterAPISessionJSONTask { + return retweet.postRetweet(request) + } + + /// Removes a retweet of a tweet. + /// - Parameter request: The request parameters containing the retweet to remove. + /// - Returns: A JSON task that will return the response. + func postUnRetweet(_ request: PostUnRetweetRequestV1) -> TwitterAPISessionJSONTask { + return retweet.postUnRetweet(request) + } + + /// Retrieves retweets of a tweet. + /// - Parameter request: The request parameters for retrieving retweets. + /// - Returns: A JSON task that will return the list of retweets. + func getRetweets(_ request: GetRetweetsRequestV1) -> TwitterAPISessionJSONTask { + return retweet.getRetweets(request) + } + + /// Retrieves tweets of the authenticated user that have been retweeted. + /// - Parameter request: The request parameters for retrieving retweeted tweets. + /// - Returns: A JSON task that will return the list of tweets. + func getRetweetsOfMe(_ request: GetRetweetsOfMeRequestV1) -> TwitterAPISessionJSONTask { + return retweet.getRetweetsOfMe(request) + } + + /// Retrieves users who have retweeted a tweet. + /// - Parameter request: The request parameters for retrieving retweeters. + /// - Returns: A JSON task that will return the list of users. + func getRetweeters(_ request: GetRetweetersRequestV1) -> TwitterAPISessionJSONTask { + return retweet.getRetweeters(request) + } + + // MARK: - SearchAPIv1 + + /// Searches for tweets matching a query. + /// - Parameter request: The request parameters containing the search query. + /// - Returns: A JSON task that will return the matching tweets. + func searchTweets(_ request: GetSearchTweetsRequestV1) -> TwitterAPISessionJSONTask { + return search.searchTweets(request) + } + + /// Retrieves the authenticated user's saved searches. + /// - Parameter request: The request parameters for retrieving saved searches. + /// - Returns: A JSON task that will return the list of saved searches. + func getSavedSearches(_ request: GetSavedSearchesListRequestV1) -> TwitterAPISessionJSONTask { + return search.getSavedSearches(request) + } + + /// Creates a new saved search for the authenticated user. + /// - Parameter request: The request parameters containing the search to save. + /// - Returns: A JSON task that will return the saved search. + func postCreateSavedSearch(_ request: PostSavedSearchesCreateRequestV1) -> TwitterAPISessionJSONTask { + return search.postCreateSavedSearch(request) + } + + /// Deletes a saved search belonging to the authenticated user. + /// - Parameter request: The request parameters containing the search to delete. + /// - Returns: A JSON task that will return the response. + func postDestroySavedSearch(_ request: PostSavedSearchesCreateRequestV1) -> TwitterAPISessionJSONTask { + return search.postDestroySavedSearch(request) + } + + // MARK: - TimelineAPIv1 + + /// Retrieves the authenticated user's home timeline. + /// - Parameter request: The request parameters for retrieving the timeline. + /// - Returns: A JSON task that will return the timeline tweets. + func getHomeTimeline(_ request: GetStatusesHomeTimelineRequestV1) -> TwitterAPISessionJSONTask { + return timeline.getHomeTimeline(request) + } + + /// Retrieves tweets mentioning the authenticated user. + /// - Parameter request: The request parameters for retrieving mentions. + /// - Returns: A JSON task that will return the mentions. + func getMentionsTimeline(_ request: GetStatusesMentionsTimelineRequestV1) -> TwitterAPISessionJSONTask { + return timeline.getMentionsTimeline(request) + } + + /// Retrieves a user's timeline. + /// - Parameter request: The request parameters for retrieving the user timeline. + /// - Returns: A JSON task that will return the timeline tweets. + func getUserTimeline(_ request: GetStatusesUserTimelineRequestV1) -> TwitterAPISessionJSONTask { + return timeline.getUserTimeline(request) + } + + // MARK: - TrendAPIv1 + + /// Retrieves locations where trending topics are available. + /// - Parameter request: The request parameters for retrieving trend locations. + /// - Returns: A JSON task that will return the available locations. + func getTrendsAvailable(_ request: GetTrendsAvailableRequestV1) -> TwitterAPISessionJSONTask { + return trend.getTrendsAvailable(request) + } + + /// Retrieves locations closest to a specified location where trends are available. + /// - Parameter request: The request parameters containing the location. + /// - Returns: A JSON task that will return the closest trend locations. + func getTrendsClosest(_ request: GetTrendsClosestRequestV1) -> TwitterAPISessionJSONTask { + return trend.getTrendsClosest(request) + } + + /// Retrieves trending topics for a specific location. + /// - Parameter request: The request parameters containing the location. + /// - Returns: A JSON task that will return the trending topics. + func getTrends(_ request: GetTrendsPlaceRequestV1) -> TwitterAPISessionJSONTask { + return trend.getTrends(request) + } + + // MARK: - TweetAPIv1 + + /// Posts a new tweet. + /// - Parameter request: The request parameters containing the tweet content. + /// - Returns: A JSON task that will return the posted tweet. + func postUpdateStatus(_ request: PostStatusesUpdateRequestV1) -> TwitterAPISessionJSONTask { + return tweet.postUpdateStatus(request) + } + + /// Deletes a tweet. + /// - Parameter request: The request parameters containing the tweet to delete. + /// - Returns: A JSON task that will return the response. + func postDestroyStatus(_ request: PostStatusesDestroyRequestV1) -> TwitterAPISessionJSONTask { + return tweet.postDestroyStatus(request) + } + + /// Retrieves a single tweet. + /// - Parameter request: The request parameters containing the tweet ID. + /// - Returns: A JSON task that will return the tweet. + func getShowStatus(_ request: GetStatusesShowRequestV1) -> TwitterAPISessionJSONTask { + return tweet.getShowStatus(request) + } + + /// Retrieves multiple tweets by their IDs. + /// - Parameter request: The request parameters containing the tweet IDs. + /// - Returns: A JSON task that will return the tweets. + func getLookupStatuses(_ request: GetStatusesLookupRequestV1) -> TwitterAPISessionJSONTask { + return tweet.getLookupStatuses(request) + } + + // MARK: - UserAPIv1 + + /// Retrieves detailed information about multiple users. + /// - Parameter request: The request parameters containing the user identifiers. + /// - Returns: A JSON task that will return the user information. + func getUsers(_ request: GetUsersLookupRequestV1) -> TwitterAPISessionJSONTask { + return user.getUsers(request) + } + + /// Retrieves detailed information about a single user. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the user information. + func getUser(_ request: GetUsersShowRequestV1) -> TwitterAPISessionJSONTask { + return user.getUser(request) + } + + /// Searches for users matching a query. + /// - Parameter request: The request parameters containing the search query. + /// - Returns: A JSON task that will return the matching users. + func searchUser(_ request: GetUsersShowRequestV1) -> TwitterAPISessionJSONTask { + return user.searchUser(request) + } + + /// Retrieves a user's profile banner. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the banner information. + func getUserProfileBanner(_ request: GetUsersProfileBannerRequestV1) -> TwitterAPISessionJSONTask { + return user.getUserProfileBanner(request) + } +} + +public extension TwitterAPIv2: TwitterAPI { + // MARK: - BlockAndMuteAPIv2 + + /// Retrieves users blocked by the authenticated user. + /// - Parameter request: The request parameters for retrieving blocked users. + /// - Returns: A JSON task that will return the list of blocked users. + func getBlockUsers(_ request: GetUsersBlockingRequestV2) -> TwitterAPISessionJSONTask { + return blockAndMute.getBlockUsers(request) + } + + /// Blocks a user. + /// - Parameter request: The request parameters containing the user to block. + /// - Returns: A JSON task that will return the response. + func blockUser(_ request: PostUsersBlockingRequestV2) -> TwitterAPISessionJSONTask { + return blockAndMute.blockUser(request) + } + + /// Unblocks a user. + /// - Parameter request: The request parameters containing the user to unblock. + /// - Returns: A JSON task that will return the response. + func unblockUser(_ request: DeleteUsersBlockingRequestV2) -> TwitterAPISessionJSONTask { + return blockAndMute.unblockUser(request) + } + + /// Retrieves users muted by the authenticated user. + /// - Parameter request: The request parameters for retrieving muted users. + /// - Returns: A JSON task that will return the list of muted users. + func getMuteUsers(_ request: GetUsersMutingRequestV2) -> TwitterAPISessionJSONTask { + return blockAndMute.getMuteUsers(request) + } + + /// Mutes a user. + /// - Parameter request: The request parameters containing the user to mute. + /// - Returns: A JSON task that will return the response. + func muteUser(_ request: PostUsersMutingRequestV2) -> TwitterAPISessionJSONTask { + return blockAndMute.muteUser(request) + } + + /// Unmutes a user. + /// - Parameter request: The request parameters containing the user to unmute. + /// - Returns: A JSON task that will return the response. + func unmuteUser(_ request: DeleteUsersMutingRequestV2) -> TwitterAPISessionJSONTask { + return blockAndMute.unmuteUser(request) + } + + // MARK: - BookmarksAPIv2 + + /// Retrieves the authenticated user's bookmarked tweets. + /// - Parameter request: The request parameters for retrieving bookmarks. + /// - Returns: A JSON task that will return the bookmarked tweets. + func getBookmarks(_ request: GetUsersBookmarksRequestV2) -> TwitterAPISessionJSONTask { + return bookmarks.getBookmarks(request) + } + + /// Bookmarks a tweet. + /// - Parameter request: The request parameters containing the tweet to bookmark. + /// - Returns: A JSON task that will return the response. + func createBookmark(_ request: PostUsersBookmarksRequestV2) -> TwitterAPISessionJSONTask { + return bookmarks.createBookmark(request) + } + + /// Removes a tweet from bookmarks. + /// - Parameter request: The request parameters containing the tweet to remove. + /// - Returns: A JSON task that will return the response. + func deleteBookmark(_ request: DeleteUsersBookmarksRequestV2) -> TwitterAPISessionJSONTask { + return bookmarks.deleteBookmark(request) + } + + // MARK: - ComplianceAPIv2 + + /// Retrieves information about a specific compliance job. + /// - Parameter request: The request parameters containing the job ID. + /// - Returns: A JSON task that will return the job information. + func getComplianceJob(_ request: GetComplianceJobRequestV2) -> TwitterAPISessionJSONTask { + return compliance.getComplianceJob(request) + } + + /// Retrieves a list of compliance jobs. + /// - Parameter request: The request parameters for retrieving compliance jobs. + /// - Returns: A JSON task that will return the list of jobs. + func getComplianceJobj(_ request: GetComplianceJobsRequestV2) -> TwitterAPISessionJSONTask { + return compliance.getComplianceJobj(request) + } + + /// Creates a new compliance job. + /// - Parameter request: The request parameters for creating the job. + /// - Returns: A JSON task that will return the created job. + func createComplianceJob(_ request: PostComplianceJobsRequestV2) -> TwitterAPISessionJSONTask { + return compliance.createComplianceJob(request) + } + + // MARK: - FriendshipsAPIv2 + + /// Retrieves users that a specified user is following. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the list of followed users. + func getFollowing(_ request: GetUsersFollowingRequestV2) -> TwitterAPISessionJSONTask { + return friendships.getFollowing(request) + } + + /// Retrieves followers of a specified user. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the list of followers. + func getFollowers(_ request: GetUsersFollowersRequestV2) -> TwitterAPISessionJSONTask { + return friendships.getFollowers(request) + } + + /// Follows a user. + /// - Parameter request: The request parameters containing the user to follow. + /// - Returns: A JSON task that will return the response. + func follow(_ request: PostUsersFollowingRequestV2) -> TwitterAPISessionJSONTask { + return friendships.follow(request) + } + + /// Unfollows a user. + /// - Parameter request: The request parameters containing the user to unfollow. + /// - Returns: A JSON task that will return the response. + func unfollow(_ request: DeleteUsersFollowingRequestV2) -> TwitterAPISessionJSONTask { + return friendships.unfollow(request) + } + + // MARK: - LikeAPIv2 + + /// Retrieves users who have liked a tweet. + /// - Parameter request: The request parameters containing the tweet ID. + /// - Returns: A JSON task that will return the list of users. + func getLikingUsers(_ request: GetTweetsLikingUsersRequestV2) -> TwitterAPISessionJSONTask { + return like.getLikingUsers(request) + } + + /// Retrieves tweets liked by a user. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the list of liked tweets. + func getLikedTweets(_ request: GetUsersLikedTweetsRequestV2) -> TwitterAPISessionJSONTask { + return like.getLikedTweets(request) + } + + /// Likes a tweet. + /// - Parameter request: The request parameters containing the tweet to like. + /// - Returns: A JSON task that will return the response. + func postLike(_ request: PostUsersLikesRequestV2) -> TwitterAPISessionJSONTask { + return like.postLike(request) + } + + /// Unlikes a tweet. + /// - Parameter request: The request parameters containing the tweet to unlike. + /// - Returns: A JSON task that will return the response. + func deleteLike(_ request: DeleteUsersLikesRequestV2) -> TwitterAPISessionJSONTask { + return like.deleteLike(request) + } + + // MARK: - ListAPIv2 + + /// Retrieves tweets from a list. + /// - Parameter request: The request parameters containing the list ID. + /// - Returns: A JSON task that will return the list tweets. + func getListTweets(_ request: GetListsTweetsRequestV2) -> TwitterAPISessionJSONTask { + return list.getListTweets(request) + } + + /// Retrieves information about a specific list. + /// - Parameter request: The request parameters containing the list ID. + /// - Returns: A JSON task that will return the list information. + func getList(_ request: GetListRequestV2) -> TwitterAPISessionJSONTask { + return list.getList(request) + } + + /// Retrieves lists owned by a user. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the owned lists. + func getLists(_ request: GetUsersOwnedListsRequestV2) -> TwitterAPISessionJSONTask { + return list.getLists(request) + } + + /// Follows a list. + /// - Parameter request: The request parameters containing the list to follow. + /// - Returns: A JSON task that will return the response. + func followList(_ request: PostUsersFollowedListsRequestV2) -> TwitterAPISessionJSONTask { + return list.followList(request) + } + + /// Unfollows a list. + /// - Parameter request: The request parameters containing the list to unfollow. + /// - Returns: A JSON task that will return the response. + func unfollowList(_ request: DeleteUsersFollowedListsRequestV2) -> TwitterAPISessionJSONTask { + return list.unfollowList(request) + } + + /// Retrieves followers of a list. + /// - Parameter request: The request parameters containing the list ID. + /// - Returns: A JSON task that will return the list followers. + func listFollowers(_ request: GetListsFollowersRequestV2) -> TwitterAPISessionJSONTask { + return list.listFollowers(request) + } + + /// Retrieves lists followed by a user. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the followed lists. + func followedLists(_ request: GetUsersFollowedListsRequestV2) -> TwitterAPISessionJSONTask { + return list.followedLists(request) + } + + /// Adds a member to a list. + /// - Parameter request: The request parameters containing the user and list. + /// - Returns: A JSON task that will return the response. + func addListMember(_ request: PostListsMembersRequestV2) -> TwitterAPISessionJSONTask { + return list.addListMember(request) + } + + /// Removes a member from a list. + /// - Parameter request: The request parameters containing the user and list. + /// - Returns: A JSON task that will return the response. + func removeListMember(_ request: DeleteListsMembersRequestV2) -> TwitterAPISessionJSONTask { + return list.removeListMember(request) + } + + /// Retrieves lists that a user is a member of. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the list memberships. + func getListMemberships(_ request: GetUsersListMembershipsRequestV2) -> TwitterAPISessionJSONTask { + return list.getListMemberships(request) + } + + /// Retrieves members of a list. + /// - Parameter request: The request parameters containing the list ID. + /// - Returns: A JSON task that will return the list members. + func getListMembers(_ request: GetListsMembersRequestV2) -> TwitterAPISessionJSONTask { + return list.getListMembers(request) + } + + /// Creates a new list. + /// - Parameter request: The request parameters for creating the list. + /// - Returns: A JSON task that will return the created list. + func createList(_ request: PostListsRequestV2) -> TwitterAPISessionJSONTask { + return list.createList(request) + } + + /// Updates a list's metadata. + /// - Parameter request: The request parameters containing the updated information. + /// - Returns: A JSON task that will return the updated list. + func updateList(_ request: PutListRequestV2) -> TwitterAPISessionJSONTask { + return list.updateList(request) + } + + /// Deletes a list. + /// - Parameter request: The request parameters containing the list to delete. + /// - Returns: A JSON task that will return the response. + func deleteList(_ request: DeleteListRequestV2) -> TwitterAPISessionJSONTask { + return list.deleteList(request) + } + + /// Retrieves a user's pinned lists. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the pinned lists. + func pinnedList(_ request: GetUsersPinnedListsRequestV2) -> TwitterAPISessionJSONTask { + return list.pinnedList(request) + } + + /// Pins a list to the user's profile. + /// - Parameter request: The request parameters containing the list to pin. + /// - Returns: A JSON task that will return the response. + func pinList(_ request: PostUsersPinnedListsRequestV2) -> TwitterAPISessionJSONTask { + return list.pinList(request) + } + + /// Unpins a list from the user's profile. + /// - Parameter request: The request parameters containing the list to unpin. + /// - Returns: A JSON task that will return the response. + func unpinList(_ request: DeleteUsersPinnedListsRequestV2) -> TwitterAPISessionJSONTask { + return list.unpinList(request) + } + + // MARK: - RetweetAPIv2 + + /// Retrieves users who have retweeted a tweet. + /// - Parameter request: The request parameters containing the tweet ID. + /// - Returns: A JSON task that will return the list of users. + func getRetweetedBy(_ request: GetTweetsRetweetedByRequestV2) -> TwitterAPISessionJSONTask { + return retweet.getRetweetedBy(request) + } + + /// Creates a retweet of a tweet. + /// - Parameter request: The request parameters containing the tweet to retweet. + /// - Returns: A JSON task that will return the response. + func postRetweet(_ request: PostUsersRetweetsRequestV2) -> TwitterAPISessionJSONTask { + return retweet.postRetweet(request) + } + + /// Removes a retweet of a tweet. + /// - Parameter request: The request parameters containing the retweet to remove. + /// - Returns: A JSON task that will return the response. + func deleteRetweet(_ request: DeleteUsersRetweetsRequestV2) -> TwitterAPISessionJSONTask { + return retweet.deleteRetweet(request) + } + + // MARK: - SearchAPIv2 + + /// Searches for recent tweets matching a query. + /// - Parameter request: The request parameters containing the search query. + /// - Returns: A JSON task that will return the matching tweets. + func searchTweetsRecent(_ request: GetTweetsSearchRecentRequestV2) -> TwitterAPISessionJSONTask { + return search.searchTweetsRecent(request) + } + + /// Searches for all tweets matching a query. + /// - Parameter request: The request parameters containing the search query. + /// - Returns: A JSON task that will return the matching tweets. + func searchTweetsAll(_ request: GetTweetsSearchAllRequestV2) -> TwitterAPISessionJSONTask { + return search.searchTweetsAll(request) + } + + // MARK: - SpacesAPIv2 + + /// Retrieves information about a specific space. + /// - Parameter request: The request parameters containing the space ID. + /// - Returns: A JSON task that will return the space information. + func getSpace(_ request: GetSpaceRequestV2) -> TwitterAPISessionJSONTask { + return spaces.getSpace(request) + } + + /// Retrieves information about multiple spaces. + /// - Parameter request: The request parameters containing the space IDs. + /// - Returns: A JSON task that will return the spaces information. + func getSpaces(_ request: GetSpacesRequestV2) -> TwitterAPISessionJSONTask { + return spaces.getSpaces(request) + } + + /// Retrieves spaces created by specified users. + /// - Parameter request: The request parameters containing the creator IDs. + /// - Returns: A JSON task that will return the spaces information. + func getSpacesByCreators(_ request: GetSpacesByCreatorIDsRequestV2) -> TwitterAPISessionJSONTask { + return spaces.getSpacesByCreators(request) + } + + /// Retrieves users who have purchased tickets to a space. + /// - Parameter request: The request parameters containing the space ID. + /// - Returns: A JSON task that will return the list of buyers. + func getSpacesBuyers(_ request: GetSpacesBuyersRequestV2) -> TwitterAPISessionJSONTask { + return spaces.getSpacesBuyers(request) + } + + /// Retrieves tweets shared in a space. + /// - Parameter request: The request parameters containing the space ID. + /// - Returns: A JSON task that will return the tweets. + func getSPacesTweets(_ request: GetSpacesTweetsRequestV2) -> TwitterAPISessionJSONTask { + return spaces.getSPacesTweets(request) + } + + /// Searches for spaces matching a query. + /// - Parameter request: The request parameters containing the search query. + /// - Returns: A JSON task that will return the matching spaces. + func searchSpaces(_ request: GetSpacesSearchRequestV2) -> TwitterAPISessionJSONTask { + return spaces.searchSpaces(request) + } + + // MARK: - StreamAPIv2 + + /// Connects to the sample stream of tweets. + /// - Parameter request: The request parameters for the sample stream. + /// - Returns: A stream task that will provide tweets in real-time. + func sampleStream(_ request: GetTweetsSampleStreamRequestV2) -> TwitterAPISessionStreamTask { + return stream.sampleStream(request) + } + + /// Retrieves rules for filtered stream. + /// - Parameter request: The request parameters for retrieving stream rules. + /// - Returns: A JSON task that will return the stream rules. + func getSearchStreamRules(_ request: GetTweetsSearchStreamRulesRequestV2) -> TwitterAPISessionJSONTask { + return stream.getSearchStreamRules(request) + } + + /// Updates rules for filtered stream. + /// - Parameter request: The request parameters containing the rule updates. + /// - Returns: A JSON task that will return the updated rules. + func postSearchStreamRules(_ request: PostTweetsSearchStreamRulesRequestV2) -> TwitterAPISessionJSONTask { + return stream.postSearchStreamRules(request) + } + + /// Connects to the filtered stream of tweets. + /// - Parameter request: The request parameters for the filtered stream. + /// - Returns: A stream task that will provide filtered tweets in real-time. + func searchStream(_ request: GetTweetsSearchStreamRequestV2) -> TwitterAPISessionStreamTask { + return stream.searchStream(request) + } + + // MARK: - TimelineAPIv2 + + /// Retrieves tweets posted by a user. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the user's tweets. + func getUserTweets(_ request: GetUsersTweetsRequestV2) -> TwitterAPISessionJSONTask { + return timeline.getUserTweets(request) + } + + /// Retrieves tweets mentioning a user. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the mentions. + func getUserMensions(_ request: GetUsersMentionsRequestV2) -> TwitterAPISessionJSONTask { + return timeline.getUserMensions(request) + } + + /// Retrieves a user's reverse chronological timeline. + /// - Parameter request: The request parameters containing the user identifier. + /// - Returns: A JSON task that will return the timeline tweets. + func getUserReverseChronological(_ request: GetUsersTimelinesReverseChronologicalRequestV2) + -> TwitterAPISessionJSONTask + { + return timeline.getUserReverseChronological(request) + } + + // MARK: - TweetAPIv2 + + /// Retrieves multiple tweets by their IDs. + /// - Parameter request: The request parameters containing the tweet IDs. + /// - Returns: A JSON task that will return the tweets. + func getTweets(_ request: GetTweetsRequestV2) -> TwitterAPISessionJSONTask { + return tweet.getTweets(request) + } + + /// Retrieves a single tweet. + /// - Parameter request: The request parameters containing the tweet ID. + /// - Returns: A JSON task that will return the tweet. + func getTweet(_ request: GetTweetRequestV2) -> TwitterAPISessionJSONTask { + return tweet.getTweet(request) + } + + /// Retrieves tweets quoting a tweet. + /// - Parameter request: The request parameters containing the tweet ID. + /// - Returns: A JSON task that will return the quote tweets. + func getQuoteTweets(_ request: GetTweetsQuoteTweetsRequestV2) -> TwitterAPISessionJSONTask { + return tweet.getQuoteTweets(request) + } + + /// Deletes a tweet. + /// - Parameter request: The request parameters containing the tweet to delete. + /// - Returns: A JSON task that will return the response. + func deleteTweet(_ request: DeleteTweetRequestV2) -> TwitterAPISessionJSONTask { + return tweet.deleteTweet(request) + } + + /// Posts a new tweet. + /// - Parameter request: The request parameters containing the tweet content. + /// - Returns: A JSON task that will return the posted tweet. + func postTweet(_ request: PostTweetsRequestV2) -> TwitterAPISessionJSONTask { + return tweet.postTweet(request) + } + + /// Hides a reply to a tweet. + /// - Parameter request: The request parameters containing the reply to hide. + /// - Returns: A JSON task that will return the response. + func hideReply(_ request: PutTweetsHiddenRequestV2) -> TwitterAPISessionJSONTask { + return tweet.hideReply(request) + } + + // MARK: - TweetCountAPIv2 + + /// Retrieves count of recent tweets matching a query. + /// - Parameter request: The request parameters containing the search query. + /// - Returns: A JSON task that will return the tweet count. + func getTweetCountRecent(_ request: GetTweetsCountsRecentRequestV2) -> TwitterAPISessionJSONTask { + return tweetCount.getTweetCountRecent(request) + } + + /// Retrieves count of all tweets matching a query. + /// - Parameter request: The request parameters containing the search query. + /// - Returns: A JSON task that will return the tweet count. + func getTweetCountAll(_ request: GetTweetsCountsAllRequestV2) -> TwitterAPISessionJSONTask { + return tweetCount.getTweetCountAll(request) + } + + // MARK: - UserAPIv2 + + /// Retrieves information about a specific user. + /// - Parameter request: The request parameters containing the user ID. + /// - Returns: A JSON task that will return the user information. + func getUser(_ request: GetUserRequestV2) -> TwitterAPISessionJSONTask { + return user.getUser(request) + } + + /// Retrieves information about multiple users. + /// - Parameter request: The request parameters containing the user IDs. + /// - Returns: A JSON task that will return the users information. + func getUsers(_ request: GetUsersRequestV2) -> TwitterAPISessionJSONTask { + return user.getUsers(request) + } + + /// Retrieves a user by their username. + /// - Parameter request: The request parameters containing the username. + /// - Returns: A JSON task that will return the user information. + func getUserByUsername(_ request: GetUsersByUsernameRequestV2) -> TwitterAPISessionJSONTask { + return user.getUserByUsername(request) + } + + /// Retrieves multiple users by their usernames. + /// - Parameter request: The request parameters containing the usernames. + /// - Returns: A JSON task that will return the users information. + func getUsersByUsernames(_ request: GetUsersByRequestV2) -> TwitterAPISessionJSONTask { + return user.getUsersByUsernames(request) + } + + /// Retrieves information about the authenticated user. + /// - Parameter request: The request parameters for retrieving user information. + /// - Returns: A JSON task that will return the user information. + func getMe(_ request: GetUsersMeRequestV2) -> TwitterAPISessionJSONTask { + return user.getMe(request) + } + + // MARK: - DirectMessageAPIv2 + + /// Retrieves direct message events. + /// - Parameter request: The request parameters for retrieving DM events. + /// - Returns: A JSON task that will return the DM events. + func getDmEvents(_ request: GetDmEventsRequestV2) -> TwitterAPISessionJSONTask { + return dm.getDmEvents(request) + } + + /// Retrieves direct message events with a specific participant. + /// - Parameter request: The request parameters containing the participant ID. + /// - Returns: A JSON task that will return the DM events. + func getDmEventsWithParticipantId(_ request: GetDmConversationsWithParticipantIdDmEventsRequestV2) + -> TwitterAPISessionJSONTask + { + return dm.getDmEventsWithParticipantId(request) + } + + /// Retrieves direct message events from a specific conversation. + /// - Parameter request: The request parameters containing the conversation ID. + /// - Returns: A JSON task that will return the DM events. + func getDmEventsByConversationsId(_ request: GetDmConversationsIdDmEventsRequestV2) -> TwitterAPISessionJSONTask { + return dm.getDmEventsByConversationsId(request) + } + + /// Posts a new direct message conversation. + /// - Parameter request: The request parameters for creating a new conversation. + /// - Returns: A JSON task that will return the created conversation. + func postDmConversationById(_ request: PostDmConversationByIdRequestV2) -> TwitterAPISessionJSONTask { + return dm.postDmConversationById(request) + } + + /// Posts a new direct message conversation with a specific user. + /// - Parameter request: The request parameters containing the user and message. + /// - Returns: A JSON task that will return the created conversation. + func postDmConversationWithUser(_ request: PostDmConversationWithUserRequestV2) -> TwitterAPISessionJSONTask { + return dm.postDmConversationWithUser(request) + } + + /// Posts a new direct message conversation with multiple participants. + /// - Parameter request: The request parameters containing the participants and message. + /// - Returns: A JSON task that will return the created conversation. + func postDmConversation(_ request: PostDmConversationRequestV2) -> TwitterAPISessionJSONTask { + return dm.postDmConversation(request) + } +} diff --git a/Sources/TwitterAPIKit/TwitterAPIClient.swift b/Sources/TwitterAPIKit/TwitterAPIClient.swift index 521a766d..36b8ff05 100644 --- a/Sources/TwitterAPIKit/TwitterAPIClient.swift +++ b/Sources/TwitterAPIKit/TwitterAPIClient.swift @@ -1,7 +1,16 @@ +// TwitterAPIClient.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// Main client class for interacting with the Twitter API. +/// This class provides access to both v1.1 and v2 Twitter APIs, as well as authentication endpoints. +/// It handles authentication, request signing, and provides specialized API clients for different Twitter features. open class TwitterAPIClient { - + /// Default JSON decoder configured for Twitter API responses. + /// This decoder handles both v1 and v2 date formats and uses snake_case key decoding. public static var defaultJSONDecoder: JSONDecoder = { let decoder = JSONDecoder() decoder.keyDecodingStrategy = .convertFromSnakeCase @@ -28,24 +37,38 @@ open class TwitterAPIClient { return date } throw DecodingError.dataCorrupted( - .init(codingPath: decoder.codingPath, debugDescription: "Unexpected date format: \(dateStr)")) + .init(codingPath: decoder.codingPath, debugDescription: "Unexpected date format: \(dateStr)") + ) } return decoder }() + /// Client for handling Twitter authentication flows (OAuth 1.0a and OAuth 2.0). public let auth: TwitterAuthAPI + + /// Client for accessing Twitter API v1.1 endpoints. public let v1: TwitterAPIv1 + + /// Client for accessing Twitter API v2 endpoints. public let v2: TwitterAPIv2 + /// The session used for making API requests. public let session: TwitterAPISession + + /// The current authentication method being used. public var apiAuth: TwitterAuthenticationMethod { return session.auth } - /// for refresh token + /// Client used for refreshing OAuth 2.0 tokens. private var refreshOAuth20TokenClient: TwitterAPIClient? + /// Creates a new TwitterAPIClient instance. + /// - Parameters: + /// - auth: The authentication method to use for API requests. + /// - configuration: The URLSession configuration to use. Defaults to .default. + /// - environment: The Twitter API environment configuration. Defaults to standard Twitter endpoints. public init( _ auth: TwitterAuthenticationMethod, configuration: URLSessionConfiguration = .default, @@ -61,8 +84,13 @@ open class TwitterAPIClient { v2 = TwitterAPIv2(session: session) } - /// for OAuth1.0a - convenience public init( + /// Convenience initializer for OAuth 1.0a authentication. + /// - Parameters: + /// - consumerKey: The application's consumer key. + /// - consumerSecret: The application's consumer secret. + /// - oauthToken: The user's OAuth token. + /// - oauthTokenSecret: The user's OAuth token secret. + public convenience init( consumerKey: String, consumerSecret: String, oauthToken: String, @@ -75,23 +103,35 @@ open class TwitterAPIClient { consumerSecret: consumerSecret, oauthToken: oauthToken, oauthTokenSecret: oauthTokenSecret - )), + ) + ), environment: .init() ) } + + deinit { + // De-init Logic Here + } } // MARK: - Refresh OAuth2.0 token -extension TwitterAPIClient { - public typealias RefreshOAuth20TokenResultValue = (token: TwitterAuthenticationMethod.OAuth20, refreshed: Bool) - /// Refresh OAuth2.0 token - public func refreshOAuth20Token( +/// Extension providing OAuth 2.0 token refresh functionality. +public extension TwitterAPIClient { + /// Type alias for the result of a token refresh operation. + typealias RefreshOAuth20TokenResultValue = (token: TwitterAuthenticationMethod.OAuth20, refreshed: Bool) + + /// Refreshes the OAuth 2.0 access token if necessary. + /// - Parameters: + /// - type: The type of OAuth 2.0 client to use for token refresh. + /// - forceRefresh: Whether to force a token refresh even if the current token is still valid. + /// - block: Completion handler called with the result of the token refresh. + func refreshOAuth20Token( type: TwitterAuthenticationMethod.OAuth20WithPKCEClientType, forceRefresh: Bool = false, _ block: @escaping (Result) -> Void ) { - guard case .oauth20(let token) = apiAuth else { + guard case let .oauth20(token) = apiAuth else { block(.failure(.refreshOAuth20TokenFailed(reason: .invalidAuthenticationMethod(apiAuth)))) return } @@ -116,9 +156,9 @@ extension TwitterAPIClient { .init(refreshToken: refreshToken, clientID: token.clientID) ) .responseObject { [weak self] response in - guard let self = self else { return } + guard let self else { return } switch response.result { - case .success(let refreshedToken): + case let .success(refreshedToken): var token = token token.refresh(token: refreshedToken) self.session.refreshOAuth20Token(token) @@ -128,7 +168,7 @@ extension TwitterAPIClient { object: self, userInfo: [TwitterAPIClient.tokenUserInfoKey: token] ) - case .failure(let error): + case let .failure(error): block(.failure(error)) } self.refreshOAuth20TokenClient = nil @@ -136,15 +176,29 @@ extension TwitterAPIClient { } } +/// Base class for Twitter API clients. +/// Provides common functionality and session management for API clients. open class TwitterAPIBase { + /// The session used for making API requests. public let session: TwitterAPISession + + /// Creates a new TwitterAPIBase instance. + /// - Parameter session: The session to use for making API requests. public init(session: TwitterAPISession) { self.session = session } + + deinit { + // De-init Logic Here + } } -extension TwitterAPIClient { - // swift-format-ignore - public static let didRefreshOAuth20Token = Notification.Name(rawValue: "TwitterAPIKit.TwitterAPIClient.Notification.didRefreshOAuth20Token") - public static let tokenUserInfoKey = "TwitterAPIKit.TwitterAPIClient.UserInfoKey.tokenUser" +/// Extension providing notification names and user info keys for OAuth 2.0 token refresh events. +public extension TwitterAPIClient { + /// Notification posted when an OAuth 2.0 token is refreshed. + static let didRefreshOAuth20Token = Notification + .Name(rawValue: "TwitterAPIKit.TwitterAPIClient.Notification.didRefreshOAuth20Token") + + /// User info key for accessing the refreshed token in the notification. + static let tokenUserInfoKey = "TwitterAPIKit.TwitterAPIClient.UserInfoKey.tokenUser" } diff --git a/Sources/TwitterAPIKit/TwitterAPIErrorResponse.swift b/Sources/TwitterAPIKit/TwitterAPIErrorResponse.swift index f650680f..9172cb92 100644 --- a/Sources/TwitterAPIKit/TwitterAPIErrorResponse.swift +++ b/Sources/TwitterAPIKit/TwitterAPIErrorResponse.swift @@ -1,145 +1,208 @@ +// TwitterAPIErrorResponse.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// Represents error responses from the Twitter API. +/// This enum can handle both v1 and v2 API error formats, as well as unknown error responses. public enum TwitterAPIErrorResponse: Equatable { - case v1(TwitterAPIErrorResponseV1) - case v2(TwitterAPIErrorResponseV2) + /// An error response from the Twitter API v1.1. + case apiVersion1(TwitterAPIErrorResponseV1) + + /// An error response from the Twitter API v2. + case apiVersion2(TwitterAPIErrorResponseV2) + + /// An unknown error response containing raw data. case unknown(Data) + /// Creates a new TwitterAPIErrorResponse from raw response data. + /// Attempts to parse the data as either a v1 or v2 error response. + /// - Parameter data: The raw response data from the Twitter API. public init(data: Data) { guard let obj = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else { self = .unknown(data) return } - if let v1 = TwitterAPIErrorResponseV1(obj: obj) { - self = .v1(v1) - } else if let v2 = TwitterAPIErrorResponseV2(obj: obj) { - self = .v2(v2) + if let version1 = TwitterAPIErrorResponseV1(obj: obj) { + self = .apiVersion1(version1) + } else if let version2 = TwitterAPIErrorResponseV2(obj: obj) { + self = .apiVersion2(version2) } else { self = .unknown(data) } } } -extension TwitterAPIErrorResponse { - public var message: String { +public extension TwitterAPIErrorResponse { + /// The error message from the response. + /// For v1 errors, this is the first error message. + /// For v2 errors, this is the detail field. + /// For unknown errors, this is the raw data as a string. + var message: String { switch self { - case .v1(let twitterAPIErrorResponseV1): - return twitterAPIErrorResponseV1.message - case .v2(let twitterAPIErrorResponseV2): - return twitterAPIErrorResponseV2.detail - case .unknown(let data): + case let .apiVersion1(version1Response): + return version1Response.message + case let .apiVersion2(version2Response): + return version2Response.detail + case let .unknown(data): return String(data: data, encoding: .utf8) ?? "Unknown" } } - public var code: Int? { - if case .v1(let v1) = self { - return v1.code + /// The error code from the response. + /// Only available for v1 errors. + var code: Int? { + if case let .apiVersion1(version1) = self { + return version1.code } return nil } - public var isV1: Bool { - return v1 != nil + /// Indicates whether this is a v1 error response. + var isVersion1: Bool { + return version1 != nil } - public var v1: TwitterAPIErrorResponseV1? { - if case let .v1(v1) = self { - return v1 + /// The v1 error response if this is a v1 error, nil otherwise. + var version1: TwitterAPIErrorResponseV1? { + if case let .apiVersion1(version1) = self { + return version1 } return nil } - public var isV2: Bool { - return v2 != nil + /// Indicates whether this is a v2 error response. + var isVersion2: Bool { + return version2 != nil } - public var v2: TwitterAPIErrorResponseV2? { - if case let .v2(v2) = self { - return v2 + /// The v2 error response if this is a v2 error, nil otherwise. + var version2: TwitterAPIErrorResponseV2? { + if case let .apiVersion2(version2) = self { + return version2 } return nil } - public var isUnknown: Bool { + /// Indicates whether this is an unknown error response. + var isUnknown: Bool { return unknownData != nil } - public var unknownData: Data? { + /// The raw data if this is an unknown error, nil otherwise. + var unknownData: Data? { if case let .unknown(data) = self { return data } return nil } - } -/// https://developer.twitter.com/ja/docs/basics/response-codes +/// Represents an error response from the Twitter API v1.1. +/// Format: {"errors":[{"message":"Sorry, that page does not exist","code":34}]} public struct TwitterAPIErrorResponseV1 { - - /// first error message + /// The first error message in the response. public let message: String - /// first error code + + /// The first error code in the response. public let code: Int + + /// All errors included in the response. public let errors: [Self] + /// Creates a new TwitterAPIErrorResponseV1. + /// - Parameters: + /// - message: The error message. + /// - code: The error code. + /// - errors: Additional errors in the response. public init(message: String, code: Int, errors: [Self]) { self.message = message self.code = code self.errors = errors } - /// {"errors":[{"message":"Sorry, that page does not exist","code":34}]} + /// Creates a new TwitterAPIErrorResponseV1 from a dictionary. + /// - Parameter obj: A dictionary containing the error response data. + /// - Returns: An initialized error response if the dictionary contains valid data, nil otherwise. public init?(obj: [String: Any]) { guard let errors = obj["errors"] as? [[String: Any]] else { return nil } - let tErrors: [TwitterAPIErrorResponseV1] = errors.compactMap { error in + let tErrors: [Self] = errors.compactMap { error in guard let message = error["message"] as? String, let code = error["code"] as? Int else { return nil } - return TwitterAPIErrorResponseV1(message: message, code: code, errors: []) + return Self(message: message, code: code, errors: []) } guard !tErrors.isEmpty else { return nil } - self.message = tErrors[0].message - self.code = tErrors[0].code + message = tErrors[0].message + code = tErrors[0].code self.errors = tErrors } + /// Checks if this error response contains a specific error code. + /// - Parameter code: The error code to check for. + /// - Returns: true if the error code is present in this response or any nested errors. public func contains(code: Int) -> Bool { - return code == self.code || errors.contains(where: { $0.code == code }) + return code == self.code || errors.contains { $0.code == code } } } extension TwitterAPIErrorResponseV1: Equatable {} /// https://developer.twitter.com/en/support/twitter-api/error-troubleshooting +/// Represents an error response from the Twitter API v2. +/// See: https://developer.twitter.com/en/support/twitter-api/error-troubleshooting public struct TwitterAPIErrorResponseV2 { - + /// Represents a specific error in a v2 error response. public struct Error: Equatable { + /// The error message. public let message: String - public let parameters: [String /* paramter name */: [String] /* values */] - + + /// Additional parameters associated with the error. + public let parameters: [String: [String]] + + /// Creates a new Error. + /// - Parameters: + /// - message: The error message. + /// - parameters: Additional parameters describing the error. public init(message: String, parameters: [String: [String]]) { self.message = message self.parameters = parameters } + /// Creates a new Error from a dictionary. + /// - Parameter obj: A dictionary containing the error data. public init(obj: [String: Any]) { message = obj["message"].map { String(describing: $0) } ?? "" parameters = (obj["parameters"] as? [String: [String]]) ?? [:] } } + /// The title of the error. public let title: String + + /// A detailed description of the error. public let detail: String + + /// The type of error. public let type: String + + /// Specific errors included in the response. public let errors: [Error] + /// Creates a new TwitterAPIErrorResponseV2. + /// - Parameters: + /// - title: The error title. + /// - detail: The detailed error description. + /// - type: The error type. + /// - errors: Specific errors included in the response. public init( title: String, detail: String, @@ -152,11 +215,13 @@ public struct TwitterAPIErrorResponseV2 { self.errors = errors } + /// Creates a new TwitterAPIErrorResponseV2 from a dictionary. + /// - Parameter obj: A dictionary containing the error response data. + /// - Returns: An initialized error response if the dictionary contains valid data, nil otherwise. public init?(obj: [String: Any]) { - guard let title = obj["title"] as? String, - let detail = obj["detail"] as? String, - let type = obj["type"] as? String + let detail = obj["detail"] as? String, + let type = obj["type"] as? String else { return nil } diff --git a/Sources/TwitterAPIKit/TwitterAPIKit.swift b/Sources/TwitterAPIKit/TwitterAPIKit.swift index 7d93ccc8..d883daa9 100644 --- a/Sources/TwitterAPIKit/TwitterAPIKit.swift +++ b/Sources/TwitterAPIKit/TwitterAPIKit.swift @@ -1,20 +1,55 @@ +// TwitterAPIKit.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation #if canImport(FoundationNetworking) @_exported import FoundationNetworking #endif +/// A protocol that represents a Twitter API kit. +public protocol TwitterAPIKit { + /// The base URL for Twitter web services. + /// Default: "https://twitter.com" + var twitterURL: URL { get } + +} + +/// Specifies the type of Twitter API base URL to use. public enum TwitterBaseURLType { - case twitter + /// The main Twitter API endpoint (api.twitter.com). case api + + /// The Twitter web endpoint (twitter.com). + case twitter + + /// The Twitter media upload endpoint (upload.twitter.com). case upload } -public struct TwitterAPIEnvironment { - let twitterURL: URL - let apiURL: URL - let uploadURL: URL +/// Configuration for Twitter API endpoints. +/// This struct defines the base URLs used for different Twitter API services. +public struct TwitterAPIEnvironment: TwitterAPIKit { + /// The base URL for Twitter web services. + /// Default: "https://twitter.com" + public let twitterURL: URL + + /// The base URL for Twitter API services. + /// Default: "https://api.twitter.com" + public let apiURL: URL + + /// The base URL for Twitter media upload services. + /// Default: "https://upload.twitter.com" + public let uploadURL: URL + // swiftlint:disable force_unwrapping + /// Creates a new Twitter API environment configuration. + /// - Parameters: + /// - twitterURL: The base URL for Twitter web services. Defaults to "https://twitter.com". + /// - apiURL: The base URL for Twitter API services. Defaults to "https://api.twitter.com". + /// - uploadURL: The base URL for Twitter media upload services. Defaults to "https://upload.twitter.com". public init( twitterURL: URL = URL(string: "https://twitter.com")!, apiURL: URL = URL(string: "https://api.twitter.com")!, @@ -24,4 +59,5 @@ public struct TwitterAPIEnvironment { self.apiURL = apiURL self.uploadURL = uploadURL } + // swiftlint:enable force_unwrapping } diff --git a/Sources/TwitterAPIKit/TwitterAPIKitError.swift b/Sources/TwitterAPIKit/TwitterAPIKitError.swift index 44490a5a..9585d708 100644 --- a/Sources/TwitterAPIKit/TwitterAPIKitError.swift +++ b/Sources/TwitterAPIKit/TwitterAPIKitError.swift @@ -1,44 +1,74 @@ +// TwitterAPIKitError.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// Represents errors that can occur while using the Twitter API Kit. public enum TwitterAPIKitError: Error { - - case requestFailed(reason: RequestFailureReason) + /// Represents specific reasons why a request might fail. public enum RequestFailureReason { - case invalidURL(url: String) - case invalidParameter(parameter: [String: Any], cause: String) - + /// Indicates that a string could not be encoded to data. case cannotEncodeStringToData(string: String) + + /// Indicates that a parameter was invalid with details about why. + case invalidParameter(parameter: [String: Any], cause: String) + + /// Indicates that the provided URL was invalid. + case invalidURL(url: String) + + /// Indicates that JSON serialization failed for an object. case jsonSerializationFailed(obj: Any) } - case responseFailed(reason: ResponseFailureReason) + /// Represents specific reasons why a response might fail. public enum ResponseFailureReason { + /// Indicates that the response was invalid. case invalidResponse(error: Error?) + + /// Indicates that the response status code was unacceptable. case unacceptableStatusCode(statusCode: Int, error: TwitterAPIErrorResponse, rateLimit: TwitterRateLimit?) } - case responseSerializeFailed(reason: ResponseSerializationFailureReason) + /// Represents specific reasons why response serialization might fail. public enum ResponseSerializationFailureReason { - case jsonSerializationFailed(error: Error) - case jsonDecodeFailed(error: Error) + /// Indicates that data could not be converted to the expected type. case cannotConvert(data: Data, toTypeName: String) - } - case uploadMediaFailed(reason: UploadMediaFailureReason) - public enum UploadMediaFailureReason { - case processingFailed(error: UploadMediaError) + /// Indicates that JSON decoding failed. + case jsonDecodeFailed(error: Error) + + /// Indicates that JSON serialization failed. + case jsonSerializationFailed(error: Error) } - case refreshOAuth20TokenFailed(reason: RefreshOAuth20TokenFailureReason) + /// Represents specific reasons why OAuth 2.0 token refresh might fail. public enum RefreshOAuth20TokenFailureReason { + /// Indicates that the authentication method was invalid. case invalidAuthenticationMethod(TwitterAuthenticationMethod) + + /// Indicates that the refresh token is missing. case refreshTokenIsMissing } + /// Represents specific reasons why media upload might fail. + public enum UploadMediaFailureReason { + /// Indicates that media processing failed. + case processingFailed(error: UploadMediaError) + } + + case refreshOAuth20TokenFailed(reason: RefreshOAuth20TokenFailureReason) + case requestFailed(reason: RequestFailureReason) + case responseFailed(reason: ResponseFailureReason) + case responseSerializeFailed(reason: ResponseSerializationFailureReason) case unkonwn(error: Error) + case uploadMediaFailed(reason: UploadMediaFailureReason) + /// Initializes a TwitterAPIKitError from a generic Error. + /// - Parameter error: The error to convert to TwitterAPIKitError. public init(error: Error) { - if let error = error as? TwitterAPIKitError { + if let error = error as? Self { self = error } else { self = .unkonwn(error: error) @@ -46,55 +76,63 @@ public enum TwitterAPIKitError: Error { } } -extension TwitterAPIKitError { - public var isRequestFailed: Bool { +public extension TwitterAPIKitError { + /// Indicates whether the error is a request failure. + var isRequestFailed: Bool { if case .requestFailed = self { return true } return false } - public var isResponseFailed: Bool { + /// Indicates whether the error is a response failure. + var isResponseFailed: Bool { if case .responseFailed = self { return true } return false } - public var isResponseSerializeFailed: Bool { + /// Indicates whether the error is a response serialization failure. + var isResponseSerializeFailed: Bool { if case .responseSerializeFailed = self { return true } return false } - public var isUploadMediaFailed: Bool { + /// Indicates whether the error is a media upload failure. + var isUploadMediaFailed: Bool { if case .uploadMediaFailed = self { return true } return false } - public var isRefreshOAuth20TokenFailed: Bool { + /// Indicates whether the error is an OAuth 2.0 token refresh failure. + var isRefreshOAuth20TokenFailed: Bool { if case .refreshOAuth20TokenFailed = self { return true } return false } - public var isUnkonwn: Bool { + /// Indicates whether the error is unknown. + var isUnkonwn: Bool { if case .unkonwn = self { return true } return false } - public var underlyingError: Error? { + /// The underlying error if one exists. + var underlyingError: Error? { switch self { - case .requestFailed(let reason): + case let .requestFailed(reason): return reason.underlyingError - case .responseFailed(let reason): + case let .responseFailed(reason): return reason.underlyingError - case .responseSerializeFailed(let reason): + case let .responseSerializeFailed(reason): return reason.underlyingError - case .uploadMediaFailed(let reason): + case let .uploadMediaFailed(reason): return reason.underlyingError - case .refreshOAuth20TokenFailed(let reason): + case let .refreshOAuth20TokenFailed(reason): return reason.underlyingError - case .unkonwn(let error): + case let .unkonwn(error): return error } } - public var isCancelled: Bool { + /// Indicates whether the error was due to request cancellation. + var isCancelled: Bool { guard let error = underlyingError as? URLError else { return false } @@ -102,12 +140,23 @@ extension TwitterAPIKitError { } } -extension TwitterAPIKitError { - public struct UploadMediaError: Decodable, Error { +public extension TwitterAPIKitError { + /// Represents an error that occurred during media upload. + struct UploadMediaError: Decodable, Error { + /// The error code returned by the Twitter API. public let code: Int + + /// The name of the error. public let name: String + + /// A detailed message describing the error. public let message: String + /// Initializes a new UploadMediaError. + /// - Parameters: + /// - code: The error code + /// - name: The error name + /// - message: The error message public init(code: Int, name: String, message: String) { self.code = code self.name = name @@ -118,60 +167,63 @@ extension TwitterAPIKitError { extension TwitterAPIKitError: LocalizedError { public var errorDescription: String? { - switch self { - case .requestFailed(let reason): + case let .requestFailed(reason): return reason.localizedDescription - case .responseFailed(let reason): + case let .responseFailed(reason): return reason.localizedDescription - case .responseSerializeFailed(let reason): + case let .responseSerializeFailed(reason): return reason.localizedDescription - case .uploadMediaFailed(let reason): + case let .uploadMediaFailed(reason): return reason.localizedDescription - case .refreshOAuth20TokenFailed(let reason): + case let .refreshOAuth20TokenFailed(reason): return reason.localizedDescription - case .unkonwn(let error): + case let .unkonwn(error): return error.localizedDescription } } } extension TwitterAPIKitError.UploadMediaError: LocalizedError { + /// A localized description of the error. public var errorDescription: String? { return "\(name)[code:\(code)]: \(message)" } } -extension TwitterAPIKitError.RequestFailureReason { - public var localizedDescription: String { +public extension TwitterAPIKitError.RequestFailureReason { + /// A localized description of the request failure reason. + var localizedDescription: String { switch self { - case .invalidURL(let url): + case let .invalidURL(url): return "URL is not valid: \(url)" - case .invalidParameter(let parameter, let cause): + case let .invalidParameter(parameter, cause): return "Parameter is not valid: \(parameter), cause: \(cause)" - case .cannotEncodeStringToData(let string): + case let .cannotEncodeStringToData(string): return "Could not encode \"\(string)\"" - case .jsonSerializationFailed(let obj): + case let .jsonSerializationFailed(obj): return "JSON could not be serialized. May be invalid object \(String(describing: obj))" } } - public var underlyingError: Error? { + /// The underlying error if one exists. + var underlyingError: Error? { switch self { case .invalidURL, - .invalidParameter, - .cannotEncodeStringToData, - .jsonSerializationFailed: + .invalidParameter, + .cannotEncodeStringToData, + .jsonSerializationFailed: return nil } } } -extension TwitterAPIKitError.ResponseFailureReason { - public var localizedDescription: String { +public extension TwitterAPIKitError.ResponseFailureReason { + /// A localized description of the response failure reason. + var localizedDescription: String { switch self { case let .invalidResponse(error: error): - if let error = error { + if let error { return "Response is invalid: \(error.localizedDescription)" } return "Response is invalid" @@ -180,25 +232,26 @@ extension TwitterAPIKitError.ResponseFailureReason { } } - public var underlyingError: Error? { + /// The underlying error if one exists. + var underlyingError: Error? { switch self { case let .invalidResponse(error: error): return error - case .unacceptableStatusCode(statusCode: _, error: _, rateLimit: _): + case .unacceptableStatusCode: return nil } } - /// A status code in the case of unacceptableStatusCode. - public var statusCode: Int? { + /// The status code in the case of unacceptableStatusCode. + var statusCode: Int? { if case .unacceptableStatusCode(statusCode: let statusCode, error: _, rateLimit: _) = self { return statusCode } return nil } - /// A rate limit in the case of unacceptableStatusCode. - public var rateLimit: TwitterRateLimit? { + /// The rate limit in the case of unacceptableStatusCode. + var rateLimit: TwitterRateLimit? { if case .unacceptableStatusCode(statusCode: _, error: _, rateLimit: let rateLimit) = self { return rateLimit } @@ -206,22 +259,24 @@ extension TwitterAPIKitError.ResponseFailureReason { } } -extension TwitterAPIKitError.ResponseSerializationFailureReason { - public var localizedDescription: String { +public extension TwitterAPIKitError.ResponseSerializationFailureReason { + /// A localized description of the response serialization failure reason. + var localizedDescription: String { switch self { - case .jsonSerializationFailed(let error): + case let .jsonSerializationFailed(error): return "Response could not be serialized because of error:\n\(error.localizedDescription)" - case .jsonDecodeFailed(let error): + case let .jsonDecodeFailed(error): return "Response could not be decoded because of error:\n\(error.localizedDescription)" case .cannotConvert(data: _, let toTypeName): return "Response could not convert to \"\(toTypeName)\"" } } - public var underlyingError: Error? { + /// The underlying error if one exists. + var underlyingError: Error? { switch self { case let .jsonSerializationFailed(error: error), - let .jsonDecodeFailed(error: error): + let .jsonDecodeFailed(error: error): return error case .cannotConvert: return nil @@ -229,15 +284,17 @@ extension TwitterAPIKitError.ResponseSerializationFailureReason { } } -extension TwitterAPIKitError.UploadMediaFailureReason { - public var localizedDescription: String { +public extension TwitterAPIKitError.UploadMediaFailureReason { + /// A localized description of the upload media failure reason. + var localizedDescription: String { switch self { - case .processingFailed(let error): + case let .processingFailed(error): return error.message } } - public var underlyingError: Error? { + /// The underlying error if one exists. + var underlyingError: Error? { switch self { case let .processingFailed(error: error): return error @@ -245,17 +302,22 @@ extension TwitterAPIKitError.UploadMediaFailureReason { } } -extension TwitterAPIKitError.RefreshOAuth20TokenFailureReason { - public var localizedDescription: String { +public extension TwitterAPIKitError.RefreshOAuth20TokenFailureReason { + /// A localized description of the refresh OAuth 2.0 token failure reason. + var localizedDescription: String { switch self { - case .invalidAuthenticationMethod(let method): - return - "Token refresh is possible only when TwitterAuthenticationMethod is .oauth20. You are currently \(method)." + case let .invalidAuthenticationMethod(method): + return """ + Token refresh is possible only when TwitterAuthenticationMethod is .oauth20. \ + You are currently \(method). + """ case .refreshTokenIsMissing: return "Refresh token is missing." } } - public var underlyingError: Error? { + + /// The underlying error if one exists. + var underlyingError: Error? { switch self { case .invalidAuthenticationMethod, .refreshTokenIsMissing: return nil @@ -263,25 +325,39 @@ extension TwitterAPIKitError.RefreshOAuth20TokenFailureReason { } } -extension TwitterAPIKitError { +public extension TwitterAPIKitError { + /// Returns the request failure reason if this error represents a request failure. + /// - Returns: The `RequestFailureReason` if present, nil otherwise. + var requestFailureReason: RequestFailureReason? { + guard case let .requestFailed(reason: reason) = self else { return nil } + return reason + } - public var requestFailureReason: RequestFailureReason? { - guard case .requestFailed(reason: let reason) = self else { return nil } + /// Returns the response failure reason if this error represents a response failure. + /// - Returns: The `ResponseFailureReason` if present, nil otherwise. + var responseFailureReason: ResponseFailureReason? { + guard case let .responseFailed(reason) = self else { return nil } return reason } - public var responseFailureReason: ResponseFailureReason? { - guard case .responseFailed(let reason) = self else { return nil } + /// Returns the response serialization failure reason if this error represents a serialization failure. + /// - Returns: The `ResponseSerializationFailureReason` if present, nil otherwise. + var responseSerializationFailureReason: ResponseSerializationFailureReason? { + guard case let .responseSerializeFailed(reason) = self else { return nil } return reason } - public var responseSerializationFailureReason: ResponseSerializationFailureReason? { - guard case .responseSerializeFailed(let reason) = self else { return nil } + /// Returns the OAuth 2.0 token refresh failure reason if this error represents a token refresh failure. + /// - Returns: The `RefreshOAuth20TokenFailureReason` if present, nil otherwise. + var refreshOAuth20TokenFailureReason: RefreshOAuth20TokenFailureReason? { + guard case let .refreshOAuth20TokenFailed(reason) = self else { return nil } return reason } - public var refreshOAuth20TokenFailureReason: RefreshOAuth20TokenFailureReason? { - guard case .refreshOAuth20TokenFailed(let reason) = self else { return nil } + /// Returns the upload media failure reason if this error represents a media upload failure. + /// - Returns: The `UploadMediaFailureReason` if present, nil otherwise. + var uploadMediaFailureReason: UploadMediaFailureReason? { + guard case let .uploadMediaFailed(reason) = self else { return nil } return reason } } diff --git a/Sources/TwitterAPIKit/TwitterAPIRequest.swift b/Sources/TwitterAPIKit/TwitterAPIRequest.swift index 3bbbf392..b88c878c 100644 --- a/Sources/TwitterAPIKit/TwitterAPIRequest.swift +++ b/Sources/TwitterAPIKit/TwitterAPIRequest.swift @@ -1,11 +1,22 @@ +// TwitterAPIRequest.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// Represents HTTP methods supported by the Twitter API. public enum HTTPMethod: String { + /// DELETE method, typically used for removing resources. + case delete = "DELETE" + /// GET method, typically used for retrieving resources. case get = "GET" + /// POST method, typically used for creating new resources. case post = "POST" + /// PUT method, typically used for updating existing resources. case put = "PUT" - case delete = "DELETE" + /// Indicates whether the method prefers parameters to be sent as query parameters. public var prefersQueryParameters: Bool { switch self { case .get, .delete: @@ -16,24 +27,33 @@ public enum HTTPMethod: String { } } +/// Represents the content type of the request body. public enum BodyContentType: String { - case wwwFormUrlEncoded = "application/x-www-form-urlencoded" - - /// In this case use MultipartFormDataPart as a parameter - /// example: UploadMediaAppendRequestV1.swift - case multipartFormData = "multipart/form-data" + /// JSON content type with UTF-8 encoding. case json = "application/json; charset=UTF-8" + + /// Multipart form data content type, used for file uploads. + /// Use MultipartFormDataPart as a parameter. + /// Example: UploadMediaAppendRequestV1.swift + case multipartFormData = "multipart/form-data" + + /// URL-encoded form data content type. + case wwwFormUrlEncoded = "application/x-www-form-urlencoded" } +/// Represents a part of a multipart form data request. public enum MultipartFormDataPart { - case value(name: String, value: Any) // value is stringified with "String(describing:)" + /// A file upload part containing binary data and metadata. case data(name: String, value: Data, filename: String, mimeType: String) - var name: String { + /// A simple key-value pair where the value is stringified using String(describing:). + case value(name: String, value: Any) + /// The name of the form part. + public var name: String { switch self { - case .value(let name, _): + case let .value(name, _): return name - case .data(let name, _, _, _): + case let .data(name, _, _, _): return name } } @@ -42,53 +62,85 @@ public enum MultipartFormDataPart { extension MultipartFormDataPart: Equatable { public static func == (lhs: MultipartFormDataPart, rhs: MultipartFormDataPart) -> Bool { switch (lhs, rhs) { - case let (.value(name: ln, value: lv), .value(name: rn, value: rv)): - return ln == rn && type(of: lv) == type(of: rv) && String(describing: lv) == String(describing: rv) + case let (.value(name: leftName, value: leftValue), .value(name: rightName, value: rightValue)): + return leftName == rightName + && type(of: leftValue) == type(of: rightValue) + && String(describing: leftValue) == String(describing: rightValue) case let ( - .data(name: ln, value: lv, filename: lf, mimeType: lm), - .data(name: rn, value: rv, filename: rf, mimeType: rm) + .data( + name: leftName, + value: leftValue, + filename: leftFilename, + mimeType: leftMimeType + ), + .data( + name: rightName, + value: rightValue, + filename: rightFilename, + mimeType: rightMimeType + ) ): - return ln == rn - && lv == rv - && lf == rf - && lm == rm + return leftName == rightName + && leftValue == rightValue + && leftFilename == rightFilename + && leftMimeType == rightMimeType default: return false } } } +/// Protocol defining the requirements for a Twitter API request. public protocol TwitterAPIRequest { + /// The HTTP method to be used for the request. var method: HTTPMethod { get } + + /// The base URL type for the request (api, upload, etc.). var baseURLType: TwitterBaseURLType { get } + + /// The path component of the request URL. var path: String { get } + + /// The complete set of parameters for the request. var parameters: [String: Any] { get } + + /// Parameters to be included in the URL query string. var queryParameters: [String: Any] { get } + + /// Parameters to be included in the request body. var bodyParameters: [String: Any] { get } + + /// The content type of the request body. var bodyContentType: BodyContentType { get } } -extension TwitterAPIRequest { - public var baseURLType: TwitterBaseURLType { +/// Default implementations for TwitterAPIRequest. +public extension TwitterAPIRequest { + /// Default base URL type is .api. + var baseURLType: TwitterBaseURLType { return .api } - public var bodyContentType: BodyContentType { + /// Default body content type is .wwwFormUrlEncoded. + var bodyContentType: BodyContentType { return .wwwFormUrlEncoded } - public var parameters: [String: Any] { + /// Default parameters is an empty dictionary. + var parameters: [String: Any] { return [:] } - public var queryParameters: [String: Any] { + /// Query parameters are derived from parameters if the method prefers query parameters. + var queryParameters: [String: Any] { if method.prefersQueryParameters { return parameters } return [:] } - public var bodyParameters: [String: Any] { + /// Body parameters are derived from parameters if the method doesn't prefer query parameters. + var bodyParameters: [String: Any] { if !method.prefersQueryParameters { return parameters } @@ -97,9 +149,11 @@ extension TwitterAPIRequest { } extension TwitterAPIRequest { - - func buildRequest(environment: TwitterAPIEnvironment) throws -> URLRequest { - + /// Builds a URL request for the given environment. + /// - Parameters: + /// - environment: The environment to build the request for. + /// - Returns: A URL request. + public func buildRequest(environment: TwitterAPIEnvironment) throws -> URLRequest { guard var urlComponent = URLComponents( url: requestURL(for: environment), @@ -111,15 +165,17 @@ extension TwitterAPIRequest { if !queryParameters.isEmpty { urlComponent.percentEncodedQueryItems = queryParameters - .sorted(by: { a, b in a.key < b.key }) - .map { .init(name: $0.urlEncodedString, value: "\($1)".urlEncodedString) } + .sorted { first, second in first.key < second.key } + .map { .init(name: $0.urlEncodedString, value: "\($1)".urlEncodedString) } } - var request = URLRequest(url: urlComponent.url!) + guard let url = urlComponent.url else { + throw TwitterAPIKitError.requestFailed(reason: .invalidURL(url: "")) + } + var request = URLRequest(url: url) request.httpMethod = method.rawValue if !bodyParameters.isEmpty { - switch bodyContentType { case .wwwFormUrlEncoded: request.setValue(bodyContentType.rawValue, forHTTPHeaderField: "Content-Type") @@ -134,9 +190,12 @@ extension TwitterAPIRequest { throw TwitterAPIKitError.requestFailed( reason: .invalidParameter( parameter: bodyParameters, - cause: - "Parameter must be specified in `MultipartFormDataPart` for `BodyContentType.multipartFormData`." - )) + cause: """ + Parameter must be specified in `MultipartFormDataPart` \ + for `BodyContentType.multipartFormData`. + """ + ) + ) } let boundary = "TwitterAPIKit-\(UUID().uuidString)" @@ -144,9 +203,11 @@ extension TwitterAPIRequest { request.setValue(contentType, forHTTPHeaderField: "Content-Type") request.httpBody = try multipartFormData( - boundary: boundary, parts: parts.sorted(by: { $0.name < $1.name })) + boundary: boundary, parts: parts.sorted { $0.name < $1.name } + ) request.setValue( - String(request.httpBody?.count ?? 0), forHTTPHeaderField: "Content-Length") + String(request.httpBody?.count ?? 0), forHTTPHeaderField: "Content-Length" + ) case .json: let param = bodyParameters @@ -168,11 +229,13 @@ extension TwitterAPIRequest { return request } - func requestURL(for environment: TwitterAPIEnvironment) -> URL { + /// Returns the URL for the request. + public func requestURL(for environment: TwitterAPIEnvironment) -> URL { return environment.baseURL(for: baseURLType).appendingPathComponent(path) } - var parameterForOAuth: [String: Any] { + /// Returns the parameters for OAuth. + public var parameterForOAuth: [String: Any] { switch bodyContentType { case .wwwFormUrlEncoded: return parameters @@ -224,8 +287,8 @@ extension TwitterAPIRequest { } } -extension TwitterAPIEnvironment { - fileprivate func baseURL(for type: TwitterBaseURLType) -> URL { +private extension TwitterAPIEnvironment { + func baseURL(for type: TwitterBaseURLType) -> URL { switch type { case .twitter: return twitterURL case .api: return apiURL @@ -234,8 +297,8 @@ extension TwitterAPIEnvironment { } } -extension Data { - fileprivate mutating func appendBody(_ string: String) throws { +private extension Data { + mutating func appendBody(_ string: String) throws { if let data = string.data(using: .utf8) { append(data) } else { diff --git a/Sources/TwitterAPIKit/TwitterAPIResponse.swift b/Sources/TwitterAPIKit/TwitterAPIResponse.swift index 511c1b81..af4fe469 100644 --- a/Sources/TwitterAPIKit/TwitterAPIResponse.swift +++ b/Sources/TwitterAPIKit/TwitterAPIResponse.swift @@ -1,17 +1,43 @@ +// TwitterAPIResponse.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// A generic response type that encapsulates the result of a Twitter API request. public struct TwitterAPIResponse { + /// The original URL request that was sent to the Twitter API. public let request: URLRequest? + + /// The HTTP response received from the Twitter API. public let response: HTTPURLResponse? + /// The raw data received in the response. public let data: Data? + + /// The result of the API call, containing either the successful response or an error. public let result: Result + + /// Rate limit information returned by the Twitter API. public let rateLimit: TwitterRateLimit? + /// The successful response value if the request succeeded, nil otherwise. public var success: Success? { return result.success } + + /// The error that occurred during the request, if any. public var error: TwitterAPIKitError? { return result.error } + + /// A boolean indicating whether the request resulted in an error. public var isError: Bool { return error != nil } + /// Creates a new TwitterAPIResponse instance. + /// - Parameters: + /// - request: The original URL request sent to the API. + /// - response: The HTTP response received from the API. + /// - data: The raw data received in the response. + /// - result: The result containing either success or error. + /// - rateLimit: Rate limit information from the API. public init( request: URLRequest?, response: HTTPURLResponse?, @@ -27,9 +53,11 @@ public struct TwitterAPIResponse { } } -extension TwitterAPIResponse { - - public func map(_ transform: (Success) -> NewSuccess) -> TwitterAPIResponse { +public extension TwitterAPIResponse { + /// Transforms the successful result to a new type using the provided transform function. + /// - Parameter transform: A closure that takes the current success value and returns a new value. + /// - Returns: A new TwitterAPIResponse with the transformed success type. + func map(_ transform: (Success) -> NewSuccess) -> TwitterAPIResponse { return .init( request: request, response: response, @@ -39,7 +67,10 @@ extension TwitterAPIResponse { ) } - public func flatMap(_ transform: (Success) -> Result) + /// Transforms the successful result to a new type using a transform function that can return a Result. + /// - Parameter transform: A closure that takes the current success value and returns a Result. + /// - Returns: A new TwitterAPIResponse with the transformed success type. + func flatMap(_ transform: (Success) -> Result) -> TwitterAPIResponse { return .init( @@ -51,12 +82,15 @@ extension TwitterAPIResponse { ) } - public func tryMap(_ transform: (Success) throws -> NewSuccess) -> TwitterAPIResponse { + /// Transforms the successful result to a new type using a transform function that can throw errors. + /// - Parameter transform: A closure that takes the current success value and can throw an error. + /// - Returns: A new TwitterAPIResponse with the transformed success type. + func tryMap(_ transform: (Success) throws -> NewSuccess) -> TwitterAPIResponse { let nextResult: Result = result.flatMap { data in - let r: Result = .init { - return try transform(data) + let result: Result = .init { + try transform(data) } - return r.mapError { TwitterAPIKitError(error: $0) } + return result.mapError { TwitterAPIKitError(error: $0) } } return .init( request: request, @@ -67,7 +101,10 @@ extension TwitterAPIResponse { ) } - public func mapError(_ tranform: (TwitterAPIKitError) -> TwitterAPIKitError) -> TwitterAPIResponse { + /// Transforms the error in the response using the provided transform function. + /// - Parameter tranform: A closure that takes the current error and returns a new error. + /// - Returns: A new TwitterAPIResponse with the transformed error. + func mapError(_ tranform: (TwitterAPIKitError) -> TwitterAPIKitError) -> TwitterAPIResponse { return .init( request: request, response: response, @@ -75,21 +112,26 @@ extension TwitterAPIResponse { result: result.mapError(tranform), rateLimit: rateLimit ) - } } -extension TwitterAPIResponse { - - /// for debug - public var prettyString: String { - +public extension TwitterAPIResponse { + /// Returns a formatted string representation of the API response for debugging purposes. + /// The string includes: + /// - Request method and URL + /// - Request headers (Content-Type, Content-Length) + /// - Response status code + /// - Response headers + /// - Rate limit information + /// - Response body (prettified if JSON) + /// - Error description (if any) + var prettyString: String { let body = data.map { data in // make pretty if let json = try? JSONSerialization.jsonObject(with: data, options: []), - let jsonData = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) + let jsonData = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) { return String(data: jsonData, encoding: .utf8) ?? "" } else { @@ -108,8 +150,8 @@ extension TwitterAPIResponse { let responseContentLength = "< Content-Length: \(response?.allHeaderFields["Content-Length"] ?? "No Content-Length")" - switch self.result { - case .failure(let error): + switch result { + case let .failure(error): return "-- Request failure --" + "\n\(request)" + "\n\(contentType)" @@ -120,7 +162,7 @@ extension TwitterAPIResponse { + "\n\(rateLimitStr)" + "\n\(error.localizedDescription)" + "\n<" - + "\n\(body.count == 0 ? "Empty body" : body.unescapeSlash)" + + "\n\(body.isEmpty ? "Empty body" : body.unescapeSlash)" case .success: return "-- Request success --" + "\n\(request)" @@ -131,18 +173,17 @@ extension TwitterAPIResponse { + "\n\(responseContentLength)" + "\n\(rateLimitStr)" + "\n<" - + "\n\(body.count == 0 ? "Empty body" : body.unescapeSlash)" + + "\n\(body.isEmpty ? "Empty body" : body.unescapeSlash)" } } } -extension String { - - fileprivate var unescapeSlash: String { +private extension String { + var unescapeSlash: String { return replacingOccurrences(of: #"\/"#, with: #"/"#) } - fileprivate var unescapingUnicodeCharacters: String { + var unescapingUnicodeCharacters: String { #if os(Linux) return self #else diff --git a/Sources/TwitterAPIKit/TwitterAPISession.swift b/Sources/TwitterAPIKit/TwitterAPISession.swift index fa9bdf14..8593b6e3 100644 --- a/Sources/TwitterAPIKit/TwitterAPISession.swift +++ b/Sources/TwitterAPIKit/TwitterAPISession.swift @@ -1,18 +1,37 @@ +// TwitterAPISession.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation +/// A session class that handles Twitter API requests and authentication. +/// This class manages the authentication state, network requests, and environment configuration. open class TwitterAPISession { - + /// The current authentication method being used for API requests. + /// This property can be read publicly but only modified internally. public private(set) var auth: TwitterAuthenticationMethod + + /// The URLSession instance used for making network requests. public let session: URLSession + + /// The Twitter API environment configuration (e.g., API endpoints, version). public let environment: TwitterAPIEnvironment - let sessionDelegate = TwitterAPISessionDelegate() + + internal let sessionDelegate = TwitterAPISessionDelegate() + + /// Creates a new TwitterAPISession instance. + /// - Parameters: + /// - auth: The authentication method to use for API requests. + /// - configuration: The URLSession configuration to use for network requests. + /// - environment: The Twitter API environment configuration. public init( auth: TwitterAuthenticationMethod, configuration: URLSessionConfiguration, environment: TwitterAPIEnvironment ) { self.auth = auth - self.session = URLSession(configuration: configuration, delegate: sessionDelegate, delegateQueue: nil) + session = URLSession(configuration: configuration, delegate: sessionDelegate, delegateQueue: nil) self.environment = environment } @@ -20,29 +39,33 @@ open class TwitterAPISession { session.invalidateAndCancel() } + /// Sends a Twitter API request and returns a JSON task. + /// - Parameter request: The Twitter API request to send. + /// - Returns: A task that will return JSON data when completed. public func send(_ request: TwitterAPIRequest) -> TwitterAPISessionJSONTask { - do { let urlRequest: URLRequest = try tryBuildURLRequest(request) let task = session.dataTask(with: urlRequest) return sessionDelegate.appendAndResume(task: task) - } catch let error { + } catch { return TwitterAPIFailedTask(.init(error: error)) } } + /// Sends a streaming Twitter API request. + /// - Parameter streamRequest: The Twitter API request to stream. + /// - Returns: A task that will stream data continuously. public func send(streamRequest: TwitterAPIRequest) -> TwitterAPISessionStreamTask { do { let urlRequest: URLRequest = try tryBuildURLRequest(streamRequest) let task = session.dataTask(with: urlRequest) return sessionDelegate.appendAndResumeStream(task: task) - } catch let error { + } catch { return TwitterAPIFailedTask(.init(error: error)) } } private func tryBuildURLRequest(_ request: TwitterAPIRequest) throws -> URLRequest { - var urlRequest = try request.buildRequest(environment: environment) switch auth { @@ -79,7 +102,7 @@ open class TwitterAPISession { urlRequest.setValue("Bearer \(oauth20.accessToken)", forHTTPHeaderField: "Authorization") case let .requestOAuth20WithPKCE(.confidentialClient(clientID: apiKey, clientSecret: apiSecretKey)), - let .basic(apiKey: apiKey, apiSecretKey: apiSecretKey): + let .basic(apiKey: apiKey, apiSecretKey: apiSecretKey): let credential = "\(apiKey):\(apiSecretKey)" guard let credentialData = credential.data(using: .utf8) else { @@ -98,7 +121,7 @@ open class TwitterAPISession { return urlRequest } - func refreshOAuth20Token(_ refreshedToken: TwitterAuthenticationMethod.OAuth20) { + internal func refreshOAuth20Token(_ refreshedToken: TwitterAuthenticationMethod.OAuth20) { guard case .oauth20 = auth else { return } diff --git a/Sources/TwitterAPIKit/TwitterAPISessionDelegate.swift b/Sources/TwitterAPIKit/TwitterAPISessionDelegate.swift index 39ce654c..a70a8324 100644 --- a/Sources/TwitterAPIKit/TwitterAPISessionDelegate.swift +++ b/Sources/TwitterAPIKit/TwitterAPISessionDelegate.swift @@ -1,20 +1,28 @@ -import Foundation +// TwitterAPISessionDelegate.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. -protocol TwitterAPISessionDelegatedTask { +import Foundation +/// Protocol for delegated tasks that can receive data in chunks and handle completion +public protocol TwitterAPISessionDelegatedTask { + /// The unique identifier for this task var taskIdentifier: Int { get } - + + /// Appends a chunk of data received from the network + /// - Parameter chunk: The data chunk to append func append(chunk: Data) - + + /// Called when the task completes, with an optional error + /// - Parameter error: The error that occurred, if any func complete(error: Error?) } -class TwitterAPISessionDelegate: NSObject, URLSessionDataDelegate { - +public class TwitterAPISessionDelegate: NSObject, URLSessionDataDelegate { private var tasks = [Int /* taskIdentifier */: TwitterAPISessionDelegatedTask]() - func appendAndResume(task: URLSessionTask) -> TwitterAPISessionJSONTask { - + public func appendAndResume(task: URLSessionTask) -> TwitterAPISessionJSONTask { let twTask = TwitterAPISessionDelegatedJSONTask(task: task) twTask.delegate = self tasks[task.taskIdentifier] = twTask @@ -24,28 +32,30 @@ class TwitterAPISessionDelegate: NSObject, URLSessionDataDelegate { return twTask } - func appendAndResumeStream(task: URLSessionTask) -> TwitterAPISessionDelegatedStreamTask { + public func appendAndResumeStream(task: URLSessionTask) -> TwitterAPISessionDelegatedStreamTask { let twTask = TwitterAPISessionDelegatedStreamTask(task: task) tasks[task.taskIdentifier] = twTask task.resume() return twTask } - func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) { - + public func urlSession(_: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) { tasks[dataTask.taskIdentifier]?.append(chunk: data) } - func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) { - + public func urlSession(_: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) { guard let task = tasks[task.taskIdentifier] else { return } task.complete(error: error) } + + deinit { + // De-init Logic Here + } } extension TwitterAPISessionDelegate: TwitterAPISessionDelegatedJSONTaskDelegate { - func didFinishQueueInJsonTask(task: TwitterAPISessionDelegatedJSONTask) { + public func didFinishQueueInJsonTask(task: TwitterAPISessionDelegatedJSONTask) { tasks[task.taskIdentifier] = nil } } diff --git a/Sources/TwitterAPIKit/TwitterAuthenticationMethod.swift b/Sources/TwitterAPIKit/TwitterAuthenticationMethod.swift index 1a7b6096..2875ccdf 100644 --- a/Sources/TwitterAPIKit/TwitterAuthenticationMethod.swift +++ b/Sources/TwitterAPIKit/TwitterAuthenticationMethod.swift @@ -1,8 +1,25 @@ +// TwitterAuthenticationMethod.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -public enum TwitterAuthenticationMethod { - case none +/// Represents different methods of authentication available for Twitter API requests. +public enum TwitterAuthenticationMethod { + // swiftlint:disable sorted_enum_cases + /// No authentication method specified. + case basic(apiKey: String, apiSecretKey: String) + /// Bearer token authentication for OAuth2 app-only access. + case bearer(String) + + // swiftlint:disable discouraged_none_name + /// No authentication required. + case `none` + // swiftlint:enable discouraged_none_name + + /// Authentication using OAuth 1.0a protocol (legacy). @available(*, deprecated, renamed: "oauth10a") case oauth( consumerKey: String, @@ -10,28 +27,40 @@ public enum TwitterAuthenticationMethod { oauthToken: String?, oauthTokenSecret: String? ) - /// Use the token created by "3-legged OAuth flow". + + /// Authentication using OAuth 1.0a protocol. case oauth10a(OAuth10a) - /// Use the token created by "OAuth 2.0 Authorization Code Flow with PKCE". + /// Authentication using OAuth 2.0 protocol. case oauth20(OAuth20) - // Used to execute the "OAuth 2.0 Authorization Code Flow with PKCE" authentication flow. + /// Used to execute the OAuth 2.0 Authorization Code Flow with PKCE authentication flow. case requestOAuth20WithPKCE(OAuth20WithPKCEClientType) - - case basic(apiKey: String, apiSecretKey: String) - - /// For OAuth2 app-only - case bearer(String) + // swiftlint:enable sorted_enum_cases } -extension TwitterAuthenticationMethod { - public struct OAuth10a: Codable { +/// Extension containing OAuth-related types and functionality. +public extension TwitterAuthenticationMethod { + /// Represents OAuth 1.0a authentication credentials. + struct OAuth10a: Codable { + /// The consumer key (API key) provided by Twitter. public var consumerKey: String + + /// The consumer secret (API secret key) provided by Twitter. public var consumerSecret: String + + /// The OAuth token obtained after user authorization. public var oauthToken: String? + + /// The OAuth token secret obtained after user authorization. public var oauthTokenSecret: String? + /// Initializes a new OAuth10a authentication structure. + /// - Parameters: + /// - consumerKey: The consumer key (API key) provided by Twitter + /// - consumerSecret: The consumer secret (API secret key) provided by Twitter + /// - oauthToken: The OAuth token obtained after user authorization + /// - oauthTokenSecret: The OAuth token secret obtained after user authorization public init( consumerKey: String, consumerSecret: String, @@ -45,28 +74,50 @@ extension TwitterAuthenticationMethod { } } - public struct OAuth20: Codable { + /// Represents OAuth 2.0 authentication credentials and state. + struct OAuth20: Codable { + /// The client ID provided by Twitter. public var clientID: String - public var scope: [String] - public var tokenType: String + + /// The creation timestamp of the token. + public var createdAt: Date + + /// The time in seconds until the token expires. public var expiresIn: Int + + /// The OAuth 2.0 access token. public var accessToken: String - - /// Only Public Client + + /// The refresh token for obtaining new access tokens (only for Public Client). public var refreshToken: String? - - public var createdAt: Date + + /// The authorized scopes for this token. + public var scope: [String] + + /// The type of token (usually "bearer"). + public var tokenType: String /// Estimates the expiration time of a token based on "expiresIn" and "createdAt". - /// Since the server response does not include the creation time of the token, it contains a margin of error of a few seconds. + /// Since the server response does not include the creation time of the token, it contains a margin of error of + /// a few seconds. public var expiresAt: Date { return createdAt.addingTimeInterval(TimeInterval(expiresIn)) } + /// Indicates whether the token has expired. public var expired: Bool { return expiresAt <= Date() } + /// Initializes a new OAuth20 authentication structure. + /// - Parameters: + /// - clientID: The client ID provided by Twitter + /// - scope: The authorized scopes for this token + /// - tokenType: The type of token (usually "bearer") + /// - expiresIn: The time in seconds until the token expires + /// - accessToken: The OAuth 2.0 access token + /// - refreshToken: The refresh token for obtaining new access tokens + /// - createdAt: The creation timestamp of the token public init( clientID: String, scope: [String], @@ -85,6 +136,11 @@ extension TwitterAuthenticationMethod { self.createdAt = createdAt } + /// Initializes a new OAuth20 authentication structure from a Twitter OAuth2 access token. + /// - Parameters: + /// - clientID: The client ID provided by Twitter + /// - token: The Twitter OAuth2 access token + /// - createdAt: The creation timestamp of the token public init(clientID: String, token: TwitterOAuth2AccessToken, createdAt: Date = Date()) { self.init( clientID: clientID, @@ -97,18 +153,25 @@ extension TwitterAuthenticationMethod { ) } - mutating public func refresh(token: TwitterOAuth2AccessToken, refreshedAt: Date = Date()) { - self.scope = token.scope - self.tokenType = token.tokenType - self.expiresIn = token.expiresIn - self.accessToken = token.accessToken - self.refreshToken = token.refreshToken - self.createdAt = refreshedAt + /// Refreshes the OAuth20 token with new values. + /// - Parameters: + /// - token: The new Twitter OAuth2 access token + /// - refreshedAt: The timestamp when the token was refreshed + public mutating func refresh(token: TwitterOAuth2AccessToken, refreshedAt: Date = Date()) { + scope = token.scope + tokenType = token.tokenType + expiresIn = token.expiresIn + accessToken = token.accessToken + refreshToken = token.refreshToken + createdAt = refreshedAt } } - public enum OAuth20WithPKCEClientType { + /// Represents the client type for OAuth 2.0 with PKCE flow. + enum OAuth20WithPKCEClientType { + /// A confidential client with client ID and secret. case confidentialClient(clientID: String, clientSecret: String) + /// A public client without a client secret. case publicClient } } diff --git a/Sources/TwitterAPIKit/TwitterRateLimit.swift b/Sources/TwitterAPIKit/TwitterRateLimit.swift index 96f78027..aaee71af 100644 --- a/Sources/TwitterAPIKit/TwitterRateLimit.swift +++ b/Sources/TwitterAPIKit/TwitterRateLimit.swift @@ -1,20 +1,36 @@ +// TwitterRateLimit.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation -/// https://developer.twitter.com/en/docs/rate-limits -/// https://developer.twitter.com/en/docs/twitter-api/v1/rate-limits -/// https://developer.twitter.com/en/docs/twitter-api/rate-limits +/// Represents Twitter API rate limit information extracted from response headers. +/// For more information, see: +/// - [Rate Limits Overview](https://developer.twitter.com/en/docs/rate-limits) +/// - [v1 Rate Limits](https://developer.twitter.com/en/docs/twitter-api/v1/rate-limits) +/// - [v2 Rate Limits](https://developer.twitter.com/en/docs/twitter-api/rate-limits) public struct TwitterRateLimit { + /// The maximum number of requests allowed in the current time window. public let limit: Int + + /// The number of requests remaining in the current time window. public let remaining: Int - /// UTC epoch seconds + /// The time when the current rate limit window resets, in UTC epoch seconds. public let reset: TimeInterval + /// Creates a rate limit object from response headers. + /// - Parameter header: The response headers containing rate limit information. + /// Expected headers: + /// - x-rate-limit-limit: Maximum requests allowed + /// - x-rate-limit-remaining: Requests remaining + /// - x-rate-limit-reset: Reset time in epoch seconds + /// - Returns: An initialized rate limit object if the headers contain valid data, nil otherwise. public init?(header: [AnyHashable: Any]) { - guard let limit = parse(header, key: "x-rate-limit-limit"), - let remaining = parse(header, key: "x-rate-limit-remaining"), - let reset = parse(header, key: "x-rate-limit-reset") + let remaining = parse(header, key: "x-rate-limit-remaining"), + let reset = parse(header, key: "x-rate-limit-reset") else { return nil } @@ -24,8 +40,10 @@ public struct TwitterRateLimit { } } -extension TwitterRateLimit { - public var resetDate: Date { +public extension TwitterRateLimit { + /// The date when the current rate limit window resets. + /// This is a convenience property that converts the reset timestamp to a Date object. + var resetDate: Date { return Date(timeIntervalSince1970: reset) } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Account/GetAccountSettingsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Account/GetAccountSettingsRequestV1Tests.swift index bff2f3c2..9d548618 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Account/GetAccountSettingsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Account/GetAccountSettingsRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetAccountSettingsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetAccountSettingsRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetAccountSettingsRequestV1Tests: XCTestCase { + public func test() throws { let req = GetAccountSettingsRequestV1() XCTAssertEqual(req.method, .get) @@ -20,4 +19,8 @@ class GetAccountSettingsRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Account/GetAccountVerifyCredentialsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Account/GetAccountVerifyCredentialsRequestV1Tests.swift index d76c2059..397f5229 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Account/GetAccountVerifyCredentialsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Account/GetAccountVerifyCredentialsRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetAccountVerifyCredentialsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetAccountVerifyCredentialsRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetAccountVerifyCredentialsRequestV1Tests: XCTestCase { + public func test() throws { let req = GetAccountVerifyCredentialsRequestV1( skipStatus: true, includeEmail: true, @@ -29,7 +28,7 @@ class GetAccountVerifyCredentialsRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetAccountVerifyCredentialsRequestV1() AssertEqualAnyDict( @@ -37,4 +36,8 @@ class GetAccountVerifyCredentialsRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountRemoveProfileBannerRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountRemoveProfileBannerRequestV1Tests.swift index 0d6f3955..064af89d 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountRemoveProfileBannerRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountRemoveProfileBannerRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostAccountRemoveProfileBannerRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostAccountRemoveProfileBannerRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostAccountRemoveProfileBannerRequestV1Tests: XCTestCase { + public func test() throws { let req = PostAccountRemoveProfileBannerRequestV1() XCTAssertEqual(req.method, .post) @@ -20,4 +19,8 @@ class PostAccountRemoveProfileBannerRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountSettingsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountSettingsRequestV1Tests.swift index 662a90c8..1092e7c3 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountSettingsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountSettingsRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostAccountSettingsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostAccountSettingsRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostAccountSettingsRequestV1Tests: XCTestCase { + public func test() throws { let req = PostAccountSettingsRequestV1( lang: "_l_", timeZone: "_t_", @@ -35,7 +34,7 @@ class PostAccountSettingsRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostAccountSettingsRequestV1() AssertEqualAnyDict( @@ -43,4 +42,8 @@ class PostAccountSettingsRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountUpdateProfileBannerRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountUpdateProfileBannerRequestV1Tests.swift index 6abd2a43..70e68cbc 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountUpdateProfileBannerRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountUpdateProfileBannerRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostAccountUpdateProfileBannerRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostAccountUpdateProfileBannerRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostAccountUpdateProfileBannerRequestV1Tests: XCTestCase { + public func test() throws { let banner = Data([0, 1, 2]) let req = PostAccountUpdateProfileBannerRequestV1( banner: banner, @@ -44,7 +43,7 @@ class PostAccountUpdateProfileBannerRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let banner = Data([0, 1]) let req = PostAccountUpdateProfileBannerRequestV1( banner: banner @@ -61,8 +60,12 @@ class PostAccountUpdateProfileBannerRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "banner": "AAE=" + "banner": "AAE=", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountUpdateProfileImageRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountUpdateProfileImageRequestV1Tests.swift index 889ab748..3246859c 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountUpdateProfileImageRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountUpdateProfileImageRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostAccountUpdateProfileImageRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostAccountUpdateProfileImageRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostAccountUpdateProfileImageRequestV1Tests: XCTestCase { + public func test() throws { let image = Data([0, 1, 2]) let req = PostAccountUpdateProfileImageRequestV1( image: image, @@ -30,7 +29,7 @@ class PostAccountUpdateProfileImageRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let image = Data([0, 1, 2]) let req = PostAccountUpdateProfileImageRequestV1( image: image @@ -39,8 +38,12 @@ class PostAccountUpdateProfileImageRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "image": "AAEC" + "image": "AAEC", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountUpdateProfileRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountUpdateProfileRequestV1Tests.swift index 4798b48c..91964dc3 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountUpdateProfileRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Account/PostAccountUpdateProfileRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostAccountUpdateProfileRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostAccountUpdateProfileRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostAccountUpdateProfileRequestV1Tests: XCTestCase { + public func test() throws { let req = PostAccountUpdateProfileRequestV1( url: "_u_", name: "_n_", @@ -37,7 +36,7 @@ class PostAccountUpdateProfileRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostAccountUpdateProfileRequestV1() AssertEqualAnyDict( @@ -45,4 +44,8 @@ class PostAccountUpdateProfileRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Application/GetApplicationRateLimitStatusRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Application/GetApplicationRateLimitStatusRequestV1Tests.swift index 623403b1..b7b7175a 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Application/GetApplicationRateLimitStatusRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Application/GetApplicationRateLimitStatusRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetApplicationRateLimitStatusRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetApplicationRateLimitStatusRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetApplicationRateLimitStatusRequestV1Tests: XCTestCase { + public func test() throws { let req = GetApplicationRateLimitStatusRequestV1( resources: ["a", "b"] ) @@ -20,12 +19,12 @@ class GetApplicationRateLimitStatusRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "resources": "a,b" + "resources": "a,b", ] ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetApplicationRateLimitStatusRequestV1() AssertEqualAnyDict( @@ -33,4 +32,8 @@ class GetApplicationRateLimitStatusRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetBlocksIDsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetBlocksIDsRequestV1Tests.swift index 6e0c1328..b7cb840d 100644 --- a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetBlocksIDsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetBlocksIDsRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetBlocksIDsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetBlocksIDsRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetBlocksIDsRequestV1Tests: XCTestCase { + public func test() throws { let req = GetBlocksIDsRequestV1( stringifyIDs: true, cursor: "_c_" @@ -27,7 +26,7 @@ class GetBlocksIDsRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetBlocksIDsRequestV1() AssertEqualAnyDict( @@ -35,4 +34,8 @@ class GetBlocksIDsRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetBlocksListRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetBlocksListRequestV1Tests.swift index 172a0cdb..c41a50aa 100644 --- a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetBlocksListRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetBlocksListRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetBlocksListRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetBlocksListRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetBlocksListRequestV1Tests: XCTestCase { + public func test() throws { let req = GetBlocksListRequestV1( includeEntities: true, skipStatus: true, @@ -29,7 +28,7 @@ class GetBlocksListRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetBlocksListRequestV1() AssertEqualAnyDict( @@ -37,4 +36,8 @@ class GetBlocksListRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetMutesUsersIDsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetMutesUsersIDsRequestV1Tests.swift index ac52ec7a..4bdeca18 100644 --- a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetMutesUsersIDsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetMutesUsersIDsRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetMutesUsersIDsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetMutesUsersIDsRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetMutesUsersIDsRequestV1Tests: XCTestCase { + public func test() throws { let req = GetMutesUsersIDsRequestV1( stringifyIDs: true, cursor: "_c_" @@ -27,7 +26,7 @@ class GetMutesUsersIDsRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetMutesUsersIDsRequestV1() AssertEqualAnyDict( @@ -35,4 +34,8 @@ class GetMutesUsersIDsRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetMutesUsersListRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetMutesUsersListRequestV1Tests.swift index 786cc56a..8cc95660 100644 --- a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetMutesUsersListRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/GetMutesUsersListRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetMutesUsersListRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetMutesUsersListRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetMutesUsersListRequestV1Tests: XCTestCase { + public func test() throws { let req = GetMutesUsersListRequestV1( cursor: "_c_", includeEntities: true, @@ -29,7 +28,7 @@ class GetMutesUsersListRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetMutesUsersListRequestV1() AssertEqualAnyDict( @@ -37,4 +36,8 @@ class GetMutesUsersListRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostBlocksCreateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostBlocksCreateRequestV1Tests.swift index c1c19be2..e1a99b17 100644 --- a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostBlocksCreateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostBlocksCreateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostBlocksCreateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostBlocksCreateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostBlocksCreateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostBlocksCreateRequestV1( user: .userID("uid"), includeEntities: true, @@ -29,7 +28,7 @@ class PostBlocksCreateRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostBlocksCreateRequestV1( user: .screenName("s") ) @@ -37,8 +36,12 @@ class PostBlocksCreateRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostBlocksDestroyRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostBlocksDestroyRequestV1Tests.swift index 751ab063..93dbe9b4 100644 --- a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostBlocksDestroyRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostBlocksDestroyRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostBlocksDestroyRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostBlocksDestroyRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostBlocksDestroyRequestV1Tests: XCTestCase { + public func test() throws { let req = PostBlocksDestroyRequestV1( user: .userID("uid"), includeEntities: true, @@ -29,7 +28,7 @@ class PostBlocksDestroyRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostBlocksDestroyRequestV1( user: .screenName("s") ) @@ -37,8 +36,12 @@ class PostBlocksDestroyRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostMutesUsersCreateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostMutesUsersCreateRequestV1Tests.swift index 1628e86d..1de317b9 100644 --- a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostMutesUsersCreateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostMutesUsersCreateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostMutesUsersCreateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostMutesUsersCreateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostMutesUsersCreateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostMutesUsersCreateRequestV1( user: .userID("uid") ) @@ -20,12 +19,12 @@ class PostMutesUsersCreateRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "user_id": "uid" + "user_id": "uid", ] ) } - func testScreenName() throws { + public func testScreenName() throws { let req = PostMutesUsersCreateRequestV1( user: .screenName("s") ) @@ -33,8 +32,12 @@ class PostMutesUsersCreateRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostMutesUsersDestroyRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostMutesUsersDestroyRequestV1Tests.swift index 689e37b5..e51b6e9d 100644 --- a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostMutesUsersDestroyRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostMutesUsersDestroyRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostMutesUsersDestroyRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostMutesUsersDestroyRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostMutesUsersDestroyRequestV1Tests: XCTestCase { + public func test() throws { let req = PostMutesUsersDestroyRequestV1( user: .userID("uid") ) @@ -20,12 +19,12 @@ class PostMutesUsersDestroyRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "user_id": "uid" + "user_id": "uid", ] ) } - func testScreenName() throws { + public func testScreenName() throws { let req = PostMutesUsersDestroyRequestV1( user: .screenName("s") ) @@ -33,8 +32,12 @@ class PostMutesUsersDestroyRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostUsersReportSpamRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostUsersReportSpamRequestV1Tests.swift index 21d4eff4..a04ae242 100644 --- a/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostUsersReportSpamRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/BlockAndMute/PostUsersReportSpamRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostUsersReportSpamRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostUsersReportSpamRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostUsersReportSpamRequestV1Tests: XCTestCase { + public func test() throws { let req = PostUsersReportSpamRequestV1( user: .userID("uid"), performBlock: true @@ -27,7 +26,7 @@ class PostUsersReportSpamRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostUsersReportSpamRequestV1( user: .screenName("s") ) @@ -35,8 +34,12 @@ class PostUsersReportSpamRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Collection/GetCollectionsEntriesRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Collection/GetCollectionsEntriesRequestV1Tests.swift index 935cd0aa..a56b30fc 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Collection/GetCollectionsEntriesRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Collection/GetCollectionsEntriesRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetCollectionsEntriesRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetCollectionsEntriesRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetCollectionsEntriesRequestV1Tests: XCTestCase { + public func test() throws { let req = GetCollectionsEntriesRequestV1( id: "_i_", count: 12, @@ -31,7 +30,7 @@ class GetCollectionsEntriesRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetCollectionsEntriesRequestV1( id: "i" ) @@ -39,8 +38,12 @@ class GetCollectionsEntriesRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "id": "i" + "id": "i", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Collection/GetCollectionsListRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Collection/GetCollectionsListRequestV1Tests.swift index 11ae145b..8fb535a6 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Collection/GetCollectionsListRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Collection/GetCollectionsListRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetCollectionsListRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetCollectionsListRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetCollectionsListRequestV1Tests: XCTestCase { + public func test() throws { let req = GetCollectionsListRequestV1( user: .userID("uid"), count: 14, @@ -31,7 +30,7 @@ class GetCollectionsListRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetCollectionsListRequestV1( user: .screenName("s") ) @@ -39,8 +38,12 @@ class GetCollectionsListRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Collection/GetCollectionsShowRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Collection/GetCollectionsShowRequestV1Tests.swift index 675de248..54d72ad5 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Collection/GetCollectionsShowRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Collection/GetCollectionsShowRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetCollectionsShowRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetCollectionsShowRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetCollectionsShowRequestV1Tests: XCTestCase { + public func test() throws { let req = GetCollectionsShowRequestV1( id: "_i_" ) @@ -20,8 +19,12 @@ class GetCollectionsShowRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "id": "_i_" + "id": "_i_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsCreateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsCreateRequestV1Tests.swift index 7e3546dc..ced19b31 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsCreateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsCreateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostCollectionsCreateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostCollectionsCreateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostCollectionsCreateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostCollectionsCreateRequestV1( name: "_n_", url: "_u_", @@ -31,7 +30,7 @@ class PostCollectionsCreateRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostCollectionsCreateRequestV1( name: "n" ) @@ -39,8 +38,12 @@ class PostCollectionsCreateRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "name": "n" + "name": "n", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsDestroyRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsDestroyRequestV1Tests.swift index 85a4bd83..742dd1a9 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsDestroyRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsDestroyRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostCollectionsDestroyRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostCollectionsDestroyRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostCollectionsDestroyRequestV1Tests: XCTestCase { + public func test() throws { let req = PostCollectionsDestroyRequestV1( id: "_i_" ) @@ -20,8 +19,12 @@ class PostCollectionsDestroyRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "id": "_i_" + "id": "_i_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesAddRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesAddRequestV1Tests.swift index 8d4c917f..fad78d34 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesAddRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesAddRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostCollectionsEntriesAddRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostCollectionsEntriesAddRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostCollectionsEntriesAddRequestV1Tests: XCTestCase { + public func test() throws { let req = PostCollectionsEntriesAddRequestV1( id: "_i_", tweetID: "_t_", @@ -31,7 +30,7 @@ class PostCollectionsEntriesAddRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostCollectionsEntriesAddRequestV1( id: "_i_", tweetID: "_t_" @@ -45,4 +44,8 @@ class PostCollectionsEntriesAddRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesCurateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesCurateRequestV1Tests.swift index 1b2e07b3..e8046b7c 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesCurateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesCurateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostCollectionsEntriesCurateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostCollectionsEntriesCurateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostCollectionsEntriesCurateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostCollectionsEntriesCurateRequestV1( id: "_i_", changes: [ @@ -32,4 +31,8 @@ class PostCollectionsEntriesCurateRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesMoveRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesMoveRequestV1Tests.swift index 0ae12a67..17bc88de 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesMoveRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesMoveRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostCollectionsEntriesMoveRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostCollectionsEntriesMoveRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostCollectionsEntriesMoveRequestV1Tests: XCTestCase { + public func test() throws { let req = PostCollectionsEntriesMoveRequestV1( id: "_i_", tweetID: "_t_", @@ -31,7 +30,7 @@ class PostCollectionsEntriesMoveRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostCollectionsEntriesMoveRequestV1( id: "_i_", tweetID: "_t_", @@ -47,4 +46,8 @@ class PostCollectionsEntriesMoveRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesRemoveRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesRemoveRequestV1Tests.swift index 62b4016d..44a0c335 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesRemoveRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsEntriesRemoveRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostCollectionsEntriesRemoveRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostCollectionsEntriesRemoveRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostCollectionsEntriesRemoveRequestV1Tests: XCTestCase { + public func test() throws { let req = PostCollectionsEntriesRemoveRequestV1( id: "_i_", tweetID: "_t_" @@ -26,4 +25,8 @@ class PostCollectionsEntriesRemoveRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsUpdateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsUpdateRequestV1Tests.swift index d8ae22df..459a8fa1 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsUpdateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Collection/PostCollectionsUpdateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostCollectionsUpdateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostCollectionsUpdateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostCollectionsUpdateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostCollectionsUpdateRequestV1( id: "_i_", url: "_u_", @@ -31,7 +30,7 @@ class PostCollectionsUpdateRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostCollectionsUpdateRequestV1( id: "i" ) @@ -39,8 +38,12 @@ class PostCollectionsUpdateRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "id": "i" + "id": "i", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/DirectMessage/DeleteDirectMessageRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/DirectMessage/DeleteDirectMessageRequestV1Tests.swift index 53535e7c..b9441134 100644 --- a/Tests/TwitterAPIKitTests/APIv1/DirectMessage/DeleteDirectMessageRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/DirectMessage/DeleteDirectMessageRequestV1Tests.swift @@ -1,15 +1,13 @@ +// DeleteDirectMessageRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class DeleteDirectMessageRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class DeleteDirectMessageRequestV1Tests: XCTestCase { + public func test() throws { let req = DeleteDirectMessageRequestV1(id: "15") XCTAssertEqual(req.method, .delete) XCTAssertEqual(req.path, "/1.1/direct_messages/events/destroy.json") @@ -17,4 +15,8 @@ class DeleteDirectMessageRequestV1Tests: XCTestCase { AssertEqualAnyDict(req.parameters, ["id": "15"]) AssertEqualAnyDict(req.queryParameters, ["id": "15"]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/DirectMessage/GetDirectMessageListRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/DirectMessage/GetDirectMessageListRequestV1Tests.swift index be035caf..a89bd302 100644 --- a/Tests/TwitterAPIKitTests/APIv1/DirectMessage/GetDirectMessageListRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/DirectMessage/GetDirectMessageListRequestV1Tests.swift @@ -1,15 +1,13 @@ +// GetDirectMessageListRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetDirectMessageListRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetDirectMessageListRequestV1Tests: XCTestCase { + public func test() throws { let req = GetDirectMessageListRequestV1( count: 100, cursor: "cursor_str" @@ -23,8 +21,12 @@ class GetDirectMessageListRequestV1Tests: XCTestCase { [ "count": 100, "cursor": "cursor_str", - ]) + ] + ) XCTAssertTrue(req.bodyParameters.isEmpty) } + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/DirectMessage/GetDirectMessageRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/DirectMessage/GetDirectMessageRequestV1Tests.swift index 7364d389..0dfd9876 100644 --- a/Tests/TwitterAPIKitTests/APIv1/DirectMessage/GetDirectMessageRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/DirectMessage/GetDirectMessageRequestV1Tests.swift @@ -1,15 +1,13 @@ +// GetDirectMessageRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetDirectMessageRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetDirectMessageRequestV1Tests: XCTestCase { + public func test() throws { let req = GetDirectMessageRequestV1(id: "dm_id") XCTAssertEqual(req.method, .get) @@ -17,4 +15,8 @@ class GetDirectMessageRequestV1Tests: XCTestCase { XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) AssertEqualAnyDict(req.parameters, ["id": "dm_id"]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/DirectMessage/PostDirectMessageRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/DirectMessage/PostDirectMessageRequestV1Tests.swift index de2f6b21..84bbdcee 100644 --- a/Tests/TwitterAPIKitTests/APIv1/DirectMessage/PostDirectMessageRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/DirectMessage/PostDirectMessageRequestV1Tests.swift @@ -1,15 +1,13 @@ +// PostDirectMessageRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostDirectMessageRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func testText() throws { +internal class PostDirectMessageRequestV1Tests: XCTestCase { + public func testText() throws { let req = PostDirectMessageRequestV1( targetUserID: "target", message: "msg" @@ -27,11 +25,12 @@ class PostDirectMessageRequestV1Tests: XCTestCase { "message_data": ["text": "msg"], "target": ["recipient_id": "target"], ], - ] - ]) + ], + ] + ) } - func testQuickReplyOptions() throws { + public func testQuickReplyOptions() throws { let req = PostDirectMessageRequestV1( targetUserID: "target", message: "msg", @@ -62,11 +61,12 @@ class PostDirectMessageRequestV1Tests: XCTestCase { ], ], ], - ] - ]) + ], + ] + ) } - func testAttachMedia() throws { + public func testAttachMedia() throws { let req = PostDirectMessageRequestV1( targetUserID: "target", message: "msg with media", @@ -87,17 +87,18 @@ class PostDirectMessageRequestV1Tests: XCTestCase { "attachment": [ "type": "media", "media": [ - "id": "media_id" + "id": "media_id", ], ], ], "target": ["recipient_id": "target"], ], - ] - ]) + ], + ] + ) } - func testAttachLocation() throws { + public func testAttachLocation() throws { XCTContext.runActivity(named: "coordinate") { _ in let req = PostDirectMessageRequestV1( targetUserID: "target", @@ -124,15 +125,16 @@ class PostDirectMessageRequestV1Tests: XCTestCase { "coordinates": [ "type": "Point", "coordinates": [10, 20], - ] + ], ], ], ], ], "target": ["recipient_id": "target"], ], - ] - ]) + ], + ] + ) } XCTContext.runActivity(named: "place") { _ in @@ -159,16 +161,21 @@ class PostDirectMessageRequestV1Tests: XCTestCase { "type": "shared_place", "shared_place": [ "place": [ - "id": "place_id" - ] + "id": "place_id", + ], ], ], ], ], "target": ["recipient_id": "target"], ], - ] - ]) + ], + ] + ) } } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/DirectMessage/PostDirectMessagesIndicateTypingRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/DirectMessage/PostDirectMessagesIndicateTypingRequestV1Tests.swift index b7d12cdc..e68ae9a9 100644 --- a/Tests/TwitterAPIKitTests/APIv1/DirectMessage/PostDirectMessagesIndicateTypingRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/DirectMessage/PostDirectMessagesIndicateTypingRequestV1Tests.swift @@ -1,15 +1,13 @@ +// PostDirectMessagesIndicateTypingRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostDirectMessagesIndicateTypingRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostDirectMessagesIndicateTypingRequestV1Tests: XCTestCase { + public func test() throws { let req = PostDirectMessagesIndicateTypingRequestV1( recipientID: "234" ) @@ -19,4 +17,8 @@ class PostDirectMessagesIndicateTypingRequestV1Tests: XCTestCase { XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) AssertEqualAnyDict(req.parameters, ["recipient_id": "234"]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/DirectMessage/PostDirectMessagesMarkReadRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/DirectMessage/PostDirectMessagesMarkReadRequestV1Tests.swift index 33458666..d0031e59 100644 --- a/Tests/TwitterAPIKitTests/APIv1/DirectMessage/PostDirectMessagesMarkReadRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/DirectMessage/PostDirectMessagesMarkReadRequestV1Tests.swift @@ -1,15 +1,13 @@ +// PostDirectMessagesMarkReadRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostDirectMessagesMarkReadRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostDirectMessagesMarkReadRequestV1Tests: XCTestCase { + public func test() throws { let req = PostDirectMessagesMarkReadRequestV1(lastReadEventID: "ev_id", recipientID: "r_id") XCTAssertEqual(req.method, .post) @@ -20,6 +18,11 @@ class PostDirectMessagesMarkReadRequestV1Tests: XCTestCase { [ "last_read_event_id": "ev_id", "recipient_id": "r_id", - ]) + ] + ) + } + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Favorite/GetFavoritesRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Favorite/GetFavoritesRequestV1Tests.swift index e981d5fb..87173c21 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Favorite/GetFavoritesRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Favorite/GetFavoritesRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetFavoritesRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetFavoritesRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetFavoritesRequestV1Tests: XCTestCase { + public func test() throws { let req = GetFavoritesRequestV1( target: .userID("uid"), count: 100, @@ -33,7 +32,7 @@ class GetFavoritesRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetFavoritesRequestV1( target: .screenName("s") ) @@ -41,8 +40,12 @@ class GetFavoritesRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Favorite/PostFavoriteRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Favorite/PostFavoriteRequestV1Tests.swift index cdf0fe0b..f105bf8f 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Favorite/PostFavoriteRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Favorite/PostFavoriteRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostFavoriteRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostFavoriteRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostFavoriteRequestV1Tests: XCTestCase { + public func test() throws { let req = PostFavoriteRequestV1( id: "_i_", includeEntities: true @@ -27,7 +26,7 @@ class PostFavoriteRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostFavoriteRequestV1( id: "_i_" ) @@ -35,8 +34,12 @@ class PostFavoriteRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "id": "_i_" + "id": "_i_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Favorite/PostUnFavoriteRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Favorite/PostUnFavoriteRequestV1Tests.swift index bd96a116..90b06a24 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Favorite/PostUnFavoriteRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Favorite/PostUnFavoriteRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostUnFavoriteRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostUnFavoriteRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostUnFavoriteRequestV1Tests: XCTestCase { + public func test() throws { let req = PostUnFavoriteRequestV1( id: "_i_", includeEntities: true @@ -27,7 +26,7 @@ class PostUnFavoriteRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostUnFavoriteRequestV1( id: "_i_" ) @@ -35,8 +34,12 @@ class PostUnFavoriteRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "id": "_i_" + "id": "_i_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFollowersIDsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFollowersIDsRequestV1Tests.swift index edfbba11..171f7313 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFollowersIDsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFollowersIDsRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetFollowersIDsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetFollowersIDsRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetFollowersIDsRequestV1Tests: XCTestCase { + public func test() throws { let req = GetFollowersIDsRequestV1( user: .userID("uid"), count: 10, @@ -31,7 +30,7 @@ class GetFollowersIDsRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetFollowersIDsRequestV1( user: .screenName("s") ) @@ -39,8 +38,12 @@ class GetFollowersIDsRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFollowersListRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFollowersListRequestV1Tests.swift index b96ab74f..d02873b0 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFollowersListRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFollowersListRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetFollowersListRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetFollowersListRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetFollowersListRequestV1Tests: XCTestCase { + public func test() throws { let req = GetFollowersListRequestV1( user: .userID("uid"), count: 1, @@ -33,7 +32,7 @@ class GetFollowersListRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetFollowersListRequestV1( user: .screenName("s") ) @@ -41,8 +40,12 @@ class GetFollowersListRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendsIDsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendsIDsRequestV1Tests.swift index 02a240af..44b4b4f1 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendsIDsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendsIDsRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetFriendsIDsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetFriendsIDsRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetFriendsIDsRequestV1Tests: XCTestCase { + public func test() throws { let req = GetFriendsIDsRequestV1( user: .userID("uid"), count: 11, @@ -31,7 +30,7 @@ class GetFriendsIDsRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetFriendsIDsRequestV1( user: .screenName("s") ) @@ -39,8 +38,12 @@ class GetFriendsIDsRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendsListRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendsListRequestV1Tests.swift index 072c6ca5..1ea3ae76 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendsListRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendsListRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetFriendsListRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetFriendsListRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetFriendsListRequestV1Tests: XCTestCase { + public func test() throws { let req = GetFriendsListRequestV1( user: .userID("uid"), count: 1, @@ -33,7 +32,7 @@ class GetFriendsListRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetFriendsListRequestV1( user: .screenName("s") ) @@ -41,8 +40,12 @@ class GetFriendsListRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsIncomingRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsIncomingRequestV1Tests.swift index e0ff4692..e9d8d48d 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsIncomingRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsIncomingRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetFriendshipsIncomingRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetFriendshipsIncomingRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetFriendshipsIncomingRequestV1Tests: XCTestCase { + public func test() throws { let req = GetFriendshipsIncomingRequestV1( cursor: "_c_", stringifyIDs: true @@ -27,7 +26,7 @@ class GetFriendshipsIncomingRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetFriendshipsIncomingRequestV1() AssertEqualAnyDict( @@ -35,4 +34,8 @@ class GetFriendshipsIncomingRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsLookupRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsLookupRequestV1Tests.swift index 5748418a..3a2d398e 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsLookupRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsLookupRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetFriendshipsLookupRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetFriendshipsLookupRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetFriendshipsLookupRequestV1Tests: XCTestCase { + public func test() throws { let req = GetFriendshipsLookupRequestV1( users: .userIDs(["uid1", "uid2"]) ) @@ -20,12 +19,12 @@ class GetFriendshipsLookupRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "user_id": "uid1,uid2" + "user_id": "uid1,uid2", ] ) } - func testScreenName() throws { + public func testScreenName() throws { let req = GetFriendshipsLookupRequestV1( users: .screenNames(["s1", "s2"]) ) @@ -34,8 +33,12 @@ class GetFriendshipsLookupRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s1,s2" + "screen_name": "s1,s2", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsNoRetweetsIDsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsNoRetweetsIDsRequestV1Tests.swift index a5952993..584fe3c7 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsNoRetweetsIDsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsNoRetweetsIDsRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetFriendshipsNoRetweetsIDsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetFriendshipsNoRetweetsIDsRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetFriendshipsNoRetweetsIDsRequestV1Tests: XCTestCase { + public func test() throws { let req = GetFriendshipsNoRetweetsIDsRequestV1( stringifyIDs: true ) @@ -20,12 +19,12 @@ class GetFriendshipsNoRetweetsIDsRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "stringify_ids": true + "stringify_ids": true, ] ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetFriendshipsNoRetweetsIDsRequestV1() AssertEqualAnyDict( @@ -33,4 +32,8 @@ class GetFriendshipsNoRetweetsIDsRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsOutgoingRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsOutgoingRequestV1Tests.swift index ae0ba96e..07bc1bcb 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsOutgoingRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsOutgoingRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetFriendshipsOutgoingRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetFriendshipsOutgoingRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetFriendshipsOutgoingRequestV1Tests: XCTestCase { + public func test() throws { let req = GetFriendshipsOutgoingRequestV1( cursor: "_c_", stringifyIDs: true @@ -27,7 +26,7 @@ class GetFriendshipsOutgoingRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetFriendshipsOutgoingRequestV1() AssertEqualAnyDict( @@ -35,4 +34,8 @@ class GetFriendshipsOutgoingRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsShowRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsShowRequestV1Tests.swift index c765feed..2d4aed44 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsShowRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Friendships/GetFriendshipsShowRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetFriendshipsShowRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetFriendshipsShowRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetFriendshipsShowRequestV1Tests: XCTestCase { + public func test() throws { let req = GetFriendshipsShowRequestV1( sourceUser: .userID("suid"), targetUser: .userID("tuid") @@ -27,7 +26,7 @@ class GetFriendshipsShowRequestV1Tests: XCTestCase { ) } - func testScreenName() throws { + public func testScreenName() throws { let req = GetFriendshipsShowRequestV1( sourceUser: .screenName("s"), targetUser: .screenName("t") @@ -41,4 +40,8 @@ class GetFriendshipsShowRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Friendships/PostFriendshipsCreateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Friendships/PostFriendshipsCreateRequestV1Tests.swift index 1e6ec859..b9f0bada 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Friendships/PostFriendshipsCreateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Friendships/PostFriendshipsCreateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostFriendshipsCreateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostFriendshipsCreateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostFriendshipsCreateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostFriendshipsCreateRequestV1( user: .userID("uid"), follow: true @@ -27,7 +26,7 @@ class PostFriendshipsCreateRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostFriendshipsCreateRequestV1( user: .screenName("s") ) @@ -35,8 +34,12 @@ class PostFriendshipsCreateRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Friendships/PostFriendshipsDestroyRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Friendships/PostFriendshipsDestroyRequestV1Tests.swift index 0e117f81..9bc7973d 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Friendships/PostFriendshipsDestroyRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Friendships/PostFriendshipsDestroyRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostFriendshipsDestroyRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostFriendshipsDestroyRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostFriendshipsDestroyRequestV1Tests: XCTestCase { + public func test() throws { let req = PostFriendshipsDestroyRequestV1( user: .userID("uid") ) @@ -20,12 +19,12 @@ class PostFriendshipsDestroyRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "user_id": "uid" + "user_id": "uid", ] ) } - func testScreenName() throws { + public func testScreenName() throws { let req = PostFriendshipsDestroyRequestV1( user: .screenName("s") ) @@ -33,8 +32,12 @@ class PostFriendshipsDestroyRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Friendships/PostFriendshipsUpdateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Friendships/PostFriendshipsUpdateRequestV1Tests.swift index 202e8433..c6af3cb5 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Friendships/PostFriendshipsUpdateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Friendships/PostFriendshipsUpdateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostFriendshipsUpdateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostFriendshipsUpdateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostFriendshipsUpdateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostFriendshipsUpdateRequestV1( user: .userID("uid"), device: true, @@ -29,7 +28,7 @@ class PostFriendshipsUpdateRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostFriendshipsUpdateRequestV1( user: .screenName("s") ) @@ -37,8 +36,12 @@ class PostFriendshipsUpdateRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Geo/GetGeoPlaceIDRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Geo/GetGeoPlaceIDRequestV1Tests.swift index 822e0e7b..0adf8ec4 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Geo/GetGeoPlaceIDRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Geo/GetGeoPlaceIDRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetGeoPlaceIDRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetGeoPlaceIDRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetGeoPlaceIDRequestV1Tests: XCTestCase { + public func test() throws { let req = GetGeoPlaceIDRequestV1( placeID: "_p_" ) @@ -22,4 +21,8 @@ class GetGeoPlaceIDRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Geo/GetGeoReverseGeocodeRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Geo/GetGeoReverseGeocodeRequestV1Tests.swift index ed74b9fb..1f07f756 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Geo/GetGeoReverseGeocodeRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Geo/GetGeoReverseGeocodeRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetGeoReverseGeocodeRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetGeoReverseGeocodeRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func testAccuracy() throws { +internal class GetGeoReverseGeocodeRequestV1Tests: XCTestCase { + public func testAccuracy() throws { XCTContext.runActivity(named: "ft") { _ in let req = GetGeoReverseGeocodeRequestV1( location: .init(lat: 1, long: 2.5), @@ -54,7 +53,7 @@ class GetGeoReverseGeocodeRequestV1Tests: XCTestCase { } } - func testGranularity() throws { + public func testGranularity() throws { XCTContext.runActivity(named: "neighborhood") { _ in let req = GetGeoReverseGeocodeRequestV1( location: .init(lat: 1, long: 2.5), @@ -133,7 +132,7 @@ class GetGeoReverseGeocodeRequestV1Tests: XCTestCase { } } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetGeoReverseGeocodeRequestV1( location: .init(lat: -10, long: 100) ) @@ -146,4 +145,8 @@ class GetGeoReverseGeocodeRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Geo/GetGeoSearchRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Geo/GetGeoSearchRequestV1Tests.swift index b71dca04..5ceaf9da 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Geo/GetGeoSearchRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Geo/GetGeoSearchRequestV1Tests.swift @@ -1,15 +1,13 @@ +// GetGeoSearchRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetGeoSearchRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class GetGeoSearchRequestV1Tests: XCTestCase { + public func test() throws { XCTContext.runActivity(named: "coordinate") { _ in let req = GetGeoSearchRequestV1( @@ -66,7 +64,7 @@ class GetGeoSearchRequestV1Tests: XCTestCase { } } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetGeoSearchRequestV1( location: .coordinate(.init(lat: 10.123, long: -20.1)) ) @@ -79,4 +77,8 @@ class GetGeoSearchRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Help/GetHelpLanguagesRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Help/GetHelpLanguagesRequestV1Tests.swift index f54e973b..3a86b891 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Help/GetHelpLanguagesRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Help/GetHelpLanguagesRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetHelpLanguagesRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetHelpLanguagesRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetHelpLanguagesRequestV1Tests: XCTestCase { + public func test() throws { let req = GetHelpLanguagesRequestV1() XCTAssertEqual(req.method, .get) @@ -20,4 +19,8 @@ class GetHelpLanguagesRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/GetListsListRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/GetListsListRequestV1Tests.swift index 253c31d6..12c35b28 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/GetListsListRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/GetListsListRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetListsListRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsListRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsListRequestV1Tests: XCTestCase { + public func test() throws { let req = GetListsListRequestV1( user: .userID("uid"), reverse: true @@ -27,7 +26,7 @@ class GetListsListRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetListsListRequestV1( user: .screenName("s") ) @@ -35,8 +34,12 @@ class GetListsListRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/GetListsMembersRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/GetListsMembersRequestV1Tests.swift index a4959bf2..b95f4129 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/GetListsMembersRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/GetListsMembersRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetListsMembersRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsMembersRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsMembersRequestV1Tests: XCTestCase { + public func test() throws { let req = GetListsMembersRequestV1( list: .listID("lid"), count: 10, @@ -33,7 +32,7 @@ class GetListsMembersRequestV1Tests: XCTestCase { ) } - func testSlugUserID() throws { + public func testSlugUserID() throws { let req = GetListsMembersRequestV1( list: .slug(slug: "s", owner: .userID("uid")) ) @@ -47,7 +46,7 @@ class GetListsMembersRequestV1Tests: XCTestCase { ) } - func testSlugScreenName() throws { + public func testSlugScreenName() throws { let req = GetListsMembersRequestV1( list: .slug(slug: "s", owner: .screenName("s")) ) @@ -60,4 +59,8 @@ class GetListsMembersRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/GetListsMembersShowRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/GetListsMembersShowRequestV1Tests.swift index 4fe47adf..1d2b211f 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/GetListsMembersShowRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/GetListsMembersShowRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetListsMembersShowRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsMembersShowRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsMembersShowRequestV1Tests: XCTestCase { + public func test() throws { let req = GetListsMembersShowRequestV1( list: .listID("lid"), user: .userID("uid"), @@ -31,7 +30,7 @@ class GetListsMembersShowRequestV1Tests: XCTestCase { ) } - func testScreenName() throws { + public func testScreenName() throws { let req = GetListsMembersShowRequestV1( list: .listID("lid"), user: .screenName("s") @@ -46,7 +45,7 @@ class GetListsMembersShowRequestV1Tests: XCTestCase { ) } - func testSlugUserID() throws { + public func testSlugUserID() throws { let req = GetListsMembersShowRequestV1( list: .slug(slug: "s", owner: .userID("ouid")), user: .userID("uid") @@ -62,7 +61,7 @@ class GetListsMembersShowRequestV1Tests: XCTestCase { ) } - func testSlugScreenName() throws { + public func testSlugScreenName() throws { let req = GetListsMembersShowRequestV1( list: .slug(slug: "s", owner: .screenName("os")), user: .userID("uid") @@ -77,4 +76,8 @@ class GetListsMembersShowRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/GetListsMembershipsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/GetListsMembershipsRequestV1Tests.swift index 810fe93f..fe2194aa 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/GetListsMembershipsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/GetListsMembershipsRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetListsMembershipsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsMembershipsRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsMembershipsRequestV1Tests: XCTestCase { + public func test() throws { let req = GetListsMembershipsRequestV1( user: .userID("uid"), count: 11, @@ -31,7 +30,7 @@ class GetListsMembershipsRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetListsMembershipsRequestV1( user: .screenName("name") ) @@ -39,8 +38,12 @@ class GetListsMembershipsRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "name" + "screen_name": "name", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/GetListsOwnershipsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/GetListsOwnershipsRequestV1Tests.swift index dfda054d..9454d194 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/GetListsOwnershipsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/GetListsOwnershipsRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetListsOwnershipsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsOwnershipsRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsOwnershipsRequestV1Tests: XCTestCase { + public func test() throws { let req = GetListsOwnershipsRequestV1( user: .userID("uid"), count: 21, @@ -29,7 +28,7 @@ class GetListsOwnershipsRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetListsOwnershipsRequestV1( user: .screenName("name") ) @@ -37,8 +36,12 @@ class GetListsOwnershipsRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "name" + "screen_name": "name", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/GetListsShowRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/GetListsShowRequestV1Tests.swift index 8edfacc4..2c2daa1e 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/GetListsShowRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/GetListsShowRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetListsShowRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsShowRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsShowRequestV1Tests: XCTestCase { + public func test() throws { let req = GetListsShowRequestV1( list: .listID("lid") ) @@ -20,12 +19,12 @@ class GetListsShowRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "list_id": "lid" + "list_id": "lid", ] ) } - func testSlugUserID() throws { + public func testSlugUserID() throws { let req = GetListsShowRequestV1( list: .slug(slug: "sl", owner: .userID("uid")) ) @@ -38,7 +37,7 @@ class GetListsShowRequestV1Tests: XCTestCase { ) } - func testSlugScreenName() throws { + public func testSlugScreenName() throws { let req = GetListsShowRequestV1( list: .slug(slug: "sl", owner: .screenName("sname")) ) @@ -50,4 +49,8 @@ class GetListsShowRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/GetListsStatusesRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/GetListsStatusesRequestV1Tests.swift index 8c6443a9..74ff7098 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/GetListsStatusesRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/GetListsStatusesRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetListsStatusesRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsStatusesRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsStatusesRequestV1Tests: XCTestCase { + public func test() throws { let req = GetListsStatusesRequestV1( list: .listID("lid"), count: 15, @@ -35,7 +34,7 @@ class GetListsStatusesRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetListsStatusesRequestV1( list: .listID("lid") ) @@ -43,8 +42,12 @@ class GetListsStatusesRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "list_id": "lid" + "list_id": "lid", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/GetListsSubscribersRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/GetListsSubscribersRequestV1Tests.swift index 7ed642b8..3d51244d 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/GetListsSubscribersRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/GetListsSubscribersRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetListsSubscribersRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsSubscribersRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsSubscribersRequestV1Tests: XCTestCase { + public func test() throws { let req = GetListsSubscribersRequestV1( list: .listID("lid"), count: 17, @@ -33,7 +32,7 @@ class GetListsSubscribersRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetListsSubscribersRequestV1( list: .slug(slug: "sl", owner: .userID("uid")) ) @@ -46,4 +45,8 @@ class GetListsSubscribersRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/GetListsSubscribersShowRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/GetListsSubscribersShowRequestV1Tests.swift index 1105f0ae..01e83caf 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/GetListsSubscribersShowRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/GetListsSubscribersShowRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetListsSubscribersShowRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsSubscribersShowRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsSubscribersShowRequestV1Tests: XCTestCase { + public func test() throws { let req = GetListsSubscribersShowRequestV1( list: .listID("lid"), user: .userID("uid"), @@ -31,7 +30,7 @@ class GetListsSubscribersShowRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetListsSubscribersShowRequestV1( list: .slug(slug: "sl", owner: .screenName("sn")), user: .userID("uid") @@ -46,4 +45,8 @@ class GetListsSubscribersShowRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/GetListsSubscriptionsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/GetListsSubscriptionsRequestV1Tests.swift index b08d0eb1..42058fc8 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/GetListsSubscriptionsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/GetListsSubscriptionsRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetListsSubscriptionsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsSubscriptionsRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsSubscriptionsRequestV1Tests: XCTestCase { + public func test() throws { let req = GetListsSubscriptionsRequestV1( user: .userID("uid"), count: 19, @@ -29,7 +28,7 @@ class GetListsSubscriptionsRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetListsSubscriptionsRequestV1( user: .screenName("sn") ) @@ -37,8 +36,12 @@ class GetListsSubscriptionsRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "sn" + "screen_name": "sn", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/ListRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/ListRequestV1Tests.swift index 4208b2ec..750b9378 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/ListRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/ListRequestV1Tests.swift @@ -1,39 +1,44 @@ +// ListRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class CustomListsListRequestV1: GetListsListRequestV1 { - - let custom: String +internal class CustomListsListRequestV1: GetListsListRequestV1 { + public let custom: String - override var parameters: [String: Any] { - var p = super.parameters - p["custom"] = custom - return p + override public var parameters: [String: Any] { + var params = super.parameters + params["custom"] = custom + return params } - init(custom: String, user: TwitterUserIdentifierV1, reverse: Bool? = .none) { + public init(custom: String, user: TwitterUserIdentifierV1, reverse: Bool? = .none) { self.custom = custom super.init(user: user, reverse: reverse) } -} -class CapsuledListsListRequestV1: GetListsListRequestV1 { - init() { - super.init(user: .userID("100"), reverse: true) + deinit { + // De-init Logic Here } } -class ListRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { +internal class CapsuledListsListRequestV1: GetListsListRequestV1 { + public init() { + super.init(user: .userID("100"), reverse: true) } - override func tearDownWithError() throws { + deinit { + // De-init Logic Here } +} - // https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-list - func testGetListsListRequestV1() throws { - +internal class ListRequestV1Tests: XCTestCase { + // https://developer.twitter.com/en/docs/twitter-api/v1/ \ + // accounts-and-users/create-manage-lists/api-reference/get-lists-list + public func testGetListsListRequestV1() throws { XCTContext.runActivity(named: "with only required parameters") { _ in let list = GetListsListRequestV1(user: .userID("1234")) @@ -48,17 +53,21 @@ class ListRequestV1Tests: XCTestCase { } } - func testCustomListsListRequestV1() throws { + public func testCustomListsListRequestV1() throws { let list = CustomListsListRequestV1(custom: "_custom_", user: .userID("12")) XCTAssertEqual(list.method, .get) XCTAssertEqual(list.path, "/1.1/lists/list.json") AssertEqualAnyDict(list.parameters, ["user_id": "12", "custom": "_custom_"]) } - func testCapsuledListsListRequestV1() throws { + public func testCapsuledListsListRequestV1() throws { let list = CapsuledListsListRequestV1() XCTAssertEqual(list.method, .get) XCTAssertEqual(list.path, "/1.1/lists/list.json") AssertEqualAnyDict(list.parameters, ["user_id": "100", "reverse": true]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/PostListsCreateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/PostListsCreateRequestV1Tests.swift index f0719eda..6060b4d1 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/PostListsCreateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/PostListsCreateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostListsCreateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostListsCreateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostListsCreateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostListsCreateRequestV1( name: "_n_", mode: .private, @@ -29,7 +28,7 @@ class PostListsCreateRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostListsCreateRequestV1( name: "n" ) @@ -37,8 +36,12 @@ class PostListsCreateRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "name": "n" + "name": "n", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/PostListsDestroyRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/PostListsDestroyRequestV1Tests.swift index 709cadd0..ff8af238 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/PostListsDestroyRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/PostListsDestroyRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostListsDestroyRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostListsDestroyRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostListsDestroyRequestV1Tests: XCTestCase { + public func test() throws { let req = PostListsDestroyRequestV1( list: .listID("lid") ) @@ -20,12 +19,12 @@ class PostListsDestroyRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "list_id": "lid" + "list_id": "lid", ] ) } - func testSlug() throws { + public func testSlug() throws { let req = PostListsDestroyRequestV1( list: .slug(slug: "sl", owner: .screenName("sname")) ) @@ -38,4 +37,8 @@ class PostListsDestroyRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersCreateAllRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersCreateAllRequestV1Tests.swift index 360af050..a902bcd6 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersCreateAllRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersCreateAllRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostListsMembersCreateAllRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostListsMembersCreateAllRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostListsMembersCreateAllRequestV1Tests: XCTestCase { + public func test() throws { let req = PostListsMembersCreateAllRequestV1( list: .listID("lid"), users: .userIDs(["uid1", "uid2"]) @@ -26,4 +25,8 @@ class PostListsMembersCreateAllRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersCreateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersCreateRequestV1Tests.swift index 28fa8456..33075f87 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersCreateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersCreateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostListsMembersCreateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostListsMembersCreateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostListsMembersCreateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostListsMembersCreateRequestV1( list: .listID("lid"), user: .userID("uid") @@ -27,7 +26,7 @@ class PostListsMembersCreateRequestV1Tests: XCTestCase { ) } - func testScreenName() throws { + public func testScreenName() throws { let req = PostListsMembersCreateRequestV1( list: .slug(slug: "sl", owner: .screenName("osname")), user: .screenName("sname") @@ -42,4 +41,8 @@ class PostListsMembersCreateRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersDestroyAllRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersDestroyAllRequestV1Tests.swift index c866a0e0..a14a0dce 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersDestroyAllRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersDestroyAllRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostListsMembersDestroyAllRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostListsMembersDestroyAllRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostListsMembersDestroyAllRequestV1Tests: XCTestCase { + public func test() throws { let req = PostListsMembersDestroyAllRequestV1( list: .listID("lid"), users: .userIDs(["uid1", "uid2"]) @@ -27,7 +26,7 @@ class PostListsMembersDestroyAllRequestV1Tests: XCTestCase { ) } - func testScreenName() throws { + public func testScreenName() throws { let req = PostListsMembersDestroyAllRequestV1( list: .slug(slug: "sl", owner: .screenName("oname")), users: .screenNames(["s1", "s2"]) @@ -42,4 +41,8 @@ class PostListsMembersDestroyAllRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersDestroyRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersDestroyRequestV1Tests.swift index 53d968d4..fa9b37ff 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersDestroyRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/PostListsMembersDestroyRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostListsMembersDestroyRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostListsMembersDestroyRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostListsMembersDestroyRequestV1Tests: XCTestCase { + public func test() throws { let req = PostListsMembersDestroyRequestV1( list: .listID("lid"), user: .userID("uid") @@ -27,7 +26,7 @@ class PostListsMembersDestroyRequestV1Tests: XCTestCase { ) } - func testScreenName() throws { + public func testScreenName() throws { let req = PostListsMembersDestroyRequestV1( list: .slug(slug: "sl", owner: .screenName("sc")), user: .screenName("name") @@ -42,4 +41,8 @@ class PostListsMembersDestroyRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/PostListsSubscribersCreateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/PostListsSubscribersCreateRequestV1Tests.swift index 74c6902a..a8be2b20 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/PostListsSubscribersCreateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/PostListsSubscribersCreateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostListsSubscribersCreateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostListsSubscribersCreateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostListsSubscribersCreateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostListsSubscribersCreateRequestV1( list: .listID("lid") ) @@ -20,12 +19,12 @@ class PostListsSubscribersCreateRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "list_id": "lid" + "list_id": "lid", ] ) } - func testScreenName() throws { + public func testScreenName() throws { let req = PostListsSubscribersCreateRequestV1( list: .slug(slug: "sl", owner: .screenName("name")) ) @@ -38,4 +37,8 @@ class PostListsSubscribersCreateRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/PostListsSubscribersDestroyRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/PostListsSubscribersDestroyRequestV1Tests.swift index e0d1a8f0..8d3d97c5 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/PostListsSubscribersDestroyRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/PostListsSubscribersDestroyRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostListsSubscribersDestroyRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostListsSubscribersDestroyRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostListsSubscribersDestroyRequestV1Tests: XCTestCase { + public func test() throws { let req = PostListsSubscribersDestroyRequestV1( list: .listID("lid") ) @@ -20,12 +19,12 @@ class PostListsSubscribersDestroyRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "list_id": "lid" + "list_id": "lid", ] ) } - func testScreenName() throws { + public func testScreenName() throws { let req = PostListsSubscribersDestroyRequestV1( list: .slug(slug: "sl", owner: .screenName("name")) ) @@ -38,4 +37,8 @@ class PostListsSubscribersDestroyRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/List/PostListsUpdateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/List/PostListsUpdateRequestV1Tests.swift index 10fc6620..c93afeea 100644 --- a/Tests/TwitterAPIKitTests/APIv1/List/PostListsUpdateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/List/PostListsUpdateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostListsUpdateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostListsUpdateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostListsUpdateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostListsUpdateRequestV1( list: .listID("lid"), name: "_n_", @@ -31,7 +30,7 @@ class PostListsUpdateRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostListsUpdateRequestV1( list: .slug(slug: "sl", owner: .screenName("name")) ) @@ -44,4 +43,8 @@ class PostListsUpdateRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Media/GetUploadMediaStatusRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Media/GetUploadMediaStatusRequestV1Tests.swift index 182ee5fe..c7b42cb3 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Media/GetUploadMediaStatusRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Media/GetUploadMediaStatusRequestV1Tests.swift @@ -1,15 +1,13 @@ +// GetUploadMediaStatusRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUploadMediaStatusRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUploadMediaStatusRequestV1Tests: XCTestCase { + public func test() throws { let req = GetUploadMediaStatusRequestV1(mediaID: "m") XCTAssertEqual(req.method, .get) @@ -20,7 +18,11 @@ class GetUploadMediaStatusRequestV1Tests: XCTestCase { [ "command": "STATUS", "media_id": "m", - ]) + ] + ) } + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Media/PostMediaMetadataCreateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Media/PostMediaMetadataCreateRequestV1Tests.swift index 6edef5ec..30039b4c 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Media/PostMediaMetadataCreateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Media/PostMediaMetadataCreateRequestV1Tests.swift @@ -1,15 +1,13 @@ +// PostMediaMetadataCreateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostMediaMetadataCreateRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostMediaMetadataCreateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostMediaMetadataCreateRequestV1( mediaID: "m", altText: "alt" @@ -27,4 +25,8 @@ class PostMediaMetadataCreateRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Media/PostMediaSubtitlesCreateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Media/PostMediaSubtitlesCreateRequestV1Tests.swift index 3bb26875..f54fcc17 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Media/PostMediaSubtitlesCreateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Media/PostMediaSubtitlesCreateRequestV1Tests.swift @@ -1,15 +1,13 @@ +// PostMediaSubtitlesCreateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostMediaSubtitlesCreateRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostMediaSubtitlesCreateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostMediaSubtitlesCreateRequestV1( mediaID: "mediaID", mediaCategory: "c", @@ -18,7 +16,7 @@ class PostMediaSubtitlesCreateRequestV1Tests: XCTestCase { mediaID: "subtitleMediaID", languageCode: "l", displayName: "d" - ) + ), ] ) @@ -37,9 +35,14 @@ class PostMediaSubtitlesCreateRequestV1Tests: XCTestCase { "media_id": "subtitleMediaID", "language_code": "l", "display_name": "d", - ] - ] + ], + ], ], - ]) + ] + ) + } + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Media/PostMediaSubtitlesDeleteRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Media/PostMediaSubtitlesDeleteRequestV1Tests.swift index 7c7d41e9..ba4a04ef 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Media/PostMediaSubtitlesDeleteRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Media/PostMediaSubtitlesDeleteRequestV1Tests.swift @@ -1,15 +1,13 @@ +// PostMediaSubtitlesDeleteRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostMediaSubtitlesDeleteRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostMediaSubtitlesDeleteRequestV1Tests: XCTestCase { + public func test() throws { let req = PostMediaSubtitlesDeleteRequestV1( mediaID: "m", mediaCategory: "c", @@ -28,9 +26,13 @@ class PostMediaSubtitlesDeleteRequestV1Tests: XCTestCase { "subtitles": [ ["language_code": "l1"], ["language_code": "l2"], - ] + ], ], ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaAppendRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaAppendRequestV1Tests.swift index 709dd507..0166ee2e 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaAppendRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaAppendRequestV1Tests.swift @@ -1,15 +1,13 @@ +// UploadMediaAppendRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class UploadMediaAppendRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class UploadMediaAppendRequestV1Tests: XCTestCase { + public func test() throws { let data = Data() let req = UploadMediaAppendRequestV1( mediaID: "m", @@ -24,17 +22,17 @@ class UploadMediaAppendRequestV1Tests: XCTestCase { XCTAssertEqual(req.path, "/1.1/media/upload.json") XCTAssertEqual(req.bodyContentType, .multipartFormData) XCTAssertEqual( - req.parameters as! [String: MultipartFormDataPart], + req.parameters as? [String: MultipartFormDataPart], [ "command": MultipartFormDataPart.value(name: "command", value: "APPEND"), "media_id": MultipartFormDataPart.value(name: "media_id", value: "m"), "media": MultipartFormDataPart.data(name: "media", value: data, filename: "f", mimeType: "m"), "segment_index": MultipartFormDataPart.value(name: "segment_index", value: 1), - ]) + ] + ) } - func testSegments() throws { - + public func testSegments() throws { let data = Data([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) let req = UploadMediaAppendRequestV1( @@ -65,7 +63,7 @@ class UploadMediaAppendRequestV1Tests: XCTestCase { XCTAssertEqual(reqs[3].segmentIndex, 3) } - func testSegumentsMiddle() throws { + public func testSegumentsMiddle() throws { // | 0 | 1 | 2 | 3 | 4 | 5 let data = Data([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) @@ -97,4 +95,8 @@ class UploadMediaAppendRequestV1Tests: XCTestCase { XCTAssertEqual(reqs[3].media, Data([10])) XCTAssertEqual(reqs[3].segmentIndex, 5) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaFinalizeRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaFinalizeRequestV1Tests.swift index 08f13e0b..46e5cdf2 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaFinalizeRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaFinalizeRequestV1Tests.swift @@ -1,15 +1,13 @@ +// UploadMediaFinalizeRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class UploadMediaFinalizeRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class UploadMediaFinalizeRequestV1Tests: XCTestCase { + public func test() throws { let req = UploadMediaFinalizeRequestV1(mediaID: "m") XCTAssertEqual(req.method, .post) @@ -21,7 +19,11 @@ class UploadMediaFinalizeRequestV1Tests: XCTestCase { [ "command": "FINALIZE", "media_id": "m", - ]) + ] + ) } + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaInitRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaInitRequestV1Tests.swift index 44f84afc..2ed319fe 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaInitRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaInitRequestV1Tests.swift @@ -1,15 +1,13 @@ +// UploadMediaInitRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class UploadMediaInitRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class UploadMediaInitRequestV1Tests: XCTestCase { + public func test() throws { let req = UploadMediaInitRequestV1( totalBytes: 10, mediaType: "image/jpg", @@ -29,6 +27,11 @@ class UploadMediaInitRequestV1Tests: XCTestCase { "media_type": "image/jpg", "media_category": "c", "additional_owners": "1,2", - ]) + ] + ) + } + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaUtilTests.swift b/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaUtilTests.swift index 06a92340..42dbf2d8 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaUtilTests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Media/UploadMediaUtilTests.swift @@ -1,17 +1,29 @@ +// UploadMediaUtilTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class UploadMediaUtilTests: XCTestCase { - - override func setUpWithError() throws { +internal class UploadMediaUtilTests: XCTestCase { + + // Helper function to safely serialize JSON + private func serializeJSON(_ object: [String: Any]) throws -> Data { + do { + return try JSONSerialization.data(withJSONObject: object, options: []) + } catch { + XCTFail("Failed to serialize JSON: \(error)") + throw error + } } - - override func tearDownWithError() throws { + + override public func tearDownWithError() throws { MockURLProtocol.cleanup() } - func testWithProcessing() throws { - + // swiftlint:disable:next function_body_length + public func testWithProcessing() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] @@ -21,7 +33,12 @@ class UploadMediaUtilTests: XCTestCase { ) var requestCount = 0 - MockURLProtocol.requestHandler = { request in + // swiftlint:disable:next closure_body_length + MockURLProtocol.requestHandler = { [weak self] request in + guard let self else { + throw URLError(.unknown) + } + defer { requestCount += 1 } @@ -33,78 +50,103 @@ class UploadMediaUtilTests: XCTestCase { } var data = Data() switch requestCount { - case 0: // INIT + case 0: // INIT XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("command=INIT")) - - data = try! JSONSerialization.data( - withJSONObject: [ - "media_id_string": "123", - "expires_after_secs": 1000, - ], options: []) - - case 1: // APPEND + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("command=INIT")) + } else { + XCTFail("Request body string is nil") + } + + data = try self.serializeJSON([ + "media_id_string": "123", + "expires_after_secs": 1_000, + ]) + case 1: // APPEND XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("\r\nAPPEND\r\n")) - case 2: // APPEND + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("\r\nAPPEND\r\n")) + } else { + XCTFail("Request body string is nil") + } + case 2: // APPEND XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("\r\nAPPEND\r\n")) - case 3: // FINALIZE + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("\r\nAPPEND\r\n")) + } else { + XCTFail("Request body string is nil") + } + case 3: // FINALIZE XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("command=FINALIZE")) - - data = try! JSONSerialization.data( - withJSONObject: [ - "media_id_string": "123", - "size": 10, - "expires_after_secs": 200, - "processingInfo": [ - "state": "pending", - "check_after_secs": 0, - ], - ], options: []) + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("command=FINALIZE")) + } else { + XCTFail("Request body string is nil") + } + + data = try self.serializeJSON([ + "media_id_string": "123", + "size": 10, + "expires_after_secs": 200, + "processingInfo": [ + "state": "pending", + "check_after_secs": 0, + ], + ]) case 4: - XCTAssertEqual(request.httpMethod, "GET") XCTAssertEqual(request.url?.path, "/1.1/media/upload.json") - XCTAssertTrue(request.url!.query!.contains("command=STATUS")) - - data = try! JSONSerialization.data( - withJSONObject: [ - "media_id_string": "123", - "processing_info": [ - "state": "in_progress", - "progress_percent": 99, - "check_after_secs": 0, - ], - ], options: [] - ) + if let url = request.url, let query = url.query { + XCTAssertTrue(query.contains("command=STATUS")) + } else { + XCTFail("URL or query is nil") + } + + data = try self.serializeJSON([ + "media_id_string": "123", + "processing_info": [ + "state": "in_progress", + "progress_percent": 99, + "check_after_secs": 0, + ], + ]) case 5: - XCTAssertEqual(request.httpMethod, "GET") XCTAssertEqual(request.url?.path, "/1.1/media/upload.json") - XCTAssertTrue(request.url!.query!.contains("command=STATUS")) - - data = try! JSONSerialization.data( - withJSONObject: [ - "media_id_string": "123", - "video": [ - "video_type": "video/mp4" - ], - "processing_info": [ - "state": "succeeded", - "progress_percent": 100, - ], - ], options: [] - ) + if let url = request.url, let query = url.query { + XCTAssertTrue(query.contains("command=STATUS")) + } else { + XCTFail("URL or query is nil") + } + + data = try self.serializeJSON([ + "media_id_string": "123", + "video": [ + "video_type": "video/mp4", + ], + "processing_info": [ + "state": "succeeded", + "progress_percent": 100, + ], + ]) default: - XCTFail() + XCTFail("Invalid Response") } - return ( - HTTPURLResponse(url: request.url!, statusCode: 200, httpVersion: "2.0", headerFields: [:])!, - data - ) + if let url = request.url { + return ( + HTTPURLResponse( + url: url, + statusCode: 200, + httpVersion: "2.0", + headerFields: [:] + ) ?? HTTPURLResponse(), + data + ) + } else { + XCTFail("Request URL is nil") + return (HTTPURLResponse(), data) + } } let exp = expectation(description: "") @@ -119,10 +161,9 @@ class UploadMediaUtilTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testInitError() throws { - + public func testInitError() throws { let config = URLSessionConfiguration.default - config.protocolClasses = [MockURLProtocol.self] + config.protocolinternal classes = [MockURLProtocol.self] let client = TwitterAPIClient( .oauth10a(.init(consumerKey: "", consumerSecret: "", oauthToken: "", oauthTokenSecret: "")), @@ -143,20 +184,33 @@ class UploadMediaUtilTests: XCTestCase { let data = Data("{}".utf8) var statusCode = 200 switch requestCount { - case 0: // INIT + case 0: // INIT XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("command=INIT")) - + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("command=INIT")) + } else { + XCTFail("Request body string is nil") + } statusCode = 404 default: - XCTFail() + XCTFail("Invalid Response") } - return ( - HTTPURLResponse(url: request.url!, statusCode: statusCode, httpVersion: "2.0", headerFields: [:])!, - data - ) + if let url = request.url { + return ( + HTTPURLResponse( + url: url, + statusCode: statusCode, + httpVersion: "2.0", + headerFields: [:] + ) ?? HTTPURLResponse(), + data + ) + } else { + XCTFail("Request URL is nil") + return (HTTPURLResponse(), data) + } } let exp = expectation(description: "") @@ -168,7 +222,6 @@ class UploadMediaUtilTests: XCTestCase { if case .responseFailed(reason: .unacceptableStatusCode(statusCode: 404, error: _, rateLimit: _)) = response .error { - } else { XCTFail(response.prettyString) } @@ -179,8 +232,7 @@ class UploadMediaUtilTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testAppendError() throws { - + public func testAppendError() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] @@ -190,7 +242,11 @@ class UploadMediaUtilTests: XCTestCase { ) var requestCount = 0 - MockURLProtocol.requestHandler = { request in + MockURLProtocol.requestHandler = { [weak self] request in + guard let self else { + throw URLError(.unknown) + } + defer { requestCount += 1 } @@ -203,32 +259,52 @@ class UploadMediaUtilTests: XCTestCase { var data = Data() var statusCode = 200 switch requestCount { - case 0: // INIT + case 0: // INIT XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("command=INIT")) - - data = try! JSONSerialization.data( - withJSONObject: [ - "media_id_string": "123", - "expires_after_secs": 1000, - ], options: []) - - case 1: // APPEND + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("command=INIT")) + } else { + XCTFail("Request body string is nil") + } + + data = try self.serializeJSON([ + "media_id_string": "123", + "expires_after_secs": 1_000, + ]) + case 1: // APPEND XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("\r\nAPPEND\r\n")) + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("\r\nAPPEND\r\n")) + } else { + XCTFail("Request body string is nil") + } statusCode = 400 - case 2: // APPEND + case 2: // APPEND XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("\r\nAPPEND\r\n")) + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("\r\nAPPEND\r\n")) + } else { + XCTFail("Request body string is nil") + } statusCode = 200 default: - XCTFail() + XCTFail("Invalid Response") } - return ( - HTTPURLResponse(url: request.url!, statusCode: statusCode, httpVersion: "2.0", headerFields: [:])!, - data - ) + if let url = request.url { + return ( + HTTPURLResponse( + url: url, + statusCode: statusCode, + httpVersion: "2.0", + headerFields: [:] + ) ?? HTTPURLResponse(), + data + ) + } else { + XCTFail("Request URL is nil") + return (HTTPURLResponse(), data) + } } let exp = expectation(description: "") @@ -240,7 +316,6 @@ class UploadMediaUtilTests: XCTestCase { if case .responseFailed(reason: .unacceptableStatusCode(statusCode: 400, error: _, rateLimit: _)) = response .error { - } else { XCTFail(response.prettyString) } @@ -251,8 +326,7 @@ class UploadMediaUtilTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testFinalizeError() throws { - + public func testFinalizeError() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] @@ -263,7 +337,11 @@ class UploadMediaUtilTests: XCTestCase { var statusCode = 200 var requestCount = 0 - MockURLProtocol.requestHandler = { request in + MockURLProtocol.requestHandler = { [weak self] request in + guard let self else { + throw URLError(.unknown) + } + defer { requestCount += 1 } @@ -275,34 +353,58 @@ class UploadMediaUtilTests: XCTestCase { } var data = Data() switch requestCount { - case 0: // INIT + case 0: // INIT XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("command=INIT")) - - data = try! JSONSerialization.data( - withJSONObject: [ - "media_id_string": "123", - "expires_after_secs": 1000, - ], options: []) - - case 1: // APPEND + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("command=INIT")) + } else { + XCTFail("Request body string is nil") + } + + data = try self.serializeJSON([ + "media_id_string": "123", + "expires_after_secs": 1_000, + ]) + case 1: // APPEND XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("\r\nAPPEND\r\n")) - case 2: // APPEND + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("\r\nAPPEND\r\n")) + } else { + XCTFail("Request body string is nil") + } + case 2: // APPEND XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("\r\nAPPEND\r\n")) - case 3: // FINALIZE + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("\r\nAPPEND\r\n")) + } else { + XCTFail("Request body string is nil") + } + case 3: // FINALIZE XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("command=FINALIZE")) + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("command=FINALIZE")) + } else { + XCTFail("Request body string is nil") + } statusCode = 500 default: - XCTFail() + XCTFail("Invalid Response") } - return ( - HTTPURLResponse(url: request.url!, statusCode: statusCode, httpVersion: "2.0", headerFields: [:])!, - data - ) + if let url = request.url { + return ( + HTTPURLResponse( + url: url, + statusCode: statusCode, + httpVersion: "2.0", + headerFields: [:] + ) ?? HTTPURLResponse(), + data + ) + } else { + XCTFail("Request URL is nil") + return (HTTPURLResponse(), data) + } } let exp = expectation(description: "") @@ -314,7 +416,6 @@ class UploadMediaUtilTests: XCTestCase { if case .responseFailed(reason: .unacceptableStatusCode(statusCode: 500, error: _, rateLimit: _)) = response .error { - } else { XCTFail(response.prettyString) } @@ -324,8 +425,8 @@ class UploadMediaUtilTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testWithProcessingError() throws { - + // swiftlint:disable:next function_body_length + public func testWithProcessingError() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] @@ -335,7 +436,12 @@ class UploadMediaUtilTests: XCTestCase { ) var requestCount = 0 - MockURLProtocol.requestHandler = { request in + // swiftlint:disable:next closure_body_length + MockURLProtocol.requestHandler = { [weak self] request in + guard let self else { + throw URLError(.unknown) + } + defer { requestCount += 1 } @@ -347,97 +453,119 @@ class UploadMediaUtilTests: XCTestCase { } var data = Data() switch requestCount { - case 0: // INIT + case 0: // INIT XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("command=INIT")) - - data = try! JSONSerialization.data( - withJSONObject: [ - "media_id_string": "123", - "expires_after_secs": 1000, - ], options: []) - - case 1: // APPEND + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("command=INIT")) + } else { + XCTFail("Request body string is nil") + } + + data = try self.serializeJSON([ + "media_id_string": "123", + "expires_after_secs": 1_000, + ]) + case 1: // APPEND XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("\r\nAPPEND\r\n")) - case 2: // APPEND + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("\r\nAPPEND\r\n")) + } else { + XCTFail("Request body string is nil") + } + case 2: // APPEND XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("\r\nAPPEND\r\n")) - case 3: // FINALIZE + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("\r\nAPPEND\r\n")) + } else { + XCTFail("Request body string is nil") + } + case 3: // FINALIZE XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("command=FINALIZE")) - - data = try! JSONSerialization.data( - withJSONObject: [ - "media_id_string": "123", - "size": 10, - "expires_after_secs": 200, - "processingInfo": [ - "state": "pending", - "check_after_secs": 0, - ], - ], options: []) + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("command=FINALIZE")) + } else { + XCTFail("Request body string is nil") + } + + data = try self.serializeJSON([ + "media_id_string": "123", + "size": 10, + "expires_after_secs": 200, + "processingInfo": [ + "state": "pending", + "check_after_secs": 0, + ], + ]) case 4: - XCTAssertEqual(request.httpMethod, "GET") XCTAssertEqual(request.url?.path, "/1.1/media/upload.json") - XCTAssertTrue(request.url!.query!.contains("command=STATUS")) - - data = try! JSONSerialization.data( - withJSONObject: [ - "media_id_string": "123", - "processing_info": [ - "state": "in_progress", - "progress_percent": 99, - "check_after_secs": 0, - ], - ], options: [] - ) + if let url = request.url, let query = url.query { + XCTAssertTrue(query.contains("command=STATUS")) + } else { + XCTFail("URL or query is nil") + } + + data = try self.serializeJSON([ + "media_id_string": "123", + "processing_info": [ + "state": "in_progress", + "progress_percent": 99, + "check_after_secs": 0, + ], + ]) case 5: - XCTAssertEqual(request.httpMethod, "GET") XCTAssertEqual(request.url?.path, "/1.1/media/upload.json") - XCTAssertTrue(request.url!.query!.contains("command=STATUS")) - - data = try! JSONSerialization.data( - withJSONObject: [ - "media_id_string": "123", - "processing_info": [ - "state": "failed", - "progress_percent": 99, - "error": [ - "code": 1, - "name": "InvalidMedia", - "message": "Unsupported video format", - ], + if let url = request.url, let query = url.query { + XCTAssertTrue(query.contains("command=STATUS")) + } else { + XCTFail("URL or query is nil") + } + + data = try self.serializeJSON([ + "media_id_string": "123", + "processing_info": [ + "state": "failed", + "error": [ + "message": "Invalid media", + "code": 1, ], - ], options: [] - ) + ], + ]) default: - XCTFail() + XCTFail("Invalid Response") } - return ( - HTTPURLResponse(url: request.url!, statusCode: 200, httpVersion: "2.0", headerFields: [:])!, - data - ) + if let url = request.url { + return ( + HTTPURLResponse( + url: url, + statusCode: 200, + httpVersion: "2.0", + headerFields: [:] + ) ?? HTTPURLResponse(), + data + ) + } else { + XCTFail("Request URL is nil") + return (HTTPURLResponse(), data) + } } let exp = expectation(description: "") let data = Data([1, 2, 3]) client.v1.media.uploadMedia(.init(media: data, mediaType: "m", filename: "f", uploadChunkSize: 2)) { response in XCTAssertTrue(response.isError) - XCTAssertTrue(response.error!.isUploadMediaFailed) + XCTAssertTrue(response.error?.isUploadMediaFailed ?? false) exp.fulfill() } wait(for: [exp], timeout: 10) } - func testWithoutProcessing() throws { - + public func testWithoutProcessing() throws { let config = URLSessionConfiguration.default - config.protocolClasses = [MockURLProtocol.self] + config.protocolinternal classes = [MockURLProtocol.self] let client = TwitterAPIClient( .oauth10a(.init(consumerKey: "", consumerSecret: "", oauthToken: "", oauthTokenSecret: "")), @@ -457,38 +585,73 @@ class UploadMediaUtilTests: XCTestCase { } var data = Data() switch requestCount { - case 0: // INIT + case 0: // INIT XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("command=INIT")) - - data = try! JSONSerialization.data( - withJSONObject: [ - "media_id_string": "123", - "expires_after_secs": 1000, - ], options: []) + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("command=INIT")) + } else { + XCTFail("Request body string is nil") + } + + do { + data = try JSONSerialization.data( + withJSONObject: [ + "media_id_string": "123", + "expires_after_secs": 1_000, + ], + options: [] + ) + } catch { + XCTFail("Failed to serialize JSON: \(error)") + } - case 1: // APPEND - XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("\r\nAPPEND\r\n")) - case 2: // FINALIZE + case 1: // APPEND XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") - XCTAssertTrue(requestBodyString!.contains("command=FINALIZE")) + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("\r\nAPPEND\r\n")) + } else { + XCTFail("Request body string is nil") + } - data = try! JSONSerialization.data( - withJSONObject: [ - "media_id_string": "123", - "size": 10, - "expires_after_secs": 200, - ], options: []) + case 2: // FINALIZE + XCTAssertEqual(request.url?.absoluteString, "https://upload.twitter.com/1.1/media/upload.json") + if let bodyString = requestBodyString { + XCTAssertTrue(bodyString.contains("command=FINALIZE")) + } else { + XCTFail("Request body string is nil") + } + + do { + data = try JSONSerialization.data( + withJSONObject: [ + "media_id_string": "123", + "size": 10, + "expires_after_secs": 200, + ], + options: [] + ) + } catch { + XCTFail("Failed to serialize JSON: \(error)") + } default: - XCTFail() + XCTFail("Invalid Response") } - return ( - HTTPURLResponse(url: request.url!, statusCode: 200, httpVersion: "2.0", headerFields: [:])!, - data - ) + if let url = request.url { + return ( + HTTPURLResponse( + url: url, + statusCode: 200, + httpVersion: "2.0", + headerFields: [:] + ) ?? HTTPURLResponse(), + data + ) + } else { + XCTFail("Request URL is nil") + return (HTTPURLResponse(), data) + } } let exp = expectation(description: "") @@ -501,4 +664,8 @@ class UploadMediaUtilTests: XCTestCase { wait(for: [exp], timeout: 10) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Retweet/GetRetweetersRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Retweet/GetRetweetersRequestV1Tests.swift index ad223e8a..b91b3e80 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Retweet/GetRetweetersRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Retweet/GetRetweetersRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetRetweetersRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetRetweetersRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetRetweetersRequestV1Tests: XCTestCase { + public func test() throws { let req = GetRetweetersRequestV1( id: "_i_", count: 100, @@ -31,7 +30,7 @@ class GetRetweetersRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetRetweetersRequestV1( id: "_i_" ) @@ -39,8 +38,12 @@ class GetRetweetersRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "id": "_i_" + "id": "_i_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Retweet/GetRetweetsOfMeRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Retweet/GetRetweetsOfMeRequestV1Tests.swift index ac2badd4..3b733fcc 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Retweet/GetRetweetsOfMeRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Retweet/GetRetweetsOfMeRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetRetweetsOfMeRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetRetweetsOfMeRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetRetweetsOfMeRequestV1Tests: XCTestCase { + public func test() throws { let req = GetRetweetsOfMeRequestV1( count: 10, sinceID: "_s_", @@ -35,7 +34,7 @@ class GetRetweetsOfMeRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetRetweetsOfMeRequestV1() AssertEqualAnyDict( @@ -43,4 +42,8 @@ class GetRetweetsOfMeRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Retweet/GetRetweetsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Retweet/GetRetweetsRequestV1Tests.swift index 943fb194..99f53207 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Retweet/GetRetweetsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Retweet/GetRetweetsRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetRetweetsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetRetweetsRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetRetweetsRequestV1Tests: XCTestCase { + public func test() throws { let req = GetRetweetsRequestV1( id: "_i_", count: 12, @@ -28,7 +27,7 @@ class GetRetweetsRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetRetweetsRequestV1( id: "_i_" ) @@ -38,4 +37,8 @@ class GetRetweetsRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Retweet/PostRetweetRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Retweet/PostRetweetRequestV1Tests.swift index 4dd75c38..efe4e659 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Retweet/PostRetweetRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Retweet/PostRetweetRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostRetweetRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostRetweetRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostRetweetRequestV1Tests: XCTestCase { + public func test() throws { let req = PostRetweetRequestV1( id: "_i_", trimUser: true @@ -21,12 +20,12 @@ class PostRetweetRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "trim_user": true + "trim_user": true, ] ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostRetweetRequestV1( id: "_i_" ) @@ -36,4 +35,8 @@ class PostRetweetRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Retweet/PostUnRetweetRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Retweet/PostUnRetweetRequestV1Tests.swift index 54247f8f..a33cc62c 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Retweet/PostUnRetweetRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Retweet/PostUnRetweetRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostUnRetweetRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostUnRetweetRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostUnRetweetRequestV1Tests: XCTestCase { + public func test() throws { let req = PostUnRetweetRequestV1( id: "_i_", trimUser: true @@ -21,12 +20,12 @@ class PostUnRetweetRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "trim_user": true + "trim_user": true, ] ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostUnRetweetRequestV1( id: "_i_" ) @@ -36,4 +35,8 @@ class PostUnRetweetRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Search/GetSavedSearchesListRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Search/GetSavedSearchesListRequestV1Tests.swift index a03ba4a6..85a92ca7 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Search/GetSavedSearchesListRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Search/GetSavedSearchesListRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetSavedSearchesListRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetSavedSearchesListRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetSavedSearchesListRequestV1Tests: XCTestCase { + public func test() throws { let req = GetSavedSearchesListRequestV1() XCTAssertEqual(req.method, .get) @@ -20,4 +19,8 @@ class GetSavedSearchesListRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Search/GetSearchTweetsRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Search/GetSearchTweetsRequestV1Tests.swift index fadb2635..dd5ee9ad 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Search/GetSearchTweetsRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Search/GetSearchTweetsRequestV1Tests.swift @@ -1,16 +1,13 @@ +// GetSearchTweetsRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetSearchTweetsRequestV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class GetSearchTweetsRequestV1Tests: XCTestCase { + public func test() throws { let req = GetSearchTweetsRequestV1( q: "あああ", lang: "lang", @@ -40,10 +37,11 @@ class GetSearchTweetsRequestV1Tests: XCTestCase { "count": 20, "max_id": "100", "locale": "locale", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetSearchTweetsRequestV1( q: "_q_" ) @@ -51,8 +49,12 @@ class GetSearchTweetsRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "q": "_q_" + "q": "_q_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Search/PostSavedSearchesCreateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Search/PostSavedSearchesCreateRequestV1Tests.swift index fc135ae1..9aa6b978 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Search/PostSavedSearchesCreateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Search/PostSavedSearchesCreateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostSavedSearchesCreateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostSavedSearchesCreateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostSavedSearchesCreateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostSavedSearchesCreateRequestV1( query: "_q_" ) @@ -20,8 +19,12 @@ class PostSavedSearchesCreateRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "query": "_q_" + "query": "_q_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Search/PostSavedSearchesDestroyRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Search/PostSavedSearchesDestroyRequestV1Tests.swift index 4caab937..5b6acc55 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Search/PostSavedSearchesDestroyRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Search/PostSavedSearchesDestroyRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostSavedSearchesDestroyRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostSavedSearchesDestroyRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostSavedSearchesDestroyRequestV1Tests: XCTestCase { + public func test() throws { let req = PostSavedSearchesDestroyRequestV1( id: "_i_" ) @@ -22,4 +21,8 @@ class PostSavedSearchesDestroyRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Timelines/GetStatusesHomeTimelineRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Timelines/GetStatusesHomeTimelineRequestV1Tests.swift index 839b5d3c..718a2b32 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Timelines/GetStatusesHomeTimelineRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Timelines/GetStatusesHomeTimelineRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetStatusesHomeTimelineRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetStatusesHomeTimelineRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetStatusesHomeTimelineRequestV1Tests: XCTestCase { + public func test() throws { let req = GetStatusesHomeTimelineRequestV1( count: 11, maxID: "_m_", @@ -35,7 +34,7 @@ class GetStatusesHomeTimelineRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetStatusesHomeTimelineRequestV1() AssertEqualAnyDict( @@ -43,4 +42,8 @@ class GetStatusesHomeTimelineRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Timelines/GetStatusesMentionsTimelineRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Timelines/GetStatusesMentionsTimelineRequestV1Tests.swift index de4e5376..08b25535 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Timelines/GetStatusesMentionsTimelineRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Timelines/GetStatusesMentionsTimelineRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetStatusesMentionsTimelineRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetStatusesMentionsTimelineRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetStatusesMentionsTimelineRequestV1Tests: XCTestCase { + public func test() throws { let req = GetStatusesMentionsTimelineRequestV1( count: 100, maxID: "_m_", @@ -33,7 +32,7 @@ class GetStatusesMentionsTimelineRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetStatusesMentionsTimelineRequestV1() AssertEqualAnyDict( @@ -41,4 +40,8 @@ class GetStatusesMentionsTimelineRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Timelines/GetStatusesUserTimelineRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Timelines/GetStatusesUserTimelineRequestV1Tests.swift index 7ebf2d54..1785906a 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Timelines/GetStatusesUserTimelineRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Timelines/GetStatusesUserTimelineRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetStatusesUserTimelineRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetStatusesUserTimelineRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetStatusesUserTimelineRequestV1Tests: XCTestCase { + public func test() throws { let req = GetStatusesUserTimelineRequestV1( user: .userID("uid"), count: 12, @@ -37,7 +36,7 @@ class GetStatusesUserTimelineRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetStatusesUserTimelineRequestV1( user: .screenName("s") ) @@ -45,8 +44,12 @@ class GetStatusesUserTimelineRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Trend/GetTrendsAvailableRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Trend/GetTrendsAvailableRequestV1Tests.swift index a9ad42ad..5f9b99ec 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Trend/GetTrendsAvailableRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Trend/GetTrendsAvailableRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetTrendsAvailableRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTrendsAvailableRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetTrendsAvailableRequestV1Tests: XCTestCase { + public func test() throws { let req = GetTrendsAvailableRequestV1() XCTAssertEqual(req.method, .get) @@ -20,4 +19,8 @@ class GetTrendsAvailableRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Trend/GetTrendsClosestRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Trend/GetTrendsClosestRequestV1Tests.swift index 32f24cd0..e100e7ac 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Trend/GetTrendsClosestRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Trend/GetTrendsClosestRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetTrendsClosestRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTrendsClosestRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetTrendsClosestRequestV1Tests: XCTestCase { + public func test() throws { let req = GetTrendsClosestRequestV1( location: TwitterCoordinateV1(lat: 37.7, long: -122.4) ) @@ -25,4 +24,8 @@ class GetTrendsClosestRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Trend/GetTrendsPlaceRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Trend/GetTrendsPlaceRequestV1Tests.swift index 3ebe4126..a640cebf 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Trend/GetTrendsPlaceRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Trend/GetTrendsPlaceRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetTrendsPlaceRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTrendsPlaceRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetTrendsPlaceRequestV1Tests: XCTestCase { + public func test() throws { let req = GetTrendsPlaceRequestV1( woeid: "_w_", exclude: true @@ -27,7 +26,7 @@ class GetTrendsPlaceRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetTrendsPlaceRequestV1( woeid: "_w_" ) @@ -35,8 +34,12 @@ class GetTrendsPlaceRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "woeid": "_w_" + "woeid": "_w_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Tweet/GetStatusesLookupRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Tweet/GetStatusesLookupRequestV1Tests.swift index 85599f1e..782cb5e2 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Tweet/GetStatusesLookupRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Tweet/GetStatusesLookupRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetStatusesLookupRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetStatusesLookupRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetStatusesLookupRequestV1Tests: XCTestCase { + public func test() throws { let req = GetStatusesLookupRequestV1( ids: ["a", "b"], map: true, @@ -35,7 +34,7 @@ class GetStatusesLookupRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetStatusesLookupRequestV1( ids: ["a"] ) @@ -43,8 +42,12 @@ class GetStatusesLookupRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "id": "a" + "id": "a", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Tweet/GetStatusesShowRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Tweet/GetStatusesShowRequestV1Tests.swift index fdfd00f7..8b48cfcb 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Tweet/GetStatusesShowRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Tweet/GetStatusesShowRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetStatusesShowRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetStatusesShowRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetStatusesShowRequestV1Tests: XCTestCase { + public func test() throws { let req = GetStatusesShowRequestV1( id: "_i_", trimUser: true, @@ -35,7 +34,7 @@ class GetStatusesShowRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetStatusesShowRequestV1( id: "_i_" ) @@ -43,8 +42,12 @@ class GetStatusesShowRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "id": "_i_" + "id": "_i_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Tweet/PostStatusesDestroyRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Tweet/PostStatusesDestroyRequestV1Tests.swift index 9c819514..556dfb2d 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Tweet/PostStatusesDestroyRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Tweet/PostStatusesDestroyRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostStatusesDestroyRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostStatusesDestroyRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostStatusesDestroyRequestV1Tests: XCTestCase { + public func test() throws { let req = PostStatusesDestroyRequestV1( id: "_i_", trimUser: true @@ -21,12 +20,12 @@ class PostStatusesDestroyRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "trim_user": true + "trim_user": true, ] ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostStatusesDestroyRequestV1( id: "_i_" ) @@ -36,4 +35,8 @@ class PostStatusesDestroyRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Tweet/PostStatusesUpdateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Tweet/PostStatusesUpdateRequestV1Tests.swift index 07383ef3..08706240 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Tweet/PostStatusesUpdateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Tweet/PostStatusesUpdateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostStatusesUpdateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostStatusesUpdateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostStatusesUpdateRequestV1Tests: XCTestCase { + public func test() throws { let req = PostStatusesUpdateRequestV1( status: "_s_", inReplyToStatusID: "_i_", @@ -52,7 +51,7 @@ class PostStatusesUpdateRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostStatusesUpdateRequestV1( status: "_s_" ) @@ -60,8 +59,12 @@ class PostStatusesUpdateRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "status": "_s_" + "status": "_s_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersLookupRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersLookupRequestV1Tests.swift index 50980dc4..20fab5f3 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersLookupRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersLookupRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetUsersLookupRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersLookupRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersLookupRequestV1Tests: XCTestCase { + public func test() throws { let req = GetUsersLookupRequestV1( users: .userIDs(["uid1", "uid2"]), tweetMode: true, @@ -29,7 +28,7 @@ class GetUsersLookupRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersLookupRequestV1( users: .screenNames(["s1", "s2"]) ) @@ -37,8 +36,12 @@ class GetUsersLookupRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s1,s2" + "screen_name": "s1,s2", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersProfileBannerRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersProfileBannerRequestV1Tests.swift index 6d8d65cd..b4af699e 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersProfileBannerRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersProfileBannerRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetUsersProfileBannerRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersProfileBannerRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersProfileBannerRequestV1Tests: XCTestCase { + public func test() throws { let req = GetUsersProfileBannerRequestV1( user: .userID("uid") ) @@ -20,12 +19,12 @@ class GetUsersProfileBannerRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "user_id": "uid" + "user_id": "uid", ] ) } - func testScreenName() throws { + public func testScreenName() throws { let req = GetUsersProfileBannerRequestV1( user: .screenName("s") ) @@ -37,8 +36,12 @@ class GetUsersProfileBannerRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersSearchRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersSearchRequestV1Tests.swift index 847efba6..31cff079 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersSearchRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersSearchRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetUsersSearchRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersSearchRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersSearchRequestV1Tests: XCTestCase { + public func test() throws { let req = GetUsersSearchRequestV1( q: "_q_", page: 11, @@ -31,7 +30,7 @@ class GetUsersSearchRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersSearchRequestV1( q: "qq" ) @@ -39,8 +38,12 @@ class GetUsersSearchRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "q": "qq" + "q": "qq", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersShowRequestV1Tests.swift b/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersShowRequestV1Tests.swift index 878ddf7c..c54056ab 100644 --- a/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersShowRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv1/Users/GetUsersShowRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetUsersShowRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersShowRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersShowRequestV1Tests: XCTestCase { + public func test() throws { let req = GetUsersShowRequestV1( user: .userID("uid"), includeEntities: true @@ -27,7 +26,7 @@ class GetUsersShowRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersShowRequestV1( user: .screenName("s") ) @@ -35,8 +34,12 @@ class GetUsersShowRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "screen_name": "s" + "screen_name": "s", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/DeleteUsersBlockingRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/DeleteUsersBlockingRequestV2Tests.swift index fe01f86e..14537f46 100644 --- a/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/DeleteUsersBlockingRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/DeleteUsersBlockingRequestV2Tests.swift @@ -1,14 +1,13 @@ +// DeleteUsersBlockingRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class DeleteUsersBlockingRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class DeleteUsersBlockingRequestV2Tests: XCTestCase { + public func test() throws { let req = DeleteUsersBlockingRequestV2( sourceUserID: "_sourceUserID_", targetUserID: "_targetUserID_" @@ -20,4 +19,8 @@ class DeleteUsersBlockingRequestV2Tests: XCTestCase { XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/DeleteUsersMutingRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/DeleteUsersMutingRequestV2Tests.swift index 532ef6cd..0e3b1edc 100644 --- a/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/DeleteUsersMutingRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/DeleteUsersMutingRequestV2Tests.swift @@ -1,14 +1,13 @@ +// DeleteUsersMutingRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class DeleteUsersMutingRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class DeleteUsersMutingRequestV2Tests: XCTestCase { + public func test() throws { let req = DeleteUsersMutingRequestV2( sourceUserID: "_sourceUserID_", targetUserID: "_targetUserID_" @@ -20,4 +19,8 @@ class DeleteUsersMutingRequestV2Tests: XCTestCase { XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/GetUsersBlockingRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/GetUsersBlockingRequestV2Tests.swift index f8cf17d9..8863b4dd 100644 --- a/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/GetUsersBlockingRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/GetUsersBlockingRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersBlockingRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersBlockingRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersBlockingRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersBlockingRequestV2( id: "_id_", expansions: [.pinnedTweetID], @@ -30,14 +29,19 @@ class GetUsersBlockingRequestV2Tests: XCTestCase { "pagination_token": "token", "tweet.fields": "context_annotations,entities,geo", "user.fields": "profile_image_url,protected,public_metrics", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersBlockingRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/GetUsersMutingRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/GetUsersMutingRequestV2Tests.swift index fb7dfc0a..4336a5d0 100644 --- a/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/GetUsersMutingRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/GetUsersMutingRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersMutingRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersMutingRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersMutingRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersMutingRequestV2( id: "_id_", expansions: [.pinnedTweetID], @@ -30,14 +29,19 @@ class GetUsersMutingRequestV2Tests: XCTestCase { "pagination_token": "t", "tweet.fields": "conversation_id,id,in_reply_to_user_id", "user.fields": "created_at,username,verified", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersMutingRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/PostUsersBlockingRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/PostUsersBlockingRequestV2Tests.swift index 9f9344fc..112906b7 100644 --- a/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/PostUsersBlockingRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/PostUsersBlockingRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostUsersBlockingRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostUsersBlockingRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostUsersBlockingRequestV2Tests: XCTestCase { + public func test() throws { let req = PostUsersBlockingRequestV2( id: "_id_", targetUserID: "_targetUserID_" @@ -21,7 +20,12 @@ class PostUsersBlockingRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "target_user_id": "_targetUserID_" - ]) + "target_user_id": "_targetUserID_", + ] + ) + } + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/PostUsersMutingRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/PostUsersMutingRequestV2Tests.swift index adc65a7b..c80fe14a 100644 --- a/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/PostUsersMutingRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/BlockAndMute/PostUsersMutingRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostUsersMutingRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostUsersMutingRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostUsersMutingRequestV2Tests: XCTestCase { + public func test() throws { let req = PostUsersMutingRequestV2( id: "_id_", targetUserID: "_targetUserID_" @@ -21,8 +20,12 @@ class PostUsersMutingRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "target_user_id": "_targetUserID_" + "target_user_id": "_targetUserID_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Bookmarks/DeleteUsersBookmarksRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Bookmarks/DeleteUsersBookmarksRequestV2Tests.swift index feec5469..4f52aa97 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Bookmarks/DeleteUsersBookmarksRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Bookmarks/DeleteUsersBookmarksRequestV2Tests.swift @@ -1,14 +1,13 @@ +// DeleteUsersBookmarksRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class DeleteUsersBookmarksRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class DeleteUsersBookmarksRequestV2Tests: XCTestCase { + public func test() throws { let req = DeleteUsersBookmarksRequestV2( id: "_i_", tweetID: "_t_" @@ -23,4 +22,8 @@ class DeleteUsersBookmarksRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Bookmarks/GetUsersBookmarksRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Bookmarks/GetUsersBookmarksRequestV2Tests.swift index 9568292f..d863f8b7 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Bookmarks/GetUsersBookmarksRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Bookmarks/GetUsersBookmarksRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersBookmarksRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersBookmarksRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersBookmarksRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersBookmarksRequestV2( id: "_i_", expansions: [.authorID], @@ -40,7 +39,7 @@ class GetUsersBookmarksRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersBookmarksRequestV2( id: "_i_" ) @@ -50,4 +49,8 @@ class GetUsersBookmarksRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Bookmarks/PostUsersBookmarksRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Bookmarks/PostUsersBookmarksRequestV2Tests.swift index b80831d0..74a989f4 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Bookmarks/PostUsersBookmarksRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Bookmarks/PostUsersBookmarksRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostUsersBookmarksRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostUsersBookmarksRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostUsersBookmarksRequestV2Tests: XCTestCase { + public func test() throws { let req = PostUsersBookmarksRequestV2( id: "_i_", tweetID: "_t_" @@ -21,8 +20,12 @@ class PostUsersBookmarksRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "tweet_id": "_t_" + "tweet_id": "_t_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Compliance/GetComplianceJobRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Compliance/GetComplianceJobRequestV2Tests.swift index f4b29d50..7496afda 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Compliance/GetComplianceJobRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Compliance/GetComplianceJobRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetComplianceJobRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetComplianceJobRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetComplianceJobRequestV2Tests: XCTestCase { + public func test() throws { let req = GetComplianceJobRequestV2( id: 1 ) @@ -19,4 +18,8 @@ class GetComplianceJobRequestV2Tests: XCTestCase { XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Compliance/GetComplianceJobsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Compliance/GetComplianceJobsRequestV2Tests.swift index 0efc6550..b8774a8a 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Compliance/GetComplianceJobsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Compliance/GetComplianceJobsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetComplianceJobsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetComplianceJobsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetComplianceJobsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetComplianceJobsRequestV2( type: .tweets, status: .complete @@ -23,10 +22,11 @@ class GetComplianceJobsRequestV2Tests: XCTestCase { [ "type": "tweets", "status": "complete", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetComplianceJobsRequestV2( type: .users ) @@ -34,7 +34,12 @@ class GetComplianceJobsRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "type": "users" - ]) + "type": "users", + ] + ) + } + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Compliance/PostComplianceJobsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Compliance/PostComplianceJobsRequestV2Tests.swift index 2f4ce6f2..4889840a 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Compliance/PostComplianceJobsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Compliance/PostComplianceJobsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostComplianceJobsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostComplianceJobsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostComplianceJobsRequestV2Tests: XCTestCase { + public func test() throws { let req = PostComplianceJobsRequestV2( type: .tweets, name: "n", @@ -25,10 +24,11 @@ class PostComplianceJobsRequestV2Tests: XCTestCase { "type": "tweets", "name": "n", "resumable": true, - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostComplianceJobsRequestV2( type: .users ) @@ -36,7 +36,12 @@ class PostComplianceJobsRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "type": "users" - ]) + "type": "users", + ] + ) + } + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/APIv2/DirectMessage/GetDmConversationsIdDmEventsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/DirectMessage/GetDmConversationsIdDmEventsRequestV2Tests.swift index 192f10f1..c1a7f6fb 100644 --- a/Tests/TwitterAPIKitTests/APIv2/DirectMessage/GetDmConversationsIdDmEventsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/DirectMessage/GetDmConversationsIdDmEventsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetDmConversationsIdDmEventsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetDmConversationsIdDmEventsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetDmConversationsIdDmEventsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetDmConversationsIdDmEventsRequestV2( id: "_i_", maxResults: 11, @@ -40,7 +39,7 @@ class GetDmConversationsIdDmEventsRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetDmConversationsIdDmEventsRequestV2( id: "i" ) @@ -50,4 +49,8 @@ class GetDmConversationsIdDmEventsRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/DirectMessage/GetDmConversationsWithParticipantIdDmEventsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/DirectMessage/GetDmConversationsWithParticipantIdDmEventsRequestV2Tests.swift index 1c3b4f98..5a9052df 100644 --- a/Tests/TwitterAPIKitTests/APIv2/DirectMessage/GetDmConversationsWithParticipantIdDmEventsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/DirectMessage/GetDmConversationsWithParticipantIdDmEventsRequestV2Tests.swift @@ -1,14 +1,14 @@ +// GetDmConversationsWithParticipantIdDmEventsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetDmConversationsWithParticipantIdDmEventsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +// swiftlint:disable:next type_name +internal class GetDmConversationsWithParticipantIdDmEventsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetDmConversationsWithParticipantIdDmEventsRequestV2( participantID: "_p_id", maxResults: 12, @@ -40,7 +40,7 @@ class GetDmConversationsWithParticipantIdDmEventsRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetDmConversationsWithParticipantIdDmEventsRequestV2( participantID: "p" ) @@ -51,4 +51,8 @@ class GetDmConversationsWithParticipantIdDmEventsRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/DirectMessage/GetDmEventsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/DirectMessage/GetDmEventsRequestV2Tests.swift index 14f7f575..ffbd7c33 100644 --- a/Tests/TwitterAPIKitTests/APIv2/DirectMessage/GetDmEventsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/DirectMessage/GetDmEventsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetDmEventsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetDmEventsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetDmEventsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetDmEventsRequestV2( maxResults: 10, paginationToken: "_p_", @@ -38,4 +37,8 @@ class GetDmEventsRequestV2Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/DirectMessage/PostDmConversationByIdRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/DirectMessage/PostDmConversationByIdRequestV2Tests.swift index 839463a2..7929452e 100644 --- a/Tests/TwitterAPIKitTests/APIv2/DirectMessage/PostDmConversationByIdRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/DirectMessage/PostDmConversationByIdRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostDmConversationByIdRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostDmConversationByIdRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostDmConversationByIdRequestV2Tests: XCTestCase { + public func test() throws { let req = PostDmConversationByIdRequestV2( dmConversationID: "_d_id", attachments: ["1", "2"], @@ -28,7 +27,7 @@ class PostDmConversationByIdRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostDmConversationByIdRequestV2( dmConversationID: "_d_" ) @@ -39,4 +38,8 @@ class PostDmConversationByIdRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/DirectMessage/PostDmConversationRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/DirectMessage/PostDmConversationRequestV2Tests.swift index 7edf056a..8539b3ec 100644 --- a/Tests/TwitterAPIKitTests/APIv2/DirectMessage/PostDmConversationRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/DirectMessage/PostDmConversationRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostDmConversationRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostDmConversationRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostDmConversationRequestV2Tests: XCTestCase { + public func test() throws { let req = PostDmConversationRequestV2( conversationType: .group, participantIDs: ["a", "b"], @@ -33,7 +32,7 @@ class PostDmConversationRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostDmConversationRequestV2( conversationType: .group, participantIDs: ["a", "b", "c"] @@ -48,4 +47,8 @@ class PostDmConversationRequestV2Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/DirectMessage/PostDmConversationWithUserRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/DirectMessage/PostDmConversationWithUserRequestV2Tests.swift index 41aaa055..b24bb440 100644 --- a/Tests/TwitterAPIKitTests/APIv2/DirectMessage/PostDmConversationWithUserRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/DirectMessage/PostDmConversationWithUserRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostDmConversationWithUserRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostDmConversationWithUserRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostDmConversationWithUserRequestV2Tests: XCTestCase { + public func test() throws { let req = PostDmConversationWithUserRequestV2( participantID: "_p_", attachments: ["10"], @@ -28,7 +27,7 @@ class PostDmConversationWithUserRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostDmConversationWithUserRequestV2( participantID: "_p_id" ) @@ -39,4 +38,8 @@ class PostDmConversationWithUserRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/ExpansionsV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/ExpansionsV2Tests.swift index 2683e7f1..95700aec 100644 --- a/Tests/TwitterAPIKitTests/APIv2/ExpansionsV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/ExpansionsV2Tests.swift @@ -1,16 +1,14 @@ +// ExpansionsV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import XCTest @testable import TwitterAPIKit -class ExpansionsV2Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func testTwitterTweetExpansionsV2() throws { +internal class ExpansionsV2Tests: XCTestCase { + public func testTwitterTweetExpansionsV2() throws { let allCases: [TwitterTweetExpansionsV2] = [ .attachmentsPollIDs, .attachmentsMediaKeys, @@ -23,53 +21,57 @@ class ExpansionsV2Tests: XCTestCase { .other("~~~"), ] - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.TweetExpansionsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.TweetExpansionsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, - "attachments.media_keys,attachments.poll_ids,author_id,entities.mentions.username,geo.place_id,in_reply_to_user_id,referenced_tweets.id,referenced_tweets.id.author_id,~~~" + "attachments.media_keys,attachments.poll_ids,author_id," + + "entities.mentions.username,geo.place_id,in_reply_to_user_id," + + "referenced_tweets.id,referenced_tweets.id.author_id,~~~" ) } - func testTwitterTweetExpansionsV2All() throws { + public func testTwitterTweetExpansionsV2All() throws { XCTAssertEqual(TwitterTweetExpansionsV2.all.count, 8) } - func testTwitterUserExpansionsV2() throws { - + public func testTwitterUserExpansionsV2() throws { let allCases: [TwitterUserExpansionsV2] = [ .pinnedTweetID, .other("~~~"), ] - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.UserExpansionsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.UserExpansionsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, "pinned_tweet_id,~~~" ) } - func testTwitterUserExpansionsV2All() throws { + public func testTwitterUserExpansionsV2All() throws { XCTAssertEqual(TwitterUserExpansionsV2.all.count, 1) } - func testTwitterListExpansionsV2() throws { + public func testTwitterListExpansionsV2() throws { let allCases: [TwitterListExpansionsV2] = [ .ownerID, .other("~~~"), ] - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.ListExpansionsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.ListExpansionsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, "owner_id,~~~" ) } - func testTwitterListExpansionsV2All() throws { + public func testTwitterListExpansionsV2All() throws { XCTAssertEqual(TwitterListExpansionsV2.all.count, 1) } - func testTwitterSpaceExpansionsV2() throws { + public func testTwitterSpaceExpansionsV2() throws { let allCases: [TwitterSpaceExpansionsV2] = [ .invitedUserIDs, .speakerIDs, @@ -79,18 +81,19 @@ class ExpansionsV2Tests: XCTestCase { .other("~~~"), ] - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.SpaceExpansionsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.SpaceExpansionsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, "creator_id,host_ids,invited_user_ids,speaker_ids,topic_ids,~~~" ) } - func testTwitterSpaceExpansionsV2All() throws { + public func testTwitterSpaceExpansionsV2All() throws { XCTAssertEqual(TwitterSpaceExpansionsV2.all.count, 5) } - func testTwitterDmEventExpansionsV2() throws { + public func testTwitterDmEventExpansionsV2() throws { let allCases: [TwitterDmEventExpansionsV2] = [ .attachmentsMediaKeys, .participantIDs, @@ -99,14 +102,19 @@ class ExpansionsV2Tests: XCTestCase { .other("~~~"), ].shuffled() - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.DmEventExpansionsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.DmEventExpansionsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, "attachments.media_keys,participant_ids,referenced_tweets.id,sender_id,~~~" ) } - func testTwitterDmEventExpansionsV2All() throws { + public func testTwitterDmEventExpansionsV2All() throws { XCTAssertEqual(TwitterDmEventExpansionsV2.all.count, 4) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/FieldsV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/FieldsV2Tests.swift index ea56727f..b85bb1d0 100644 --- a/Tests/TwitterAPIKitTests/APIv2/FieldsV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/FieldsV2Tests.swift @@ -1,16 +1,14 @@ +// FieldsV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import XCTest @testable import TwitterAPIKit -class FieldsV2Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - func testTwitterTweetFieldsV2() throws { - +internal class FieldsV2Tests: XCTestCase { + public func testTwitterTweetFieldsV2() throws { let allCases: [TwitterTweetFieldsV2] = [ .attachments, .authorID, @@ -35,18 +33,23 @@ class FieldsV2Tests: XCTestCase { .other("~~~"), ].shuffled() - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.TweetFieldsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.TweetFieldsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, - "attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,non_public_metrics,organic_metrics,possibly_sensitive,promoted_metrics,public_metrics,referenced_tweets,reply_settings,source,text,withheld,~~~" + "attachments,author_id,context_annotations," + + "conversation_id,created_at,entities,geo,id," + + "in_reply_to_user_id,lang,non_public_metrics," + + "organic_metrics,possibly_sensitive,promoted_metrics," + + "public_metrics,referenced_tweets,reply_settings,source,text,withheld,~~~" ) } - func testTwitterTweetFieldsV2All() throws { + public func testTwitterTweetFieldsV2All() throws { XCTAssertEqual(TwitterTweetFieldsV2.all.count, 20) } - func testTwitterUserFieldsV2() throws { + public func testTwitterUserFieldsV2() throws { let allCases: [TwitterUserFieldsV2] = [ .createdAt, .description, @@ -65,18 +68,21 @@ class FieldsV2Tests: XCTestCase { .other("~~"), ].shuffled() - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.UserFieldsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.UserFieldsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, - "created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld,~~" + "created_at,description,entities," + + "id,location,name,pinned_tweet_id," + + "profile_image_url,protected,public_metrics,url,username,verified,withheld,~~" ) } - func testTwitterUserFieldsV2All() throws { + public func testTwitterUserFieldsV2All() throws { XCTAssertEqual(TwitterUserFieldsV2.all.count, 14) } - func testTwitterPlaceFieldsV2() throws { + public func testTwitterPlaceFieldsV2() throws { let allCases: [TwitterPlaceFieldsV2] = [ .containedWithin, .country, @@ -89,18 +95,19 @@ class FieldsV2Tests: XCTestCase { .other("~~~"), ].shuffled() - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.PlaceFieldsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.PlaceFieldsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, "contained_within,country,country_code,full_name,geo,id,name,place_type,~~~" ) } - func testTwitterPlaceFieldsV2All() throws { + public func testTwitterPlaceFieldsV2All() throws { XCTAssertEqual(TwitterPlaceFieldsV2.all.count, 8) } - func testTwitterPollFieldsV2() throws { + public func testTwitterPollFieldsV2() throws { let allCases: [TwitterPollFieldsV2] = [ .durationMinutes, .endDatetime, @@ -110,17 +117,19 @@ class FieldsV2Tests: XCTestCase { .other("~~"), ].shuffled() - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.PollFieldsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.PollFieldsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, "duration_minutes,end_datetime,id,options,voting_status,~~" ) } - func testTwitterPollFieldsV2All() throws { + + public func testTwitterPollFieldsV2All() throws { XCTAssertEqual(TwitterPollFieldsV2.all.count, 5) } - func testTwitterMediaFieldsV2() throws { + public func testTwitterMediaFieldsV2() throws { let allCases: [TwitterMediaFieldsV2] = [ .durationMs, .height, @@ -138,26 +147,30 @@ class FieldsV2Tests: XCTestCase { .other("~~~"), ].shuffled() - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.MediaFieldsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.MediaFieldsParameter.schema.items.enum | sort | join(",")' - // Note: `url` is missing in https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/media + // Note: `url` is missing in + // https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/media // https://twittercommunity.com/t/documentation-for-media-object-missing-url-field/163062 XCTAssertEqual( allCases.commaSeparatedString, - "alt_text,duration_ms,height,media_key,non_public_metrics,organic_metrics,preview_image_url,promoted_metrics,public_metrics,type,url,variants,width,~~~" + "alt_text,duration_ms,height,media_key" + + ",non_public_metrics,organic_metrics,preview_image_url" + + ",promoted_metrics,public_metrics,type,url,variants,width,~~~" ) } - func testTwitterMediaFieldsV2All() throws { + public func testTwitterMediaFieldsV2All() throws { XCTAssertEqual(TwitterMediaFieldsV2.all.count, 13) } - func testTwitterListFieldsV2() throws { + public func testTwitterListFieldsV2() throws { let allCases: [TwitterListFieldsV2] = [ .createdAt, .followerCount, .memberCount, - .`private`, + .private, .description, .id, .name, @@ -165,17 +178,19 @@ class FieldsV2Tests: XCTestCase { .other("~"), ].shuffled() - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.ListFieldsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.ListFieldsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, "created_at,description,follower_count,id,member_count,name,owner_id,private,~" ) } - func testTwitterListFieldsV2All() throws { + + public func testTwitterListFieldsV2All() throws { XCTAssertEqual(TwitterListFieldsV2.all.count, 8) } - func testTwitterSpaceFieldsV2() throws { + public func testTwitterSpaceFieldsV2() throws { let allCases: [TwitterSpaceFieldsV2] = [ .id, .state, @@ -197,18 +212,21 @@ class FieldsV2Tests: XCTestCase { .other("~~"), ].shuffled() - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.SpaceFieldsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.SpaceFieldsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, - "created_at,creator_id,ended_at,host_ids,id,invited_user_ids,is_ticketed,lang,participant_count,scheduled_start,speaker_ids,started_at,state,subscriber_count,title,topic_ids,updated_at,~~" + "created_at,creator_id,ended_at,host_ids," + + "id,invited_user_ids,is_ticketed,lang,participant_count," + + "scheduled_start,speaker_ids,started_at,state,subscriber_count,title,topic_ids,updated_at,~~" ) } - func testTwitterSpaceFieldsV2All() throws { + public func testTwitterSpaceFieldsV2All() throws { XCTAssertEqual(TwitterSpaceFieldsV2.all.count, 17) } - func testTwitterTopicFieldsV2() throws { + public func testTwitterTopicFieldsV2() throws { let allCases: [TwitterTopicFieldsV2] = [ .id, .name, @@ -216,18 +234,19 @@ class FieldsV2Tests: XCTestCase { .other("~"), ].shuffled() - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.TopicFieldsParameter.schema.items.enum | sort | join(",")' + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.TopicFieldsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, "description,id,name,~" ) } - func testTwitterTopicFieldsV2All() throws { + public func testTwitterTopicFieldsV2All() throws { XCTAssertEqual(TwitterTopicFieldsV2.all.count, 3) } - func testTwitterDmEventFieldsV2() throws { + public func testTwitterDmEventFieldsV2() throws { let allCases: [TwitterDmEventFieldsV2] = [ .attachments, .createdAt, @@ -240,18 +259,20 @@ class FieldsV2Tests: XCTestCase { .text, .other("~"), ].shuffled() - // curl https://api.twitter.com/2/openapi.json | jq '.components.parameters.DmEventFieldsParameter.schema.items.enum | sort | join(",")' + + // curl https://api.twitter.com/2/openapi.json | \ + // jq '.components.parameters.DmEventFieldsParameter.schema.items.enum | sort | join(",")' XCTAssertEqual( allCases.commaSeparatedString, "attachments,created_at,dm_conversation_id,event_type,id,participant_ids,referenced_tweets,sender_id,text,~" ) } - func testTwitterDmEventFieldsV2All() throws { + public func testTwitterDmEventFieldsV2All() throws { XCTAssertEqual(TwitterDmEventFieldsV2.all.count, 9) } - func testTwitterDmConversationFieldsV2() throws { + public func testTwitterDmConversationFieldsV2() throws { let allCases: [TwitterDmConversationFieldsV2] = [ .id, .other("~"), @@ -259,7 +280,11 @@ class FieldsV2Tests: XCTestCase { XCTAssertEqual(allCases.commaSeparatedString, "id,~") } - func testTwitterDmConversationFieldsV2All() throws { + public func testTwitterDmConversationFieldsV2All() throws { XCTAssertEqual(TwitterDmConversationFieldsV2.all.count, 1) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Friendships/DeleteUsersFollowingRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Friendships/DeleteUsersFollowingRequestV2Tests.swift index 947b37c8..7937af30 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Friendships/DeleteUsersFollowingRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Friendships/DeleteUsersFollowingRequestV2Tests.swift @@ -1,14 +1,13 @@ +// DeleteUsersFollowingRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class DeleteUsersFollowingRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class DeleteUsersFollowingRequestV2Tests: XCTestCase { + public func test() throws { let req = DeleteUsersFollowingRequestV2( sourceUserID: "_sourceUserID_", targetUserID: "_targetUserID_" @@ -20,4 +19,8 @@ class DeleteUsersFollowingRequestV2Tests: XCTestCase { XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Friendships/GetUsersFollowersRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Friendships/GetUsersFollowersRequestV2Tests.swift index 20bb49ea..a5a8d080 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Friendships/GetUsersFollowersRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Friendships/GetUsersFollowersRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersFollowersRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersFollowersRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersFollowersRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersFollowersRequestV2( id: "_id_", expansions: [.pinnedTweetID], @@ -30,14 +29,19 @@ class GetUsersFollowersRequestV2Tests: XCTestCase { "pagination_token": "token", "tweet.fields": "conversation_id", "user.fields": "username", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersFollowersRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Friendships/GetUsersFollowingRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Friendships/GetUsersFollowingRequestV2Tests.swift index e767c69e..05b7c9ba 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Friendships/GetUsersFollowingRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Friendships/GetUsersFollowingRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersFollowingRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersFollowingRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersFollowingRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersFollowingRequestV2( id: "_id_", expansions: [.pinnedTweetID], @@ -30,14 +29,19 @@ class GetUsersFollowingRequestV2Tests: XCTestCase { "pagination_token": "t", "tweet.fields": "text", "user.fields": "name", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersFollowingRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Friendships/PostUsersFollowingRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Friendships/PostUsersFollowingRequestV2Tests.swift index 3b0c0544..81686c8f 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Friendships/PostUsersFollowingRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Friendships/PostUsersFollowingRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostUsersFollowingRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostUsersFollowingRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostUsersFollowingRequestV2Tests: XCTestCase { + public func test() throws { let req = PostUsersFollowingRequestV2( id: "_id_", targetUserID: "_targetUserID_" @@ -20,4 +19,8 @@ class PostUsersFollowingRequestV2Tests: XCTestCase { XCTAssertEqual(req.bodyContentType, .json) AssertEqualAnyDict(req.parameters, ["target_user_id": "_targetUserID_"]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Like/DeleteUsersLikesRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Like/DeleteUsersLikesRequestV2Tests.swift index 0e50c4c7..7ed68309 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Like/DeleteUsersLikesRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Like/DeleteUsersLikesRequestV2Tests.swift @@ -1,14 +1,13 @@ +// DeleteUsersLikesRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class DeleteUsersLikesRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class DeleteUsersLikesRequestV2Tests: XCTestCase { + public func test() throws { let req = DeleteUsersLikesRequestV2( id: "_id_", tweetID: "_tweetID_" @@ -23,4 +22,8 @@ class DeleteUsersLikesRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Like/GetTweetsLikingUsersRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Like/GetTweetsLikingUsersRequestV2Tests.swift index 839b518f..ad16e45f 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Like/GetTweetsLikingUsersRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Like/GetTweetsLikingUsersRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetTweetsLikingUsersRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTweetsLikingUsersRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetTweetsLikingUsersRequestV2Tests: XCTestCase { + public func test() throws { let req = GetTweetsLikingUsersRequestV2( id: "_id_", expansions: [.pinnedTweetID], @@ -40,7 +39,7 @@ class GetTweetsLikingUsersRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetTweetsLikingUsersRequestV2( id: "_id_" ) @@ -50,4 +49,8 @@ class GetTweetsLikingUsersRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Like/GetUsersLikedTweetsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Like/GetUsersLikedTweetsRequestV2Tests.swift index 9c2bc14b..fad44b66 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Like/GetUsersLikedTweetsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Like/GetUsersLikedTweetsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersLikedTweetsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersLikedTweetsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersLikedTweetsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersLikedTweetsRequestV2( id: "_id_", expansions: [.authorID], @@ -40,7 +39,7 @@ class GetUsersLikedTweetsRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersLikedTweetsRequestV2( id: "_id_" ) @@ -50,4 +49,8 @@ class GetUsersLikedTweetsRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Like/PostUsersLikesRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Like/PostUsersLikesRequestV2Tests.swift index deb016de..64fadfcf 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Like/PostUsersLikesRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Like/PostUsersLikesRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostUsersLikesRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostUsersLikesRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostUsersLikesRequestV2Tests: XCTestCase { + public func test() throws { let req = PostUsersLikesRequestV2( id: "_id_", tweetID: "_tweetID_" @@ -21,8 +20,12 @@ class PostUsersLikesRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "tweet_id": "_tweetID_" + "tweet_id": "_tweetID_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/DeleteListRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/DeleteListRequestV2Tests.swift index d25edd9f..c9b4a46f 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/DeleteListRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/DeleteListRequestV2Tests.swift @@ -1,14 +1,13 @@ +// DeleteListRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class DeleteListRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class DeleteListRequestV2Tests: XCTestCase { + public func test() throws { let req = DeleteListRequestV2( id: "_id_" ) @@ -19,4 +18,8 @@ class DeleteListRequestV2Tests: XCTestCase { XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/DeleteListsMembersRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/DeleteListsMembersRequestV2Tests.swift index 5df0d59e..d8ed5f94 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/DeleteListsMembersRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/DeleteListsMembersRequestV2Tests.swift @@ -1,14 +1,13 @@ +// DeleteListsMembersRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class DeleteListsMembersRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class DeleteListsMembersRequestV2Tests: XCTestCase { + public func test() throws { let req = DeleteListsMembersRequestV2( id: "_id_", userID: "_userID_" @@ -20,4 +19,8 @@ class DeleteListsMembersRequestV2Tests: XCTestCase { XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/DeleteUsersFollowedListsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/DeleteUsersFollowedListsRequestV2Tests.swift index 6d2af544..6be14b4c 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/DeleteUsersFollowedListsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/DeleteUsersFollowedListsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// DeleteUsersFollowedListsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class DeleteUsersFollowedListsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class DeleteUsersFollowedListsRequestV2Tests: XCTestCase { + public func test() throws { let req = DeleteUsersFollowedListsRequestV2( id: "_id_", listID: "_listID_" @@ -20,4 +19,8 @@ class DeleteUsersFollowedListsRequestV2Tests: XCTestCase { XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/DeleteUsersPinnedListsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/DeleteUsersPinnedListsRequestV2Tests.swift index 3e8339c6..163c5c1a 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/DeleteUsersPinnedListsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/DeleteUsersPinnedListsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// DeleteUsersPinnedListsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class DeleteUsersPinnedListsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class DeleteUsersPinnedListsRequestV2Tests: XCTestCase { + public func test() throws { let req = DeleteUsersPinnedListsRequestV2( id: "_id_", listID: "_listID_" @@ -20,4 +19,8 @@ class DeleteUsersPinnedListsRequestV2Tests: XCTestCase { XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/GetListRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/GetListRequestV2Tests.swift index 4505f091..db3a08cc 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/GetListRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/GetListRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetListRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListRequestV2Tests: XCTestCase { + public func test() throws { let req = GetListRequestV2( id: "_id_", expansions: [.ownerID], @@ -26,14 +25,19 @@ class GetListRequestV2Tests: XCTestCase { "expansions": "owner_id", "list.fields": "description,owner_id", "user.fields": "username", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetListRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/GetListsFollowersRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/GetListsFollowersRequestV2Tests.swift index 8c7a40c0..4adc4136 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/GetListsFollowersRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/GetListsFollowersRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetListsFollowersRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsFollowersRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsFollowersRequestV2Tests: XCTestCase { + public func test() throws { let req = GetListsFollowersRequestV2( id: "_id_", expansions: [.pinnedTweetID], @@ -30,14 +29,19 @@ class GetListsFollowersRequestV2Tests: XCTestCase { "pagination_token": "t", "tweet.fields": "entities", "user.fields": "verified", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetListsFollowersRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/GetListsMembersRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/GetListsMembersRequestV2Tests.swift index 374b771b..f09f2a07 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/GetListsMembersRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/GetListsMembersRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetListsMembersRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsMembersRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsMembersRequestV2Tests: XCTestCase { + public func test() throws { let req = GetListsMembersRequestV2( id: "_id_", expansions: [.pinnedTweetID], @@ -30,14 +29,19 @@ class GetListsMembersRequestV2Tests: XCTestCase { "pagination_token": "t", "tweet.fields": "created_at", "user.fields": "protected", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetListsMembersRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/GetListsTweetsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/GetListsTweetsRequestV2Tests.swift index 71e2ac6b..31b67516 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/GetListsTweetsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/GetListsTweetsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetListsTweetsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetListsTweetsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetListsTweetsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetListsTweetsRequestV2( id: "_id_", expansions: [.referencedTweetsIDAuthorID], @@ -30,15 +29,19 @@ class GetListsTweetsRequestV2Tests: XCTestCase { "pagination_token": "t", "tweet.fields": "text", "user.fields": "profile_image_url", - - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetListsTweetsRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/GetUsersFollowedListsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/GetUsersFollowedListsRequestV2Tests.swift index 11991bc7..746653b8 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/GetUsersFollowedListsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/GetUsersFollowedListsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersFollowedListsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersFollowedListsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersFollowedListsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersFollowedListsRequestV2( id: "_id_", expansions: [.ownerID], @@ -30,14 +29,19 @@ class GetUsersFollowedListsRequestV2Tests: XCTestCase { "max_results": 10, "pagination_token": "t", "user.fields": "entities", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersFollowedListsRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/GetUsersListMembershipsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/GetUsersListMembershipsRequestV2Tests.swift index 27848efd..9502fd1b 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/GetUsersListMembershipsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/GetUsersListMembershipsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersListMembershipsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersListMembershipsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersListMembershipsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersListMembershipsRequestV2( id: "_id_", expansions: [.ownerID], @@ -30,14 +29,19 @@ class GetUsersListMembershipsRequestV2Tests: XCTestCase { "max_results": 10, "pagination_token": "t", "user.fields": "protected", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersListMembershipsRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/GetUsersOwnedListsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/GetUsersOwnedListsRequestV2Tests.swift index 20889c01..681a9351 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/GetUsersOwnedListsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/GetUsersOwnedListsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersOwnedListsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersOwnedListsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersOwnedListsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersOwnedListsRequestV2( id: "_id_", expansions: [.ownerID], @@ -30,15 +29,19 @@ class GetUsersOwnedListsRequestV2Tests: XCTestCase { "max_results": 11, "pagination_token": "t", "user.fields": "created_at", - - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersOwnedListsRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/GetUsersPinnedListsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/GetUsersPinnedListsRequestV2Tests.swift index 60889066..f8e2b2a5 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/GetUsersPinnedListsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/GetUsersPinnedListsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersPinnedListsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersPinnedListsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersPinnedListsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersPinnedListsRequestV2( id: "_id_", expansions: [.ownerID], @@ -26,14 +25,19 @@ class GetUsersPinnedListsRequestV2Tests: XCTestCase { "expansions": "owner_id", "list.fields": "id", "user.fields": "username", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersPinnedListsRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/PostListsMembersRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/PostListsMembersRequestV2Tests.swift index 03025998..5145d5e9 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/PostListsMembersRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/PostListsMembersRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostListsMembersRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostListsMembersRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostListsMembersRequestV2Tests: XCTestCase { + public func test() throws { let req = PostListsMembersRequestV2( id: "_id_", userID: "_userID_" @@ -21,7 +20,12 @@ class PostListsMembersRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "user_id": "_userID_" - ]) + "user_id": "_userID_", + ] + ) + } + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/PostListsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/PostListsRequestV2Tests.swift index 0a676658..d07f9655 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/PostListsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/PostListsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostListsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostListsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostListsRequestV2Tests: XCTestCase { + public func test() throws { let req = PostListsRequestV2( name: "_name_", description: "d", @@ -29,7 +28,7 @@ class PostListsRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostListsRequestV2( name: "n" ) @@ -37,8 +36,12 @@ class PostListsRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "name": "n" + "name": "n", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/PostUsersFollowedListsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/PostUsersFollowedListsRequestV2Tests.swift index c9ec300a..a62e03ba 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/PostUsersFollowedListsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/PostUsersFollowedListsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostUsersFollowedListsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostUsersFollowedListsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostUsersFollowedListsRequestV2Tests: XCTestCase { + public func test() throws { let req = PostUsersFollowedListsRequestV2( id: "_id_", listID: "_listID_" @@ -21,8 +20,12 @@ class PostUsersFollowedListsRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "list_id": "_listID_" + "list_id": "_listID_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/PostUsersPinnedListsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/PostUsersPinnedListsRequestV2Tests.swift index 90f01272..9a190e3c 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/PostUsersPinnedListsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/PostUsersPinnedListsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostUsersPinnedListsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostUsersPinnedListsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostUsersPinnedListsRequestV2Tests: XCTestCase { + public func test() throws { let req = PostUsersPinnedListsRequestV2( id: "_id_", listID: "_listID_" @@ -21,8 +20,12 @@ class PostUsersPinnedListsRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "list_id": "_listID_" + "list_id": "_listID_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/List/PutListRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/List/PutListRequestV2Tests.swift index 9cbd992e..1d88ec80 100644 --- a/Tests/TwitterAPIKitTests/APIv2/List/PutListRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/List/PutListRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PutListRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PutListRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PutListRequestV2Tests: XCTestCase { + public func test() throws { let req = PutListRequestV2( id: "_id_", description: "d", @@ -30,7 +29,7 @@ class PutListRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PutListRequestV2( id: "_id_" ) @@ -40,4 +39,8 @@ class PutListRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Retweet/DeleteUsersRetweetsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Retweet/DeleteUsersRetweetsRequestV2Tests.swift index 66553608..9b8d41a7 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Retweet/DeleteUsersRetweetsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Retweet/DeleteUsersRetweetsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// DeleteUsersRetweetsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class DeleteUsersRetweetsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class DeleteUsersRetweetsRequestV2Tests: XCTestCase { + public func test() throws { let req = DeleteUsersRetweetsRequestV2( id: "_id_", sourceTweetID: "_sourceTweetID_" @@ -20,4 +19,8 @@ class DeleteUsersRetweetsRequestV2Tests: XCTestCase { XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Retweet/GetTweetsRetweetedByRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Retweet/GetTweetsRetweetedByRequestV2Tests.swift index 3b98ee1b..cded8ad1 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Retweet/GetTweetsRetweetedByRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Retweet/GetTweetsRetweetedByRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetTweetsRetweetedByRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTweetsRetweetedByRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetTweetsRetweetedByRequestV2Tests: XCTestCase { + public func test() throws { let req = GetTweetsRetweetedByRequestV2( id: "_id_", expansions: [.pinnedTweetID], @@ -36,14 +35,19 @@ class GetTweetsRetweetedByRequestV2Tests: XCTestCase { "poll.fields": "end_datetime,options", "tweet.fields": "context_annotations,non_public_metrics", "user.fields": "username,withheld", - ]) + ] + ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetTweetsRetweetedByRequestV2( id: "_id_" ) AssertEqualAnyDict(req.parameters, [:]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Retweet/PostUsersRetweetsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Retweet/PostUsersRetweetsRequestV2Tests.swift index 89516c32..ae19e8be 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Retweet/PostUsersRetweetsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Retweet/PostUsersRetweetsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostUsersRetweetsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostUsersRetweetsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostUsersRetweetsRequestV2Tests: XCTestCase { + public func test() throws { let req = PostUsersRetweetsRequestV2( id: "_id_", tweetID: "_tweetID_" @@ -21,7 +20,12 @@ class PostUsersRetweetsRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "tweet_id": "_tweetID_" - ]) + "tweet_id": "_tweetID_", + ] + ) + } + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Search/GetTweetsSearchAllRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Search/GetTweetsSearchAllRequestV2Tests.swift index 177a3429..2428545d 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Search/GetTweetsSearchAllRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Search/GetTweetsSearchAllRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetTweetsSearchAllRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTweetsSearchAllRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetTweetsSearchAllRequestV2Tests: XCTestCase { + public func test() throws { let req = GetTweetsSearchAllRequestV2( query: "_q_", endTime: Date(timeIntervalSince1970: 2), @@ -51,7 +50,7 @@ class GetTweetsSearchAllRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetTweetsSearchAllRequestV2( query: "_q1_" ) @@ -59,8 +58,12 @@ class GetTweetsSearchAllRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "query": "_q1_" + "query": "_q1_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Search/GetTweetsSearchRecentRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Search/GetTweetsSearchRecentRequestV2Tests.swift index 66c15e14..dea9cf54 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Search/GetTweetsSearchRecentRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Search/GetTweetsSearchRecentRequestV2Tests.swift @@ -1,16 +1,13 @@ +// GetTweetsSearchRecentRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTweetsSearchRecentRequestV2Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class GetTweetsSearchRecentRequestV2Tests: XCTestCase { + public func test() throws { let req = GetTweetsSearchRecentRequestV2( query: "Q", endTime: Date(timeIntervalSince1970: 100), @@ -52,4 +49,7 @@ class GetTweetsSearchRecentRequestV2Tests: XCTestCase { ) } + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpaceRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpaceRequestV2Tests.swift index 601c64a8..c908b46b 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpaceRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpaceRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetSpaceRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetSpaceRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetSpaceRequestV2Tests: XCTestCase { + public func test() throws { let req = GetSpaceRequestV2( id: "_i_", expansions: [.hostIDs], @@ -32,7 +31,7 @@ class GetSpaceRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetSpaceRequestV2( id: "_i_" ) @@ -42,4 +41,8 @@ class GetSpaceRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesBuyersRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesBuyersRequestV2Tests.swift index ad34df1f..a0fa6524 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesBuyersRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesBuyersRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetSpacesBuyersRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetSpacesBuyersRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetSpacesBuyersRequestV2Tests: XCTestCase { + public func test() throws { let req = GetSpacesBuyersRequestV2( id: "_i_", expansions: [.pinnedTweetID], @@ -36,7 +35,7 @@ class GetSpacesBuyersRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetSpacesBuyersRequestV2( id: "_i_" ) @@ -46,4 +45,8 @@ class GetSpacesBuyersRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesByCreatorIDsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesByCreatorIDsRequestV2Tests.swift index 43a4a24c..97158a9c 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesByCreatorIDsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesByCreatorIDsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetSpacesByCreatorIDsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetSpacesByCreatorIDsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetSpacesByCreatorIDsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetSpacesByCreatorIDsRequestV2( userIDs: ["a", "b"], expansions: [.invitedUserIDs], @@ -33,7 +32,7 @@ class GetSpacesByCreatorIDsRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetSpacesByCreatorIDsRequestV2( userIDs: ["a", "b", "c"] ) @@ -41,8 +40,12 @@ class GetSpacesByCreatorIDsRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "user_ids": "a,b,c" + "user_ids": "a,b,c", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesRequestV2Tests.swift index 321fa0bd..8db312b2 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetSpacesRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetSpacesRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetSpacesRequestV2Tests: XCTestCase { + public func test() throws { let req = GetSpacesRequestV2( ids: ["a", "b"], expansions: [.speakerIDs], @@ -33,7 +32,7 @@ class GetSpacesRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetSpacesRequestV2( ids: ["a", "b", "あ"] ) @@ -41,8 +40,12 @@ class GetSpacesRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "ids": "a,b,あ" + "ids": "a,b,あ", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesSearchRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesSearchRequestV2Tests.swift index caf3b621..ecbd8405 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesSearchRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesSearchRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetSpacesSearchRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetSpacesSearchRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetSpacesSearchRequestV2Tests: XCTestCase { + public func test() throws { let req = GetSpacesSearchRequestV2( query: "_q_", expansions: [.creatorID], @@ -35,7 +34,7 @@ class GetSpacesSearchRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetSpacesSearchRequestV2( query: "あ" ) @@ -43,8 +42,12 @@ class GetSpacesSearchRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "query": "あ" + "query": "あ", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesTweetsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesTweetsRequestV2Tests.swift index 968503ad..5013ad0a 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesTweetsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Spaces/GetSpacesTweetsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetSpacesTweetsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetSpacesTweetsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetSpacesTweetsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetSpacesTweetsRequestV2( id: "_i_", expansions: [.entitiesMentionsUsername], @@ -36,7 +35,7 @@ class GetSpacesTweetsRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetSpacesTweetsRequestV2( id: "_i_" ) @@ -46,4 +45,8 @@ class GetSpacesTweetsRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Stream/GetTweetsSampleStreamRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Stream/GetTweetsSampleStreamRequestV2Tests.swift index cc6eb04c..956f0aa4 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Stream/GetTweetsSampleStreamRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Stream/GetTweetsSampleStreamRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetTweetsSampleStreamRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTweetsSampleStreamRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetTweetsSampleStreamRequestV2Tests: XCTestCase { + public func test() throws { let req = GetTweetsSampleStreamRequestV2( backfillMinutes: 2, expansions: [.entitiesMentionsUsername], @@ -37,7 +36,7 @@ class GetTweetsSampleStreamRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetTweetsSampleStreamRequestV2() AssertEqualAnyDict( @@ -45,4 +44,8 @@ class GetTweetsSampleStreamRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Stream/GetTweetsSearchStreamRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Stream/GetTweetsSearchStreamRequestV2Tests.swift index 00c6b506..2a91e438 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Stream/GetTweetsSearchStreamRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Stream/GetTweetsSearchStreamRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetTweetsSearchStreamRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTweetsSearchStreamRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetTweetsSearchStreamRequestV2Tests: XCTestCase { + public func test() throws { let req = GetTweetsSearchStreamRequestV2( backfillMinutes: 1, expansions: [.referencedTweetsIDAuthorID], @@ -37,7 +36,7 @@ class GetTweetsSearchStreamRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetTweetsSearchStreamRequestV2() AssertEqualAnyDict( @@ -45,4 +44,8 @@ class GetTweetsSearchStreamRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Stream/GetTweetsSearchStreamRulesRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Stream/GetTweetsSearchStreamRulesRequestV2Tests.swift index c02e7250..b1205f22 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Stream/GetTweetsSearchStreamRulesRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Stream/GetTweetsSearchStreamRulesRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetTweetsSearchStreamRulesRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTweetsSearchStreamRulesRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetTweetsSearchStreamRulesRequestV2Tests: XCTestCase { + public func test() throws { let req = GetTweetsSearchStreamRulesRequestV2( ids: ["10", "20"] ) @@ -20,12 +19,12 @@ class GetTweetsSearchStreamRulesRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "ids": "10,20" + "ids": "10,20", ] ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetTweetsSearchStreamRulesRequestV2() AssertEqualAnyDict( @@ -33,4 +32,8 @@ class GetTweetsSearchStreamRulesRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Stream/PostTweetsSearchStreamRulesRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Stream/PostTweetsSearchStreamRulesRequestV2Tests.swift index af0486db..3cf7b104 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Stream/PostTweetsSearchStreamRulesRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Stream/PostTweetsSearchStreamRulesRequestV2Tests.swift @@ -1,23 +1,21 @@ +// PostTweetsSearchStreamRulesRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostTweetsSearchStreamRulesRequestV2Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class PostTweetsSearchStreamRulesRequestV2Tests: XCTestCase { + public func test() throws { XCTContext.runActivity(named: "add") { _ in let add = PostTweetsSearchStreamRulesRequestV2( operation: .add([ .init(value: "value", tag: "tag"), .init(value: "hoge"), - ])) + ]) + ) XCTAssertEqual(add.method, .post) XCTAssertEqual(add.path, "/2/tweets/search/stream/rules") @@ -30,8 +28,9 @@ class PostTweetsSearchStreamRulesRequestV2Tests: XCTestCase { "add": [ ["value": "value", "tag": "tag"], ["value": "hoge"], - ] - ]) + ], + ] + ) AssertEqualAnyDict(add.queryParameters, [:]) } @@ -48,20 +47,21 @@ class PostTweetsSearchStreamRulesRequestV2Tests: XCTestCase { delete.bodyParameters, [ "delete": [ - "ids": ["1", "20"] - ] - ]) + "ids": ["1", "20"], + ], + ] + ) AssertEqualAnyDict(delete.queryParameters, [:]) } } - func testDryRun() throws { - + public func testDryRun() throws { let add = PostTweetsSearchStreamRulesRequestV2( operation: .add([ .init(value: "value", tag: "tag"), .init(value: "hoge"), - ]), dryRun: true) + ]), dryRun: true + ) XCTAssertEqual(add.method, .post) XCTAssertEqual(add.path, "/2/tweets/search/stream/rules") @@ -74,10 +74,14 @@ class PostTweetsSearchStreamRulesRequestV2Tests: XCTestCase { "add": [ ["value": "value", "tag": "tag"], ["value": "hoge"], - ] - ]) + ], + ] + ) AssertEqualAnyDict(add.queryParameters, ["dry_run": true]) } + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Timeline/GetUsersMentionsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Timeline/GetUsersMentionsRequestV2Tests.swift index 6e6db4cf..b22a7215 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Timeline/GetUsersMentionsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Timeline/GetUsersMentionsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersMentionsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersMentionsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersMentionsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersMentionsRequestV2( id: "_i_", endTime: Date(timeIntervalSince1970: 11), @@ -48,7 +47,7 @@ class GetUsersMentionsRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersMentionsRequestV2( id: "_i_" ) @@ -58,4 +57,8 @@ class GetUsersMentionsRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Timeline/GetUsersTimelinesReverseChronologicalRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Timeline/GetUsersTimelinesReverseChronologicalRequestV2Tests.swift index 4248b32f..750da741 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Timeline/GetUsersTimelinesReverseChronologicalRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Timeline/GetUsersTimelinesReverseChronologicalRequestV2Tests.swift @@ -1,14 +1,14 @@ +// GetUsersTimelinesReverseChronologicalRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersTimelinesReverseChronologicalRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +// swiftlint:disable:next type_name +internal class GetUsersTimelinesReverseChronologicalRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersTimelinesReverseChronologicalRequestV2( id: "_i_", endTime: Date(timeIntervalSince1970: 50), @@ -50,7 +50,7 @@ class GetUsersTimelinesReverseChronologicalRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersTimelinesReverseChronologicalRequestV2( id: "_i_" ) @@ -60,4 +60,8 @@ class GetUsersTimelinesReverseChronologicalRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Timeline/GetUsersTweetsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Timeline/GetUsersTweetsRequestV2Tests.swift index 7b544fd6..d9f36aac 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Timeline/GetUsersTweetsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Timeline/GetUsersTweetsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersTweetsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersTweetsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersTweetsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersTweetsRequestV2( id: "_i_", endTime: Date(timeIntervalSince1970: 10), @@ -50,7 +49,7 @@ class GetUsersTweetsRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersTweetsRequestV2( id: "_i_" ) @@ -60,4 +59,8 @@ class GetUsersTweetsRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Tweet/DeleteTweetRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Tweet/DeleteTweetRequestV2Tests.swift index 0550358a..36938018 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Tweet/DeleteTweetRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Tweet/DeleteTweetRequestV2Tests.swift @@ -1,19 +1,21 @@ +// DeleteTweetRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class DeleteTweetRequestV2Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class DeleteTweetRequestV2Tests: XCTestCase { + public func test() throws { let request = DeleteTweetRequestV2(id: "123") XCTAssertEqual(request.method, .delete) XCTAssertEqual(request.path, "/2/tweets/123") XCTAssertEqual(request.bodyContentType, .wwwFormUrlEncoded) XCTAssertTrue(request.parameters.isEmpty) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetRequestV2Tests.swift index cc41f0f4..df515645 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetRequestV2Tests.swift @@ -1,16 +1,13 @@ +// GetTweetRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTweetRequestV2Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class GetTweetRequestV2Tests: XCTestCase { + public func test() throws { XCTContext.runActivity(named: "with only required parameters") { _ in let tweet = GetTweetRequestV2(id: "123") @@ -41,8 +38,12 @@ class GetTweetRequestV2Tests: XCTestCase { "poll.fields": "id", "tweet.fields": "id,text", "user.fields": "entities", - ]) + ] + ) } } + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetsQuoteTweetsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetsQuoteTweetsRequestV2Tests.swift index 05c6e806..6d412031 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetsQuoteTweetsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetsQuoteTweetsRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetTweetsQuoteTweetsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTweetsQuoteTweetsRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetTweetsQuoteTweetsRequestV2Tests: XCTestCase { + public func test() throws { let req = GetTweetsQuoteTweetsRequestV2( id: "_i_", expansions: [.attachmentsMediaKeys], @@ -40,7 +39,7 @@ class GetTweetsQuoteTweetsRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetTweetsQuoteTweetsRequestV2( id: "i" ) @@ -51,4 +50,8 @@ class GetTweetsQuoteTweetsRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetsRequestV2Tests.swift index dad21667..ffd2df19 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetsRequestV2Tests.swift @@ -1,16 +1,13 @@ +// GetTweetsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTweetsRequestV2Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class GetTweetsRequestV2Tests: XCTestCase { + public func test() throws { XCTContext.runActivity(named: "with only required parameters") { _ in let tweet = GetTweetsRequestV2(ids: ["123", "abc"]) @@ -42,8 +39,12 @@ class GetTweetsRequestV2Tests: XCTestCase { "poll.fields": "id", "tweet.fields": "id,text", "user.fields": "entities", - ]) + ] + ) } } + deinit { + // De-init Logic Her + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Tweet/PostTweetsRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Tweet/PostTweetsRequestV2Tests.swift index e082e7f1..0f3cc653 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Tweet/PostTweetsRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Tweet/PostTweetsRequestV2Tests.swift @@ -1,23 +1,21 @@ +// PostTweetsRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostTweetsRequestV2Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class PostTweetsRequestV2Tests: XCTestCase { + public func test() throws { let request = PostTweetsRequestV2( directMessageDeepLink: "deep_link", forSuperFollowersOnly: true, geo: .init(placeID: "place"), media: .init( mediaIDs: ["media_1", "media_2"], - taggedUserIDs: ["user_1", "user_2"]), + taggedUserIDs: ["user_1", "user_2"] + ), poll: .init(durationMinutes: 100, options: ["o1", "o2"]), quoteTweetID: "quote_id", reply: .init(excludeReplyUserIDs: ["r_1", "r_2"], inReplyToTweetID: "t_1"), @@ -41,6 +39,11 @@ class PostTweetsRequestV2Tests: XCTestCase { "reply": ["in_reply_to_tweet_id": "t_1", "exclude_reply_user_ids": ["r_1", "r_2"]], "reply_settings": "following", "text": "text", - ]) + ] + ) + } + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Tweet/PutTweetsHiddenRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Tweet/PutTweetsHiddenRequestV2Tests.swift index 409d3edb..ac2a3fea 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Tweet/PutTweetsHiddenRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Tweet/PutTweetsHiddenRequestV2Tests.swift @@ -1,20 +1,21 @@ +// PutTweetsHiddenRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PutTweetsHiddenRequestV2Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class PutTweetsHiddenRequestV2Tests: XCTestCase { + public func test() throws { let req = PutTweetsHiddenRequestV2(id: "12", hidden: true) XCTAssertEqual(req.method, .put) XCTAssertEqual(req.path, "/2/tweets/12/hidden") XCTAssertEqual(req.bodyContentType, .json) AssertEqualAnyDict(req.parameters, ["hidden": true]) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/TweetCount/GetTweetsCountsAllRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/TweetCount/GetTweetsCountsAllRequestV2Tests.swift index f42ef400..ca741db8 100644 --- a/Tests/TwitterAPIKitTests/APIv2/TweetCount/GetTweetsCountsAllRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/TweetCount/GetTweetsCountsAllRequestV2Tests.swift @@ -1,15 +1,13 @@ +// GetTweetsCountsAllRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTweetsCountsAllRequestV2Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetTweetsCountsAllRequestV2Tests: XCTestCase { + public func test() throws { let req = GetTweetsCountsAllRequestV2( query: "a", endTime: Date(timeIntervalSince1970: 10), @@ -33,6 +31,11 @@ class GetTweetsCountsAllRequestV2Tests: XCTestCase { "since_id": "s", "start_time": "1970-01-01T00:00:05Z", "until_id": "u", - ]) + ] + ) + } + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/APIv2/TweetCount/GetTweetsCountsRecentRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/TweetCount/GetTweetsCountsRecentRequestV2Tests.swift index de343f6d..3dbc5ec1 100644 --- a/Tests/TwitterAPIKitTests/APIv2/TweetCount/GetTweetsCountsRecentRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/TweetCount/GetTweetsCountsRecentRequestV2Tests.swift @@ -1,15 +1,13 @@ +// GetTweetsCountsRecentRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetTweetsCountsRecentRequestV2Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetTweetsCountsRecentRequestV2Tests: XCTestCase { + public func test() throws { let req = GetTweetsCountsRecentRequestV2( query: "q", endTime: Date(timeIntervalSince1970: 0), @@ -31,6 +29,11 @@ class GetTweetsCountsRecentRequestV2Tests: XCTestCase { "since_id": "s", "start_time": "1970-01-01T00:02:00Z", "until_id": "u", - ]) + ] + ) + } + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Users/GetUserRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Users/GetUserRequestV2Tests.swift index d247be4e..22a30b7a 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Users/GetUserRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Users/GetUserRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUserRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUserRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUserRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUserRequestV2( id: "_id_", expansions: [.pinnedTweetID], @@ -30,7 +29,7 @@ class GetUserRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUserRequestV2( id: "_id_" ) @@ -40,4 +39,8 @@ class GetUserRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersByRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersByRequestV2Tests.swift index 86490bdd..0d5daece 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersByRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersByRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersByRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersByRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersByRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersByRequestV2( usernames: ["a", "b"], expansions: [.pinnedTweetID], @@ -31,7 +30,7 @@ class GetUsersByRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersByRequestV2( usernames: ["a", "b"] ) @@ -39,8 +38,12 @@ class GetUsersByRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "usernames": "a,b" + "usernames": "a,b", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersByUsernameRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersByUsernameRequestV2Tests.swift index b5e12a6b..dec89b07 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersByUsernameRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersByUsernameRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersByUsernameRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersByUsernameRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersByUsernameRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersByUsernameRequestV2( username: "_username_", expansions: [.pinnedTweetID], @@ -30,7 +29,7 @@ class GetUsersByUsernameRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersByUsernameRequestV2( username: "_username_" ) @@ -40,4 +39,8 @@ class GetUsersByUsernameRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersMeRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersMeRequestV2Tests.swift index 5abf22fb..601b13fe 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersMeRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersMeRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersMeRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersMeRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersMeRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersMeRequestV2( expansions: [.pinnedTweetID], tweetFields: [.geo], @@ -29,7 +28,7 @@ class GetUsersMeRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersMeRequestV2() AssertEqualAnyDict( @@ -37,4 +36,8 @@ class GetUsersMeRequestV2Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersRequestV2Tests.swift b/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersRequestV2Tests.swift index 70b1a17b..603ef9f3 100644 --- a/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/APIv2/Users/GetUsersRequestV2Tests.swift @@ -1,14 +1,13 @@ +// GetUsersRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetUsersRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetUsersRequestV2Tests: XCTestCase { + public func test() throws { let req = GetUsersRequestV2( ids: ["a", "b"], expansions: [.pinnedTweetID], @@ -31,7 +30,7 @@ class GetUsersRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetUsersRequestV2( ids: ["a", "b"] ) @@ -39,8 +38,12 @@ class GetUsersRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "ids": "a,b" + "ids": "a,b", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/GetOAuth2AuthorizeRequestV1Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/GetOAuth2AuthorizeRequestV1Tests.swift index 5f32c4f8..11740df0 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/GetOAuth2AuthorizeRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/GetOAuth2AuthorizeRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetOAuth2AuthorizeRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetOAuth2AuthorizeRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetOAuth2AuthorizeRequestV1Tests: XCTestCase { + public func test() throws { let req = GetOAuth2AuthorizeRequestV1( responseType: "_r_", clientID: "_c_id_", @@ -37,7 +36,7 @@ class GetOAuth2AuthorizeRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetOAuth2AuthorizeRequestV1( clientID: "_ci_", redirectURI: "_r_", @@ -60,4 +59,8 @@ class GetOAuth2AuthorizeRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/GetOAuthAuthenticateRequestV1Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/GetOAuthAuthenticateRequestV1Tests.swift index 263b7946..70f27eae 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/GetOAuthAuthenticateRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/GetOAuthAuthenticateRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetOAuthAuthenticateRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetOAuthAuthenticateRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetOAuthAuthenticateRequestV1Tests: XCTestCase { + public func test() throws { let req = GetOAuthAuthenticateRequestV1( oauthToken: "_o_", forceLogin: true, @@ -29,7 +28,7 @@ class GetOAuthAuthenticateRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetOAuthAuthenticateRequestV1( oauthToken: "_o_" ) @@ -37,9 +36,12 @@ class GetOAuthAuthenticateRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "oauth_token": "_o_" - + "oauth_token": "_o_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/GetOAuthAuthorizeRequestV1Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/GetOAuthAuthorizeRequestV1Tests.swift index 473ccd89..418d4534 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/GetOAuthAuthorizeRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/GetOAuthAuthorizeRequestV1Tests.swift @@ -1,14 +1,13 @@ +// GetOAuthAuthorizeRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class GetOAuthAuthorizeRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class GetOAuthAuthorizeRequestV1Tests: XCTestCase { + public func test() throws { let req = GetOAuthAuthorizeRequestV1( oauthToken: "_o_", forceLogin: true, @@ -29,7 +28,7 @@ class GetOAuthAuthorizeRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = GetOAuthAuthorizeRequestV1( oauthToken: "_o_" ) @@ -37,8 +36,12 @@ class GetOAuthAuthorizeRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "oauth_token": "_o_" + "oauth_token": "_o_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2AccessTokenRequestV2Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2AccessTokenRequestV2Tests.swift index 72cb94ac..60dde3ad 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2AccessTokenRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2AccessTokenRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostOAuth2AccessTokenRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostOAuth2AccessTokenRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostOAuth2AccessTokenRequestV2Tests: XCTestCase { + public func test() throws { let req = PostOAuth2AccessTokenRequestV2( code: "_c_", grantType: "_g_", @@ -33,7 +32,7 @@ class PostOAuth2AccessTokenRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostOAuth2AccessTokenRequestV2( code: "_c_", redirectURI: "_r_", @@ -50,4 +49,8 @@ class PostOAuth2AccessTokenRequestV2Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2InvalidateTokenRequestV1Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2InvalidateTokenRequestV1Tests.swift index 6ea17bc9..e85bffd5 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2InvalidateTokenRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2InvalidateTokenRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostOAuth2InvalidateTokenRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostOAuth2InvalidateTokenRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostOAuth2InvalidateTokenRequestV1Tests: XCTestCase { + public func test() throws { let req = PostOAuth2InvalidateTokenRequestV1( accessToken: "_a_" ) @@ -20,8 +19,12 @@ class PostOAuth2InvalidateTokenRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "access_token": "_a_" + "access_token": "_a_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2RefreshTokenRequestV2Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2RefreshTokenRequestV2Tests.swift index 2d8329d8..f89adc82 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2RefreshTokenRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2RefreshTokenRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostOAuth2RefreshTokenRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostOAuth2RefreshTokenRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostOAuth2RefreshTokenRequestV2Tests: XCTestCase { + public func test() throws { let req = PostOAuth2RefreshTokenRequestV2( refreshToken: "_r_", grantType: "_g_", @@ -29,7 +28,7 @@ class PostOAuth2RefreshTokenRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostOAuth2RefreshTokenRequestV2( refreshToken: "_rt_" ) @@ -42,4 +41,8 @@ class PostOAuth2RefreshTokenRequestV2Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2RevokeTokenRequestV2Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2RevokeTokenRequestV2Tests.swift index 041293a5..24e95a5a 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2RevokeTokenRequestV2Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2RevokeTokenRequestV2Tests.swift @@ -1,14 +1,13 @@ +// PostOAuth2RevokeTokenRequestV2Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostOAuth2RevokeTokenRequestV2Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostOAuth2RevokeTokenRequestV2Tests: XCTestCase { + public func test() throws { let req = PostOAuth2RevokeTokenRequestV2( token: "_t_", clientID: "_c_", @@ -29,7 +28,7 @@ class PostOAuth2RevokeTokenRequestV2Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostOAuth2RevokeTokenRequestV2( token: "_tt_" ) @@ -37,8 +36,12 @@ class PostOAuth2RevokeTokenRequestV2Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "token": "_tt_" + "token": "_tt_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2TokenRequestV1Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2TokenRequestV1Tests.swift index be03019a..7f6853e0 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2TokenRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuth2TokenRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostOAuth2TokenRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostOAuth2TokenRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostOAuth2TokenRequestV1Tests: XCTestCase { + public func test() throws { let req = PostOAuth2TokenRequestV1( grantType: "_g_" ) @@ -20,19 +19,23 @@ class PostOAuth2TokenRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "grant_type": "_g_" + "grant_type": "_g_", ] ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostOAuth2TokenRequestV1() AssertEqualAnyDict( req.parameters, [ - "grant_type": "client_credentials" + "grant_type": "client_credentials", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuthAccessTokenRequestV1Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuthAccessTokenRequestV1Tests.swift index bc63ff75..3aa517e3 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuthAccessTokenRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuthAccessTokenRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostOAuthAccessTokenRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostOAuthAccessTokenRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostOAuthAccessTokenRequestV1Tests: XCTestCase { + public func test() throws { let req = PostOAuthAccessTokenRequestV1( oauthToken: "_ot_", oauthVerifier: "_ov_" @@ -26,4 +25,8 @@ class PostOAuthAccessTokenRequestV1Tests: XCTestCase { ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuthInvalidateTokenRequestV1Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuthInvalidateTokenRequestV1Tests.swift index a96eeac8..a741762e 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuthInvalidateTokenRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuthInvalidateTokenRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostOAuthInvalidateTokenRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostOAuthInvalidateTokenRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostOAuthInvalidateTokenRequestV1Tests: XCTestCase { + public func test() throws { let req = PostOAuthInvalidateTokenRequestV1() XCTAssertEqual(req.method, .post) @@ -20,4 +19,8 @@ class PostOAuthInvalidateTokenRequestV1Tests: XCTestCase { [:] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuthRequestTokenRequestV1Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuthRequestTokenRequestV1Tests.swift index a1f9799b..ee10657a 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/PostOAuthRequestTokenRequestV1Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/PostOAuthRequestTokenRequestV1Tests.swift @@ -1,14 +1,13 @@ +// PostOAuthRequestTokenRequestV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class PostOAuthRequestTokenRequestV1Tests: XCTestCase { - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { +internal class PostOAuthRequestTokenRequestV1Tests: XCTestCase { + public func test() throws { let req = PostOAuthRequestTokenRequestV1( oauthCallback: "_o_", xAuthAccessType: "_x_" @@ -27,7 +26,7 @@ class PostOAuthRequestTokenRequestV1Tests: XCTestCase { ) } - func testDefaultArg() throws { + public func testDefaultArg() throws { let req = PostOAuthRequestTokenRequestV1( oauthCallback: "_o_" ) @@ -35,8 +34,12 @@ class PostOAuthRequestTokenRequestV1Tests: XCTestCase { AssertEqualAnyDict( req.parameters, [ - "oauth_callback": "_o_" + "oauth_callback": "_o_", ] ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/TwitterAuthAPITests.swift b/Tests/TwitterAPIKitTests/AuthAPI/TwitterAuthAPITests.swift index f93d04e3..6a508528 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/TwitterAuthAPITests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/TwitterAuthAPITests.swift @@ -1,12 +1,15 @@ +// TwitterAuthAPITests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class TwitterAuthAPITests: XCTestCase { - - var client: TwitterAuthAPI! - - override func setUpWithError() throws { +internal class TwitterAuthAPITests: XCTestCase { + public var client: TwitterAuthAPI! + override public func setUpWithError() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] @@ -17,29 +20,31 @@ class TwitterAuthAPITests: XCTestCase { ).auth } - override func tearDownWithError() throws { + override public func tearDownWithError() throws { MockURLProtocol.cleanup() } - func testMakeOAuthAuthorizeURL() throws { + public func testMakeOAuthAuthorizeURL() throws { let url = client.oauth10a.makeOAuthAuthorizeURL( .init(oauthToken: "token", forceLogin: true, screenName: "name") ) XCTAssertEqual( url?.absoluteString, - "https://api.twitter.com/oauth/authorize?force_login=true&oauth_token=token&screen_name=name") + "https://api.twitter.com/oauth/authorize?force_login=true&oauth_token=token&screen_name=name" + ) } - func testMakeOAuthAuthenticateURL() throws { + public func testMakeOAuthAuthenticateURL() throws { let url = client.oauth10a.makeOAuthAuthenticateURL( .init(oauthToken: "token", forceLogin: true, screenName: "name") ) XCTAssertEqual( url?.absoluteString, - "https://api.twitter.com/oauth/authenticate?force_login=true&oauth_token=token&screen_name=name") + "https://api.twitter.com/oauth/authenticate?force_login=true&oauth_token=token&screen_name=name" + ) } - func testMakeOAuth2AuthorizeURL() throws { + public func testMakeOAuth2AuthorizeURL() throws { let url = client.oauth20.makeOAuth2AuthorizeURL( .init( clientID: "cid", @@ -49,12 +54,19 @@ class TwitterAuthAPITests: XCTestCase { codeChallengeMethod: "plain", scopes: [ "users.read", "tweet.read", - ]) + ] + ) ) XCTAssertEqual( - url!.absoluteString, - "https://twitter.com/i/oauth2/authorize?client_id=cid&code_challenge=challenge&code_challenge_method=plain&redirect_uri=callback&response_type=code&scope=users.read%20tweet.read&state=state" + url?.absoluteString, + "https://twitter.com/i/oauth2/authorize?client_id=cid&code_challenge=challenge&" + + "code_challenge_method=plain&redirect_uri=callback&response_type=code&" + + "scope=users.read%20tweet.read&state=state" ) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuth2AccessTokenTests.swift b/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuth2AccessTokenTests.swift index 781fc946..35c252ad 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuth2AccessTokenTests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuth2AccessTokenTests.swift @@ -1,10 +1,14 @@ +// TwitterOAuth2AccessTokenTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import XCTest @testable import TwitterAPIKit -class TwitterOAuth2AccessTokenTests: XCTestCase { - - func test() throws { +internal class TwitterOAuth2AccessTokenTests: XCTestCase { + public func test() throws { try XCTContext.runActivity(named: "without refresh_token") { _ in let data = Data( @@ -15,11 +19,15 @@ class TwitterOAuth2AccessTokenTests: XCTestCase { "expires_in" : 7200, "access_token" : "" } - """#.utf8) - let token = try TwitterOAuth2AccessToken(jsonData: data)! + """#.utf8 + ) + guard let token = try TwitterOAuth2AccessToken(jsonData: data) else { + XCTFail("Failed to create test token") + return + } XCTAssertEqual(token.scope, ["tweet.write", "tweet.read"]) XCTAssertEqual(token.tokenType, "bearer") - XCTAssertEqual(token.expiresIn, 7200) + XCTAssertEqual(token.expiresIn, 7_200) XCTAssertEqual(token.accessToken, "") XCTAssertNil(token.refreshToken) } @@ -35,28 +43,43 @@ class TwitterOAuth2AccessTokenTests: XCTestCase { "access_token" : "", "refresh_token" : "" } - """#.utf8) - let token = try TwitterOAuth2AccessToken(jsonData: data)! + """#.utf8 + ) + guard let token = try TwitterOAuth2AccessToken(jsonData: data) else { + XCTFail("Failed to create test token") + return + } XCTAssertEqual(token.scope, ["tweet.write", "tweet.read", "offline.access"]) XCTAssertEqual(token.tokenType, "bearer") - XCTAssertEqual(token.expiresIn, 7200) + XCTAssertEqual(token.expiresIn, 7_200) XCTAssertEqual(token.accessToken, "") XCTAssertEqual(token.refreshToken, "") } } - func testError() throws { - + public func testError() throws { try XCTContext.runActivity(named: "Not json") { _ in XCTAssertThrowsError(try TwitterOAuth2AccessToken.fromResponse(data: Data("aa".utf8))) { error in - XCTAssertTrue((error as! TwitterAPIKitError).isResponseSerializeFailed) + guard error is TwitterAPIKitError else { + XCTFail("Expected TwitterAPIKitError") + return + } + XCTAssertTrue(error.isResponseSerializeFailed) } } try XCTContext.runActivity(named: "valid json but invalid object") { _ in XCTAssertThrowsError(try TwitterOAuth2AccessToken.fromResponse(data: Data("{}".utf8))) { error in - XCTAssertTrue((error as! TwitterAPIKitError).isResponseSerializeFailed) + guard error is TwitterAPIKitError else { + XCTFail("Expected TwitterAPIKitError") + return + } + XCTAssertTrue(error.isResponseSerializeFailed) } } } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuth2BearerTokenTests.swift b/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuth2BearerTokenTests.swift index 10c0e2fe..0ec0751f 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuth2BearerTokenTests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuth2BearerTokenTests.swift @@ -1,30 +1,34 @@ +// TwitterOAuth2BearerTokenTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class TwitterOAuth2BearerTokenTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func testJsonData() throws { - +internal class TwitterOAuth2BearerTokenTests: XCTestCase { + public func testJsonData() throws { let data = Data(#"{"token_type":"bearer","access_token":"token"}"#.utf8) - let token = try TwitterOAuth2BearerToken(jsonData: data)! + guard let token = try TwitterOAuth2BearerToken(jsonData: data) else { + XCTFail("Failed to create test token") + return + } XCTAssertEqual(token.tokenType, "bearer") XCTAssertEqual(token.accessToken, "token") } - func testNil() throws { + public func testNil() throws { let data = Data("{}".utf8) XCTAssertNil(try TwitterOAuth2BearerToken(jsonData: data)) } - func testThrow() throws { + public func testThrow() throws { let data = Data("".utf8) XCTAssertThrowsError(try TwitterOAuth2BearerToken(jsonData: data)) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuthAccessTokenV1Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuthAccessTokenV1Tests.swift index 393e495b..8259b4db 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuthAccessTokenV1Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuthAccessTokenV1Tests.swift @@ -1,30 +1,30 @@ +// TwitterOAuthAccessTokenV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class TwitterOAuthAccessTokenV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class TwitterOAuthAccessTokenV1Tests: XCTestCase { + public func test() throws { let token = TwitterOAuthAccessTokenV1( - oauthToken: "token", oauthTokenSecret: "secret", userID: "uid", screenName: "sn") + oauthToken: "token", oauthTokenSecret: "secret", userID: "uid", screenName: "sn" + ) XCTAssertEqual(token.oauthToken, "token") XCTAssertEqual(token.oauthTokenSecret, "secret") XCTAssertEqual(token.userID, "uid") XCTAssertEqual(token.screenName, "sn") } - func testQueryStringData() throws { + public func testQueryStringData() throws { let data = Data( - "oauth_token=token&oauth_token_secret=secret&user_id=uid&screen_name=name" - .utf8) + "oauth_token=token&oauth_token_secret=secret&user_id=uid&screen_name=name".utf8 + ) - let token = TwitterOAuthAccessTokenV1(queryStringData: data)! + guard let token = TwitterOAuthAccessTokenV1(queryStringData: data) else { + XCTFail("Failed to decode token Response") + } XCTAssertEqual(token.oauthToken, "token") XCTAssertEqual(token.oauthTokenSecret, "secret") @@ -32,8 +32,12 @@ class TwitterOAuthAccessTokenV1Tests: XCTestCase { XCTAssertEqual(token.screenName, "name") } - func testNil() throws { + public func testNil() throws { let data = Data("".utf8) XCTAssertNil(TwitterOAuthAccessTokenV1(queryStringData: data)) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuthTokenV1Tests.swift b/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuthTokenV1Tests.swift index bfd53bc1..505ce8f1 100644 --- a/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuthTokenV1Tests.swift +++ b/Tests/TwitterAPIKitTests/AuthAPI/TwitterOAuthTokenV1Tests.swift @@ -1,34 +1,37 @@ +// TwitterOAuthTokenV1Tests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class TwitterOAuthTokenV1Tests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class TwitterOAuthTokenV1Tests: XCTestCase { + public func test() throws { let token = TwitterOAuthTokenV1(oauthToken: "token", oauthTokenSecret: "secret", oauthCallbackConfirmed: true) XCTAssertEqual(token.oauthToken, "token") XCTAssertEqual(token.oauthTokenSecret, "secret") - XCTAssertTrue(token.oauthCallbackConfirmed!) + XCTAssertTrue(token.oauthCallbackConfirmed ?? false) } - func testQueryStringData() { - + public func testQueryStringData() { let data = Data("oauth_token=token&oauth_token_secret=secret&oauth_callback_confirmed=true".utf8) - let token = TwitterOAuthTokenV1(queryStringData: data)! + guard let token = TwitterOAuthTokenV1(queryStringData: data) else { + XCTFail("Failed to create test token") + return + } XCTAssertEqual(token.oauthToken, "token") XCTAssertEqual(token.oauthTokenSecret, "secret") - XCTAssertTrue(token.oauthCallbackConfirmed!) + XCTAssertTrue(token.oauthCallbackConfirmed ?? false) } - func testNil() { + public func testNil() { let data = Data("".utf8) XCTAssertNil(TwitterOAuthTokenV1(queryStringData: data)) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/Extensions/ConcurrencyTests.swift b/Tests/TwitterAPIKitTests/Extensions/ConcurrencyTests.swift index 56dd0302..ae73d482 100644 --- a/Tests/TwitterAPIKitTests/Extensions/ConcurrencyTests.swift +++ b/Tests/TwitterAPIKitTests/Extensions/ConcurrencyTests.swift @@ -1,3 +1,8 @@ +// ConcurrencyTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import XCTest @testable import TwitterAPIKit @@ -5,15 +10,8 @@ import XCTest #if compiler(>=5.5.2) && canImport(_Concurrency) @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) - class ConcurrencyTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() async throws { + internal class ConcurrencyTests: XCTestCase { + public func test() async throws { let mockTask = MockTwitterAPISessionTask(taskIdentifier: 1) let task = TwitterAPISessionDelegatedJSONTask( @@ -25,7 +23,11 @@ import XCTest task.append(chunk: Data(":\"value\"}".utf8)) mockTask.httpResponse = .init( - url: URL(string: "http://example.com")!, statusCode: 200, httpVersion: "1.1", headerFields: [:]) + url: URL(string: "http://example.com"), + statusCode: 200, + httpVersion: "1.1", + headerFields: [:] + ) task.complete(error: nil) } @@ -42,7 +44,7 @@ import XCTest do { let obj = await responseObj.success - AssertEqualAnyDict(obj as! [String: Any], ["key": "value"]) + AssertEqualAnyDict(obj as? [String: Any] ?? [:], ["key": "value"]) } do { @@ -51,12 +53,12 @@ import XCTest } do { - let a = await aResponse.success - XCTAssertEqual(a, "a") + let aSuccess = await aResponse.success + XCTAssertEqual(aSuccess, "a") } } - func testCancel() async throws { + public func testCancel() async throws { let mockTask = MockTwitterAPISessionTask(taskIdentifier: 1) let task = TwitterAPISessionDelegatedJSONTask( @@ -79,29 +81,28 @@ import XCTest do { let error = await response.error - XCTAssertTrue(error!.isCancelled) + XCTAssertTrue(error ? error.isCancelled : false) } do { let error = await responseObj.error - XCTAssertTrue(error!.isCancelled) + XCTAssertTrue(error ? error.isCancelled : false) } do { let error = await responseDecodable.error - XCTAssertTrue(error!.isCancelled) + XCTAssertTrue(error ? error.isCancelled : false) } do { let error = await aResponse.error - XCTAssertTrue(error!.isCancelled) + XCTAssertTrue(error ? error.isCancelled : false) } XCTAssertTrue(mockTask.cancelled) } - func testTaskCancel() async throws { - + public func testTaskCancel() async throws { let mockTask = MockTwitterAPISessionTask(taskIdentifier: 1) let task = TwitterAPISessionDelegatedJSONTask( @@ -109,11 +110,11 @@ import XCTest ) let asyncTask = Task { () -> [TwitterAPIResponse] in - async let r0 = task.responseData.map { _ in () } - async let r1 = task.responseObject.map { _ in () } - async let r2 = task.responseDecodable(type: DecodableObj.self).map { _ in () } - async let r3 = task.specialized { _ in () }.responseObject - return await [r0, r1, r2, r3] + async let rt0 = task.responseData.map { _ in () } + async let rt1 = task.responseObject.map { _ in () } + async let rt2 = task.responseDecodable(type: DecodableObj.self).map { _ in () } + async let rt3 = task.specialized { _ in () }.responseObject + return await [rt0, rt1, rt2, rt3] } DispatchQueue.global(qos: .default).async { @@ -124,22 +125,25 @@ import XCTest task.complete(error: URLError(.cancelled)) } - let rs = await asyncTask.value + let rss = await asyncTask.value XCTAssertTrue(mockTask.cancelled) XCTAssertTrue(asyncTask.isCancelled) - XCTAssertEqual(rs.count, 4) - for r in rs { - XCTAssertTrue(r.error!.isCancelled) + XCTAssertEqual(rss.count, 4) + for res in rss { + XCTAssertTrue(r.error.isCancelled) } } - func testStream() async throws { + public func testStream() async throws { let mockTask = MockTwitterAPISessionTask( taskIdentifier: 1, currentRequest: nil, originalRequest: nil, httpResponse: .init( - url: URL(string: "http://example.com")!, statusCode: 200, httpVersion: "1.1", headerFields: [:] + url: URL(string: "http://example.com"), + statusCode: 200, + httpVersion: "1.1", + headerFields: [:] ) ) @@ -153,7 +157,6 @@ import XCTest var count = 0 for await response in stream { - switch count { case 0: XCTAssertEqual(response.success.map { String(data: $0, encoding: .utf8) }, "aaaa") @@ -164,7 +167,7 @@ import XCTest case 3: XCTAssertEqual(response.success.map { String(data: $0, encoding: .utf8) }, "あ") default: - XCTFail() + XCTFail("Invalid Response") } count += 1 if count == 4 { @@ -174,8 +177,7 @@ import XCTest XCTAssertEqual(count, 4) } - func testStreamCancel() async throws { - + public func testStreamCancel() async throws { let mockTask = MockTwitterAPISessionTask( taskIdentifier: 1, currentRequest: nil, @@ -202,24 +204,28 @@ import XCTest XCTAssertTrue(mockTask.cancelled) } - func testStreamError() async throws { - + public func testStreamError() async throws { let mockTask = MockTwitterAPISessionTask( taskIdentifier: 1, currentRequest: nil, originalRequest: nil, httpResponse: .init( - url: URL(string: "http://example.com")!, statusCode: 200, httpVersion: "1.1", headerFields: [:] + url: URL(string: "http://example.com"), + statusCode: 200, + httpVersion: "1.1", + headerFields: [:] ) ) let task = TwitterAPISessionDelegatedStreamTask(task: mockTask) - let stream = task.streamResponse(queue: .main).map({ resp in resp.map { String(data: $0, encoding: .utf8)! } - }) + let stream = task + .streamResponse( + queue: .main + ) + .map { resp in resp.compactMap { String(data: $0, encoding: .utf8) } } let asyncTask = Task { var count = 0 for await resp in stream { - switch count { case 0: XCTAssertEqual(resp.success, "aaaa") @@ -230,7 +236,7 @@ import XCTest case 2: XCTAssertTrue(resp.isError) default: - XCTFail() + XCTFail("Invalid Response") } count += 1 } @@ -244,5 +250,9 @@ import XCTest await asyncTask.value } + + deinit { + // De-init Logic Here + } } #endif diff --git a/Tests/TwitterAPIKitTests/Extensions/DataTests.swift b/Tests/TwitterAPIKitTests/Extensions/DataTests.swift index 82bd3d9d..0a9eb764 100644 --- a/Tests/TwitterAPIKitTests/Extensions/DataTests.swift +++ b/Tests/TwitterAPIKitTests/Extensions/DataTests.swift @@ -1,43 +1,53 @@ +// DataTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import XCTest @testable import TwitterAPIKit -class DataTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func testSerialize() throws { +internal class DataTests: XCTestCase { + public func testSerialize() throws { XCTContext.runActivity(named: "success") { _ in let data = Data("{\"a\":1}".utf8) let serialized = data.serialize() - XCTAssertEqual(serialized.success as! [String: Int], ["a": 1]) + XCTAssertEqual(serialized.success as? [String: Int], ["a": 1]) } XCTContext.runActivity(named: "failure") { _ in let data = Data() let serialized = data.serialize() - XCTAssertTrue(serialized.error!.isResponseSerializeFailed) + guard let error = serialized.error else { + XCTFail("Expected error but got nil") + return + } + XCTAssertTrue(error.isResponseSerializeFailed) } } - func testDecode() throws { + public func testDecode() throws { struct Obj: Decodable { - let a: Int + let abc: Int } XCTContext.runActivity(named: "success") { _ in - let data = Data("{\"a\":1}".utf8) + let data = Data("{\"abc\":1}".utf8) let serialized = data.decode(Obj.self, decoder: JSONDecoder()) - XCTAssertEqual(serialized.success?.a, 1) + XCTAssertEqual(serialized.success?.abc, 1) } XCTContext.runActivity(named: "failure") { _ in let data = Data() let serialized = data.decode(Obj.self, decoder: JSONDecoder()) - XCTAssertTrue(serialized.error!.isResponseSerializeFailed) + guard let error = serialized.error else { + XCTFail("Expected error but got nil") + return + } + XCTAssertTrue(error.isResponseSerializeFailed) } } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/Extensions/StringTests.swift b/Tests/TwitterAPIKitTests/Extensions/StringTests.swift index dfc36282..3176a199 100644 --- a/Tests/TwitterAPIKitTests/Extensions/StringTests.swift +++ b/Tests/TwitterAPIKitTests/Extensions/StringTests.swift @@ -1,18 +1,15 @@ +// StringTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import XCTest @testable import TwitterAPIKit -class StringTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - +internal class StringTests: XCTestCase { /// https://developer.twitter.com/en/docs/authentication/oauth-1-0a/percent-encoding-parameters - func testEncode() throws { - + public func testEncode() throws { XCTAssertEqual("Ladies + Gentlemen".urlEncodedString, "Ladies%20%2B%20Gentlemen") XCTAssertEqual("An encoded string!".urlEncodedString, "An%20encoded%20string%21") XCTAssertEqual("Dogs, Cats & Mice".urlEncodedString, "Dogs%2C%20Cats%20%26%20Mice") @@ -20,4 +17,7 @@ class StringTests: XCTestCase { XCTAssertEqual("1970-01-01T00:01:00Z".urlEncodedString, "1970-01-01T00%3A01%3A00Z") } + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/Helper/Assert.swift b/Tests/TwitterAPIKitTests/Helper/Assert.swift index 5250071e..757f709a 100644 --- a/Tests/TwitterAPIKitTests/Helper/Assert.swift +++ b/Tests/TwitterAPIKitTests/Helper/Assert.swift @@ -1,11 +1,19 @@ +// Assert.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation import XCTest -// swift-format-ignore: AlwaysUseLowerCamelCase -func AssertEqualAnyDict( - _ l: [String: Any], _ r: [String: Any], _ message: @autoclosure () -> String = "", file: StaticString = #filePath, +// swiftlint:disable:next identifier_name +internal func AssertEqualAnyDict( + _ left: [String: Any], + _ right: [String: Any], + _ message: @autoclosure () -> String = "", + file: StaticString = #filePath, line: UInt = #line ) { // It works well most of the time. - XCTAssertEqual(NSDictionary(dictionary: l), NSDictionary(dictionary: r), message(), file: file, line: line) + XCTAssertEqual(NSDictionary(dictionary: left), NSDictionary(dictionary: right), message(), file: file, line: line) } diff --git a/Tests/TwitterAPIKitTests/Helper/CombinationsSequence.swift b/Tests/TwitterAPIKitTests/Helper/CombinationsSequence.swift index 3220f283..8ff30a51 100644 --- a/Tests/TwitterAPIKitTests/Helper/CombinationsSequence.swift +++ b/Tests/TwitterAPIKitTests/Helper/CombinationsSequence.swift @@ -1,39 +1,30 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Algorithms open source project -// -// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// +// CombinationsSequence.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. /// A collection wrapper that generates combinations of a base collection. public struct CombinationsSequence { /// The collection to iterate over for combinations. - @usableFromInline - internal let base: Base + @usableFromInline internal let base: Base - @usableFromInline - internal let baseCount: Int + @usableFromInline internal let baseCount: Int /// The range of accepted sizes of combinations. /// /// - Note: This may be `nil` if the attempted range entirely exceeds the /// upper bounds of the size of the `base` collection. - @usableFromInline - internal let kRange: Range? + @usableFromInline internal let combinationRange: Range? /// Initializes a `CombinationsSequence` for all combinations of `base` of /// size `k`. /// /// - Parameters: /// - base: The collection to iterate over for combinations. - /// - k: The expected size of each combination. + /// - size: The expected size of each combination. @inlinable - internal init(_ base: Base, k: Int) { - self.init(base, kRange: k...k) + internal init(_ base: Base, size: Int) { + self.init(base, kRange: size ... size) } /// Initializes a `CombinationsSequence` for all combinations of `base` of @@ -51,64 +42,61 @@ public struct CombinationsSequence { let baseCount = base.count self.baseCount = baseCount let upperBound = baseCount + 1 - self.kRange = + self.combinationRange = range.lowerBound < upperBound - ? range.clamped(to: 0.. Int { - switch k { - case n, 0: return 1 - case n...: return 0 - case (n / 2 + 1)...: return binomial(n: n, k: n - k) - default: return n * binomial(n: n - 1, k: k - 1) / k + internal func binomial(total: Int, size: Int) -> Int { + switch size { + case total, 0: return 1 + case total...: return 0 + case (total / 2 + 1)...: return binomial(total: total, size: total - size) + default: return total * binomial(total: total - 1, size: size - 1) / size } } - return k.map { - binomial(n: n, k: $0) - }.reduce(0, +) + return range + .map { + binomial(total: total, size: $0) + } + .reduce(0, +) } } extension CombinationsSequence: Sequence { /// The iterator for a `CombinationsSequence` instance. public struct Iterator: IteratorProtocol { - @usableFromInline - internal let base: Base + @usableFromInline internal let base: Base /// The current range of accepted sizes of combinations. /// /// - Note: The range is contracted until empty while iterating over /// combinations of different sizes. When the range is empty, iteration is /// finished. - @usableFromInline - internal var kRange: Range + @usableFromInline internal var kRange: Range /// Whether or not iteration is finished (`kRange` is empty) - @inlinable - internal var isFinished: Bool { + @inlinable internal var isFinished: Bool { return kRange.isEmpty } - @usableFromInline - internal var indexes: [Base.Index] + @usableFromInline internal var indexes: [Base.Index] @inlinable internal init(_ combinations: CombinationsSequence) { - self.base = combinations.base - self.kRange = combinations.kRange ?? 0..<0 - self.indexes = Array(combinations.base.indices.prefix(kRange.lowerBound)) + base = combinations.base + kRange = combinations.combinationRange ?? 0 ..< 0 + indexes = Array(combinations.base.indices.prefix(kRange.lowerBound)) } /// Advances the current indices to the next set of combinations. If @@ -131,12 +119,12 @@ extension CombinationsSequence: Sequence { /// // so the iteration is finished. @inlinable internal mutating func advance() { - /// Advances `kRange` by incrementing its `lowerBound` until the range is - /// empty, when iteration is finished. - func advanceKRange() { + // Advances `kRange` by incrementing its `lowerBound` until the range is + // empty, when iteration is finished. + internal func advanceKRange() { if kRange.lowerBound < kRange.upperBound { let advancedLowerBound = kRange.lowerBound + 1 - kRange = advancedLowerBound..= 0 else { + var currentIndex = lastIndex + while indexes[lastIndex] == base.endIndex { + currentIndex -= 1 + guard currentIndex >= 0 else { // Finished iterating over combinations of this size. advanceKRange() return } - base.formIndex(after: &indexes[j]) - for k in indexes.indices[(j + 1)...] { - indexes[k] = base.index(after: indexes[k - 1]) - if indexes[k] == base.endIndex { + base.formIndex(after: &indexes[currentIndex]) + for nextIndex in indexes.indices[(currentIndex + 1)...] { + indexes[nextIndex] = base.index(after: indexes[nextIndex - 1]) + if indexes[nextIndex] == base.endIndex { break } } @@ -177,7 +165,7 @@ extension CombinationsSequence: Sequence { public mutating func next() -> [Base.Element]? { guard !isFinished else { return nil } defer { advance() } - return indexes.map { i in base[i] } + return indexes.map { index in base[index] } } } @@ -188,13 +176,13 @@ extension CombinationsSequence: Sequence { } extension CombinationsSequence: LazySequenceProtocol -where Base: LazySequenceProtocol {} + where Base: LazySequenceProtocol {} -//===----------------------------------------------------------------------===// +// ===----------------------------------------------------------------------===// // combinations(ofCount:) -//===----------------------------------------------------------------------===// +// ===----------------------------------------------------------------------===// -extension Collection { +public extension Collection { /// Returns a collection of combinations of this collection's elements, with /// each combination having the specified number of elements. /// @@ -258,43 +246,22 @@ extension Collection { /// `CombinationsSequence` accesses the `count` of the base collection. @inlinable public func combinations( - ofCount kRange: R + ofCount range: R ) -> CombinationsSequence where R.Bound == Int { - CombinationsSequence(self, kRange: kRange) + return CombinationsSequence(self, kRange: range) } /// Returns a collection of combinations of this collection's elements, with /// each combination having the specified number of elements. /// - /// This example prints the different combinations of three from an array of - /// four colors: - /// - /// let colors = ["fuchsia", "cyan", "mauve", "magenta"] - /// for combo in colors.combinations(ofCount: 3) { - /// print(combo.joined(separator: ", ")) - /// } - /// // fuchsia, cyan, mauve - /// // fuchsia, cyan, magenta - /// // fuchsia, mauve, magenta - /// // cyan, mauve, magenta - /// - /// The returned collection presents combinations in a consistent order, where - /// the indices in each combination are in ascending lexicographical order. - /// That is, in the example above, the combinations in order are the elements - /// at `[0, 1, 2]`, `[0, 1, 3]`, `[0, 2, 3]`, and finally `[1, 2, 3]`. - /// - /// If `k` is zero, the resulting sequence has exactly one element, an empty - /// array. If `k` is greater than the number of elements in this sequence, - /// the resulting sequence has no elements. - /// - /// - Parameter k: The number of elements to include in each combination. + /// - Parameter size: The number of elements to include in each combination. /// /// - Complexity: O(1) for random-access base collections. O(*n*) where *n* - /// is the number of elements in the base collection, since - /// `CombinationsSequence` accesses the `count` of the base collection. + /// is the number of elements in the base collection, since + /// `CombinationsSequence` accesses the `count` of the base collection. @inlinable - public func combinations(ofCount k: Int) -> CombinationsSequence { - precondition(k >= 0, "Can't have combinations with a negative number of elements.") - return CombinationsSequence(self, k: k) + public func combinations(ofCount size: Int) -> CombinationsSequence { + precondition(size >= 0, "Can't have combinations with a negative number of elements.") + return CombinationsSequence(self, size: size) } } diff --git a/Tests/TwitterAPIKitTests/Mock/MockURLProtocol.swift b/Tests/TwitterAPIKitTests/Mock/MockURLProtocol.swift index 2ee46f92..78da7037 100644 --- a/Tests/TwitterAPIKitTests/Mock/MockURLProtocol.swift +++ b/Tests/TwitterAPIKitTests/Mock/MockURLProtocol.swift @@ -1,44 +1,55 @@ -import Foundation +// MockURLProtocol.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. -class MockURLProtocol: URLProtocol { +import Foundation - static var requestHandler: ((URLRequest) throws -> (HTTPURLResponse, Data?))? - static var requestAssert: ((URLRequest) throws -> Void)? +internal class MockURLProtocol: URLProtocol { + public static var requestHandler: ((URLRequest) throws -> (HTTPURLResponse, Data?))? + public static var requestAssert: ((URLRequest) throws -> Void)? - override class func canInit(with request: URLRequest) -> Bool { + override public class func canInit(with _: URLRequest) -> Bool { return true } - override class func canonicalRequest(for request: URLRequest) -> URLRequest { + override public class func canonicalRequest(for request: URLRequest) -> URLRequest { return request } - static func cleanup() { - MockURLProtocol.requestHandler = nil - MockURLProtocol.requestAssert = nil + public static func cleanup() { + requestHandler = nil + requestAssert = nil } - override func startLoading() { + override public func startLoading() { + guard let url = request.url else { + client?.urlProtocol(self, didFailWithError: URLError(.badURL)) + return + } - let handler: ((URLRequest) throws -> (HTTPURLResponse, Data?)) - if let h = MockURLProtocol.requestHandler { - handler = h - } else { - handler = { request in - return ( - HTTPURLResponse(url: request.url!, statusCode: 200, httpVersion: "2.0", headerFields: nil)!, Data() - ) + let handler: (URLRequest) throws -> (HTTPURLResponse, Data?) = Self.requestHandler ?? { request in + guard let requestURL = request.url else { + throw URLError(.badURL) } + return ( + HTTPURLResponse( + url: requestURL, + statusCode: 200, + httpVersion: "2.0", + headerFields: nil + ) ?? HTTPURLResponse(), + Data() + ) } do { - - try MockURLProtocol.requestAssert?(request) + try Self.requestAssert?(request) let (response, data): (URLResponse, Data?) = try handler(request) client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed) - if let data = data { + if let data { client?.urlProtocol(self, didLoad: data) } @@ -48,7 +59,9 @@ class MockURLProtocol: URLProtocol { } } - override func stopLoading() { + override public func stopLoading() {} + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/MultipartFormDataPartTests.swift b/Tests/TwitterAPIKitTests/MultipartFormDataPartTests.swift index 927b6139..324c6a34 100644 --- a/Tests/TwitterAPIKitTests/MultipartFormDataPartTests.swift +++ b/Tests/TwitterAPIKitTests/MultipartFormDataPartTests.swift @@ -1,41 +1,47 @@ +// MultipartFormDataPartTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class MultipartFormDataPartTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func testEqualValue() throws { +internal class MultipartFormDataPartTests: XCTestCase { + public func testEqualValue() throws { + let dataA = MultipartFormDataPart.value(name: "n", value: 1) + let dataB = MultipartFormDataPart.value(name: "n", value: "1") + let dataC = MultipartFormDataPart.value(name: "n", value: Float(1)) + let dataD = MultipartFormDataPart.value(name: "m", value: 1) - let a = MultipartFormDataPart.value(name: "n", value: 1) - let b = MultipartFormDataPart.value(name: "n", value: "1") - let c = MultipartFormDataPart.value(name: "n", value: Float(1)) - let d = MultipartFormDataPart.value(name: "m", value: 1) - - [a, b, c, d].combinations(ofCount: 2).forEach { combo in + for combo in [dataA, dataB, dataC, dataD].combinations(ofCount: 2) { XCTAssertNotEqual(combo[0], combo[1]) } } - func testEqualData() throws { + public func testEqualData() throws { let data = Data() - let a = MultipartFormDataPart.data(name: "n", value: data, filename: "f", mimeType: "m") - let b = MultipartFormDataPart.data(name: "m", value: data, filename: "f", mimeType: "m") - let c = MultipartFormDataPart.data(name: "n", value: data, filename: "ff", mimeType: "m") - let d = MultipartFormDataPart.data(name: "n", value: data, filename: "f", mimeType: "mm") - let e = MultipartFormDataPart.data(name: "n", value: Data(repeating: 1, count: 1), filename: "f", mimeType: "m") - let f = MultipartFormDataPart.value(name: "n", value: data) - - let a1 = MultipartFormDataPart.data(name: "n", value: Data(), filename: "f", mimeType: "m") - - [a, b, c, d, e, f].combinations(ofCount: 2).forEach { combo in + let dataA = MultipartFormDataPart.data(name: "n", value: data, filename: "f", mimeType: "m") + let dataB = MultipartFormDataPart.data(name: "m", value: data, filename: "f", mimeType: "m") + let dataC = MultipartFormDataPart.data(name: "n", value: data, filename: "ff", mimeType: "m") + let dataD = MultipartFormDataPart.data(name: "n", value: data, filename: "f", mimeType: "mm") + let dataE = MultipartFormDataPart.data( + name: "n", + value: Data(repeating: 1, count: 1), + filename: "f", + mimeType: "m" + ) + let dataF = MultipartFormDataPart.value(name: "n", value: data) + + let dataA1 = MultipartFormDataPart.data(name: "n", value: Data(), filename: "f", mimeType: "m") + + for combo in [dataA, dataB, dataC, dataD, dataE, dataF].combinations(ofCount: 2) { XCTAssertNotEqual(combo[0], combo[1]) } - XCTAssertEqual(a, a1) + XCTAssertEqual(dataA, dataA1) + } + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/OAuthHelperTests.swift b/Tests/TwitterAPIKitTests/OAuthHelperTests.swift index de4343ca..8447045f 100644 --- a/Tests/TwitterAPIKitTests/OAuthHelperTests.swift +++ b/Tests/TwitterAPIKitTests/OAuthHelperTests.swift @@ -1,24 +1,28 @@ +// OAuthHelperTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import XCTest @testable import TwitterAPIKit -class OAuthHelperTests: XCTestCase { - - override func setUpWithError() throws { - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDownWithError() throws { - // Put teardown code here. This method is called after the invocation of each test method in the class. +internal class OAuthHelperTests: XCTestCase { + override public func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the internal class. } // https://developer.twitter.com/en/docs/authentication/oauth-1-0a/authorizing-a-request // https://developer.twitter.com/en/docs/authentication/oauth-1-0a/creating-a-signature - func test() throws { - + public func test() throws { + guard let url = URL(string: "https://api.twitter.com/1.1/statuses/update.json") else { + XCTFail("Failed to create test URL") + return + } + let header = authorizationHeader( for: .post, - url: URL(string: "https://api.twitter.com/1.1/statuses/update.json")!, + url: url, parameters: ["status": "Hello Ladies + Gentlemen, a signed OAuth request!", "include_entities": true], consumerKey: "xvz1evFS4wEEPTGEFPHBog", consumerSecret: "kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw", @@ -27,11 +31,19 @@ class OAuthHelperTests: XCTestCase { oauthTimestamp: "1318622958", oauthNonce: "kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg" ) + let expectedHeader = #""" + OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog", \ + oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg", \ + oauth_signature="hCtSmYh%2BiHYCEqBWrE7C7hYmtUk%3D", \ + oauth_signature_method="HMAC-SHA1", \ + oauth_timestamp="1318622958", \ + oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb", \ + oauth_version="1.0" + """# + XCTAssertEqual(header, expectedHeader) + } - XCTAssertEqual( - header, - #"OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog", oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg", oauth_signature="hCtSmYh%2BiHYCEqBWrE7C7hYmtUk%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318622958", oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb", oauth_version="1.0""# - ) - + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/SessionTask/MockTwitterAPISessionTask.swift b/Tests/TwitterAPIKitTests/SessionTask/MockTwitterAPISessionTask.swift index 92376d4c..3b8ff0e9 100644 --- a/Tests/TwitterAPIKitTests/SessionTask/MockTwitterAPISessionTask.swift +++ b/Tests/TwitterAPIKitTests/SessionTask/MockTwitterAPISessionTask.swift @@ -1,15 +1,19 @@ +// MockTwitterAPISessionTask.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import Foundation import TwitterAPIKit -class MockTwitterAPISessionTask: TwitterAPISessionTask { - - var taskIdentifier: Int - var currentRequest: URLRequest? - var originalRequest: URLRequest? - var httpResponse: HTTPURLResponse? - var cancelled = false +internal class MockTwitterAPISessionTask: TwitterAPISessionTask { + public var taskIdentifier: Int + public var currentRequest: URLRequest? + public var originalRequest: URLRequest? + public var httpResponse: HTTPURLResponse? + public var cancelled = false - init( + public init( taskIdentifier: Int, currentRequest: URLRequest? = nil, originalRequest: URLRequest? = nil, @@ -21,16 +25,19 @@ class MockTwitterAPISessionTask: TwitterAPISessionTask { self.httpResponse = httpResponse } - func cancel() { + public func cancel() { cancelled = true } -} -class MockTwitterAPISessionDataTask: MockTwitterAPISessionTask, TwitterAPISessionDataTask { + deinit { + // De-init Logic Here + } +} - var data: Data +internal class MockTwitterAPISessionDataTask: MockTwitterAPISessionTask, TwitterAPISessionDataTask { + public var data: Data - init( + public init( data: Data, taskIdentifier: Int, currentRequest: URLRequest? = nil, @@ -39,27 +46,34 @@ class MockTwitterAPISessionDataTask: MockTwitterAPISessionTask, TwitterAPISessio ) { self.data = data super.init( - taskIdentifier: taskIdentifier, currentRequest: currentRequest, originalRequest: originalRequest, - httpResponse: httpResponse) + taskIdentifier: taskIdentifier, + currentRequest: currentRequest, + originalRequest: originalRequest, + httpResponse: httpResponse + ) } - func responseData(queue: DispatchQueue, _ block: @escaping (TwitterAPIResponse) -> Void) -> Self { - + public func responseData(queue: DispatchQueue, _ block: @escaping (TwitterAPIResponse) -> Void) -> Self { queue.async { [weak self] in - guard let self = self else { return } + guard let self else { return } block( .init( - request: self.currentRequest, - response: self.httpResponse, - data: self.data, - result: .success(self.data), + request: currentRequest, + response: httpResponse, + data: data, + result: .success(data), rateLimit: TwitterRateLimit(header: [:]) - )) + ) + ) } return self } - func responseData(_ block: @escaping (TwitterAPIResponse) -> Void) -> Self { + public func responseData(_ block: @escaping (TwitterAPIResponse) -> Void) -> Self { return responseData(queue: .main, block) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/SessionTask/TwitterAPIFailedTaskTests.swift b/Tests/TwitterAPIKitTests/SessionTask/TwitterAPIFailedTaskTests.swift index 82c547d7..061fdece 100644 --- a/Tests/TwitterAPIKitTests/SessionTask/TwitterAPIFailedTaskTests.swift +++ b/Tests/TwitterAPIKitTests/SessionTask/TwitterAPIFailedTaskTests.swift @@ -1,16 +1,13 @@ +// TwitterAPIFailedTaskTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class TwitterAPIFailedTaskTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class TwitterAPIFailedTaskTests: XCTestCase { + public func test() throws { let task = TwitterAPIFailedTask(.responseFailed(reason: .invalidResponse(error: nil))) XCTAssertTrue(task.error.isResponseFailed) @@ -63,8 +60,11 @@ class TwitterAPIFailedTaskTests: XCTestCase { dispatchPrecondition(condition: .onQueue(.main)) exp.fulfill() } - .responseDecodable(type: DecodableObj.self, decoder: JSONDecoder(), queue: .global(qos: .userInteractive)) { - response in + .responseDecodable( + type: DecodableObj.self, + decoder: JSONDecoder(), + queue: .global(qos: .userInteractive) + ) { response in XCTAssertNotNil(response.error) XCTAssertTrue(response.isError) @@ -75,7 +75,7 @@ class TwitterAPIFailedTaskTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testStream() throws { + public func testStream() throws { let task = TwitterAPIFailedTask(.responseFailed(reason: .invalidResponse(error: nil))) let exp = expectation(description: "") @@ -95,4 +95,8 @@ class TwitterAPIFailedTaskTests: XCTestCase { wait(for: [exp], timeout: 10) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/SessionTask/TwitterAPISessionDelegatedJSONTaskTests.swift b/Tests/TwitterAPIKitTests/SessionTask/TwitterAPISessionDelegatedJSONTaskTests.swift index fddfff60..22df47a5 100644 --- a/Tests/TwitterAPIKitTests/SessionTask/TwitterAPISessionDelegatedJSONTaskTests.swift +++ b/Tests/TwitterAPIKitTests/SessionTask/TwitterAPISessionDelegatedJSONTaskTests.swift @@ -1,20 +1,21 @@ +// TwitterAPISessionDelegatedJSONTaskTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import XCTest @testable import TwitterAPIKit -struct DecodableObj: Decodable, Equatable { - let key: String +internal struct DecodableObj: Decodable, Equatable { + public let key: String } -class TwitterAPISessionDelegatedJSONTaskTests: XCTestCase { - - override func setUpWithError() throws { - } +internal class TwitterAPISessionDelegatedJSONTaskTests: XCTestCase { + // swiftlint:disable:next force_unwrapping + internal let testURL = URL(string: "http://example.com")! - override func tearDownWithError() throws { - } - - func testSuccess() throws { + public func testSuccess() throws { let mockTask = MockTwitterAPISessionTask(taskIdentifier: 1) let task = TwitterAPISessionDelegatedJSONTask( @@ -42,7 +43,11 @@ class TwitterAPISessionDelegatedJSONTaskTests: XCTestCase { exp.fulfill() } .responseObject(queue: .global(qos: .background)) { response in - AssertEqualAnyDict(response.success as! [String: Any], ["key": "value"]) + if let dict = response.success as? [String: Any] { + AssertEqualAnyDict(dict, ["key": "value"]) + } else { + XCTFail("Expected response.success to be [String: Any]") + } XCTAssertFalse(Thread.isMainThread) exp.fulfill() } @@ -65,7 +70,7 @@ class TwitterAPISessionDelegatedJSONTaskTests: XCTestCase { task.append(chunk: Data(":\"value\"}".utf8)) mockTask.httpResponse = .init( - url: URL(string: "http://example.com")!, + url: self.testURL, statusCode: 200, httpVersion: "1.1", headerFields: [ @@ -81,7 +86,7 @@ class TwitterAPISessionDelegatedJSONTaskTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testInvalidStatusCode() throws { + public func testInvalidStatusCode() throws { let mockTask = MockTwitterAPISessionTask(taskIdentifier: 1) let task = TwitterAPISessionDelegatedJSONTask( @@ -91,21 +96,24 @@ class TwitterAPISessionDelegatedJSONTaskTests: XCTestCase { let exp = expectation(description: "") exp.expectedFulfillmentCount = 3 - _ = task.responseData(queue: .global(qos: .background)) { response in - XCTAssertTrue(response.isError) - XCTAssertNotNil(response.rateLimit) - XCTAssertEqual(response.rateLimit?.limit, 100) - XCTAssertEqual(response.rateLimit?.remaining, 2) - XCTAssertEqual(response.rateLimit?.reset, 1_647_099_945) - - exp.fulfill() - }.responseObject(queue: .global(qos: .background)) { response in - XCTAssertTrue(response.isError) - exp.fulfill() - }.responseDecodable(type: DecodableObj.self, queue: .global(qos: .background)) { response in - XCTAssertTrue(response.isError) - exp.fulfill() - } + _ = task + .responseData(queue: .global(qos: .background)) { response in + XCTAssertTrue(response.isError) + XCTAssertNotNil(response.rateLimit) + XCTAssertEqual(response.rateLimit?.limit, 100) + XCTAssertEqual(response.rateLimit?.remaining, 2) + XCTAssertEqual(response.rateLimit?.reset, 1_647_099_945) + + exp.fulfill() + } + .responseObject(queue: .global(qos: .background)) { response in + XCTAssertTrue(response.isError) + exp.fulfill() + } + .responseDecodable(type: DecodableObj.self, queue: .global(qos: .background)) { response in + XCTAssertTrue(response.isError) + exp.fulfill() + } DispatchQueue.global(qos: .background).async { task.append(chunk: Data("{\"key\"".utf8)) @@ -113,7 +121,7 @@ class TwitterAPISessionDelegatedJSONTaskTests: XCTestCase { // Status code is 400 mockTask.httpResponse = .init( - url: URL(string: "http://example.com")!, + url: self.testURL, statusCode: 400, httpVersion: "1.1", headerFields: [ @@ -129,8 +137,7 @@ class TwitterAPISessionDelegatedJSONTaskTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testCompleteWithError() throws { - + public func testCompleteWithError() throws { let mockTask = MockTwitterAPISessionTask(taskIdentifier: 1) let task = TwitterAPISessionDelegatedJSONTask( @@ -140,33 +147,40 @@ class TwitterAPISessionDelegatedJSONTaskTests: XCTestCase { let exp = expectation(description: "") exp.expectedFulfillmentCount = 3 - _ = task.responseData(queue: .global(qos: .background)) { response in - XCTAssertTrue(response.isError) - XCTAssertEqual(response.error?.underlyingError as! URLError, URLError(.badServerResponse)) - exp.fulfill() - }.responseObject(queue: .global(qos: .background)) { response in - XCTAssertTrue(response.isError) - exp.fulfill() - }.responseDecodable(type: DecodableObj.self, queue: .global(qos: .background)) { response in - XCTAssertTrue(response.isError) - exp.fulfill() - } + _ = task + .responseData(queue: .global(qos: .background)) { response in + XCTAssertTrue(response.isError) + if let urlError = response.error?.underlyingError as? URLError { + XCTAssertEqual(urlError, URLError(.badServerResponse)) + } else { + XCTFail("Expected URLError") + } + exp.fulfill() + } + .responseObject(queue: .global(qos: .background)) { response in + XCTAssertTrue(response.isError) + exp.fulfill() + } + .responseDecodable(type: DecodableObj.self, queue: .global(qos: .background)) { response in + XCTAssertTrue(response.isError) + exp.fulfill() + } DispatchQueue.global(qos: .background).async { task.append(chunk: Data("{\"key\"".utf8)) task.append(chunk: Data(":\"value\"}".utf8)) mockTask.httpResponse = .init( - url: URL(string: "http://example.com")!, statusCode: 200, httpVersion: "1.1", headerFields: [:]) + url: self.testURL, statusCode: 200, httpVersion: "1.1", headerFields: [:] + ) - task.complete(error: URLError.init(.badServerResponse)) + task.complete(error: URLError(.badServerResponse)) } wait(for: [exp], timeout: 10) } - func testCancel() throws { - + public func testCancel() throws { let mockTask = MockTwitterAPISessionTask(taskIdentifier: 1) let task = TwitterAPISessionDelegatedJSONTask( @@ -176,26 +190,39 @@ class TwitterAPISessionDelegatedJSONTaskTests: XCTestCase { let exp = expectation(description: "") exp.expectedFulfillmentCount = 3 - _ = task.responseData(queue: .global(qos: .background)) { response in - XCTAssertTrue(response.isError) - XCTAssertEqual(response.error?.underlyingError as! URLError, URLError(.cancelled)) - exp.fulfill() - }.responseObject(queue: .global(qos: .background)) { response in - XCTAssertTrue(response.isError) - exp.fulfill() - }.responseDecodable(type: DecodableObj.self, queue: .global(qos: .background)) { response in - XCTAssertTrue(response.isError) - exp.fulfill() - } + _ = task + .responseData(queue: .global(qos: .background)) { response in + XCTAssertTrue(response.isError) + if let urlError = response.error?.underlyingError as? URLError { + XCTAssertEqual(urlError, URLError(.cancelled)) + } else { + XCTFail("Expected URLError") + } + exp.fulfill() + } + .responseObject(queue: .global(qos: .background)) { response in + XCTAssertTrue(response.isError) + exp.fulfill() + } + .responseDecodable(type: DecodableObj.self, queue: .global(qos: .background)) { response in + XCTAssertTrue(response.isError) + if let urlError = response.error?.underlyingError as? URLError { + XCTAssertEqual(urlError, URLError(.cancelled)) + } else { + XCTFail("Expected URLError") + } + exp.fulfill() + } DispatchQueue.global(qos: .background).async { task.append(chunk: Data("{\"key\"".utf8)) task.append(chunk: Data(":\"value\"}".utf8)) mockTask.httpResponse = .init( - url: URL(string: "http://example.com")!, statusCode: 200, httpVersion: "1.1", headerFields: [:]) + url: self.testURL, statusCode: 200, httpVersion: "1.1", headerFields: [:] + ) - task.complete(error: URLError.init(.cancelled)) + task.complete(error: URLError(.cancelled)) } task.cancel() @@ -204,9 +231,13 @@ class TwitterAPISessionDelegatedJSONTaskTests: XCTestCase { XCTAssertTrue(mockTask.cancelled) } - func testEXC_BAD_INSTRUCTION() throws { + public func testEXC_BAD_INSTRUCTION() throws { // EXC_BAD_INSTRUCTION will occur if the Dispatch Queue is released while suspended. let mockTask = MockTwitterAPISessionTask(taskIdentifier: 1) _ = TwitterAPISessionDelegatedJSONTask(task: mockTask) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/SessionTask/TwitterAPISessionDelegatedStreamTaskTests.swift b/Tests/TwitterAPIKitTests/SessionTask/TwitterAPISessionDelegatedStreamTaskTests.swift index d8b2e094..c60649f6 100644 --- a/Tests/TwitterAPIKitTests/SessionTask/TwitterAPISessionDelegatedStreamTaskTests.swift +++ b/Tests/TwitterAPIKitTests/SessionTask/TwitterAPISessionDelegatedStreamTaskTests.swift @@ -1,24 +1,37 @@ +// TwitterAPISessionDelegatedStreamTaskTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import XCTest @testable import TwitterAPIKit -class TwitterAPISessionDelegatedStreamTaskTests: XCTestCase { - - override func setUpWithError() throws { - } +internal class TwitterAPISessionDelegatedStreamTaskTests: XCTestCase { + override public func setUpWithError() throws {} - override func tearDownWithError() throws { - } + override public func tearDownWithError() throws {} - func testProps() throws { - let cReq = URLRequest(url: URL(string: "http://example.com/current")!) - let oReq = URLRequest(url: URL(string: "http://example.com/original")!) - let resp = HTTPURLResponse( - url: URL(string: "https://example.com")!, + public func testProps() throws { + guard let currentURL = URL(string: "http://example.com/current"), + let originalURL = URL(string: "http://example.com/original"), + let responseURL = URL(string: "https://example.com") else { + XCTFail("Failed to create test URLs") + return + } + + let cReq = URLRequest(url: currentURL) + let oReq = URLRequest(url: originalURL) + guard let resp = HTTPURLResponse( + url: responseURL, statusCode: 200, httpVersion: "1.1", headerFields: [:] - ) + ) else { + XCTFail("Failed to create test response") + return + } + let mockTask = MockTwitterAPISessionTask( taskIdentifier: 1, currentRequest: cReq, @@ -31,17 +44,12 @@ class TwitterAPISessionDelegatedStreamTaskTests: XCTestCase { XCTAssertEqual(mockTask.currentRequest, cReq) XCTAssertEqual(mockTask.originalRequest, oReq) XCTAssertEqual(task.httpResponse, resp) - } - func test() throws { - - let mockTask = MockTwitterAPISessionTask( - taskIdentifier: 1, - currentRequest: nil, - originalRequest: nil, - httpResponse: HTTPURLResponse( - url: URL(string: "https://example.com")!, + public func test() throws { + guard let responseURL = URL(string: "https://example.com"), + let response = HTTPURLResponse( + url: responseURL, statusCode: 200, httpVersion: "1.1", headerFields: [ @@ -49,13 +57,21 @@ class TwitterAPISessionDelegatedStreamTaskTests: XCTestCase { "x-rate-limit-remaining": "1", "x-rate-limit-reset": "1647099944", ] - ) + ) else { + XCTFail("Failed to create test response") + return + } + + let mockTask = MockTwitterAPISessionTask( + taskIdentifier: 1, + currentRequest: nil, + originalRequest: nil, + httpResponse: response ) let task = TwitterAPISessionDelegatedStreamTask(task: mockTask) DispatchQueue.main.async { - task.append(chunk: Data("aaaa\r\nbbbb".utf8)) task.append(chunk: Data("🥓🥓\r\nあ".utf8)) task.complete(error: nil) @@ -65,46 +81,48 @@ class TwitterAPISessionDelegatedStreamTaskTests: XCTestCase { exp.expectedFulfillmentCount = 8 var count = 0 - task.streamResponse { response in - - XCTAssertTrue(Thread.isMainThread) - - XCTAssertNotNil(response.rateLimit) - XCTAssertEqual(response.rateLimit?.limit, 15) - XCTAssertEqual(response.rateLimit?.remaining, 1) - XCTAssertEqual(response.rateLimit?.reset, 1_647_099_944) - - switch count { - case 0: - XCTAssertEqual(response.success.map { String(data: $0, encoding: .utf8) }, "aaaa") - case 1: - XCTAssertEqual(response.success.map { String(data: $0, encoding: .utf8) }, "bbbb") - case 2: - XCTAssertEqual(response.success.map { String(data: $0, encoding: .utf8) }, "🥓🥓") - case 3: - XCTAssertEqual(response.success.map { String(data: $0, encoding: .utf8) }, "あ") - default: - XCTFail() + task + .streamResponse { response in + XCTAssertTrue(Thread.isMainThread) + + guard let rateLimit = response.rateLimit else { + XCTFail("Rate limit should not be nil") + return + } + + XCTAssertEqual(rateLimit.limit, 15) + XCTAssertEqual(rateLimit.remaining, 1) + XCTAssertEqual(rateLimit.reset, 1_647_099_944) + + switch count { + case 0: + XCTAssertEqual(response.success.map { String(data: $0, encoding: .utf8) }, "aaaa") + case 1: + XCTAssertEqual(response.success.map { String(data: $0, encoding: .utf8) }, "bbbb") + case 2: + XCTAssertEqual(response.success.map { String(data: $0, encoding: .utf8) }, "🥓🥓") + case 3: + XCTAssertEqual(response.success.map { String(data: $0, encoding: .utf8) }, "あ") + default: + XCTFail("Invalid Response") + } + + count += 1 + exp.fulfill() + } + .streamResponse(queue: .global(qos: .default)) { _ in + XCTAssertFalse(Thread.isMainThread) + exp.fulfill() } - - count += 1 - exp.fulfill() - }.streamResponse(queue: .global(qos: .default)) { _ in - XCTAssertFalse(Thread.isMainThread) - exp.fulfill() - } wait(for: [exp], timeout: 100) XCTAssertEqual(count, 4) } - func testInvalidStatusCode() throws { - let mockTask = MockTwitterAPISessionTask( - taskIdentifier: 2, - currentRequest: nil, - originalRequest: nil, - httpResponse: HTTPURLResponse( - url: URL(string: "https://example.com")!, + public func testInvalidStatusCode() throws { + guard let responseURL = URL(string: "https://example.com"), + let response = HTTPURLResponse( + url: responseURL, statusCode: 400, httpVersion: "1.1", headerFields: [ @@ -112,17 +130,30 @@ class TwitterAPISessionDelegatedStreamTaskTests: XCTestCase { "x-rate-limit-remaining": "1", "x-rate-limit-reset": "1647099944", ] - ) + ) else { + XCTFail("Failed to create test response") + return + } + + let mockTask = MockTwitterAPISessionTask( + taskIdentifier: 2, + currentRequest: nil, + originalRequest: nil, + httpResponse: response ) let task = TwitterAPISessionDelegatedStreamTask(task: mockTask) DispatchQueue.main.async { - task.append( chunk: Data( - "{\"detail\":\"Authenticating with OAuth 1.0a User Context is forbidden for this endpoint. Supported authentication types are [OAuth 2.0 Application-Only].\",\"title\":\"Unsupported Authentication\",\"status\":403,\"type\":\"https://api.twitter.com/2/problems/unsupported-authentication\"}" - .utf8)) + "{\"detail\":\"Authenticating with OAuth 1.0a User Context is forbidden for this endpoint. " + + "Supported authentication types are [OAuth 2.0 Application-Only].\",\"title\":\"Unsupported " + + "Authentication\",\"status\":403,\"type\":\"https://api.twitter.com/2/problems/unsupported-" + + "authentication\"}" + .utf8 + ) + ) task.complete(error: nil) } @@ -130,36 +161,48 @@ class TwitterAPISessionDelegatedStreamTaskTests: XCTestCase { exp.expectedFulfillmentCount = 2 var count = 0 - task.streamResponse { response in - - XCTAssertTrue(Thread.isMainThread) - - XCTAssertNotNil(response.rateLimit) - XCTAssertEqual(response.rateLimit?.limit, 15) - XCTAssertEqual(response.rateLimit?.remaining, 1) - XCTAssertEqual(response.rateLimit?.reset, 1_647_099_944) - - switch count { - case 0: - XCTAssertTrue(response.error!.isResponseFailed) - default: - XCTFail() + task + .streamResponse { response in + XCTAssertTrue(Thread.isMainThread) + + guard let rateLimit = response.rateLimit else { + XCTFail("Rate limit should not be nil") + return + } + + XCTAssertEqual(rateLimit.limit, 15) + XCTAssertEqual(rateLimit.remaining, 1) + XCTAssertEqual(rateLimit.reset, 1_647_099_944) + + switch count { + case 0: + guard let error = response.error else { + XCTFail("Expected error but got nil") + return + } + XCTAssertTrue(error.isResponseFailed) + default: + XCTFail("Invalid Response") + } + + count += 1 + exp.fulfill() + } + .streamResponse(queue: .global(qos: .default)) { response in + XCTAssertFalse(Thread.isMainThread) + guard let error = response.error else { + XCTFail("Expected error but got nil") + return + } + XCTAssertTrue(error.isResponseFailed) + exp.fulfill() } - - count += 1 - exp.fulfill() - }.streamResponse(queue: .global(qos: .default)) { response in - XCTAssertFalse(Thread.isMainThread) - XCTAssertTrue(response.error!.isResponseFailed) - exp.fulfill() - } wait(for: [exp], timeout: 100) XCTAssertEqual(count, 1) } - func testNilResponse() throws { - + public func testNilResponse() throws { let mockTask = MockTwitterAPISessionTask( taskIdentifier: 1, currentRequest: nil, @@ -177,32 +220,35 @@ class TwitterAPISessionDelegatedStreamTaskTests: XCTestCase { exp.expectedFulfillmentCount = 2 var count = 0 - task.streamResponse { response in - - XCTAssertTrue(Thread.isMainThread) - - switch count { - case 0: - XCTAssertTrue(response.isError) - XCTAssertTrue(response.error!.isResponseFailed) - default: - XCTFail() + task + .streamResponse { response in + XCTAssertTrue(Thread.isMainThread) + + switch count { + case 0: + XCTAssertTrue(response.isError) + guard let error = response.error else { + XCTFail("Expected error but got nil") + return + } + XCTAssertTrue(error.isResponseFailed) + default: + XCTFail("Invalid Response") + } + + count += 1 + exp.fulfill() + } + .streamResponse(queue: .global(qos: .default)) { _ in + XCTAssertFalse(Thread.isMainThread) + exp.fulfill() } - count += 1 - exp.fulfill() - }.streamResponse(queue: .global(qos: .default)) { _ in - XCTAssertFalse(Thread.isMainThread) - exp.fulfill() - } - - wait(for: [exp], timeout: 10) + wait(for: [exp], timeout: 100) XCTAssertEqual(count, 1) - } - func testError() throws { - + public func testError() throws { let mockTask = MockTwitterAPISessionTask( taskIdentifier: 1, currentRequest: nil, @@ -220,29 +266,35 @@ class TwitterAPISessionDelegatedStreamTaskTests: XCTestCase { exp.expectedFulfillmentCount = 2 var count = 0 - task.streamResponse { response in + task + .streamResponse { response in - XCTAssertTrue(Thread.isMainThread) + XCTAssertTrue(Thread.isMainThread) - XCTAssertNil(response.rateLimit) + XCTAssertNil(response.rateLimit) - switch count { - case 0: - XCTAssertTrue(response.isError) + switch count { + case 0: + XCTAssertTrue(response.isError) - default: - XCTFail() - } + default: + XCTFail("Invalid Response") + } - count += 1 - exp.fulfill() - }.streamResponse(queue: .global(qos: .default)) { response in - XCTAssertFalse(Thread.isMainThread) - XCTAssertTrue(response.isError) - exp.fulfill() - } + count += 1 + exp.fulfill() + } + .streamResponse(queue: .global(qos: .default)) { response in + XCTAssertFalse(Thread.isMainThread) + XCTAssertTrue(response.isError) + exp.fulfill() + } wait(for: [exp], timeout: 100) XCTAssertEqual(count, 1) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/SessionTask/TwitterAPISessionSpecializedTaskTests.swift b/Tests/TwitterAPIKitTests/SessionTask/TwitterAPISessionSpecializedTaskTests.swift index 9397fadd..e90b83f6 100644 --- a/Tests/TwitterAPIKitTests/SessionTask/TwitterAPISessionSpecializedTaskTests.swift +++ b/Tests/TwitterAPIKitTests/SessionTask/TwitterAPISessionSpecializedTaskTests.swift @@ -1,40 +1,42 @@ +// TwitterAPISessionSpecializedTaskTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import XCTest @testable import TwitterAPIKit -class TwitterAPISessionSpecializedTaskTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class TwitterAPISessionSpecializedTaskTests: XCTestCase { + public func test() throws { let mockTask = MockTwitterAPISessionDataTask( data: Data("hoge".utf8), taskIdentifier: 10, currentRequest: nil, originalRequest: nil, httpResponse: nil ) let task = TwitterAPISessionSpecializedTask(task: mockTask) { data in - return String(data: data, encoding: .utf8)! + guard let str = String(data: data, encoding: .utf8) else { + XCTFail("Failed to decode UTF-8 string") + return "" + } + return str } let exp = expectation(description: "") exp.expectedFulfillmentCount = 2 - task.responseObject(queue: .main) { response in - XCTAssertEqual(response.success, "hoge") - exp.fulfill() - }.responseData { response in - XCTAssertEqual(response.success, Data("hoge".utf8)) - exp.fulfill() - } + task + .responseObject(queue: .main) { response in + XCTAssertEqual(response.success, "hoge") + exp.fulfill() + } + .responseData { response in + XCTAssertEqual(response.success, Data("hoge".utf8)) + exp.fulfill() + } wait(for: [exp], timeout: 100) } - func testArray() throws { - + public func testArray() throws { let mockTask1 = MockTwitterAPISessionDataTask( data: Data("hoge1".utf8), taskIdentifier: 10, currentRequest: nil, originalRequest: nil, httpResponse: nil ) @@ -43,11 +45,19 @@ class TwitterAPISessionSpecializedTaskTests: XCTestCase { ) let task1 = TwitterAPISessionSpecializedTask(task: mockTask1) { data in - return String(data: data, encoding: .utf8)! + guard let str = String(data: data, encoding: .utf8) else { + XCTFail("Failed to decode UTF-8 string") + return "" + } + return str } let task2 = TwitterAPISessionSpecializedTask(task: mockTask2) { data in - return String(data: data, encoding: .utf8)! + guard let str = String(data: data, encoding: .utf8) else { + XCTFail("Failed to decode UTF-8 string") + return "" + } + return str } let exp = expectation(description: "") @@ -62,4 +72,8 @@ class TwitterAPISessionSpecializedTaskTests: XCTestCase { wait(for: [exp], timeout: 100) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/TwitterAPIClientTests.swift b/Tests/TwitterAPIKitTests/TwitterAPIClientTests.swift index b823f891..80ea6e14 100644 --- a/Tests/TwitterAPIKitTests/TwitterAPIClientTests.swift +++ b/Tests/TwitterAPIKitTests/TwitterAPIClientTests.swift @@ -1,17 +1,17 @@ +// TwitterAPIClientTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class TwitterAPIClientTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { +internal class TwitterAPIClientTests: XCTestCase { + override public func tearDownWithError() throws { MockURLProtocol.cleanup() } - func testJSONDecoder() throws { - + public func testJSONDecoder() throws { let decoder = TwitterAPIClient.defaultJSONDecoder let dateV1 = try decoder.decode(Date.self, from: Data("\"Sun Jul 03 04:32:05 +0000 2022\"".utf8)) @@ -19,17 +19,22 @@ class TwitterAPIClientTests: XCTestCase { XCTAssertEqual(dateV1, dateV2) } - func testRefreshToken() throws { + public func testRefreshToken() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] let client = TwitterAPIClient( .oauth20( - .init(clientID: "c", scope: [], tokenType: "t", expiresIn: 0, accessToken: "a", refreshToken: "r")), + .init(clientID: "c", scope: [], tokenType: "t", expiresIn: 0, accessToken: "a", refreshToken: "r") + ), configuration: config ) MockURLProtocol.requestHandler = { request in + guard let url = request.url else { + throw URLError(.badURL) + } + let data = Data( #""" { @@ -39,17 +44,26 @@ class TwitterAPIClientTests: XCTestCase { "access_token" : "", "refresh_token" : "" } - """#.utf8) - return ( - HTTPURLResponse(url: request.url!, statusCode: 200, httpVersion: "2.0", headerFields: nil)!, data + """#.utf8 ) + + guard let response = HTTPURLResponse( + url: url, + statusCode: 200, + httpVersion: "2.0", + headerFields: nil + ) else { + throw URLError(.badServerResponse) + } + + return (response, data) } if case let .oauth20(token) = client.apiAuth { XCTAssertEqual(token.accessToken, "a") XCTAssertEqual(token.refreshToken, "r") } else { - XCTFail() + XCTFail("Invalid Response") } let exp = expectation(description: "") @@ -71,22 +85,26 @@ class TwitterAPIClientTests: XCTestCase { XCTAssertEqual(token.accessToken, "") XCTAssertEqual(token.refreshToken, "") } else { - XCTFail() + XCTFail("Invalid Response") } } - func testRefreshTokenForceRefresh() throws { + public func testRefreshTokenForceRefresh() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] let client = TwitterAPIClient( .oauth20( - .init(clientID: "c", scope: [], tokenType: "t", expiresIn: 1000, accessToken: "a", refreshToken: "r") + .init(clientID: "c", scope: [], tokenType: "t", expiresIn: 1_000, accessToken: "a", refreshToken: "r") ), configuration: config ) MockURLProtocol.requestHandler = { request in + guard let url = request.url else { + throw URLError(.badURL) + } + let data = Data( #""" { @@ -96,10 +114,19 @@ class TwitterAPIClientTests: XCTestCase { "access_token" : "", "refresh_token" : "" } - """#.utf8) - return ( - HTTPURLResponse(url: request.url!, statusCode: 200, httpVersion: "2.0", headerFields: nil)!, data + """#.utf8 ) + + guard let response = HTTPURLResponse( + url: url, + statusCode: 200, + httpVersion: "2.0", + headerFields: nil + ) else { + throw URLError(.badServerResponse) + } + + return (response, data) } let exp = expectation(description: "") @@ -121,10 +148,11 @@ class TwitterAPIClientTests: XCTestCase { XCTAssertEqual(token.accessToken, "") XCTAssertEqual(token.refreshToken, "") } else { - XCTFail() + XCTFail("Invalid Response") } } - func testRefreshToken_invalidAuthenticationMethod() throws { + + public func testRefreshToken_invalidAuthenticationMethod() throws { let client = TwitterAPIClient(.none) let exp = expectation(description: "") client.refreshOAuth20Token(type: .publicClient) { result in @@ -132,14 +160,14 @@ class TwitterAPIClientTests: XCTestCase { case .failure(.refreshOAuth20TokenFailed(reason: .invalidAuthenticationMethod(.none))): break default: - XCTFail() + XCTFail("Invalid Response") } exp.fulfill() } wait(for: [exp], timeout: 10) } - func testRefreshToken_refreshTokenIsMissing() throws { + public func testRefreshToken_refreshTokenIsMissing() throws { let client = TwitterAPIClient( .oauth20( .init( @@ -149,21 +177,23 @@ class TwitterAPIClientTests: XCTestCase { expiresIn: 0, accessToken: "", refreshToken: nil - ))) + ) + ) + ) let exp = expectation(description: "") client.refreshOAuth20Token(type: .publicClient) { result in switch result { case .failure(.refreshOAuth20TokenFailed(reason: .refreshTokenIsMissing)): break default: - XCTFail() + XCTFail("Invalid Response") } exp.fulfill() } wait(for: [exp], timeout: 10) } - func testRefreshTokenNotExpired() throws { + public func testRefreshTokenNotExpired() throws { let now = Date() let client = TwitterAPIClient( .oauth20( @@ -175,18 +205,20 @@ class TwitterAPIClientTests: XCTestCase { accessToken: "a", refreshToken: "r", createdAt: now - ))) + ) + ) + ) let exp = expectation(description: "") client.refreshOAuth20Token(type: .publicClient) { result in switch result { - case .success(let newToken): + case let .success(newToken): XCTAssertFalse(newToken.refreshed) XCTAssertEqual(newToken.token.clientID, "c") XCTAssertEqual(newToken.token.refreshToken, "r") XCTAssertEqual(newToken.token.createdAt, now) default: - XCTFail() + XCTFail("Invalid Response") } exp.fulfill() } @@ -196,17 +228,22 @@ class TwitterAPIClientTests: XCTestCase { #if compiler(>=5.5.2) && canImport(_Concurrency) @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) - func testRefreshTokenAsync() async throws { + public func testRefreshTokenAsync() async throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] let client = TwitterAPIClient( .oauth20( - .init(clientID: "c", scope: [], tokenType: "t", expiresIn: 0, accessToken: "a", refreshToken: "r")), + .init(clientID: "c", scope: [], tokenType: "t", expiresIn: 0, accessToken: "a", refreshToken: "r") + ), configuration: config ) MockURLProtocol.requestHandler = { request in + guard let url = request.url else { + throw URLError(.badURL) + } + let data = Data( #""" { @@ -216,10 +253,19 @@ class TwitterAPIClientTests: XCTestCase { "access_token" : "", "refresh_token" : "" } - """#.utf8) - return ( - HTTPURLResponse(url: request.url!, statusCode: 200, httpVersion: "2.0", headerFields: nil)!, data + """#.utf8 ) + + guard let response = HTTPURLResponse( + url: url, + statusCode: 200, + httpVersion: "2.0", + headerFields: nil + ) else { + throw URLError(.badServerResponse) + } + + return (response, data) } let newToken = try await client.refreshOAuth20Token(type: .publicClient) @@ -232,25 +278,29 @@ class TwitterAPIClientTests: XCTestCase { XCTAssertEqual(token.accessToken, "") XCTAssertEqual(token.refreshToken, "") } else { - XCTFail() + XCTFail("Invalid Response") } } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) - func testRefreshTokenInvalidAuthenticationMethodAsync() async throws { + public func testRefreshTokenInvalidAuthenticationMethodAsync() async throws { let client = TwitterAPIClient(.none) do { _ = try await client.refreshOAuth20Token(type: .publicClient) - XCTFail() + XCTFail("Invalid Response") } catch { switch error { case TwitterAPIKitError.refreshOAuth20TokenFailed(reason: .invalidAuthenticationMethod(.none)): break default: - XCTFail() + XCTFail("Invalid Response") } } } #endif + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/TwitterAPIErrorResponseTests.swift b/Tests/TwitterAPIKitTests/TwitterAPIErrorResponseTests.swift index cdf5a9fc..7580c2aa 100644 --- a/Tests/TwitterAPIKitTests/TwitterAPIErrorResponseTests.swift +++ b/Tests/TwitterAPIKitTests/TwitterAPIErrorResponseTests.swift @@ -1,24 +1,21 @@ +// TwitterAPIErrorResponseTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class TwitterAPIErrorResponseTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func testTwitterAPIErrorResponseV1() throws { - +internal class TwitterAPIErrorResponseTests: XCTestCase { + public func testTwitterAPIErrorResponseV1() throws { XCTContext.runActivity(named: "") { _ in - let v1 = TwitterAPIErrorResponseV1(message: "_message_", code: 100, errors: []) - XCTAssertEqual(v1.message, "_message_") - XCTAssertEqual(v1.code, 100) - XCTAssertEqual(v1.errors, [TwitterAPIErrorResponseV1]()) - XCTAssertTrue(v1.contains(code: 100)) - XCTAssertFalse(v1.contains(code: 1)) + let v1Response = TwitterAPIErrorResponseV1(message: "_message_", code: 100, errors: []) + XCTAssertEqual(v1Response.message, "_message_") + XCTAssertEqual(v1Response.code, 100) + XCTAssertEqual(v1Response.errors, [TwitterAPIErrorResponseV1]()) + XCTAssertTrue(v1Response.contains(code: 100)) + XCTAssertFalse(v1Response.contains(code: 1)) } XCTContext.runActivity(named: "from obj") { _ in @@ -33,30 +30,36 @@ class TwitterAPIErrorResponseTests: XCTestCase { "message": "message2", "code": 2, ], - ] - + ], ] - let v1 = TwitterAPIErrorResponseV1(obj: obj)! - XCTAssertEqual(v1.message, "message1") - XCTAssertEqual(v1.code, 1) + guard let v1Response = TwitterAPIErrorResponseV1(obj: obj) else { + return XCTFail("Failed to parse response") + } + + XCTAssertEqual(v1Response.message, "message1") + XCTAssertEqual(v1Response.code, 1) XCTAssertEqual( - v1.errors, + v1Response.errors, [ .init(message: "message1", code: 1, errors: []), .init(message: "message2", code: 2, errors: []), - ]) - XCTAssertTrue(v1.contains(code: 1)) - XCTAssertFalse(v1.contains(code: 100)) + ] + ) + XCTAssertTrue(v1Response.contains(code: 1)) + XCTAssertFalse(v1Response.contains(code: 100)) XCTAssertEqual( - v1, + v1Response, .init( - message: "message1", code: 1, + message: "message1", + code: 1, errors: [ .init(message: "message1", code: 1, errors: []), .init(message: "message2", code: 2, errors: []), - ])) + ] + ) + ) } XCTContext.runActivity(named: "Invalid") { _ in @@ -64,15 +67,14 @@ class TwitterAPIErrorResponseTests: XCTestCase { } } - func testTwitterAPIErrorResponseV2() throws { - + public func testTwitterAPIErrorResponseV2() throws { XCTContext.runActivity(named: "") { _ in - let v2 = TwitterAPIErrorResponseV2(title: "t", detail: "d", type: "ty", errors: []) - XCTAssertEqual(v2.title, "t") - XCTAssertEqual(v2.detail, "d") - XCTAssertEqual(v2.type, "ty") - XCTAssertEqual(v2.errors, []) + let v2Response = TwitterAPIErrorResponseV2(title: "t", detail: "d", type: "ty", errors: []) + XCTAssertEqual(v2Response.title, "t") + XCTAssertEqual(v2Response.detail, "d") + XCTAssertEqual(v2Response.type, "ty") + XCTAssertEqual(v2Response.errors, []) } XCTContext.runActivity(named: "from obj") { _ in @@ -81,22 +83,29 @@ class TwitterAPIErrorResponseTests: XCTestCase { "detail": "_detail_", "type": "_type_", "errors": [ - ["message": "_message_", "parameters": ["param": ["b"]]] + ["message": "_message_", "parameters": ["param": ["b"]]], ], ] - let v2 = TwitterAPIErrorResponseV2(obj: obj)! - XCTAssertEqual(v2.title, "_title_") - XCTAssertEqual(v2.detail, "_detail_") - XCTAssertEqual(v2.type, "_type_") - XCTAssertEqual(v2.errors.first?.message, "_message_") - XCTAssertEqual(v2.errors.first?.parameters["param"], ["b"]) + guard let v2Response = TwitterAPIErrorResponseV2(obj: obj) else { + return XCTFail("Failed to parse response") + } + + XCTAssertEqual(v2Response.title, "_title_") + XCTAssertEqual(v2Response.detail, "_detail_") + XCTAssertEqual(v2Response.type, "_type_") + XCTAssertEqual(v2Response.errors.first?.message, "_message_") + XCTAssertEqual(v2Response.errors.first?.parameters["param"], ["b"]) XCTAssertEqual( - v2, + v2Response, TwitterAPIErrorResponseV2( - title: "_title_", detail: "_detail_", type: "_type_", - errors: [.init(message: "_message_", parameters: ["param": ["b"]])])) + title: "_title_", + detail: "_detail_", + type: "_type_", + errors: [.init(message: "_message_", parameters: ["param": ["b"]])] + ) + ) } XCTContext.runActivity(named: "Invalid") { _ in @@ -104,8 +113,7 @@ class TwitterAPIErrorResponseTests: XCTestCase { } } - func testTwitterAPIErrorResponse() throws { - + public func testTwitterAPIErrorResponse() throws { try XCTContext.runActivity(named: "V1") { _ in let obj: [String: Any] = [ "errors": [ @@ -117,7 +125,7 @@ class TwitterAPIErrorResponseTests: XCTestCase { "message": "message2", "code": 2, ], - ] + ], ] let data = try JSONSerialization.data(withJSONObject: obj, options: []) @@ -142,7 +150,7 @@ class TwitterAPIErrorResponseTests: XCTestCase { "detail": "_detail_", "type": "_type_", "errors": [ - ["message": "_message_", "parameters": ["param": ["b"]]] + ["message": "_message_", "parameters": ["param": ["b"]]], ], ] @@ -173,7 +181,7 @@ class TwitterAPIErrorResponseTests: XCTestCase { } XCTContext.runActivity(named: "invalid") { _ in - let data = "{}".data(using: .utf8)! + let data = Data("{}") let error = TwitterAPIErrorResponse(data: data) XCTAssertEqual(error, .unknown(data)) XCTAssertTrue(error.isUnknown) @@ -182,4 +190,8 @@ class TwitterAPIErrorResponseTests: XCTestCase { } } } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/TwitterAPIKitErrorTests.swift b/Tests/TwitterAPIKitTests/TwitterAPIKitErrorTests.swift index 0b2b38ff..3cb83034 100644 --- a/Tests/TwitterAPIKitTests/TwitterAPIKitErrorTests.swift +++ b/Tests/TwitterAPIKitTests/TwitterAPIKitErrorTests.swift @@ -1,15 +1,13 @@ +// TwitterAPIKitErrorTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class TwitterAPIKitErrorTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func testInit() throws { +internal class TwitterAPIKitErrorTests: XCTestCase { + public func testInit() throws { XCTContext.runActivity(named: "unknown") { _ in let error = TwitterAPIKitError(error: NSError(domain: "", code: 0, userInfo: nil)) @@ -24,49 +22,63 @@ class TwitterAPIKitErrorTests: XCTestCase { } } - func testRequestFailed() throws { + public func testRequestFailed() throws { XCTAssertTrue(TwitterAPIKitError.requestFailed(reason: .invalidURL(url: "")).isRequestFailed) XCTAssertTrue( - TwitterAPIKitError.requestFailed(reason: .invalidParameter(parameter: [:], cause: "hoge")).isRequestFailed) + TwitterAPIKitError.requestFailed(reason: .invalidParameter(parameter: [:], cause: "hoge")).isRequestFailed + ) XCTAssertTrue(TwitterAPIKitError.requestFailed(reason: .cannotEncodeStringToData(string: "")).isRequestFailed) XCTAssertTrue( TwitterAPIKitError.requestFailed( reason: .jsonSerializationFailed(obj: [:]) - ).isRequestFailed) + ).isRequestFailed + ) } - func testResponseFailed() throws { + public func testResponseFailed() throws { XCTAssertTrue(TwitterAPIKitError.responseFailed(reason: .invalidResponse(error: nil)).isResponseFailed) XCTAssertTrue( TwitterAPIKitError.responseFailed( reason: .unacceptableStatusCode(statusCode: 200, error: .unknown(Data()), rateLimit: .init(header: [:])) - ).isResponseFailed) + ).isResponseFailed + ) } - func testResponseSerializationFailure() throws { + public func testResponseSerializationFailure() throws { XCTAssertTrue( TwitterAPIKitError.responseSerializeFailed( reason: .jsonSerializationFailed(error: NSError(domain: "", code: 0, userInfo: nil)) - ).isResponseSerializeFailed) + ).isResponseSerializeFailed + ) XCTAssertTrue( TwitterAPIKitError.responseSerializeFailed( reason: .jsonDecodeFailed( error: DecodingError.typeMismatch( - Any.self, .init(codingPath: [], debugDescription: "", underlyingError: nil))) - ).isResponseSerializeFailed) + Any.self, .init(codingPath: [], debugDescription: "", underlyingError: nil) + ) + ) + ).isResponseSerializeFailed + ) XCTAssertTrue( - TwitterAPIKitError.responseSerializeFailed(reason: .cannotConvert(data: Data(), toTypeName: "")) - .isResponseSerializeFailed) + TwitterAPIKitError.responseSerializeFailed( + reason: .cannotConvert(data: Data(), toTypeName: "") + ).isResponseSerializeFailed + ) } - func testUploadMediaFailure() throws { + public func testUploadMediaFailure() throws { XCTAssertTrue( TwitterAPIKitError.uploadMediaFailed( reason: .processingFailed(error: .init(code: 1, name: "n", message: "m")) - ).isUploadMediaFailed) + ).isUploadMediaFailed + ) } - func testUnknown() throws { + public func testUnknown() throws { XCTAssertTrue(TwitterAPIKitError.unkonwn(error: NSError(domain: "", code: 0, userInfo: nil)).isUnkonwn) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/TwitterAPIKitTests.swift b/Tests/TwitterAPIKitTests/TwitterAPIKitTests.swift index d09b1608..51fd3079 100644 --- a/Tests/TwitterAPIKitTests/TwitterAPIKitTests.swift +++ b/Tests/TwitterAPIKitTests/TwitterAPIKitTests.swift @@ -1,7 +1,15 @@ +// TwitterAPIKitTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -final class TwitterAPIKitTests: XCTestCase { - func testExample() throws { +internal final class TwitterAPIKitTests: XCTestCase { + public func testExample() throws {} + + deinit { + // De-init Logic Here } } diff --git a/Tests/TwitterAPIKitTests/TwitterAPIRequestTests.swift b/Tests/TwitterAPIKitTests/TwitterAPIRequestTests.swift index 1af35f93..9e882b89 100644 --- a/Tests/TwitterAPIKitTests/TwitterAPIRequestTests.swift +++ b/Tests/TwitterAPIKitTests/TwitterAPIRequestTests.swift @@ -1,9 +1,13 @@ +// TwitterAPIRequestTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import XCTest @testable import TwitterAPIKit -class TwitterAPIRequestTests: XCTestCase { - +internal class TwitterAPIRequestTests: XCTestCase { private struct MockTwitterAPIRequest: TwitterAPIRequest { var method: HTTPMethod = .get var path: String = "/mock" @@ -21,19 +25,23 @@ class TwitterAPIRequestTests: XCTestCase { var bodyContentType: BodyContentType = .wwwFormUrlEncoded } - private let env = TwitterAPIEnvironment( - apiURL: .init(string: "https://api.example.com")!, - uploadURL: .init(string: "https://upload.example.com")! - ) + private var env: TwitterAPIEnvironment - override func setUpWithError() throws { - } + override public init() { + let apiUrl = URL(string: "https://api.example.com") + let uploadUrl = URL(string: "https://upload.example.com") - override func tearDownWithError() throws { - } + guard let apiUrl, let uploadUrl else { + XCTFail("apiUrl / uploadUrl isn't valid") + } - func testRequestURL() throws { + env = .init( + apiURL: apiUrl, + uploadURL: uploadUrl + ) + } + public func testRequestURL() throws { XCTContext.runActivity(named: "api") { _ in let req = MockTwitterAPIRequest(parameters: ["key": "value"], baseURLType: .api) XCTAssertEqual(req.requestURL(for: env).absoluteString, "https://api.example.com/mock") @@ -45,26 +53,24 @@ class TwitterAPIRequestTests: XCTestCase { } } - func testParameterForOAuth() throws { - + public func testParameterForOAuth() throws { XCTContext.runActivity(named: "wwwFormUrlEncoded") { _ in let req = MockTwitterAPIRequest(parameters: ["key": "value"], bodyContentType: .wwwFormUrlEncoded) - XCTAssertEqual(req.parameterForOAuth as! [String: String], ["key": "value"]) + XCTAssertEqual(req.parameterForOAuth as? [String: String], ["key": "value"]) } XCTContext.runActivity(named: "json") { _ in let req = MockTwitterAPIRequest(parameters: ["key": "value"], bodyContentType: .json) - XCTAssertEqual(req.parameterForOAuth as! [String: String], [:]) + XCTAssertEqual(req.parameterForOAuth as? [String: String], [:]) } XCTContext.runActivity(named: "multipartFormData") { _ in let req = MockTwitterAPIRequest(parameters: ["key": "value"], bodyContentType: .multipartFormData) - XCTAssertEqual(req.parameterForOAuth as! [String: String], [:]) + XCTAssertEqual(req.parameterForOAuth as? [String: String], [:]) } } - func testParameterByMethods() throws { - + public func testParameterByMethods() throws { // 🥓 = F0 9F A5 93 try XCTContext.runActivity(named: "GET") { _ in @@ -73,8 +79,8 @@ class TwitterAPIRequestTests: XCTestCase { parameters: ["key": "value,🥓"] ) - XCTAssertEqual(req.queryParameters as! [String: String], ["key": "value,🥓"]) - XCTAssertEqual(req.bodyParameters as! [String: String], [:]) + XCTAssertEqual(req.queryParameters as? [String: String], ["key": "value,🥓"]) + XCTAssertEqual(req.bodyParameters as? [String: String], [:]) let urlReq = try req.buildRequest(environment: env) @@ -89,14 +95,16 @@ class TwitterAPIRequestTests: XCTestCase { parameters: ["key": "value,🥓"] ) - XCTAssertEqual(req.queryParameters as! [String: String], [:]) - XCTAssertEqual(req.bodyParameters as! [String: String], ["key": "value,🥓"]) + XCTAssertEqual(req.queryParameters as? [String: String], [:]) + XCTAssertEqual(req.bodyParameters as? [String: String], ["key": "value,🥓"]) let urlReq = try req.buildRequest(environment: env) XCTAssertEqual(urlReq.httpMethod, "POST") XCTAssertNil(urlReq.url?.query) - XCTAssertEqual(String(data: urlReq.httpBody!, encoding: .utf8)!, "key=value%2C%F0%9F%A5%93") + let httpBody = try XCTUnwrap(urlReq.httpBody) + let bodyString = try XCTUnwrap(String(data: httpBody, encoding: .utf8)) + XCTAssertEqual(bodyString, "key=value%2C%F0%9F%A5%93") } try XCTContext.runActivity(named: "PUT") { _ in @@ -105,14 +113,16 @@ class TwitterAPIRequestTests: XCTestCase { parameters: ["key": "value,🥓"] ) - XCTAssertEqual(req.queryParameters as! [String: String], [:]) - XCTAssertEqual(req.bodyParameters as! [String: String], ["key": "value,🥓"]) + XCTAssertEqual(req.queryParameters as? [String: String], [:]) + XCTAssertEqual(req.bodyParameters as? [String: String], ["key": "value,🥓"]) let urlReq = try req.buildRequest(environment: env) XCTAssertEqual(urlReq.httpMethod, "PUT") XCTAssertNil(urlReq.url?.query) - XCTAssertEqual(String(data: urlReq.httpBody!, encoding: .utf8)!, "key=value%2C%F0%9F%A5%93") + let httpBody = try XCTUnwrap(urlReq.httpBody) + let bodyString = try XCTUnwrap(String(data: httpBody, encoding: .utf8)) + XCTAssertEqual(bodyString, "key=value%2C%F0%9F%A5%93") } try XCTContext.runActivity(named: "DELETE") { _ in @@ -121,8 +131,8 @@ class TwitterAPIRequestTests: XCTestCase { parameters: ["key": "value,🥓"] ) - XCTAssertEqual(req.queryParameters as! [String: String], ["key": "value,🥓"]) - XCTAssertEqual(req.bodyParameters as! [String: String], [:]) + XCTAssertEqual(req.queryParameters as? [String: String], ["key": "value,🥓"]) + XCTAssertEqual(req.bodyParameters as? [String: String], [:]) let urlReq = try req.buildRequest(environment: env) @@ -132,8 +142,7 @@ class TwitterAPIRequestTests: XCTestCase { } } - func testURLQueryPercentEncode() throws { - + public func testURLQueryPercentEncode() throws { let req = MockTwitterAPIRequest( method: .get, parameters: [ @@ -150,78 +159,111 @@ class TwitterAPIRequestTests: XCTestCase { ) } - func testBodyAndQueryParameter() throws { + public func testBodyAndQueryParameter() throws { let req = MockTwitterAPIQueryAndBodyRequest( method: .post, queryParameters: ["key": "value,🥓"], bodyParameters: ["body": "あ"] ) - XCTAssertEqual(req.parameters as! [String: String], [:]) - XCTAssertEqual(req.queryParameters as! [String: String], ["key": "value,🥓"]) - XCTAssertEqual(req.bodyParameters as! [String: String], ["body": "あ"]) + XCTAssertEqual(req.parameters as? [String: String], [:]) + XCTAssertEqual(req.queryParameters as? [String: String], ["key": "value,🥓"]) + XCTAssertEqual(req.bodyParameters as? [String: String], ["body": "あ"]) let urlReq = try req.buildRequest(environment: env) XCTAssertEqual(urlReq.httpMethod, "POST") XCTAssertEqual(urlReq.url?.query, "key=value%2C%F0%9F%A5%93") - XCTAssertEqual(String(data: urlReq.httpBody!, encoding: .utf8)!, "body=%E3%81%82") + let httpBody = try XCTUnwrap(urlReq.httpBody) + let bodyString = try XCTUnwrap(String(data: httpBody, encoding: .utf8)) + XCTAssertEqual(bodyString, "body=%E3%81%82") } - func testBodyContentType() throws { + public func testBodyContentType() throws { + try testWWWFormUrlEncoded() + try testMultipartFormData() + try testJSON() + } + public func testWWWFormUrlEncoded() throws { try XCTContext.runActivity(named: "wwwFormUrlEncoded") { _ in - let req = try MockTwitterAPIRequest( method: .post, parameters: ["key": "value,🥓"], bodyContentType: .wwwFormUrlEncoded ).buildRequest(environment: env) - let body = String(data: req.httpBody!, encoding: .utf8) - + let httpBody = try XCTUnwrap(req.httpBody) + let body = try XCTUnwrap(String(data: httpBody, encoding: .utf8)) XCTAssertEqual(body, "key=value%2C%F0%9F%A5%93") } + } + public func testMultipartFormData() throws { try XCTContext.runActivity(named: "multipartFormData") { _ in - let req = try MockTwitterAPIRequest( method: .post, parameters: [ "a-value": MultipartFormDataPart.value(name: "a", value: "value"), "b-data": MultipartFormDataPart.data( - name: "b", value: Data("ab".utf8), filename: "hoge.txt", mimeType: "plain/text"), + name: "b", + value: Data("ab".utf8), + filename: "hoge.txt", + mimeType: "plain/text" + ), ], bodyContentType: .multipartFormData ).buildRequest(environment: env) - XCTAssertTrue( - req.allHTTPHeaderFields!["Content-Type"]!.hasPrefix("multipart/form-data; boundary=TwitterAPIKit-")) - - let boundary = req.allHTTPHeaderFields!["Content-Type"]!.replacingOccurrences( - of: "multipart/form-data; boundary=", with: "") + guard let contentType = req.allHTTPHeaderFields?["Content-Type"] else { + XCTFail("Content-Type header not found") + return + } + XCTAssertTrue(contentType.hasPrefix("multipart/form-data; boundary=TwitterAPIKit-")) - let body = String(data: req.httpBody!, encoding: .utf8)! + let boundary = contentType.replacingOccurrences( + of: "multipart/form-data; boundary=", with: "" + ) + + guard let httpBody = req.httpBody, + let body = String(data: httpBody, encoding: .utf8) else { + XCTFail("Failed to get HTTP body or decode as UTF-8") + return + } - let expect = - "--\(boundary)\r\nContent-Disposition: form-data; name=\"a\"\r\n\r\nvalue\r\n--\(boundary)\r\nContent-Disposition: form-data; name=\"b\"; filename=\"hoge.txt\"\r\nContent-Type: plain/text\r\n\r\nab\r\n--\(boundary)--\r\n" + let expect = """ + --\(boundary)\r\n + Content-Disposition: form-data; name="a"\r\n + \r\n + value\r\n + --\(boundary)\r\n + Content-Disposition: form-data; name="b"; filename="hoge.txt"\r\n + Content-Type: plain/text\r\n + \r\n + ab\r\n + --\(boundary)--\r\n + """ XCTAssertEqual(body, expect) + try testInvalidMultipartFormData() + } + } - try XCTContext.runActivity(named: "Invalid parameter") { _ in - - XCTAssertThrowsError( - try MockTwitterAPIRequest( - method: .post, - parameters: ["key": "value,🥓"], - bodyContentType: .multipartFormData - ).buildRequest(environment: env) - ) { error in - XCTAssertTrue(error is TwitterAPIKitError) - } + public func testInvalidMultipartFormData() throws { + try XCTContext.runActivity(named: "Invalid parameter") { _ in + XCTAssertThrowsError( + try MockTwitterAPIRequest( + method: .post, + parameters: ["key": "value,🥓"], + bodyContentType: .multipartFormData + ).buildRequest(environment: env) + ) { error in + XCTAssertTrue(error is TwitterAPIKitError) } } + } + public func testJSON() throws { try XCTContext.runActivity(named: "json") { _ in let req = try MockTwitterAPIRequest( method: .post, @@ -229,52 +271,64 @@ class TwitterAPIRequestTests: XCTestCase { bodyContentType: .json ).buildRequest(environment: env) - let body = try JSONSerialization.jsonObject(with: req.httpBody!, options: []) - - XCTAssertEqual(body as! [String: String], ["key": "value,🥓"]) - - try XCTContext.runActivity( - named: "Invalid", - block: { _ in - XCTAssertThrowsError( - try MockTwitterAPIRequest( - method: .post, - parameters: ["key": Data()], - bodyContentType: .json - ).buildRequest(environment: env) - ) { error in - if case .jsonSerializationFailed(obj: _) = (error as! TwitterAPIKitError).requestFailureReason { - - } else { - XCTFail() - } - } - } - ) + let httpBody = try XCTUnwrap(req.httpBody) + let body = try JSONSerialization.jsonObject(with: httpBody, options: []) + XCTAssertEqual(body as? [String: String], ["key": "value,🥓"]) + + try testInvalidJSON() + try testInvalidJSONValue() + } + } - try XCTContext.runActivity( - named: "Invalid value", - block: { _ in - XCTAssertThrowsError( - try MockTwitterAPIRequest( - method: .post, - parameters: [ - String(bytes: [0xD8, 0x00] as [UInt8], encoding: String.Encoding.utf16BigEndian)!: - String(bytes: [0xD8, 0x00] as [UInt8], encoding: String.Encoding.utf16BigEndian)! - ], - bodyContentType: .json - ).buildRequest(environment: env) - ) { error in - - if case .jsonSerializationFailed(obj: _) = (error as! TwitterAPIKitError).requestFailureReason { - - } else { - XCTFail() - } - } + public func testInvalidJSON() throws { + try XCTContext.runActivity(named: "Invalid") { _ in + XCTAssertThrowsError( + try MockTwitterAPIRequest( + method: .post, + parameters: ["key": Data()], + bodyContentType: .json + ).buildRequest(environment: env) + ) { error in + if + let error = error as? TwitterAPIKitError, + case .jsonSerializationFailed = error.requestFailureReason + { + } else { + XCTFail("Unknown Error") } - ) + } + } + } + public func testInvalidJSONValue() throws { + try XCTContext.runActivity(named: "Invalid value") { _ in + // Create invalid UTF-16 string bytes + let invalidBytes: [UInt8] = [0xD8, 0x00] + + guard let invalidString = String(bytes: invalidBytes, encoding: .utf16BigEndian) else { + XCTFail("Failed to create test string") + return + } + + XCTAssertThrowsError( + try MockTwitterAPIRequest( + method: .post, + parameters: [invalidString: invalidString], + bodyContentType: .json + ).buildRequest(environment: env) + ) { error in + if + let error = error as? TwitterAPIKitError, + case .jsonSerializationFailed = error.requestFailureReason + { + } else { + XCTFail("Unknown Error") + } + } } } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/TwitterAPIResponseTests.swift b/Tests/TwitterAPIKitTests/TwitterAPIResponseTests.swift index f29d0bd8..256e1d42 100644 --- a/Tests/TwitterAPIKitTests/TwitterAPIResponseTests.swift +++ b/Tests/TwitterAPIKitTests/TwitterAPIResponseTests.swift @@ -1,23 +1,22 @@ +// TwitterAPIResponseTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class TwitterAPIResponseTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class TwitterAPIResponseTests: XCTestCase { + public func test() throws { let rateLimit = TwitterRateLimit(header: [ "x-rate-limit-limit": "10", "x-rate-limit-remaining": "1", "x-rate-limit-reset": "10000", ]) let data = Data("{}".utf8) - let url = URL(string: "https://example.com")! + guard let url = URL(string: "https://example.com") else { + XCTFail("Failed to decode url Response") + } let response: TwitterAPIResponse = TwitterAPIResponse( request: .init(url: url), @@ -36,17 +35,17 @@ class TwitterAPIResponseTests: XCTestCase { XCTAssertTrue(response.prettyString.hasPrefix("-- Request success --")) XCTContext.runActivity(named: "map") { _ in - let mapped = response.map { data in - return try! JSONSerialization.jsonObject(with: data, options: []) + let mapped = response.compactMap { data in + try? JSONSerialization.jsonObject(with: data, options: []) } - XCTAssertEqual(mapped.success as! [String: String], [:]) + XCTAssertEqual(mapped.success as? [String: String], [:]) } XCTContext.runActivity(named: "tryMap") { _ in let mapped = response.tryMap { data in - return try JSONSerialization.jsonObject(with: data, options: []) + try JSONSerialization.jsonObject(with: data, options: []) } - XCTAssertEqual(mapped.success as! [String: String], [:]) + XCTAssertEqual(mapped.success as? [String: String], [:]) } XCTContext.runActivity(named: "tryMapWithError") { _ in @@ -54,15 +53,15 @@ class TwitterAPIResponseTests: XCTestCase { throw NSError(domain: "", code: 0, userInfo: nil) } XCTAssertTrue(mapped.isError) - XCTAssertTrue(mapped.error!.isUnkonwn) + XCTAssertTrue(mapped.error.isMockURLProtocolUnkonwn) XCTAssertTrue(mapped.prettyString.hasPrefix("-- Request failure --")) XCTContext.runActivity(named: "mapError") { _ in - let errored = mapped.mapError { error in - return .responseFailed(reason: .invalidResponse(error: nil)) + let errored = mapped.mapError { _ in + .responseFailed(reason: .invalidResponse(error: nil)) } - XCTAssertTrue(errored.error!.isResponseFailed) + XCTAssertTrue(errored.error.isResponseFailed) } } @@ -75,4 +74,8 @@ class TwitterAPIResponseTests: XCTestCase { XCTAssertNotNil(mapped.success) } } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/TwitterAPISessionTests.swift b/Tests/TwitterAPIKitTests/TwitterAPISessionTests.swift index a1f9493e..669423d4 100644 --- a/Tests/TwitterAPIKitTests/TwitterAPISessionTests.swift +++ b/Tests/TwitterAPIKitTests/TwitterAPISessionTests.swift @@ -1,3 +1,8 @@ +// TwitterAPISessionTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import XCTest @testable import TwitterAPIKit @@ -6,7 +11,11 @@ private class GetTwitterReqeust: TwitterAPIRequest { var method: HTTPMethod { return .get } var path: String { return "/get.json" } var parameters: [String: Any] { - return ["hoge": "😀"] //= %F0%9F%98%80 + return ["hoge": "😀"] // = %F0%9F%98%80 + } + + deinit { + // De-init Logic Here } } @@ -14,7 +23,11 @@ private class PostTwitterReqeust: TwitterAPIRequest { var method: HTTPMethod { return .post } var path: String { return "/post.json" } var parameters: [String: Any] { - return ["hoge": "😀"] //= %F0%9F%98%80 + return ["hoge": "😀"] // = %F0%9F%98%80 + } + + deinit { + // De-init Logic Here } } @@ -24,38 +37,42 @@ private class EmptyRequest: TwitterAPIRequest { var parameters: [String: Any] { return [:] } -} - -class TwitterAPISessionTests: XCTestCase { - - private let environment = TwitterAPIEnvironment( - twitterURL: URL(string: "https://twitter.example.com")!, - apiURL: URL(string: "https://api.example.com")!, - uploadURL: URL(string: "https://upload.example.com")! - ) - lazy var session: TwitterAPISession = - ({ + deinit { + // De-init Logic Here + } +} - let config = URLSessionConfiguration.default - config.protocolClasses = [MockURLProtocol.self] +internal class TwitterAPISessionTests: XCTestCase { + private let environment: TwitterAPIEnvironment = { + guard let twitterURL = URL(string: "https://twitter.example.com"), + let apiURL = URL(string: "https://api.example.com"), + let uploadURL = URL(string: "https://upload.xample.com") else { + fatalError("Invalid test URLs") + } + return TwitterAPIEnvironment( + twitterURL: twitterURL, + apiURL: apiURL, + uploadURL: uploadURL + ) + }() - return TwitterAPISession( - auth: .oauth10a(.init(consumerKey: "", consumerSecret: "", oauthToken: "", oauthTokenSecret: "")), - configuration: config, - environment: environment - ) - })() + private lazy var session: TwitterAPISession = { + let config = URLSessionConfiguration.default + config.protocolClasses = [MockURLProtocol.self] - override func setUpWithError() throws { - } + return TwitterAPISession( + auth: .oauth10a(.init(consumerKey: "", consumerSecret: "", oauthToken: "", oauthTokenSecret: "")), + configuration: config, + environment: environment + ) + }() - override func tearDownWithError() throws { + override public func tearDownWithError() throws { MockURLProtocol.cleanup() } - func testGET() throws { - + public func testGET() throws { MockURLProtocol.requestAssert = { request in XCTAssertEqual(request.httpMethod, "GET") XCTAssertEqual(request.url?.absoluteString, "https://api.example.com/get.json?hoge=%F0%9F%98%80") @@ -69,14 +86,27 @@ class TwitterAPISessionTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testPOST() throws { + public func testPOST() throws { MockURLProtocol.requestAssert = { request in XCTAssertEqual(request.httpMethod, "POST") XCTAssertEqual(request.url?.absoluteString, "https://api.example.com/post.json") XCTAssertNil(request.httpBody) - let data = try! Data(reading: request.httpBodyStream!) - let body = String(data: data, encoding: .utf8)! - XCTAssertEqual(body, "hoge=%F0%9F%98%80") + + guard let bodyStream = request.httpBodyStream else { + XCTFail("HTTP body stream is nil") + return + } + + do { + let data = try Data(reading: bodyStream) + guard let body = String(data: data, encoding: .utf8) else { + XCTFail("Failed to decode body data as UTF-8") + return + } + XCTAssertEqual(body, "hoge=%F0%9F%98%80") + } catch { + XCTFail("Failed to read HTTP body stream: \(error)") + } } let exp = expectation(description: "") @@ -86,7 +116,7 @@ class TwitterAPISessionTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testEmpty() throws { + public func testEmpty() throws { MockURLProtocol.requestAssert = { request in XCTAssertEqual(request.httpMethod, "GET") XCTAssertEqual(request.url?.absoluteString, "https://api.example.com/empty.json") @@ -100,8 +130,7 @@ class TwitterAPISessionTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testStream() throws { - + public func testStream() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] @@ -112,12 +141,21 @@ class TwitterAPISessionTests: XCTestCase { ) MockURLProtocol.requestHandler = { request in + guard let url = request.url else { + throw URLError(.badURL) + } + + let data = Data("aaaa\r\nbbbb\r\n".utf8) + guard let response = HTTPURLResponse( + url: url, + statusCode: 200, + httpVersion: "2.0", + headerFields: nil + ) else { + throw URLError(.badServerResponse) + } - let data = "aaaa\r\nbbbb\r\n".data(using: .utf8)! - - return ( - HTTPURLResponse(url: request.url!, statusCode: 200, httpVersion: "2.0", headerFields: nil)!, data - ) + return (response, data) } MockURLProtocol.requestAssert = { request in @@ -127,9 +165,10 @@ class TwitterAPISessionTests: XCTestCase { let exp = expectation(description: "") exp.expectedFulfillmentCount = 4 session.send(streamRequest: GetTwitterReqeust()) - .streamResponse(queue: .global(qos: .default)) { response in + .streamResponse(queue: .global(qos: .default)) { _ in exp.fulfill() - }.streamResponse { response in + } + .streamResponse { _ in XCTAssertTrue(Thread.isMainThread) exp.fulfill() } @@ -138,7 +177,7 @@ class TwitterAPISessionTests: XCTestCase { // MARK: - Auth - func testBasicAuth() throws { + public func testBasicAuth() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] @@ -159,7 +198,7 @@ class TwitterAPISessionTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testBearerAuth() throws { + public func testBearerAuth() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] @@ -180,7 +219,7 @@ class TwitterAPISessionTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testNoneAuth() throws { + public func testNoneAuth() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] @@ -201,7 +240,7 @@ class TwitterAPISessionTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testOAuth10aAuth() throws { + public func testOAuth10aAuth() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] let session = TwitterAPISession( @@ -221,7 +260,7 @@ class TwitterAPISessionTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testOAuth20() throws { + public func testOAuth20() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] let session = TwitterAPISession( @@ -250,7 +289,7 @@ class TwitterAPISessionTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testRequestOAuth20WithPKCEConfidentialClient() throws { + public func testRequestOAuth20WithPKCEConfidentialClient() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] let session = TwitterAPISession( @@ -270,7 +309,7 @@ class TwitterAPISessionTests: XCTestCase { wait(for: [exp], timeout: 10) } - func testRequestOAuth20WithPKCEPublicClient() throws { + public func testRequestOAuth20WithPKCEPublicClient() throws { let config = URLSessionConfiguration.default config.protocolClasses = [MockURLProtocol.self] let session = TwitterAPISession( @@ -289,9 +328,16 @@ class TwitterAPISessionTests: XCTestCase { } wait(for: [exp], timeout: 10) } + + deinit { + // De-init Logic Here + } } -extension Data { +public extension Data { + /// Initialize a Data object by reading from an InputStream. + /// - Parameter input: The InputStream to read from. + /// - Throws: An error if the InputStream is nil or an error occurs while reading. init(reading input: InputStream) throws { self.init() input.open() @@ -299,7 +345,7 @@ extension Data { input.close() } - let bufferSize = 1024 + let bufferSize = 1_024 let buffer = UnsafeMutablePointer.allocate(capacity: bufferSize) defer { buffer.deallocate() @@ -307,13 +353,13 @@ extension Data { while input.hasBytesAvailable { let read = input.read(buffer, maxLength: bufferSize) if read < 0 { - //Stream error occured - throw input.streamError! + // Stream error occured + throw input.streamError ?? URLError(.unknown) } else if read == 0 { - //EOF + // EOF break } - self.append(buffer, count: read) + append(buffer, count: read) } } } diff --git a/Tests/TwitterAPIKitTests/TwitterAuthenticationMethodTests.swift b/Tests/TwitterAPIKitTests/TwitterAuthenticationMethodTests.swift index 1dcf6559..19cbf4e8 100644 --- a/Tests/TwitterAPIKitTests/TwitterAuthenticationMethodTests.swift +++ b/Tests/TwitterAPIKitTests/TwitterAuthenticationMethodTests.swift @@ -1,18 +1,15 @@ +// TwitterAuthenticationMethodTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -final class TwitterAuthenticationMethodTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - +internal final class TwitterAuthenticationMethodTests: XCTestCase { // MARK: - OAuth10a - func testOAuth10aInit() throws { - + public func testOAuth10aInit() throws { let oauth10 = TwitterAuthenticationMethod.OAuth10a( consumerKey: "ck", consumerSecret: "cs", @@ -24,13 +21,11 @@ final class TwitterAuthenticationMethodTests: XCTestCase { XCTAssertEqual(oauth10.consumerSecret, "cs") XCTAssertEqual(oauth10.oauthToken, "t") XCTAssertEqual(oauth10.oauthTokenSecret, "ts") - } // MARK: - OAuth20 - func testOAuth20Init() throws { - + public func testOAuth20Init() throws { do { let createdAt = Date(timeIntervalSince1970: 2) @@ -64,8 +59,11 @@ final class TwitterAuthenticationMethodTests: XCTestCase { "expires_in" : 7200, "access_token" : "" } - """.utf8) - let token = try TwitterOAuth2AccessToken(jsonData: tokenJSON)! + """.utf8 + ) + guard let token = try TwitterOAuth2AccessToken(jsonData: tokenJSON) else { + XCTFail("Failed to decode token Response") + } let oauth20 = TwitterAuthenticationMethod.OAuth20( clientID: "_client_id_", token: token, @@ -75,14 +73,14 @@ final class TwitterAuthenticationMethodTests: XCTestCase { XCTAssertEqual(oauth20.clientID, "_client_id_") XCTAssertEqual(oauth20.scope, ["tweet.write", "tweet.read", "offline.access"]) XCTAssertEqual(oauth20.tokenType, "bearer") - XCTAssertEqual(oauth20.expiresIn, 7200) + XCTAssertEqual(oauth20.expiresIn, 7_200) XCTAssertEqual(oauth20.accessToken, "") XCTAssertEqual(oauth20.refreshToken, "") XCTAssertEqual(oauth20.createdAt, createdAt) } } - func testOAuth20Refresh() throws { + public func testOAuth20Refresh() throws { let createdAt = Date(timeIntervalSince1970: 2) var oauth20 = TwitterAuthenticationMethod.OAuth20( @@ -108,21 +106,24 @@ final class TwitterAuthenticationMethodTests: XCTestCase { "expires_in" : 7200, "access_token" : "" } - """.utf8) - let token = try TwitterOAuth2AccessToken(jsonData: tokenJSON)! + """.utf8 + ) + guard let token = try TwitterOAuth2AccessToken(jsonData: tokenJSON) else { + XCTFail("Failed to decode token Response") + } oauth20.refresh(token: token, refreshedAt: refreshedAt) XCTAssertEqual(oauth20.clientID, "client_id") XCTAssertEqual(oauth20.scope, ["tweet.write", "tweet.read", "offline.access"]) XCTAssertEqual(oauth20.tokenType, "bearer") - XCTAssertEqual(oauth20.expiresIn, 7200) + XCTAssertEqual(oauth20.expiresIn, 7_200) XCTAssertEqual(oauth20.accessToken, "") XCTAssertEqual(oauth20.refreshToken, "") XCTAssertEqual(oauth20.createdAt, refreshedAt) } - func testOAuth20Expired() throws { + public func testOAuth20Expired() throws { let createdAt = Date(timeIntervalSince1970: 0) let oauth20 = TwitterAuthenticationMethod.OAuth20( clientID: "", @@ -138,7 +139,7 @@ final class TwitterAuthenticationMethodTests: XCTestCase { XCTAssertTrue(oauth20.expired) } - func testOAuth20NotExpired() throws { + public func testOAuth20NotExpired() throws { let createdAt = Date() let oauth20 = TwitterAuthenticationMethod.OAuth20( clientID: "", @@ -153,4 +154,8 @@ final class TwitterAuthenticationMethodTests: XCTestCase { XCTAssertEqual(oauth20.expiresAt, createdAt.addingTimeInterval(10)) XCTAssertFalse(oauth20.expired) } + + deinit { + // De-init Logic Here + } } diff --git a/Tests/TwitterAPIKitTests/TwitterRateLimitTests.swift b/Tests/TwitterAPIKitTests/TwitterRateLimitTests.swift index 101e988a..ccf2dd86 100644 --- a/Tests/TwitterAPIKitTests/TwitterRateLimitTests.swift +++ b/Tests/TwitterAPIKitTests/TwitterRateLimitTests.swift @@ -1,16 +1,13 @@ +// TwitterRateLimitTests.swift +// Copyright (c) 2025 GetAutomaApp +// All source code and related assets are the property of GetAutomaApp. +// All rights reserved. + import TwitterAPIKit import XCTest -class TwitterRateLimitTests: XCTestCase { - - override func setUpWithError() throws { - } - - override func tearDownWithError() throws { - } - - func test() throws { - +internal class TwitterRateLimitTests: XCTestCase { + public func test() throws { XCTContext.runActivity(named: "from int") { _ in let header = [ "x-rate-limit-limit": 15, @@ -18,7 +15,9 @@ class TwitterRateLimitTests: XCTestCase { "x-rate-limit-reset": 1_644_417_523, ] - let rateLimit = TwitterRateLimit(header: header)! + guard let rateLimit = TwitterRateLimit(header: header) else { + XCTFail("Failed to decode rateLimit Response") + } XCTAssertEqual(rateLimit.limit, 15) XCTAssertEqual(rateLimit.remaining, 13) @@ -33,16 +32,17 @@ class TwitterRateLimitTests: XCTestCase { "x-rate-limit-reset": "1644417524", ] - let rateLimit = TwitterRateLimit(header: header)! + guard let rateLimit = TwitterRateLimit(header: header) else { + XCTFail("Failed to decode rateLimit Response") + } XCTAssertEqual(rateLimit.limit, 15) XCTAssertEqual(rateLimit.remaining, 3) XCTAssertEqual(rateLimit.reset, 1_644_417_524) } - } - func testNil() throws { + public func testNil() throws { XCTContext.runActivity(named: "limit") { _ in let header = [ "x-rate-limit-remaining": "3", @@ -68,7 +68,9 @@ class TwitterRateLimitTests: XCTestCase { XCTAssertNil(TwitterRateLimit(header: header)) } - } + deinit { + // De-init Logic Here + } } diff --git a/lint.txt b/lint.txt new file mode 100644 index 00000000..2c89f460 --- /dev/null +++ b/lint.txt @@ -0,0 +1,4 @@ + +> twitterapikit@1.0.0 lint +> swiftlint --config=.swiftlint.yml . + diff --git a/scripts/.gitignore b/scripts/.gitignore deleted file mode 100644 index db43c9b1..00000000 --- a/scripts/.gitignore +++ /dev/null @@ -1 +0,0 @@ -gen_init_params diff --git a/scripts/gen_init_params.swift b/scripts/gen_init_params.swift deleted file mode 100644 index 6e4736ae..00000000 --- a/scripts/gen_init_params.swift +++ /dev/null @@ -1,162 +0,0 @@ -import Foundation - -/* - public let target: TwitterUserIdentifierV1 - public let count: Int? - - ↓ - - public init( - target: TwitterUserIdentifierV1, - count: Int? = none - ) { - self.target = target - self.count = count - } - */ - -func initializer(input: String) -> String { - let regex = try! NSRegularExpression(pattern: #"[^ ] ([a-zA-Z]+): ([a-zA-Z\d<>\[\]]+\??)$"#) - - let pairs = input.split(separator: "\n") - .map { line -> String in line.trimmingCharacters(in: .whitespacesAndNewlines) } - .compactMap { line -> (name: String, type: String)? in - guard let match = regex.firstMatch(in: line, options: [], range: .init(location: 0, length: line.count)) - else { - return nil - } - guard match.numberOfRanges == 3 else { - return nil - } - - let firstRange: Range = Range(match.range(at: 1), in: line)! - let secondRange: Range = Range(match.range(at: 2), in: line)! - let name = String(line[firstRange]) - let type = String(line[secondRange]) - return (name: name, type: type) - } - - let initArgs: [String] = pairs.map { (name: String, type: String) in - if type.hasSuffix("?") { - return "\(name): \(type) = .none" - } - return "\(name): \(type)" - } - - let initBody: [String] = pairs.map { (name: String, type: String) in - return "self.\(name) = \(name)" - } - - let body = """ - public init( - \(initArgs.joined(separator: ",\n ")) - ) { - \(initBody.joined(separator: "\n ")) - } - """ - - return body -} - -// Thanks https://gist.github.com/dmsl1805/ad9a14b127d0409cf9621dc13d237457 -extension String { - func camelCaseToSnakeCase() -> String { - let acronymPattern = "([A-Z]+)([A-Z][a-z]|[0-9])" - let normalPattern = "([a-z0-9])([A-Z])" - return self.processCamalCaseRegex(pattern: acronymPattern)? - .processCamalCaseRegex(pattern: normalPattern)?.lowercased() ?? self.lowercased() - } - - fileprivate func processCamalCaseRegex(pattern: String) -> String? { - let regex = try? NSRegularExpression(pattern: pattern, options: []) - let range = NSRange(location: 0, length: count) - return regex?.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "$1_$2") - } -} - -extension String { - func preperForSpecialPattern() -> String { - // "XXs" -> "XXS", ex) IDs, RTs -> IDS, RTS - let pattern = "([A-Z]{2})(s)$" - let regex = try? NSRegularExpression(pattern: pattern, options: []) - guard let match = regex?.firstMatch(in: self, options: [], range: NSRange(location: 0, length: count)), - let range = Range(match.range, in: self) - else { return self } - return replacingCharacters(in: range, with: self[range].uppercased()) - } -} - -extension NSRegularExpression { - func matches(in str: String, at index: Int) -> [String] { - return matches(in: str, options: [], range: .init(location: 0, length: str.utf16.count)) - .map { match in - let range = Range(match.range(at: index), in: str)! - let substring = str[range] - return String(substring) - } - } -} - -/* -public let hoge: String -public let fooBar: String? - ↓ ↓ ↓ ↓ -p["hoge"] = hoge -fooBar.map { p["foo_bar"] = $0 } -*/ -func body(input: String) -> String { - let primitiveTypes = [": Int", ": String", ": Bool"] - - let regex = try! NSRegularExpression(pattern: "[^ ] ([a-zA-Z\\d]*?): ") - - let params: [String] = input.split(separator: "\n") - .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } - .compactMap { line in - let names = regex.matches(in: line, at: 1) - guard let name = names.first else { return nil } - let snakeCaseName = name.preperForSpecialPattern().camelCaseToSnakeCase() - - if !primitiveTypes.contains(where: { line.contains($0) }) { - // ex: public let users: TwitterUsersIdentifier - - let optional = line.hasSuffix("?") ? "?" : "" - return "\(name)\(optional).bind(param: &p)" - } else if line.hasSuffix("?") { - if line.hasSuffix("]?") { - // may be optional array. ex: [String]? - // In the case of Dictionary, it breaks. - // additionalOwners.map { p["additional_owners"] = $0.joined(separator: ",") } - return "\(name).map { p[\"\(snakeCaseName)\"] = $0.joined(separator: \",\") }" - } - - // optional value - return "\(name).map { p[\"\(snakeCaseName)\"] = $0 }" - - } else { - return "p[\"\(snakeCaseName)\"] = \(name) " - } - } - let body = """ - open var parameters: [String: Any] { - var p = [String: Any]() - \(params.joined(separator: "\n ")) - return p - } - """ - return body -} - -func exec() { - let input = FileHandle.standardInput - - guard let input = String(bytes: input.availableData, encoding: .utf8) else { - print("pbpaste | ./gen_init_params.swift") - return - } - - print(body(input: input)) - print("") - print(initializer(input: input)) -} - -exec() diff --git a/scripts/gen_v1.js b/scripts/gen_v1.js deleted file mode 100644 index 0d4e31f0..00000000 --- a/scripts/gen_v1.js +++ /dev/null @@ -1,119 +0,0 @@ - -// In Twitter's API documentation, paste it into the Chrome DevTools console and run it. - -(function () { - /** - * - * @param {{[index: string]: string}} propsMap - * @param {string[]} fromProps - * @param {string} toProp - */ - function replaceProps(propsMap, fromProps, toProp) { - if (fromProps.every(p => !!propsMap[p])) { - fromProps.forEach(p => { - delete propsMap[p] - }) - propsMap[toProp] = "required" - } - } - - const title = document.querySelector("h1").textContent - // POST users/report_spam-> [POST/users/report/spam] - const tokens = title.replace(/([A-Z]+) /g, "$1/").replace("_", "/").split("/") - - const method = tokens[0] - - const className = tokens.reduce((prev, current) => { - const low = current.toLowerCase() - return prev + low.charAt(0).toUpperCase() + low.slice(1); - - }, "").replace("Id", "ID") + "RequestV1" - - - const url = document.querySelector("#resource-url").nextElementSibling.textContent - - const nameToTypeMap = { - "q": "String", - "page": "Int", - "count": "Int", - "cursor": "String", - "description": "String", - "user": "TwitterUserIdentifierV1", - "sourceUser": "TwitterUserIdentifierV1", - "targetUser": "TwitterUserIdentifierV1", - "includeEntities": "Bool", - "includeUserEntities": "Bool", - "includeExtAltText": "Bool", - "includeCardUri": "Bool", - "includeExtAltText": "Bool", - "includeMyRetweet": "Bool", - "includeRTs": "Bool", - "excludeReplies": "Bool", - "trimUser": "Bool", - "maxID": "String", - "sinceID": "String", - "stringifyIDs": "Bool", - "skipStatus": "Bool", - "query": "String", - "follow": "Bool", - "tweetID": "String", - "relativeTo": "String", - } - - function getParameterTableRows() { - - const maybeTable = document.querySelector("#parameters").nextElementSibling - if (maybeTable instanceof HTMLTableElement) { - return Array(...maybeTable.rows) - } - return [] - } - - - const propsMap = getParameterTableRows().slice(1).reduce((prev, row) => { - const [nameElem, requiredElem] = row.children - const required = requiredElem.textContent - const name = nameElem.textContent.replace(/_./g, - function (s) { - return s.charAt(1).toUpperCase(); - }).replace("Id", "ID") - - prev[name] = required - return prev - }, {}) - - - replaceProps(propsMap, ["userID", "screenName"], "user") - replaceProps(propsMap, ["sourceID", "sourceScreenName"], "sourceUser") - replaceProps(propsMap, ["targetID", "targetScreenName"], "targetUser") - - const props = Object.keys(propsMap) - .sort((a, b) => a.length - b.length) - .map(name => { - const type = nameToTypeMap[name] ?? "Unknown" - const optional = propsMap[name] === "required" ? "" : "?" - return `public let ${name}: ${type}${optional}` - }) - - - const source = `import Foundation - - /// ${location.href} - open class ${className}: TwitterAPIRequest { - - ${props.join("\n ")} - - public var method: HTTPMethod { - return .${method.toLowerCase()} - } - - public var path: String { - return "${url.replace("https://api.twitter.com", "")}" - } - - } - ` - console.log(source) - copy(source) -})() - diff --git a/scripts/gen_v2.js b/scripts/gen_v2.js deleted file mode 100644 index 9601e797..00000000 --- a/scripts/gen_v2.js +++ /dev/null @@ -1,314 +0,0 @@ - -/** - * @typedef {{type: string, name: string, rawName: string, required: boolean, kind: "path" | "query" | "json", swiftType?: string, parent: Prop?}} Prop - */ - -// In Twitter's API documentation, paste it into the Chrome DevTools console and run it. - -(function () { - - /** - * @returns {{className: string, method: string}} - */ - function createClassNameAndMethod() { - const title = document.querySelector("h1").textContent - const titleTokens = title.split("/") - - // GET /2/tweets/:id/retweeted_by -> GET /tweets/retweeted_by -> GetTweetsRetweetedByRequestV2 - const removed = titleTokens.filter(s => !s.startsWith(":") && s !== "2").join("/") - const tokens = removed.replace(/([A-Z]+) /g, "$1/").replace("_", "/").split("/") - let name = tokens.reduce((prev, current) => { - const low = current.toLowerCase() - return prev + low.charAt(0).toUpperCase() + low.slice(1); - }, "").replace("Id", "ID") - - // GET /2/tweets -> GetTweetsRequestV2 - // GET /2/tweets/:id -> GetTweetRequestV2 - if (name.endsWith("s") && titleTokens[titleTokens.length - 1] === ":id") { - name = name.slice(0, -1) - } - - const className = name + "RequestV2" - const method = tokens[0].toLowerCase() - return { className, method } - } - - - function createURL() { - const url = Array(...document.querySelectorAll("h3")).find(elem => elem.innerText === "Endpoint URL").nextElementSibling.textContent - return url.split("/").map(s => { - if (s.startsWith(":")) { - const camel = s.replace(":", "").split("_").reduce((prev, current) => { - if (prev.length === 0) { - return current - } - return prev + current.charAt(0).toUpperCase() + current.slice(1) - }, "").replace("Id", "ID") - - return "\\(" + camel + ")" - } - return s - }).join("/") - } - - /** - * // Path parameters or Query parameters - * @param {string} name - * @returns {HTMLTableRowElement[]} - */ - function getParameterTableRows(name) { - - const pathParamHeading = Array(...document.querySelectorAll("h3")).find(elem => elem.innerText === name) - if (!pathParamHeading) { - return [] - } - - const maybeTable = pathParamHeading.nextElementSibling - if (maybeTable instanceof HTMLTableElement) { - return Array(...maybeTable.rows) - } - return [] - } - - - /** - * - * @param {Prop} prop - */ - function bindSwiftType(prop) { - - function toType() { - - if (prop.name === "ids" && prop.type === "string" - || prop.rawName.endsWith("_ids") && prop.type === "string" - ||prop.rawName.endsWith("_ids") && prop.type === "array") { - return "[String]" - } - - if (prop.name === "expansions") { - if (prop.type.includes("enum (attachments.poll_ids, attachments.media_keys")) { - return "Set" - } else if (prop.type.includes("enum (pinned_tweet_id")) { - return "Set" - } else if (prop.type.includes("enum (owner_id)")) { - return "Set" - } else if (prop.type.includes("enum (invited_user_ids, speaker_ids, creator_id, host_ids)")) { - return "Set" - } - } - - const nameToType = { - "media.fields": "Set", - "place.fields": "Set", - "poll.fields": "Set", - "tweet.fields": "Set", - "user.fields": "Set", - "list.fields": "Set", - "space.fields": "Set", - "topic.fields": "Set" - } - - const typeToSwiftType = { - "integer": "Int", - "number": "Int", - "string": "String", - "date (ISO 8601)": "Date", - "boolean": "Bool" - } - - return nameToType[prop.rawName] ?? typeToSwiftType[prop.type] - } - const type = toType() - if (type) { - prop.swiftType = type - } else { - console.warn("Unkown type for", prop) - } - - return prop - } - - /** - * @param {HTMLTableRowElement[]} rows - * @param {"path" | "query" | "json"} kind - * @return {Prop[]} - */ - function pickupProps(rows, kind) { - - /** @type {Prop[]} */ - const init = [] - return rows.slice(1).reduce((prev, row) => { - - const [nameElem, typeElem] = row.children - const required = nameElem.querySelector("small").textContent.trim().toLowerCase() == "required" - const type = typeElem.textContent - const rawName = nameElem.querySelector("code").textContent - const name = rawName.replace(/[_.]./g, - function (s) { - return s.charAt(1).toUpperCase(); - }).replace("Id", "ID") - - const parent = rawName.includes(".") ? prev.find(p => p.rawName === rawName.split(".")[0]) : undefined - - const prop = { - name, - rawName, - type, - required, - kind, - parent, - } - bindSwiftType(prop) - - prev.push(prop) - return prev - }, init) - } - - /** - * - * @param {Prop} prop - * @param {Prop[]} allProps - */ - function swiftPropertyString(prop, allProps) { - const type = prop.swiftType ?? "Unknown" - const optional = prop.required ? "" : "?" - const properties = allProps.filter(p => p.parent && p.parent.name == prop.name) - .map(p => { - const name = p.name.replace(prop.name, "") - const replacedName = name.charAt(0).toLowerCase() + name.slice(1) - const replacedRawName = p.rawName.replace(prop.rawName + ".", "") - return { ...p, name: replacedName, rawName: replacedRawName } - }) - - const structName = properties.length > 0 ? prop.name.charAt(0).toUpperCase() + prop.name.slice(1) : undefined - const structStr = ` - // The properties of ${prop.name} are such a struct. If enum is more suitable, please modify it. - public struct ${structName} { - ${properties.map(p => swiftPropertyString(p, allPathProps)).join("\n")} - - func bind(param: inout [String: Any]) { - var p = [String: Any]() - - ${properties.map(p => { return `p["${p.rawName}"]` }).join("\n")} - - param["${prop.rawName}"] = p - } - }` - - let string = `public let ${prop.name}: ${structName || type}${optional}` - if (properties.length > 0) { - string = `${structStr} - ${string} - ` - } - - return string - } - - /** - * - * @param {Prop[]} props - */ - function createParameterFunc(props) { - if (props.length === 0) { - return `open var parameters: [String: Any] { - return [:] - }` - } - const body = props.map(prop => { - const isPrimitiveType = prop.type === "string" || prop.type === "integer" || prop.type === "boolean" - const isArray = prop.swiftType === "[String]" || prop.swiftType === "[Int]" - const optional = prop.required ? "" : "?" - const join = isArray ? `.joined(separator: ",")` : "" - if (isPrimitiveType) { - if (optional) { - return `${prop.name}.map { p["${prop.rawName}"] = $0${join} }` - } - return `p["${prop.rawName}"] = ${prop.name}${join}` - } else { - return `${prop.name}${optional}.bind(param: &p)` - } - }) - return `open var parameters: [String: Any] { - var p = [String: Any]() - ${body.join("\n ")} - return p - }` - } - - /** - * - * @param {Prop[]} props - * @returns - */ - function createInitFunc(props) { - - const initParams = props.map(p => { - const optional = p.required ? "" : "?" - const defaultArg = p.required ? "" : " = .none" - return `${p.name}: ${p.swiftType ?? "Unkown"}${optional}${defaultArg}` - }) - - const initBody = props.map(p => { - return `self.${p.name} = ${p.name}` - }) - - return `public init( - ${initParams.join(",\n ")} - ) { - ${initBody.join("\n ")} - }` - } - - const classNameAndMethod = createClassNameAndMethod() - const url = createURL() - - const allPathProps = pickupProps(getParameterTableRows("Path parameters"), "path") - const allQueryProps = pickupProps(getParameterTableRows("Query parameters"), "query") - const allJsonProps = pickupProps(getParameterTableRows("JSON body parameters"), "json") - - const topLevelPathProps = allPathProps.filter(p => !p.parent) - const topLevelQueryProps = allQueryProps.filter(p => !p.parent) - const topLevelJsonProps = allJsonProps.filter(p => !p.parent) - - const props = [ - ...topLevelPathProps.map(p => swiftPropertyString(p, allPathProps)), - ...topLevelQueryProps.filter(p => !p.parent).map(p => swiftPropertyString(p, allQueryProps)), - ...topLevelJsonProps.filter(p => !p.parent).map(p => swiftPropertyString(p, allJsonProps)) - ] - - const bodyContentType = allJsonProps.length === 0 ? "" : - ` - public var bodyContentType: BodyContentType { - return .json - } -` - const parameterFunc = createParameterFunc([...topLevelQueryProps, ...topLevelJsonProps]) - - const initFunc = createInitFunc([...topLevelPathProps, ...topLevelQueryProps, ...topLevelJsonProps]) - - const source = `import Foundation - -/// ${location.href} -open class ${classNameAndMethod.className}: TwitterAPIRequest { - - ${props.join("\n ")} - - public var method: HTTPMethod { - return .${classNameAndMethod.method} - } - - public var path: String { - return "${url.replace("https://api.twitter.com", "")}" - } - ${bodyContentType} - ${parameterFunc} - - ${initFunc} -} -` - console.log(source) - copy(source) -})() -