mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-19 22:06:54 +03:00
gsa: GrandSlamMethod -> GrandSlamRequestContent
This commit is contained in:
@@ -24,17 +24,19 @@ struct GrandSlamClient: Sendable {
|
||||
let anisetteData = try await anisetteDataProvider.fetchAnisetteData()
|
||||
let url = try await lookupManager.fetchURL(forEndpoint: R.endpoint)
|
||||
|
||||
let method = request.method(anisetteData: anisetteData)
|
||||
var httpRequest = HTTPRequest(method: method.httpMethod, url: url)
|
||||
let content = request.content(anisetteData: anisetteData)
|
||||
var httpRequest = HTTPRequest(method: content.httpMethod, url: url)
|
||||
httpRequest.headerFields[.contentType] = "text/x-xml-plist"
|
||||
httpRequest.headerFields[.init(DeviceInfo.clientInfoKey)!] = anisetteData.deviceInfo.clientInfo
|
||||
let body: Data? = switch method {
|
||||
let body: Data? = switch content {
|
||||
case .get:
|
||||
nil
|
||||
case .post(let body):
|
||||
case .data(let body, _, .xml):
|
||||
try PropertyListSerialization.data(
|
||||
fromPropertyList: body, format: .xml, options: 0
|
||||
)
|
||||
case .data(let body, _, .json):
|
||||
try JSONSerialization.data(withJSONObject: body)
|
||||
}
|
||||
request.configure(request: &httpRequest, anisetteData: anisetteData)
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ struct GrandSlamSMSAuthRequest: GrandSlamTwoFactorRequest {
|
||||
let loginData: GrandSlamLoginData
|
||||
let phoneNumberID: String
|
||||
|
||||
func method(anisetteData: AnisetteData) -> GrandSlamMethod {
|
||||
func content(anisetteData: AnisetteData) -> GrandSlamRequestContent {
|
||||
.post([
|
||||
"serverInfo": [
|
||||
"phoneNumber.id": phoneNumberID
|
||||
|
||||
@@ -36,7 +36,7 @@ struct GrandSlamValidateSMSRequest: GrandSlamTwoFactorRequest {
|
||||
let phoneNumberID: String
|
||||
let verificationCode: String
|
||||
|
||||
func method(anisetteData: AnisetteData) -> GrandSlamMethod {
|
||||
func content(anisetteData: AnisetteData) -> GrandSlamRequestContent {
|
||||
.post([
|
||||
"securityCode.code": verificationCode,
|
||||
"serverInfo": [
|
||||
|
||||
@@ -74,7 +74,7 @@ extension GrandSlamOperationRequest {
|
||||
request.headerFields[.userAgent] = anisetteData.deviceInfo.akdUserAgent
|
||||
}
|
||||
|
||||
func method(anisetteData: AnisetteData) -> GrandSlamMethod {
|
||||
func content(anisetteData: AnisetteData) -> GrandSlamRequestContent {
|
||||
var clientData: [String: Any] = [
|
||||
"bootstrap": true,
|
||||
"icscrec": true,
|
||||
|
||||
@@ -7,15 +7,29 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import HTTPTypes
|
||||
|
||||
enum GrandSlamRequestContent {
|
||||
enum ContentType {
|
||||
case xml
|
||||
case json
|
||||
}
|
||||
|
||||
enum GrandSlamMethod {
|
||||
case get
|
||||
case post([String: Any])
|
||||
case data([String: Any], method: HTTPRequest.Method, type: ContentType = .xml)
|
||||
|
||||
static func post(_ body: [String: Any], type: ContentType = .xml) -> Self {
|
||||
.data(body, method: .post, type: type)
|
||||
}
|
||||
|
||||
static func put(_ body: [String: Any], type: ContentType = .xml) -> Self {
|
||||
.data(body, method: .put, type: type)
|
||||
}
|
||||
|
||||
var httpMethod: HTTPRequest.Method {
|
||||
switch self {
|
||||
case .get: return .get
|
||||
case .post: return .post
|
||||
case .data(_, let method, _): return method
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,5 +45,5 @@ protocol GrandSlamRequest: Sendable {
|
||||
static var endpoint: GrandSlamEndpoint { get }
|
||||
|
||||
func configure(request: inout HTTPRequest, anisetteData: AnisetteData)
|
||||
func method(anisetteData: AnisetteData) -> GrandSlamMethod
|
||||
func content(anisetteData: AnisetteData) -> GrandSlamRequestContent
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ extension GrandSlamTwoFactorRequest {
|
||||
extraHeaders.forEach { request.headerFields[.init($0)!] = $1 }
|
||||
}
|
||||
|
||||
func method(anisetteData: AnisetteData) -> GrandSlamMethod {
|
||||
func content(anisetteData: AnisetteData) -> GrandSlamRequestContent {
|
||||
.get
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user