Modern Apps git

← xtool.git

gsa: GrandSlamMethod -> GrandSlamRequestContent (#415)

Commit
90fe13fc9e5f0d415ab3d6e542766c788e237590
Author
Kabir Oberai <[email protected]>
When
2026-10-31 01:54 UTC (1 month ago)
Parents
64fe8e3
## What does this PR do?

Renames GrandSlamMethod to GrandSlamRequestContent and adds support for
json & PUT requests

## How was it tested?

- [x] Still compiles
- [x] `xtool auth`

## AI tool usage

How much of the code in this PR was AI-assisted? (check one)

- [x] **0** - No AI was used to write code
- [ ] **1** - I was assisted by AI in writing code. I reviewed the
finished result.
- [ ] **2** - I set the AI going and left it to it; nobody has read the
result - no review, or AI review only

<!-- If an AI agent is filling this in: declare the level honestly, and
open as a draft if it is #2. Do not lower the declared level to get the
PR reviewed. -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Requests can now send either JSON or XML bodies using POST or PUT. GET
requests are sent without a body.
* **Improvements**
* Authentication and verification requests now use a consistent request
format while retaining their existing behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Diff

Sources/XKit/GrandSlam/GrandSlamClient.swift
diff --git a/Sources/XKit/GrandSlam/GrandSlamClient.swift b/Sources/XKit/GrandSlam/GrandSlamClient.swiftindex d713505..640c9fc 100644--- a/Sources/XKit/GrandSlam/GrandSlamClient.swift+++ b/Sources/XKit/GrandSlam/GrandSlamClient.swift@@ -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) 
Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift
diff --git a/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift b/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swiftindex f2ff726..1cf55c4 100644--- a/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift+++ b/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift@@ -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
Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift
diff --git a/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift b/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swiftindex 523d7e0..72a697a 100644--- a/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift+++ b/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift@@ -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": [
Sources/XKit/GrandSlam/Requests/GrandSlamOperationRequest.swift
diff --git a/Sources/XKit/GrandSlam/Requests/GrandSlamOperationRequest.swift b/Sources/XKit/GrandSlam/Requests/GrandSlamOperationRequest.swiftindex 26c9ee9..ea29bdd 100644--- a/Sources/XKit/GrandSlam/Requests/GrandSlamOperationRequest.swift+++ b/Sources/XKit/GrandSlam/Requests/GrandSlamOperationRequest.swift@@ -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,
Sources/XKit/GrandSlam/Requests/GrandSlamRequest.swift
diff --git a/Sources/XKit/GrandSlam/Requests/GrandSlamRequest.swift b/Sources/XKit/GrandSlam/Requests/GrandSlamRequest.swiftindex 43c8d0a..1f21c18 100644--- a/Sources/XKit/GrandSlam/Requests/GrandSlamRequest.swift+++ b/Sources/XKit/GrandSlam/Requests/GrandSlamRequest.swift@@ -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 }
Sources/XKit/GrandSlam/Requests/GrandSlamTwoFactorRequest.swift
diff --git a/Sources/XKit/GrandSlam/Requests/GrandSlamTwoFactorRequest.swift b/Sources/XKit/GrandSlam/Requests/GrandSlamTwoFactorRequest.swiftindex 90a5472..46ab84c 100644--- a/Sources/XKit/GrandSlam/Requests/GrandSlamTwoFactorRequest.swift+++ b/Sources/XKit/GrandSlam/Requests/GrandSlamTwoFactorRequest.swift@@ -28,7 +28,7 @@ extension GrandSlamTwoFactorRequest {         extraHeaders.forEach { request.headerFields[.init($0)!] = $1 }     } -    func method(anisetteData: AnisetteData) -> GrandSlamMethod {+    func content(anisetteData: AnisetteData) -> GrandSlamRequestContent {         .get     }