From 30ac6883a272290b03f5baa499ae2b61ac168259 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 30 Mar 2026 02:02:10 +0000 Subject: [PATCH 01/15] feat(api): api update --- .github/workflows/publish-sonatype.yml | 41 ------- .github/workflows/release-doctor.yml | 24 ---- .release-please-manifest.json | 3 - .stats.yml | 2 +- README.md | 16 +-- bin/check-release-environment | 33 ------ build.gradle.kts | 15 +-- buildSrc/build.gradle.kts | 3 + .../kotlin/x-twitter-scraper.java.gradle.kts | 9 -- .../x-twitter-scraper.publish.gradle.kts | 107 +++++++++--------- release-please-config.json | 67 ----------- .../com/x_twitter_scraper/api/core/Check.kt | 2 +- 12 files changed, 64 insertions(+), 258 deletions(-) delete mode 100644 .github/workflows/publish-sonatype.yml delete mode 100644 .github/workflows/release-doctor.yml delete mode 100644 .release-please-manifest.json delete mode 100644 bin/check-release-environment delete mode 100644 release-please-config.json diff --git a/.github/workflows/publish-sonatype.yml b/.github/workflows/publish-sonatype.yml deleted file mode 100644 index a599124..0000000 --- a/.github/workflows/publish-sonatype.yml +++ /dev/null @@ -1,41 +0,0 @@ -# This workflow is triggered when a GitHub release is created. -# It can also be run manually to re-publish to Sonatype in case it failed for some reason. -# You can run this workflow by navigating to https://www.github.com/Xquik-dev/x-twitter-scraper-java/actions/workflows/publish-sonatype.yml -name: Publish Sonatype -on: - workflow_dispatch: - - release: - types: [published] - -jobs: - publish: - name: publish - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v6 - - - name: Set up Java - uses: actions/setup-java@v5 - with: - distribution: temurin - java-version: | - 8 - 21 - cache: gradle - - - name: Set up Gradle - uses: gradle/gradle-build-action@v2 - - - name: Publish to Sonatype - run: |- - export -- GPG_SIGNING_KEY_ID - printenv -- GPG_SIGNING_KEY | gpg --batch --passphrase-fd 3 --import 3<<< "$GPG_SIGNING_PASSWORD" - GPG_SIGNING_KEY_ID="$(gpg --with-colons --list-keys | awk -F : -- '/^pub:/ { getline; print "0x" substr($10, length($10) - 7) }')" - ./gradlew publish --no-configuration-cache - env: - SONATYPE_USERNAME: ${{ secrets.X_TWITTER_SCRAPER_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }} - SONATYPE_PASSWORD: ${{ secrets.X_TWITTER_SCRAPER_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }} - GPG_SIGNING_KEY: ${{ secrets.X_TWITTER_SCRAPER_SONATYPE_GPG_SIGNING_KEY || secrets.GPG_SIGNING_KEY }} - GPG_SIGNING_PASSWORD: ${{ secrets.X_TWITTER_SCRAPER_SONATYPE_GPG_SIGNING_PASSWORD || secrets.GPG_SIGNING_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml deleted file mode 100644 index f0a6dd9..0000000 --- a/.github/workflows/release-doctor.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Release Doctor -on: - pull_request: - branches: - - main - workflow_dispatch: - -jobs: - release_doctor: - name: release doctor - runs-on: ubuntu-latest - if: github.repository == 'Xquik-dev/x-twitter-scraper-java' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next') - - steps: - - uses: actions/checkout@v6 - - - name: Check release environment - run: | - bash ./bin/check-release-environment - env: - SONATYPE_USERNAME: ${{ secrets.X_TWITTER_SCRAPER_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }} - SONATYPE_PASSWORD: ${{ secrets.X_TWITTER_SCRAPER_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }} - GPG_SIGNING_KEY: ${{ secrets.X_TWITTER_SCRAPER_SONATYPE_GPG_SIGNING_KEY || secrets.GPG_SIGNING_KEY }} - GPG_SIGNING_PASSWORD: ${{ secrets.X_TWITTER_SCRAPER_SONATYPE_GPG_SIGNING_PASSWORD || secrets.GPG_SIGNING_PASSWORD }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json deleted file mode 100644 index 3d2ac0b..0000000 --- a/.release-please-manifest.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - ".": "0.1.0" -} \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 9f265c5..ab7f688 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 115 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/xquik%2Fx-twitter-scraper-af60c455e2c8579c3d7f0e33c07c0b8332aa3fe8869688c47b2fbf151e271235.yml openapi_spec_hash: a49d40286e54da6a4978a103b118d33f -config_hash: cec075ca53645b9620ec200be71bdc48 +config_hash: fc946e63e0b0ca32b93bc437d58e470b diff --git a/README.md b/README.md index 3ae77da..6aa9e1a 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,18 @@ # X Twitter Scraper Java API Library - - [![Maven Central](https://img.shields.io/maven-central/v/com.x_twitter_scraper.api/x-twitter-scraper-java)](https://central.sonatype.com/artifact/com.x_twitter_scraper.api/x-twitter-scraper-java/0.1.0) [![javadoc](https://javadoc.io/badge2/com.x_twitter_scraper.api/x-twitter-scraper-java/0.1.0/javadoc.svg)](https://javadoc.io/doc/com.x_twitter_scraper.api/x-twitter-scraper-java/0.1.0) - - The X Twitter Scraper Java SDK provides convenient access to the [X Twitter Scraper REST API](https://xquik.com) from applications written in Java. -It is generated with [Stainless](https://www.stainless.com/). +The X Twitter Scraper Java SDK is similar to the X Twitter Scraper Kotlin SDK but with minor differences that make it more ergonomic for use in Java, such as `Optional` instead of nullable values, `Stream` instead of `Sequence`, and `CompletableFuture` instead of suspend functions. - +It is generated with [Stainless](https://www.stainless.com/). The REST API documentation can be found on [xquik.com](https://xquik.com). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.x_twitter_scraper.api/x-twitter-scraper-java/0.1.0). - - ## Installation - - ### Gradle ```kotlin @@ -37,8 +29,6 @@ implementation("com.x_twitter_scraper.api:x-twitter-scraper-java:0.1.0") ``` - - ## Requirements This library requires Java 8 or later. @@ -768,4 +758,4 @@ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) con We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience. -We are keen for your feedback; please open an [issue](https://www.github.com/Xquik-dev/x-twitter-scraper-java/issues) with questions, bugs, or suggestions. +We are keen for your feedback; please open an [issue](https://www.github.com/stainless-sdks/x-twitter-scraper-java/issues) with questions, bugs, or suggestions. diff --git a/bin/check-release-environment b/bin/check-release-environment deleted file mode 100644 index 3a6a7b4..0000000 --- a/bin/check-release-environment +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash - -errors=() - -if [ -z "${SONATYPE_USERNAME}" ]; then - errors+=("The SONATYPE_USERNAME secret has not been set. Please set it in either this repository's secrets or your organization secrets") -fi - -if [ -z "${SONATYPE_PASSWORD}" ]; then - errors+=("The SONATYPE_PASSWORD secret has not been set. Please set it in either this repository's secrets or your organization secrets") -fi - -if [ -z "${GPG_SIGNING_KEY}" ]; then - errors+=("The GPG_SIGNING_KEY secret has not been set. Please set it in either this repository's secrets or your organization secrets") -fi - -if [ -z "${GPG_SIGNING_PASSWORD}" ]; then - errors+=("The GPG_SIGNING_PASSWORD secret has not been set. Please set it in either this repository's secrets or your organization secrets") -fi - -lenErrors=${#errors[@]} - -if [[ lenErrors -gt 0 ]]; then - echo -e "Found the following errors in the release environment:\n" - - for error in "${errors[@]}"; do - echo -e "- $error\n" - done - - exit 1 -fi - -echo "The environment is ready to push releases!" diff --git a/build.gradle.kts b/build.gradle.kts index 9022e4c..6837dbf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,4 @@ plugins { - id("io.github.gradle-nexus.publish-plugin") version "1.1.0" id("org.jetbrains.dokka") version "2.0.0" } @@ -9,7 +8,7 @@ repositories { allprojects { group = "com.x_twitter_scraper.api" - version = "0.1.0" // x-release-please-version + version = "0.1.0" } subprojects { @@ -35,15 +34,3 @@ tasks.named("dokkaJavadocCollector").configure { .filter { it.project.name != "x-twitter-scraper-java" && it.name == "dokkaJavadocJar" } .forEach { mustRunAfter(it) } } - -nexusPublishing { - repositories { - sonatype { - nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) - snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) - - username.set(System.getenv("SONATYPE_USERNAME")) - password.set(System.getenv("SONATYPE_PASSWORD")) - } - } -} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 0b14135..c6dc92e 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,12 +1,15 @@ plugins { `kotlin-dsl` kotlin("jvm") version "1.9.20" + id("com.vanniktech.maven.publish") version "0.28.0" } repositories { gradlePluginPortal() + mavenCentral() } dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20") + implementation("com.vanniktech:gradle-maven-publish-plugin:0.28.0") } diff --git a/buildSrc/src/main/kotlin/x-twitter-scraper.java.gradle.kts b/buildSrc/src/main/kotlin/x-twitter-scraper.java.gradle.kts index a3cfe28..8f4f902 100644 --- a/buildSrc/src/main/kotlin/x-twitter-scraper.java.gradle.kts +++ b/buildSrc/src/main/kotlin/x-twitter-scraper.java.gradle.kts @@ -8,11 +8,6 @@ repositories { mavenCentral() } -configure { - withJavadocJar() - withSourcesJar() -} - java { toolchain { languageVersion.set(JavaLanguageVersion.of(21)) @@ -27,10 +22,6 @@ tasks.withType().configureEach { options.release.set(8) } -tasks.named("javadocJar") { - setZip64(true) -} - tasks.named("jar") { manifest { attributes(mapOf( diff --git a/buildSrc/src/main/kotlin/x-twitter-scraper.publish.gradle.kts b/buildSrc/src/main/kotlin/x-twitter-scraper.publish.gradle.kts index 9edc4d2..2b64738 100644 --- a/buildSrc/src/main/kotlin/x-twitter-scraper.publish.gradle.kts +++ b/buildSrc/src/main/kotlin/x-twitter-scraper.publish.gradle.kts @@ -1,69 +1,72 @@ +import com.vanniktech.maven.publish.JavadocJar +import com.vanniktech.maven.publish.KotlinJvm +import com.vanniktech.maven.publish.MavenPublishBaseExtension +import com.vanniktech.maven.publish.SonatypeHost + plugins { - `maven-publish` - signing + id("com.vanniktech.maven.publish") +} + +publishing { + repositories { + if (project.hasProperty("publishLocal")) { + maven { + name = "LocalFileSystem" + url = uri("${rootProject.layout.buildDirectory.get()}/local-maven-repo") + } + } + } } -configure { - publications { - register("maven") { - from(components["java"]) +repositories { + gradlePluginPortal() + mavenCentral() +} - pom { - name.set("Xquik API") - description.set("X real-time data platform — extractions, giveaway draws, monitoring, webhooks.") - url.set("https://xquik.com") +extra["signingInMemoryKey"] = System.getenv("GPG_SIGNING_KEY") +extra["signingInMemoryKeyId"] = System.getenv("GPG_SIGNING_KEY_ID") +extra["signingInMemoryKeyPassword"] = System.getenv("GPG_SIGNING_PASSWORD") - licenses { - license { - name.set("Apache-2.0") - } - } +configure { + if (!project.hasProperty("publishLocal")) { + signAllPublications() + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) + } - developers { - developer { - name.set("X Twitter Scraper") - email.set("support@xquik.com") - } - } + coordinates(project.group.toString(), project.name, project.version.toString()) + configure( + KotlinJvm( + javadocJar = JavadocJar.Dokka("dokkaJavadoc"), + sourcesJar = true, + ) + ) - scm { - connection.set("scm:git:git://github.com/Xquik-dev/x-twitter-scraper-java.git") - developerConnection.set("scm:git:git://github.com/Xquik-dev/x-twitter-scraper-java.git") - url.set("https://github.com/Xquik-dev/x-twitter-scraper-java") - } + pom { + name.set("Xquik API") + description.set("X real-time data platform — extractions, giveaway draws, monitoring, webhooks.") + url.set("https://xquik.com") - versionMapping { - allVariants { - fromResolutionResult() - } - } + licenses { + license { + name.set("Apache-2.0") } } - } - repositories { - if (project.hasProperty("publishLocal")) { - maven { - name = "LocalFileSystem" - url = uri("${rootProject.layout.buildDirectory.get()}/local-maven-repo") + + developers { + developer { + name.set("X Twitter Scraper") + email.set("support@xquik.com") } } - } -} -signing { - val signingKeyId = System.getenv("GPG_SIGNING_KEY_ID")?.ifBlank { null } - val signingKey = System.getenv("GPG_SIGNING_KEY")?.ifBlank { null } - val signingPassword = System.getenv("GPG_SIGNING_PASSWORD")?.ifBlank { null } - if (signingKey != null && signingPassword != null) { - useInMemoryPgpKeys( - signingKeyId, - signingKey, - signingPassword, - ) - sign(publishing.publications["maven"]) + scm { + connection.set("scm:git:git://github.com/stainless-sdks/x-twitter-scraper-java.git") + developerConnection.set("scm:git:git://github.com/stainless-sdks/x-twitter-scraper-java.git") + url.set("https://github.com/stainless-sdks/x-twitter-scraper-java") + } } } -tasks.named("publish") { - dependsOn(":closeAndReleaseSonatypeStagingRepository") +tasks.withType().configureEach { + isZip64 = true } diff --git a/release-please-config.json b/release-please-config.json deleted file mode 100644 index 8f98719..0000000 --- a/release-please-config.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "packages": { - ".": {} - }, - "$schema": "https://raw.githubusercontent.com/stainless-api/release-please/main/schemas/config.json", - "include-v-in-tag": true, - "include-component-in-tag": false, - "versioning": "prerelease", - "prerelease": true, - "bump-minor-pre-major": true, - "bump-patch-for-minor-pre-major": false, - "pull-request-header": "Automated Release PR", - "pull-request-title-pattern": "release: ${version}", - "changelog-sections": [ - { - "type": "feat", - "section": "Features" - }, - { - "type": "fix", - "section": "Bug Fixes" - }, - { - "type": "perf", - "section": "Performance Improvements" - }, - { - "type": "revert", - "section": "Reverts" - }, - { - "type": "chore", - "section": "Chores" - }, - { - "type": "docs", - "section": "Documentation" - }, - { - "type": "style", - "section": "Styles" - }, - { - "type": "refactor", - "section": "Refactors" - }, - { - "type": "test", - "section": "Tests", - "hidden": true - }, - { - "type": "build", - "section": "Build System" - }, - { - "type": "ci", - "section": "Continuous Integration", - "hidden": true - } - ], - "release-type": "simple", - "extra-files": [ - "README.md", - "build.gradle.kts" - ] -} \ No newline at end of file diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/core/Check.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/core/Check.kt index ac0d703..02a38c9 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/core/Check.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/core/Check.kt @@ -77,7 +77,7 @@ This can happen if you are either: Double-check that you are depending on compatible Jackson versions. -See https://www.github.com/Xquik-dev/x-twitter-scraper-java#jackson for more information. +See https://www.github.com/stainless-sdks/x-twitter-scraper-java#jackson for more information. """ .trimIndent() } From 782893865814d3758be6fef59b6daefb8f21c9c4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 30 Mar 2026 22:17:38 +0000 Subject: [PATCH 02/15] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index ab7f688..408e9b8 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 115 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/xquik%2Fx-twitter-scraper-af60c455e2c8579c3d7f0e33c07c0b8332aa3fe8869688c47b2fbf151e271235.yml -openapi_spec_hash: a49d40286e54da6a4978a103b118d33f +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/xquik%2Fx-twitter-scraper-fab8cd6999dbd1fc8e331b7f83d7af46d89bc35801f7a384534be7d65191da2c.yml +openapi_spec_hash: 72a97c6cb83103355099af6e0b0a19e1 config_hash: fc946e63e0b0ca32b93bc437d58e470b From 31b819aeae39651f9f9204561f6be9719c7a8d6a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 1 Apr 2026 07:22:16 +0000 Subject: [PATCH 03/15] feat(api): api update --- .stats.yml | 4 +- README.md | 38 +- .../api/models/PaginatedTweets.kt | 798 ++++++++++- .../api/models/PaginatedUsers.kt | 574 +++++++- .../api/models/apikeys/ApiKeyListResponse.kt | 374 ++++- .../api/models/drafts/DraftCreateResponse.kt | 347 +++++ .../api/models/drafts/DraftListResponse.kt | 302 ++++ .../models/drafts/DraftRetrieveResponse.kt | 347 +++++ .../api/models/draws/DrawListResponse.kt | 437 +++++- .../api/models/draws/DrawRetrieveResponse.kt | 1004 ++++++++++++- .../api/models/draws/DrawRunResponse.kt | 276 ++++ .../api/models/events/Event.kt | 169 ++- .../api/models/events/EventDetail.kt | 169 ++- .../api/models/events/EventListParams.kt | 158 +- .../api/models/events/EventListResponse.kt | 599 ++++++++ .../models/events/EventRetrieveResponse.kt | 642 +++++++++ .../extractions/ExtractionListResponse.kt | 761 +++++++++- .../api/models/integrations/Integration.kt | 154 +- .../integrations/IntegrationCreateParams.kt | 154 +- .../integrations/IntegrationCreateResponse.kt | 1045 ++++++++++++++ .../IntegrationListDeliveriesResponse.kt | 540 ++++++- .../integrations/IntegrationListResponse.kt | 1054 ++++++++++++++ .../IntegrationRetrieveResponse.kt | 1045 ++++++++++++++ .../integrations/IntegrationUpdateParams.kt | 155 +- .../integrations/IntegrationUpdateResponse.kt | 1045 ++++++++++++++ .../api/models/monitors/Monitor.kt | 155 +- .../models/monitors/MonitorCreateParams.kt | 155 +- .../models/monitors/MonitorCreateResponse.kt | 155 +- .../models/monitors/MonitorListResponse.kt | 529 +++++++ .../monitors/MonitorRetrieveResponse.kt | 522 +++++++ .../models/monitors/MonitorUpdateParams.kt | 155 +- .../models/monitors/MonitorUpdateResponse.kt | 522 +++++++ .../RadarRetrieveTrendingTopicsResponse.kt | 496 ++++++- .../api/models/styles/StyleAnalyzeResponse.kt | 609 ++++++++ .../api/models/styles/StyleCompareResponse.kt | 1276 ++++++++++++++++- .../api/models/styles/StyleListResponse.kt | 312 +++- .../models/styles/StyleRetrieveResponse.kt | 609 ++++++++ .../api/models/styles/StyleUpdateResponse.kt | 609 ++++++++ .../api/models/webhooks/Webhook.kt | 155 +- .../models/webhooks/WebhookCreateParams.kt | 155 +- .../models/webhooks/WebhookCreateResponse.kt | 155 +- .../webhooks/WebhookListDeliveriesResponse.kt | 447 ++++++ .../models/webhooks/WebhookListResponse.kt | 484 +++++++ .../models/webhooks/WebhookUpdateParams.kt | 155 +- .../models/webhooks/WebhookUpdateResponse.kt | 489 +++++++ .../api/models/x/XGetArticleResponse.kt | 332 ++++- .../api/models/x/XGetHomeTimelineResponse.kt | 1037 ++++++++++++++ .../models/x/accounts/AccountListResponse.kt | 330 ++++- .../x/accounts/AccountRetrieveResponse.kt | 449 ++++++ .../x/bookmarks/BookmarkListResponse.kt | 1037 ++++++++++++++ .../x/communities/join/JoinCreateResponse.kt | 254 ++++ .../communities/join/JoinDeleteAllResponse.kt | 254 ++++ .../x/tweets/TweetGetFavoritersResponse.kt | 811 +++++++++++ .../models/x/tweets/TweetGetQuotesResponse.kt | 1037 ++++++++++++++ .../x/tweets/TweetGetRepliesResponse.kt | 1037 ++++++++++++++ .../x/tweets/TweetGetRetweetersResponse.kt | 811 +++++++++++ .../models/x/tweets/TweetGetThreadResponse.kt | 1037 ++++++++++++++ .../models/x/tweets/TweetRetrieveResponse.kt | 834 ++++++++++- .../models/x/tweets/TweetSearchResponse.kt | 1037 ++++++++++++++ .../UserRetrieveFollowersYouKnowResponse.kt | 815 +++++++++++ .../x/users/UserRetrieveLikesResponse.kt | 1037 ++++++++++++++ .../x/users/UserRetrieveMediaResponse.kt | 1037 ++++++++++++++ .../models/x/users/UserRetrieveResponse.kt | 534 +++++++ .../x/users/UserRetrieveTweetsResponse.kt | 1037 ++++++++++++++ .../api/services/async/DraftServiceAsync.kt | 43 +- .../services/async/DraftServiceAsyncImpl.kt | 19 +- .../api/services/async/EventServiceAsync.kt | 32 +- .../services/async/EventServiceAsyncImpl.kt | 10 +- .../services/async/IntegrationServiceAsync.kt | 74 +- .../async/IntegrationServiceAsyncImpl.kt | 28 +- .../api/services/async/MonitorServiceAsync.kt | 66 +- .../services/async/MonitorServiceAsyncImpl.kt | 18 +- .../api/services/async/StyleServiceAsync.kt | 60 +- .../services/async/StyleServiceAsyncImpl.kt | 28 +- .../api/services/async/WebhookServiceAsync.kt | 34 +- .../services/async/WebhookServiceAsyncImpl.kt | 9 +- .../api/services/async/XServiceAsync.kt | 20 +- .../api/services/async/XServiceAsyncImpl.kt | 10 +- .../services/async/x/AccountServiceAsync.kt | 29 +- .../async/x/AccountServiceAsyncImpl.kt | 10 +- .../services/async/x/BookmarkServiceAsync.kt | 19 +- .../async/x/BookmarkServiceAsyncImpl.kt | 10 +- .../api/services/async/x/TweetServiceAsync.kt | 159 +- .../services/async/x/TweetServiceAsyncImpl.kt | 56 +- .../api/services/async/x/UserServiceAsync.kt | 154 +- .../services/async/x/UserServiceAsyncImpl.kt | 48 +- .../async/x/communities/JoinServiceAsync.kt | 35 +- .../x/communities/JoinServiceAsyncImpl.kt | 19 +- .../api/services/blocking/DraftService.kt | 40 +- .../api/services/blocking/DraftServiceImpl.kt | 22 +- .../api/services/blocking/EventService.kt | 30 +- .../api/services/blocking/EventServiceImpl.kt | 10 +- .../services/blocking/IntegrationService.kt | 74 +- .../blocking/IntegrationServiceImpl.kt | 28 +- .../api/services/blocking/MonitorService.kt | 66 +- .../services/blocking/MonitorServiceImpl.kt | 24 +- .../api/services/blocking/StyleService.kt | 61 +- .../api/services/blocking/StyleServiceImpl.kt | 34 +- .../api/services/blocking/WebhookService.kt | 36 +- .../services/blocking/WebhookServiceImpl.kt | 12 +- .../api/services/blocking/XService.kt | 21 +- .../api/services/blocking/XServiceImpl.kt | 10 +- .../api/services/blocking/x/AccountService.kt | 29 +- .../services/blocking/x/AccountServiceImpl.kt | 10 +- .../services/blocking/x/BookmarkService.kt | 19 +- .../blocking/x/BookmarkServiceImpl.kt | 13 +- .../api/services/blocking/x/TweetService.kt | 144 +- .../services/blocking/x/TweetServiceImpl.kt | 56 +- .../api/services/blocking/x/UserService.kt | 153 +- .../services/blocking/x/UserServiceImpl.kt | 51 +- .../blocking/x/communities/JoinService.kt | 36 +- .../blocking/x/communities/JoinServiceImpl.kt | 19 +- .../api/models/PaginatedTweetsTest.kt | 13 +- .../api/models/PaginatedUsersTest.kt | 7 +- .../models/apikeys/ApiKeyListResponseTest.kt | 6 +- .../models/drafts/DraftCreateResponseTest.kt | 56 + .../models/drafts/DraftListResponseTest.kt | 6 +- .../drafts/DraftRetrieveResponseTest.kt | 56 + .../api/models/draws/DrawListResponseTest.kt | 6 +- .../models/draws/DrawRetrieveResponseTest.kt | 12 +- .../api/models/draws/DrawRunResponseTest.kt | 6 +- .../api/models/events/EventDetailTest.kt | 7 +- .../api/models/events/EventListParamsTest.kt | 5 +- .../models/events/EventListResponseTest.kt | 19 +- .../events/EventRetrieveResponseTest.kt | 72 + .../api/models/events/EventTest.kt | 7 +- .../extractions/ExtractionListResponseTest.kt | 18 +- .../IntegrationCreateParamsTest.kt | 7 +- .../IntegrationCreateResponseTest.kt | 99 ++ .../IntegrationListDeliveriesResponseTest.kt | 6 +- .../IntegrationListResponseTest.kt | 31 +- .../IntegrationRetrieveResponseTest.kt | 99 ++ .../models/integrations/IntegrationTest.kt | 7 +- .../IntegrationUpdateParamsTest.kt | 8 +- .../IntegrationUpdateResponseTest.kt | 99 ++ .../monitors/MonitorCreateParamsTest.kt | 10 +- .../monitors/MonitorCreateResponseTest.kt | 8 +- .../monitors/MonitorListResponseTest.kt | 13 +- .../monitors/MonitorRetrieveResponseTest.kt | 56 + .../api/models/monitors/MonitorTest.kt | 7 +- .../monitors/MonitorUpdateParamsTest.kt | 8 +- .../monitors/MonitorUpdateResponseTest.kt | 56 + ...RadarRetrieveTrendingTopicsResponseTest.kt | 6 +- .../models/styles/StyleAnalyzeResponseTest.kt | 74 + .../models/styles/StyleCompareResponseTest.kt | 24 +- .../models/styles/StyleListResponseTest.kt | 6 +- .../styles/StyleRetrieveResponseTest.kt | 74 + .../models/styles/StyleUpdateResponseTest.kt | 74 + .../webhooks/WebhookCreateParamsTest.kt | 7 +- .../webhooks/WebhookCreateResponseTest.kt | 8 +- .../WebhookListDeliveriesResponseTest.kt | 6 +- .../webhooks/WebhookListResponseTest.kt | 13 +- .../api/models/webhooks/WebhookTest.kt | 7 +- .../webhooks/WebhookUpdateParamsTest.kt | 8 +- .../webhooks/WebhookUpdateResponseTest.kt | 53 + .../api/models/x/XGetArticleResponseTest.kt | 7 +- .../models/x/XGetHomeTimelineResponseTest.kt | 105 ++ .../x/accounts/AccountListResponseTest.kt | 6 +- .../x/accounts/AccountRetrieveResponseTest.kt | 63 + .../x/bookmarks/BookmarkListResponseTest.kt | 105 ++ .../join/JoinCreateResponseTest.kt | 41 + .../join/JoinDeleteAllResponseTest.kt | 41 + .../tweets/TweetGetFavoritersResponseTest.kt | 87 ++ .../x/tweets/TweetGetQuotesResponseTest.kt | 105 ++ .../x/tweets/TweetGetRepliesResponseTest.kt | 105 ++ .../tweets/TweetGetRetweetersResponseTest.kt | 87 ++ .../x/tweets/TweetGetThreadResponseTest.kt | 105 ++ .../x/tweets/TweetRetrieveResponseTest.kt | 12 +- .../x/tweets/TweetSearchResponseTest.kt | 105 ++ ...serRetrieveFollowersYouKnowResponseTest.kt | 88 ++ .../x/users/UserRetrieveLikesResponseTest.kt | 105 ++ .../x/users/UserRetrieveMediaResponseTest.kt | 105 ++ .../x/users/UserRetrieveResponseTest.kt | 68 + .../x/users/UserRetrieveTweetsResponseTest.kt | 105 ++ .../services/async/DraftServiceAsyncTest.kt | 12 +- .../services/async/EventServiceAsyncTest.kt | 9 +- .../async/IntegrationServiceAsyncTest.kt | 5 +- .../services/async/MonitorServiceAsyncTest.kt | 5 +- .../services/async/StyleServiceAsyncTest.kt | 18 +- .../services/async/WebhookServiceAsyncTest.kt | 5 +- .../api/services/async/XServiceAsyncTest.kt | 6 +- .../async/x/AccountServiceAsyncTest.kt | 6 +- .../async/x/BookmarkServiceAsyncTest.kt | 6 +- .../services/async/x/TweetServiceAsyncTest.kt | 36 +- .../services/async/x/UserServiceAsyncTest.kt | 30 +- .../x/communities/JoinServiceAsyncTest.kt | 12 +- .../api/services/blocking/DraftServiceTest.kt | 8 +- .../api/services/blocking/EventServiceTest.kt | 7 +- .../blocking/IntegrationServiceTest.kt | 5 +- .../services/blocking/MonitorServiceTest.kt | 5 +- .../api/services/blocking/StyleServiceTest.kt | 12 +- .../services/blocking/WebhookServiceTest.kt | 5 +- .../api/services/blocking/XServiceTest.kt | 4 +- .../services/blocking/x/AccountServiceTest.kt | 4 +- .../blocking/x/BookmarkServiceTest.kt | 4 +- .../services/blocking/x/TweetServiceTest.kt | 24 +- .../services/blocking/x/UserServiceTest.kt | 20 +- .../blocking/x/communities/JoinServiceTest.kt | 8 +- 198 files changed, 38557 insertions(+), 1394 deletions(-) create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftCreateResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftRetrieveResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventRetrieveResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationCreateResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationRetrieveResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationUpdateResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorRetrieveResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorUpdateResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleAnalyzeResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleRetrieveResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleUpdateResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/webhooks/WebhookUpdateResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/XGetHomeTimelineResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/accounts/AccountRetrieveResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/bookmarks/BookmarkListResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/communities/join/JoinCreateResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/communities/join/JoinDeleteAllResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/tweets/TweetGetFavoritersResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/tweets/TweetGetQuotesResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/tweets/TweetGetRepliesResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/tweets/TweetGetRetweetersResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/tweets/TweetGetThreadResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/tweets/TweetSearchResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/users/UserRetrieveFollowersYouKnowResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/users/UserRetrieveLikesResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/users/UserRetrieveMediaResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/users/UserRetrieveResponse.kt create mode 100644 x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/x/users/UserRetrieveTweetsResponse.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/drafts/DraftCreateResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/drafts/DraftRetrieveResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/events/EventRetrieveResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationCreateResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationRetrieveResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationUpdateResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorRetrieveResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorUpdateResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/styles/StyleAnalyzeResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/styles/StyleRetrieveResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/styles/StyleUpdateResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/webhooks/WebhookUpdateResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/XGetHomeTimelineResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/accounts/AccountRetrieveResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/bookmarks/BookmarkListResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/communities/join/JoinCreateResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/communities/join/JoinDeleteAllResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/tweets/TweetGetFavoritersResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/tweets/TweetGetQuotesResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/tweets/TweetGetRepliesResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/tweets/TweetGetRetweetersResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/tweets/TweetGetThreadResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/tweets/TweetSearchResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/users/UserRetrieveFollowersYouKnowResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/users/UserRetrieveLikesResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/users/UserRetrieveMediaResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/users/UserRetrieveResponseTest.kt create mode 100644 x-twitter-scraper-java-core/src/test/kotlin/com/x_twitter_scraper/api/models/x/users/UserRetrieveTweetsResponseTest.kt diff --git a/.stats.yml b/.stats.yml index 408e9b8..8e615a1 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 115 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/xquik%2Fx-twitter-scraper-fab8cd6999dbd1fc8e331b7f83d7af46d89bc35801f7a384534be7d65191da2c.yml -openapi_spec_hash: 72a97c6cb83103355099af6e0b0a19e1 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/xquik%2Fx-twitter-scraper-3b2c6c771ad1da0bbfeb0af115972929ed2c7fcd5e47a79556d66cd21431b224.yml +openapi_spec_hash: de2890233b68387bf5f9b6d19e7d87dc config_hash: fc946e63e0b0ca32b93bc437d58e470b diff --git a/README.md b/README.md index 6aa9e1a..bb3fc49 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,8 @@ This library requires Java 8 or later. ```java import com.x_twitter_scraper.api.client.XTwitterScraperClient; import com.x_twitter_scraper.api.client.okhttp.XTwitterScraperOkHttpClient; -import com.x_twitter_scraper.api.models.PaginatedTweets; import com.x_twitter_scraper.api.models.x.tweets.TweetSearchParams; +import com.x_twitter_scraper.api.models.x.tweets.TweetSearchResponse; // Configures using the `xtwitterscraper.apiKey`, `xtwitterscraper.bearerToken` and `xtwitterscraper.baseUrl` system properties // Or configures using the `X_TWITTER_SCRAPER_API_KEY`, `X_TWITTER_SCRAPER_BEARER_TOKEN` and `X_TWITTER_SCRAPER_BASE_URL` environment variables @@ -49,7 +49,7 @@ TweetSearchParams params = TweetSearchParams.builder() .q("from:elonmusk") .limit(10L) .build(); -PaginatedTweets paginatedTweets = client.x().tweets().search(params); +TweetSearchResponse response = client.x().tweets().search(params); ``` ## Client configuration @@ -124,7 +124,7 @@ The `withOptions()` method does not affect the original client or service. To send a request to the X Twitter Scraper API, build an instance of some `Params` class and pass it to the corresponding client method. When the response is received, it will be deserialized into an instance of a Java class. -For example, `client.x().tweets().search(...)` should be called with an instance of `TweetSearchParams`, and it will return an instance of `PaginatedTweets`. +For example, `client.x().tweets().search(...)` should be called with an instance of `TweetSearchParams`, and it will return an instance of `TweetSearchResponse`. ## Immutability @@ -141,8 +141,8 @@ The default client is synchronous. To switch to asynchronous execution, call the ```java import com.x_twitter_scraper.api.client.XTwitterScraperClient; import com.x_twitter_scraper.api.client.okhttp.XTwitterScraperOkHttpClient; -import com.x_twitter_scraper.api.models.PaginatedTweets; import com.x_twitter_scraper.api.models.x.tweets.TweetSearchParams; +import com.x_twitter_scraper.api.models.x.tweets.TweetSearchResponse; import java.util.concurrent.CompletableFuture; // Configures using the `xtwitterscraper.apiKey`, `xtwitterscraper.bearerToken` and `xtwitterscraper.baseUrl` system properties @@ -153,7 +153,7 @@ TweetSearchParams params = TweetSearchParams.builder() .q("from:elonmusk") .limit(10L) .build(); -CompletableFuture paginatedTweets = client.async().x().tweets().search(params); +CompletableFuture response = client.async().x().tweets().search(params); ``` Or create an asynchronous client from the beginning: @@ -161,8 +161,8 @@ Or create an asynchronous client from the beginning: ```java import com.x_twitter_scraper.api.client.XTwitterScraperClientAsync; import com.x_twitter_scraper.api.client.okhttp.XTwitterScraperOkHttpClientAsync; -import com.x_twitter_scraper.api.models.PaginatedTweets; import com.x_twitter_scraper.api.models.x.tweets.TweetSearchParams; +import com.x_twitter_scraper.api.models.x.tweets.TweetSearchResponse; import java.util.concurrent.CompletableFuture; // Configures using the `xtwitterscraper.apiKey`, `xtwitterscraper.bearerToken` and `xtwitterscraper.baseUrl` system properties @@ -173,7 +173,7 @@ TweetSearchParams params = TweetSearchParams.builder() .q("from:elonmusk") .limit(10L) .build(); -CompletableFuture paginatedTweets = client.x().tweets().search(params); +CompletableFuture response = client.x().tweets().search(params); ``` The asynchronous client supports the same options as the synchronous one, except most methods return `CompletableFuture`s. @@ -299,25 +299,25 @@ To access this data, prefix any HTTP method call on a client or service with `wi ```java import com.x_twitter_scraper.api.core.http.Headers; import com.x_twitter_scraper.api.core.http.HttpResponseFor; -import com.x_twitter_scraper.api.models.PaginatedTweets; import com.x_twitter_scraper.api.models.x.tweets.TweetSearchParams; +import com.x_twitter_scraper.api.models.x.tweets.TweetSearchResponse; TweetSearchParams params = TweetSearchParams.builder() .q("from:elonmusk") .limit(10L) .build(); -HttpResponseFor paginatedTweets = client.x().tweets().withRawResponse().search(params); +HttpResponseFor response = client.x().tweets().withRawResponse().search(params); -int statusCode = paginatedTweets.statusCode(); -Headers headers = paginatedTweets.headers(); +int statusCode = response.statusCode(); +Headers headers = response.headers(); ``` You can still deserialize the response into an instance of a Java class if needed: ```java -import com.x_twitter_scraper.api.models.PaginatedTweets; +import com.x_twitter_scraper.api.models.x.tweets.TweetSearchResponse; -PaginatedTweets parsedPaginatedTweets = paginatedTweets.parse(); +TweetSearchResponse parsedResponse = response.parse(); ``` ## Error handling @@ -415,9 +415,9 @@ Requests time out after 1 minute by default. To set a custom timeout, configure the method call using the `timeout` method: ```java -import com.x_twitter_scraper.api.models.PaginatedTweets; +import com.x_twitter_scraper.api.models.x.tweets.TweetSearchResponse; -PaginatedTweets paginatedTweets = client.x().tweets().search( +TweetSearchResponse response = client.x().tweets().search( params, RequestOptions.builder().timeout(Duration.ofSeconds(30)).build() ); ``` @@ -693,17 +693,17 @@ By default, the SDK will not throw an exception in this case. It will throw [`XT If you would prefer to check that the response is completely well-typed upfront, then either call `validate()`: ```java -import com.x_twitter_scraper.api.models.PaginatedTweets; +import com.x_twitter_scraper.api.models.x.tweets.TweetSearchResponse; -PaginatedTweets paginatedTweets = client.x().tweets().search(params).validate(); +TweetSearchResponse response = client.x().tweets().search(params).validate(); ``` Or configure the method call to validate the response using the `responseValidation` method: ```java -import com.x_twitter_scraper.api.models.PaginatedTweets; +import com.x_twitter_scraper.api.models.x.tweets.TweetSearchResponse; -PaginatedTweets paginatedTweets = client.x().tweets().search( +TweetSearchResponse response = client.x().tweets().search( params, RequestOptions.builder().responseValidation(true).build() ); ``` diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/PaginatedTweets.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/PaginatedTweets.kt index 5e8f256..2880aa9 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/PaginatedTweets.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/PaginatedTweets.kt @@ -14,9 +14,9 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException -import com.x_twitter_scraper.api.models.x.tweets.SearchTweet import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull class PaginatedTweets @@ -24,7 +24,7 @@ class PaginatedTweets private constructor( private val hasNextPage: JsonField, private val nextCursor: JsonField, - private val tweets: JsonField>, + private val tweets: JsonField>, private val additionalProperties: MutableMap, ) { @@ -36,9 +36,7 @@ private constructor( @JsonProperty("next_cursor") @ExcludeMissing nextCursor: JsonField = JsonMissing.of(), - @JsonProperty("tweets") - @ExcludeMissing - tweets: JsonField> = JsonMissing.of(), + @JsonProperty("tweets") @ExcludeMissing tweets: JsonField> = JsonMissing.of(), ) : this(hasNextPage, nextCursor, tweets, mutableMapOf()) /** @@ -57,7 +55,7 @@ private constructor( * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun tweets(): List = tweets.getRequired("tweets") + fun tweets(): List = tweets.getRequired("tweets") /** * Returns the raw JSON value of [hasNextPage]. @@ -80,7 +78,7 @@ private constructor( * * Unlike [tweets], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("tweets") @ExcludeMissing fun _tweets(): JsonField> = tweets + @JsonProperty("tweets") @ExcludeMissing fun _tweets(): JsonField> = tweets @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -114,7 +112,7 @@ private constructor( private var hasNextPage: JsonField? = null private var nextCursor: JsonField? = null - private var tweets: JsonField>? = null + private var tweets: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -147,25 +145,25 @@ private constructor( */ fun nextCursor(nextCursor: JsonField) = apply { this.nextCursor = nextCursor } - fun tweets(tweets: List) = tweets(JsonField.of(tweets)) + fun tweets(tweets: List) = tweets(JsonField.of(tweets)) /** * Sets [Builder.tweets] to an arbitrary JSON value. * - * You should usually call [Builder.tweets] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * You should usually call [Builder.tweets] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun tweets(tweets: JsonField>) = apply { + fun tweets(tweets: JsonField>) = apply { this.tweets = tweets.map { it.toMutableList() } } /** - * Adds a single [SearchTweet] to [tweets]. + * Adds a single [Tweet] to [tweets]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addTweet(tweet: SearchTweet) = apply { + fun addTweet(tweet: Tweet) = apply { tweets = (tweets ?: JsonField.of(mutableListOf())).also { checkKnown("tweets", it).add(tweet) @@ -246,6 +244,776 @@ private constructor( (if (nextCursor.asKnown().isPresent) 1 else 0) + (tweets.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class Tweet + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val text: JsonField, + private val author: JsonField, + private val bookmarkCount: JsonField, + private val createdAt: JsonField, + private val likeCount: JsonField, + private val quoteCount: JsonField, + private val replyCount: JsonField, + private val retweetCount: JsonField, + private val viewCount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("author") @ExcludeMissing author: JsonField = JsonMissing.of(), + @JsonProperty("bookmarkCount") + @ExcludeMissing + bookmarkCount: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("likeCount") + @ExcludeMissing + likeCount: JsonField = JsonMissing.of(), + @JsonProperty("quoteCount") + @ExcludeMissing + quoteCount: JsonField = JsonMissing.of(), + @JsonProperty("replyCount") + @ExcludeMissing + replyCount: JsonField = JsonMissing.of(), + @JsonProperty("retweetCount") + @ExcludeMissing + retweetCount: JsonField = JsonMissing.of(), + @JsonProperty("viewCount") @ExcludeMissing viewCount: JsonField = JsonMissing.of(), + ) : this( + id, + text, + author, + bookmarkCount, + createdAt, + likeCount, + quoteCount, + replyCount, + retweetCount, + viewCount, + mutableMapOf(), + ) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun text(): String = text.getRequired("text") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun author(): Optional = author.getOptional("author") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun bookmarkCount(): Optional = bookmarkCount.getOptional("bookmarkCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun likeCount(): Optional = likeCount.getOptional("likeCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun quoteCount(): Optional = quoteCount.getOptional("quoteCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun replyCount(): Optional = replyCount.getOptional("replyCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun retweetCount(): Optional = retweetCount.getOptional("retweetCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun viewCount(): Optional = viewCount.getOptional("viewCount") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + /** + * Returns the raw JSON value of [author]. + * + * Unlike [author], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("author") @ExcludeMissing fun _author(): JsonField = author + + /** + * Returns the raw JSON value of [bookmarkCount]. + * + * Unlike [bookmarkCount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("bookmarkCount") + @ExcludeMissing + fun _bookmarkCount(): JsonField = bookmarkCount + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [likeCount]. + * + * Unlike [likeCount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("likeCount") @ExcludeMissing fun _likeCount(): JsonField = likeCount + + /** + * Returns the raw JSON value of [quoteCount]. + * + * Unlike [quoteCount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("quoteCount") @ExcludeMissing fun _quoteCount(): JsonField = quoteCount + + /** + * Returns the raw JSON value of [replyCount]. + * + * Unlike [replyCount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("replyCount") @ExcludeMissing fun _replyCount(): JsonField = replyCount + + /** + * Returns the raw JSON value of [retweetCount]. + * + * Unlike [retweetCount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("retweetCount") + @ExcludeMissing + fun _retweetCount(): JsonField = retweetCount + + /** + * Returns the raw JSON value of [viewCount]. + * + * Unlike [viewCount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("viewCount") @ExcludeMissing fun _viewCount(): JsonField = viewCount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Tweet]. + * + * The following fields are required: + * ```java + * .id() + * .text() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Tweet]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var text: JsonField? = null + private var author: JsonField = JsonMissing.of() + private var bookmarkCount: JsonField = JsonMissing.of() + private var createdAt: JsonField = JsonMissing.of() + private var likeCount: JsonField = JsonMissing.of() + private var quoteCount: JsonField = JsonMissing.of() + private var replyCount: JsonField = JsonMissing.of() + private var retweetCount: JsonField = JsonMissing.of() + private var viewCount: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(tweet: Tweet) = apply { + id = tweet.id + text = tweet.text + author = tweet.author + bookmarkCount = tweet.bookmarkCount + createdAt = tweet.createdAt + likeCount = tweet.likeCount + quoteCount = tweet.quoteCount + replyCount = tweet.replyCount + retweetCount = tweet.retweetCount + viewCount = tweet.viewCount + additionalProperties = tweet.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun text(text: JsonField) = apply { this.text = text } + + fun author(author: Author) = author(JsonField.of(author)) + + /** + * Sets [Builder.author] to an arbitrary JSON value. + * + * You should usually call [Builder.author] with a well-typed [Author] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun author(author: JsonField) = apply { this.author = author } + + fun bookmarkCount(bookmarkCount: Long) = bookmarkCount(JsonField.of(bookmarkCount)) + + /** + * Sets [Builder.bookmarkCount] to an arbitrary JSON value. + * + * You should usually call [Builder.bookmarkCount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun bookmarkCount(bookmarkCount: JsonField) = apply { + this.bookmarkCount = bookmarkCount + } + + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + fun likeCount(likeCount: Long) = likeCount(JsonField.of(likeCount)) + + /** + * Sets [Builder.likeCount] to an arbitrary JSON value. + * + * You should usually call [Builder.likeCount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun likeCount(likeCount: JsonField) = apply { this.likeCount = likeCount } + + fun quoteCount(quoteCount: Long) = quoteCount(JsonField.of(quoteCount)) + + /** + * Sets [Builder.quoteCount] to an arbitrary JSON value. + * + * You should usually call [Builder.quoteCount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun quoteCount(quoteCount: JsonField) = apply { this.quoteCount = quoteCount } + + fun replyCount(replyCount: Long) = replyCount(JsonField.of(replyCount)) + + /** + * Sets [Builder.replyCount] to an arbitrary JSON value. + * + * You should usually call [Builder.replyCount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun replyCount(replyCount: JsonField) = apply { this.replyCount = replyCount } + + fun retweetCount(retweetCount: Long) = retweetCount(JsonField.of(retweetCount)) + + /** + * Sets [Builder.retweetCount] to an arbitrary JSON value. + * + * You should usually call [Builder.retweetCount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun retweetCount(retweetCount: JsonField) = apply { + this.retweetCount = retweetCount + } + + fun viewCount(viewCount: Long) = viewCount(JsonField.of(viewCount)) + + /** + * Sets [Builder.viewCount] to an arbitrary JSON value. + * + * You should usually call [Builder.viewCount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun viewCount(viewCount: JsonField) = apply { this.viewCount = viewCount } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Tweet]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .text() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tweet = + Tweet( + checkRequired("id", id), + checkRequired("text", text), + author, + bookmarkCount, + createdAt, + likeCount, + quoteCount, + replyCount, + retweetCount, + viewCount, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tweet = apply { + if (validated) { + return@apply + } + + id() + text() + author().ifPresent { it.validate() } + bookmarkCount() + createdAt() + likeCount() + quoteCount() + replyCount() + retweetCount() + viewCount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (text.asKnown().isPresent) 1 else 0) + + (author.asKnown().getOrNull()?.validity() ?: 0) + + (if (bookmarkCount.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (likeCount.asKnown().isPresent) 1 else 0) + + (if (quoteCount.asKnown().isPresent) 1 else 0) + + (if (replyCount.asKnown().isPresent) 1 else 0) + + (if (retweetCount.asKnown().isPresent) 1 else 0) + + (if (viewCount.asKnown().isPresent) 1 else 0) + + class Author + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val username: JsonField, + private val verified: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("username") + @ExcludeMissing + username: JsonField = JsonMissing.of(), + @JsonProperty("verified") + @ExcludeMissing + verified: JsonField = JsonMissing.of(), + ) : this(id, name, username, verified, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun name(): String = name.getRequired("name") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun username(): String = username.getRequired("username") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun verified(): Optional = verified.getOptional("verified") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [username]. + * + * Unlike [username], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("username") @ExcludeMissing fun _username(): JsonField = username + + /** + * Returns the raw JSON value of [verified]. + * + * Unlike [verified], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("verified") @ExcludeMissing fun _verified(): JsonField = verified + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Author]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * .username() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Author]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var name: JsonField? = null + private var username: JsonField? = null + private var verified: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(author: Author) = apply { + id = author.id + name = author.name + username = author.username + verified = author.verified + additionalProperties = author.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun username(username: String) = username(JsonField.of(username)) + + /** + * Sets [Builder.username] to an arbitrary JSON value. + * + * You should usually call [Builder.username] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun username(username: JsonField) = apply { this.username = username } + + fun verified(verified: Boolean) = verified(JsonField.of(verified)) + + /** + * Sets [Builder.verified] to an arbitrary JSON value. + * + * You should usually call [Builder.verified] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun verified(verified: JsonField) = apply { this.verified = verified } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Author]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * .username() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Author = + Author( + checkRequired("id", id), + checkRequired("name", name), + checkRequired("username", username), + verified, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Author = apply { + if (validated) { + return@apply + } + + id() + name() + username() + verified() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (username.asKnown().isPresent) 1 else 0) + + (if (verified.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Author && + id == other.id && + name == other.name && + username == other.username && + verified == other.verified && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, name, username, verified, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Author{id=$id, name=$name, username=$username, verified=$verified, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tweet && + id == other.id && + text == other.text && + author == other.author && + bookmarkCount == other.bookmarkCount && + createdAt == other.createdAt && + likeCount == other.likeCount && + quoteCount == other.quoteCount && + replyCount == other.replyCount && + retweetCount == other.retweetCount && + viewCount == other.viewCount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + text, + author, + bookmarkCount, + createdAt, + likeCount, + quoteCount, + replyCount, + retweetCount, + viewCount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tweet{id=$id, text=$text, author=$author, bookmarkCount=$bookmarkCount, createdAt=$createdAt, likeCount=$likeCount, quoteCount=$quoteCount, replyCount=$replyCount, retweetCount=$retweetCount, viewCount=$viewCount, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/PaginatedUsers.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/PaginatedUsers.kt index 50b15e7..c3e969c 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/PaginatedUsers.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/PaginatedUsers.kt @@ -14,9 +14,9 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException -import com.x_twitter_scraper.api.models.x.users.UserProfile import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull class PaginatedUsers @@ -24,7 +24,7 @@ class PaginatedUsers private constructor( private val hasNextPage: JsonField, private val nextCursor: JsonField, - private val users: JsonField>, + private val users: JsonField>, private val additionalProperties: MutableMap, ) { @@ -36,9 +36,7 @@ private constructor( @JsonProperty("next_cursor") @ExcludeMissing nextCursor: JsonField = JsonMissing.of(), - @JsonProperty("users") - @ExcludeMissing - users: JsonField> = JsonMissing.of(), + @JsonProperty("users") @ExcludeMissing users: JsonField> = JsonMissing.of(), ) : this(hasNextPage, nextCursor, users, mutableMapOf()) /** @@ -57,7 +55,7 @@ private constructor( * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun users(): List = users.getRequired("users") + fun users(): List = users.getRequired("users") /** * Returns the raw JSON value of [hasNextPage]. @@ -80,7 +78,7 @@ private constructor( * * Unlike [users], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("users") @ExcludeMissing fun _users(): JsonField> = users + @JsonProperty("users") @ExcludeMissing fun _users(): JsonField> = users @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -114,7 +112,7 @@ private constructor( private var hasNextPage: JsonField? = null private var nextCursor: JsonField? = null - private var users: JsonField>? = null + private var users: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -147,25 +145,25 @@ private constructor( */ fun nextCursor(nextCursor: JsonField) = apply { this.nextCursor = nextCursor } - fun users(users: List) = users(JsonField.of(users)) + fun users(users: List) = users(JsonField.of(users)) /** * Sets [Builder.users] to an arbitrary JSON value. * - * You should usually call [Builder.users] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * You should usually call [Builder.users] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun users(users: JsonField>) = apply { + fun users(users: JsonField>) = apply { this.users = users.map { it.toMutableList() } } /** - * Adds a single [UserProfile] to [users]. + * Adds a single [User] to [users]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addUser(user: UserProfile) = apply { + fun addUser(user: User) = apply { users = (users ?: JsonField.of(mutableListOf())).also { checkKnown("users", it).add(user) } } @@ -244,6 +242,552 @@ private constructor( (if (nextCursor.asKnown().isPresent) 1 else 0) + (users.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class User + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val name: JsonField, + private val username: JsonField, + private val createdAt: JsonField, + private val description: JsonField, + private val followers: JsonField, + private val following: JsonField, + private val location: JsonField, + private val profilePicture: JsonField, + private val statusesCount: JsonField, + private val verified: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("username") + @ExcludeMissing + username: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("followers") + @ExcludeMissing + followers: JsonField = JsonMissing.of(), + @JsonProperty("following") + @ExcludeMissing + following: JsonField = JsonMissing.of(), + @JsonProperty("location") + @ExcludeMissing + location: JsonField = JsonMissing.of(), + @JsonProperty("profilePicture") + @ExcludeMissing + profilePicture: JsonField = JsonMissing.of(), + @JsonProperty("statusesCount") + @ExcludeMissing + statusesCount: JsonField = JsonMissing.of(), + @JsonProperty("verified") + @ExcludeMissing + verified: JsonField = JsonMissing.of(), + ) : this( + id, + name, + username, + createdAt, + description, + followers, + following, + location, + profilePicture, + statusesCount, + verified, + mutableMapOf(), + ) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun name(): String = name.getRequired("name") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun username(): String = username.getRequired("username") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun followers(): Optional = followers.getOptional("followers") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun following(): Optional = following.getOptional("following") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun location(): Optional = location.getOptional("location") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun profilePicture(): Optional = profilePicture.getOptional("profilePicture") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun statusesCount(): Optional = statusesCount.getOptional("statusesCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun verified(): Optional = verified.getOptional("verified") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [username]. + * + * Unlike [username], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("username") @ExcludeMissing fun _username(): JsonField = username + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [followers]. + * + * Unlike [followers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("followers") @ExcludeMissing fun _followers(): JsonField = followers + + /** + * Returns the raw JSON value of [following]. + * + * Unlike [following], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("following") @ExcludeMissing fun _following(): JsonField = following + + /** + * Returns the raw JSON value of [location]. + * + * Unlike [location], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("location") @ExcludeMissing fun _location(): JsonField = location + + /** + * Returns the raw JSON value of [profilePicture]. + * + * Unlike [profilePicture], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("profilePicture") + @ExcludeMissing + fun _profilePicture(): JsonField = profilePicture + + /** + * Returns the raw JSON value of [statusesCount]. + * + * Unlike [statusesCount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("statusesCount") + @ExcludeMissing + fun _statusesCount(): JsonField = statusesCount + + /** + * Returns the raw JSON value of [verified]. + * + * Unlike [verified], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("verified") @ExcludeMissing fun _verified(): JsonField = verified + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [User]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * .username() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [User]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var name: JsonField? = null + private var username: JsonField? = null + private var createdAt: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var followers: JsonField = JsonMissing.of() + private var following: JsonField = JsonMissing.of() + private var location: JsonField = JsonMissing.of() + private var profilePicture: JsonField = JsonMissing.of() + private var statusesCount: JsonField = JsonMissing.of() + private var verified: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(user: User) = apply { + id = user.id + name = user.name + username = user.username + createdAt = user.createdAt + description = user.description + followers = user.followers + following = user.following + location = user.location + profilePicture = user.profilePicture + statusesCount = user.statusesCount + verified = user.verified + additionalProperties = user.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun username(username: String) = username(JsonField.of(username)) + + /** + * Sets [Builder.username] to an arbitrary JSON value. + * + * You should usually call [Builder.username] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun username(username: JsonField) = apply { this.username = username } + + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + fun followers(followers: Long) = followers(JsonField.of(followers)) + + /** + * Sets [Builder.followers] to an arbitrary JSON value. + * + * You should usually call [Builder.followers] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun followers(followers: JsonField) = apply { this.followers = followers } + + fun following(following: Long) = following(JsonField.of(following)) + + /** + * Sets [Builder.following] to an arbitrary JSON value. + * + * You should usually call [Builder.following] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun following(following: JsonField) = apply { this.following = following } + + fun location(location: String) = location(JsonField.of(location)) + + /** + * Sets [Builder.location] to an arbitrary JSON value. + * + * You should usually call [Builder.location] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun location(location: JsonField) = apply { this.location = location } + + fun profilePicture(profilePicture: String) = + profilePicture(JsonField.of(profilePicture)) + + /** + * Sets [Builder.profilePicture] to an arbitrary JSON value. + * + * You should usually call [Builder.profilePicture] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun profilePicture(profilePicture: JsonField) = apply { + this.profilePicture = profilePicture + } + + fun statusesCount(statusesCount: Long) = statusesCount(JsonField.of(statusesCount)) + + /** + * Sets [Builder.statusesCount] to an arbitrary JSON value. + * + * You should usually call [Builder.statusesCount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun statusesCount(statusesCount: JsonField) = apply { + this.statusesCount = statusesCount + } + + fun verified(verified: Boolean) = verified(JsonField.of(verified)) + + /** + * Sets [Builder.verified] to an arbitrary JSON value. + * + * You should usually call [Builder.verified] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun verified(verified: JsonField) = apply { this.verified = verified } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [User]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * .username() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): User = + User( + checkRequired("id", id), + checkRequired("name", name), + checkRequired("username", username), + createdAt, + description, + followers, + following, + location, + profilePicture, + statusesCount, + verified, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): User = apply { + if (validated) { + return@apply + } + + id() + name() + username() + createdAt() + description() + followers() + following() + location() + profilePicture() + statusesCount() + verified() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (username.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (followers.asKnown().isPresent) 1 else 0) + + (if (following.asKnown().isPresent) 1 else 0) + + (if (location.asKnown().isPresent) 1 else 0) + + (if (profilePicture.asKnown().isPresent) 1 else 0) + + (if (statusesCount.asKnown().isPresent) 1 else 0) + + (if (verified.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is User && + id == other.id && + name == other.name && + username == other.username && + createdAt == other.createdAt && + description == other.description && + followers == other.followers && + following == other.following && + location == other.location && + profilePicture == other.profilePicture && + statusesCount == other.statusesCount && + verified == other.verified && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + name, + username, + createdAt, + description, + followers, + following, + location, + profilePicture, + statusesCount, + verified, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "User{id=$id, name=$name, username=$username, createdAt=$createdAt, description=$description, followers=$followers, following=$following, location=$location, profilePicture=$profilePicture, statusesCount=$statusesCount, verified=$verified, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/apikeys/ApiKeyListResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/apikeys/ApiKeyListResponse.kt index dc1a8f1..cc46a86 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/apikeys/ApiKeyListResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/apikeys/ApiKeyListResponse.kt @@ -14,34 +14,36 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull class ApiKeyListResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val keys: JsonField>, + private val keys: JsonField>, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("keys") @ExcludeMissing keys: JsonField> = JsonMissing.of() + @JsonProperty("keys") @ExcludeMissing keys: JsonField> = JsonMissing.of() ) : this(keys, mutableMapOf()) /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun keys(): List = keys.getRequired("keys") + fun keys(): List = keys.getRequired("keys") /** * Returns the raw JSON value of [keys]. * * Unlike [keys], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("keys") @ExcludeMissing fun _keys(): JsonField> = keys + @JsonProperty("keys") @ExcludeMissing fun _keys(): JsonField> = keys @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -71,7 +73,7 @@ private constructor( /** A builder for [ApiKeyListResponse]. */ class Builder internal constructor() { - private var keys: JsonField>? = null + private var keys: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -80,25 +82,22 @@ private constructor( additionalProperties = apiKeyListResponse.additionalProperties.toMutableMap() } - fun keys(keys: List) = keys(JsonField.of(keys)) + fun keys(keys: List) = keys(JsonField.of(keys)) /** * Sets [Builder.keys] to an arbitrary JSON value. * - * You should usually call [Builder.keys] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * You should usually call [Builder.keys] with a well-typed `List` value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun keys(keys: JsonField>) = apply { - this.keys = keys.map { it.toMutableList() } - } + fun keys(keys: JsonField>) = apply { this.keys = keys.map { it.toMutableList() } } /** - * Adds a single [ApiKey] to [keys]. + * Adds a single [Key] to [keys]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addKey(key: ApiKey) = apply { + fun addKey(key: Key) = apply { keys = (keys ?: JsonField.of(mutableListOf())).also { checkKnown("keys", it).add(key) } } @@ -168,6 +167,353 @@ private constructor( internal fun validity(): Int = (keys.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class Key + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val isActive: JsonField, + private val name: JsonField, + private val prefix: JsonField, + private val lastUsedAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("isActive") + @ExcludeMissing + isActive: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("prefix") @ExcludeMissing prefix: JsonField = JsonMissing.of(), + @JsonProperty("lastUsedAt") + @ExcludeMissing + lastUsedAt: JsonField = JsonMissing.of(), + ) : this(id, createdAt, isActive, name, prefix, lastUsedAt, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun isActive(): Boolean = isActive.getRequired("isActive") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun name(): String = name.getRequired("name") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun prefix(): String = prefix.getRequired("prefix") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun lastUsedAt(): Optional = lastUsedAt.getOptional("lastUsedAt") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [isActive]. + * + * Unlike [isActive], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("isActive") @ExcludeMissing fun _isActive(): JsonField = isActive + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [prefix]. + * + * Unlike [prefix], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prefix") @ExcludeMissing fun _prefix(): JsonField = prefix + + /** + * Returns the raw JSON value of [lastUsedAt]. + * + * Unlike [lastUsedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("lastUsedAt") + @ExcludeMissing + fun _lastUsedAt(): JsonField = lastUsedAt + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Key]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .isActive() + * .name() + * .prefix() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Key]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var isActive: JsonField? = null + private var name: JsonField? = null + private var prefix: JsonField? = null + private var lastUsedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(key: Key) = apply { + id = key.id + createdAt = key.createdAt + isActive = key.isActive + name = key.name + prefix = key.prefix + lastUsedAt = key.lastUsedAt + additionalProperties = key.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { + this.createdAt = createdAt + } + + fun isActive(isActive: Boolean) = isActive(JsonField.of(isActive)) + + /** + * Sets [Builder.isActive] to an arbitrary JSON value. + * + * You should usually call [Builder.isActive] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isActive(isActive: JsonField) = apply { this.isActive = isActive } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun prefix(prefix: String) = prefix(JsonField.of(prefix)) + + /** + * Sets [Builder.prefix] to an arbitrary JSON value. + * + * You should usually call [Builder.prefix] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prefix(prefix: JsonField) = apply { this.prefix = prefix } + + fun lastUsedAt(lastUsedAt: OffsetDateTime) = lastUsedAt(JsonField.of(lastUsedAt)) + + /** + * Sets [Builder.lastUsedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.lastUsedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastUsedAt(lastUsedAt: JsonField) = apply { + this.lastUsedAt = lastUsedAt + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Key]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .isActive() + * .name() + * .prefix() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Key = + Key( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("isActive", isActive), + checkRequired("name", name), + checkRequired("prefix", prefix), + lastUsedAt, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Key = apply { + if (validated) { + return@apply + } + + id() + createdAt() + isActive() + name() + prefix() + lastUsedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (isActive.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (prefix.asKnown().isPresent) 1 else 0) + + (if (lastUsedAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Key && + id == other.id && + createdAt == other.createdAt && + isActive == other.isActive && + name == other.name && + prefix == other.prefix && + lastUsedAt == other.lastUsedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, isActive, name, prefix, lastUsedAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Key{id=$id, createdAt=$createdAt, isActive=$isActive, name=$name, prefix=$prefix, lastUsedAt=$lastUsedAt, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftCreateResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftCreateResponse.kt new file mode 100644 index 0000000..37fd934 --- /dev/null +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftCreateResponse.kt @@ -0,0 +1,347 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.x_twitter_scraper.api.models.drafts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.ExcludeMissing +import com.x_twitter_scraper.api.core.JsonField +import com.x_twitter_scraper.api.core.JsonMissing +import com.x_twitter_scraper.api.core.JsonValue +import com.x_twitter_scraper.api.core.checkRequired +import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional + +class DraftCreateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val text: JsonField, + private val updatedAt: JsonField, + private val goal: JsonField, + private val topic: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("updatedAt") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + @JsonProperty("goal") @ExcludeMissing goal: JsonField = JsonMissing.of(), + @JsonProperty("topic") @ExcludeMissing topic: JsonField = JsonMissing.of(), + ) : this(id, createdAt, text, updatedAt, goal, topic, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun text(): String = text.getRequired("text") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun updatedAt(): OffsetDateTime = updatedAt.getRequired("updatedAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun goal(): Optional = goal.getOptional("goal") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun topic(): Optional = topic.getOptional("topic") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updatedAt") + @ExcludeMissing + fun _updatedAt(): JsonField = updatedAt + + /** + * Returns the raw JSON value of [goal]. + * + * Unlike [goal], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("goal") @ExcludeMissing fun _goal(): JsonField = goal + + /** + * Returns the raw JSON value of [topic]. + * + * Unlike [topic], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("topic") @ExcludeMissing fun _topic(): JsonField = topic + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [DraftCreateResponse]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .text() + * .updatedAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DraftCreateResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var text: JsonField? = null + private var updatedAt: JsonField? = null + private var goal: JsonField = JsonMissing.of() + private var topic: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(draftCreateResponse: DraftCreateResponse) = apply { + id = draftCreateResponse.id + createdAt = draftCreateResponse.createdAt + text = draftCreateResponse.text + updatedAt = draftCreateResponse.updatedAt + goal = draftCreateResponse.goal + topic = draftCreateResponse.topic + additionalProperties = draftCreateResponse.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + fun updatedAt(updatedAt: OffsetDateTime) = updatedAt(JsonField.of(updatedAt)) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + fun goal(goal: String) = goal(JsonField.of(goal)) + + /** + * Sets [Builder.goal] to an arbitrary JSON value. + * + * You should usually call [Builder.goal] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun goal(goal: JsonField) = apply { this.goal = goal } + + fun topic(topic: String) = topic(JsonField.of(topic)) + + /** + * Sets [Builder.topic] to an arbitrary JSON value. + * + * You should usually call [Builder.topic] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun topic(topic: JsonField) = apply { this.topic = topic } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [DraftCreateResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .text() + * .updatedAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DraftCreateResponse = + DraftCreateResponse( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("text", text), + checkRequired("updatedAt", updatedAt), + goal, + topic, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): DraftCreateResponse = apply { + if (validated) { + return@apply + } + + id() + createdAt() + text() + updatedAt() + goal() + topic() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (text.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + (if (goal.asKnown().isPresent) 1 else 0) + + (if (topic.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DraftCreateResponse && + id == other.id && + createdAt == other.createdAt && + text == other.text && + updatedAt == other.updatedAt && + goal == other.goal && + topic == other.topic && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, text, updatedAt, goal, topic, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DraftCreateResponse{id=$id, createdAt=$createdAt, text=$text, updatedAt=$updatedAt, goal=$goal, topic=$topic, additionalProperties=$additionalProperties}" +} diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftListResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftListResponse.kt index ee471eb..da62295 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftListResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftListResponse.kt @@ -14,6 +14,7 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects import java.util.Optional @@ -235,6 +236,307 @@ private constructor( (if (hasMore.asKnown().isPresent) 1 else 0) + (if (nextCursor.asKnown().isPresent) 1 else 0) + class Draft + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val text: JsonField, + private val goal: JsonField, + private val topic: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("goal") @ExcludeMissing goal: JsonField = JsonMissing.of(), + @JsonProperty("topic") @ExcludeMissing topic: JsonField = JsonMissing.of(), + ) : this(id, createdAt, text, goal, topic, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun text(): String = text.getRequired("text") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun goal(): Optional = goal.getOptional("goal") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun topic(): Optional = topic.getOptional("topic") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + /** + * Returns the raw JSON value of [goal]. + * + * Unlike [goal], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("goal") @ExcludeMissing fun _goal(): JsonField = goal + + /** + * Returns the raw JSON value of [topic]. + * + * Unlike [topic], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("topic") @ExcludeMissing fun _topic(): JsonField = topic + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Draft]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .text() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Draft]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var text: JsonField? = null + private var goal: JsonField = JsonMissing.of() + private var topic: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(draft: Draft) = apply { + id = draft.id + createdAt = draft.createdAt + text = draft.text + goal = draft.goal + topic = draft.topic + additionalProperties = draft.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { + this.createdAt = createdAt + } + + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun text(text: JsonField) = apply { this.text = text } + + fun goal(goal: String) = goal(JsonField.of(goal)) + + /** + * Sets [Builder.goal] to an arbitrary JSON value. + * + * You should usually call [Builder.goal] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun goal(goal: JsonField) = apply { this.goal = goal } + + fun topic(topic: String) = topic(JsonField.of(topic)) + + /** + * Sets [Builder.topic] to an arbitrary JSON value. + * + * You should usually call [Builder.topic] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun topic(topic: JsonField) = apply { this.topic = topic } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Draft]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .text() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Draft = + Draft( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("text", text), + goal, + topic, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Draft = apply { + if (validated) { + return@apply + } + + id() + createdAt() + text() + goal() + topic() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (text.asKnown().isPresent) 1 else 0) + + (if (goal.asKnown().isPresent) 1 else 0) + + (if (topic.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Draft && + id == other.id && + createdAt == other.createdAt && + text == other.text && + goal == other.goal && + topic == other.topic && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, text, goal, topic, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Draft{id=$id, createdAt=$createdAt, text=$text, goal=$goal, topic=$topic, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftRetrieveResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftRetrieveResponse.kt new file mode 100644 index 0000000..45f2c57 --- /dev/null +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftRetrieveResponse.kt @@ -0,0 +1,347 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.x_twitter_scraper.api.models.drafts + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.ExcludeMissing +import com.x_twitter_scraper.api.core.JsonField +import com.x_twitter_scraper.api.core.JsonMissing +import com.x_twitter_scraper.api.core.JsonValue +import com.x_twitter_scraper.api.core.checkRequired +import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional + +class DraftRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val text: JsonField, + private val updatedAt: JsonField, + private val goal: JsonField, + private val topic: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("updatedAt") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + @JsonProperty("goal") @ExcludeMissing goal: JsonField = JsonMissing.of(), + @JsonProperty("topic") @ExcludeMissing topic: JsonField = JsonMissing.of(), + ) : this(id, createdAt, text, updatedAt, goal, topic, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun text(): String = text.getRequired("text") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun updatedAt(): OffsetDateTime = updatedAt.getRequired("updatedAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun goal(): Optional = goal.getOptional("goal") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun topic(): Optional = topic.getOptional("topic") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updatedAt") + @ExcludeMissing + fun _updatedAt(): JsonField = updatedAt + + /** + * Returns the raw JSON value of [goal]. + * + * Unlike [goal], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("goal") @ExcludeMissing fun _goal(): JsonField = goal + + /** + * Returns the raw JSON value of [topic]. + * + * Unlike [topic], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("topic") @ExcludeMissing fun _topic(): JsonField = topic + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [DraftRetrieveResponse]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .text() + * .updatedAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DraftRetrieveResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var text: JsonField? = null + private var updatedAt: JsonField? = null + private var goal: JsonField = JsonMissing.of() + private var topic: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(draftRetrieveResponse: DraftRetrieveResponse) = apply { + id = draftRetrieveResponse.id + createdAt = draftRetrieveResponse.createdAt + text = draftRetrieveResponse.text + updatedAt = draftRetrieveResponse.updatedAt + goal = draftRetrieveResponse.goal + topic = draftRetrieveResponse.topic + additionalProperties = draftRetrieveResponse.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + fun updatedAt(updatedAt: OffsetDateTime) = updatedAt(JsonField.of(updatedAt)) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + fun goal(goal: String) = goal(JsonField.of(goal)) + + /** + * Sets [Builder.goal] to an arbitrary JSON value. + * + * You should usually call [Builder.goal] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun goal(goal: JsonField) = apply { this.goal = goal } + + fun topic(topic: String) = topic(JsonField.of(topic)) + + /** + * Sets [Builder.topic] to an arbitrary JSON value. + * + * You should usually call [Builder.topic] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun topic(topic: JsonField) = apply { this.topic = topic } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [DraftRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .text() + * .updatedAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DraftRetrieveResponse = + DraftRetrieveResponse( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("text", text), + checkRequired("updatedAt", updatedAt), + goal, + topic, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): DraftRetrieveResponse = apply { + if (validated) { + return@apply + } + + id() + createdAt() + text() + updatedAt() + goal() + topic() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (text.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + (if (goal.asKnown().isPresent) 1 else 0) + + (if (topic.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DraftRetrieveResponse && + id == other.id && + createdAt == other.createdAt && + text == other.text && + updatedAt == other.updatedAt && + goal == other.goal && + topic == other.topic && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, text, updatedAt, goal, topic, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DraftRetrieveResponse{id=$id, createdAt=$createdAt, text=$text, updatedAt=$updatedAt, goal=$goal, topic=$topic, additionalProperties=$additionalProperties}" +} diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawListResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawListResponse.kt index 0dd6e51..fd73ddd 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawListResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawListResponse.kt @@ -14,6 +14,7 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects import java.util.Optional @@ -22,7 +23,7 @@ import kotlin.jvm.optionals.getOrNull class DrawListResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val draws: JsonField>, + private val draws: JsonField>, private val hasMore: JsonField, private val nextCursor: JsonField, private val additionalProperties: MutableMap, @@ -30,9 +31,7 @@ private constructor( @JsonCreator private constructor( - @JsonProperty("draws") - @ExcludeMissing - draws: JsonField> = JsonMissing.of(), + @JsonProperty("draws") @ExcludeMissing draws: JsonField> = JsonMissing.of(), @JsonProperty("hasMore") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), @JsonProperty("nextCursor") @ExcludeMissing nextCursor: JsonField = JsonMissing.of(), ) : this(draws, hasMore, nextCursor, mutableMapOf()) @@ -41,7 +40,7 @@ private constructor( * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun draws(): List = draws.getRequired("draws") + fun draws(): List = draws.getRequired("draws") /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is @@ -60,7 +59,7 @@ private constructor( * * Unlike [draws], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("draws") @ExcludeMissing fun _draws(): JsonField> = draws + @JsonProperty("draws") @ExcludeMissing fun _draws(): JsonField> = draws /** * Returns the raw JSON value of [hasMore]. @@ -105,7 +104,7 @@ private constructor( /** A builder for [DrawListResponse]. */ class Builder internal constructor() { - private var draws: JsonField>? = null + private var draws: JsonField>? = null private var hasMore: JsonField? = null private var nextCursor: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -118,25 +117,25 @@ private constructor( additionalProperties = drawListResponse.additionalProperties.toMutableMap() } - fun draws(draws: List) = draws(JsonField.of(draws)) + fun draws(draws: List) = draws(JsonField.of(draws)) /** * Sets [Builder.draws] to an arbitrary JSON value. * - * You should usually call [Builder.draws] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * You should usually call [Builder.draws] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun draws(draws: JsonField>) = apply { + fun draws(draws: JsonField>) = apply { this.draws = draws.map { it.toMutableList() } } /** - * Adds a single [DrawListItem] to [draws]. + * Adds a single [Draw] to [draws]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addDraw(draw: DrawListItem) = apply { + fun addDraw(draw: Draw) = apply { draws = (draws ?: JsonField.of(mutableListOf())).also { checkKnown("draws", it).add(draw) } } @@ -235,6 +234,416 @@ private constructor( (if (hasMore.asKnown().isPresent) 1 else 0) + (if (nextCursor.asKnown().isPresent) 1 else 0) + class Draw + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val status: JsonField, + private val totalEntries: JsonField, + private val tweetUrl: JsonField, + private val validEntries: JsonField, + private val drawnAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("totalEntries") + @ExcludeMissing + totalEntries: JsonField = JsonMissing.of(), + @JsonProperty("tweetUrl") + @ExcludeMissing + tweetUrl: JsonField = JsonMissing.of(), + @JsonProperty("validEntries") + @ExcludeMissing + validEntries: JsonField = JsonMissing.of(), + @JsonProperty("drawnAt") + @ExcludeMissing + drawnAt: JsonField = JsonMissing.of(), + ) : this( + id, + createdAt, + status, + totalEntries, + tweetUrl, + validEntries, + drawnAt, + mutableMapOf(), + ) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun status(): String = status.getRequired("status") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun totalEntries(): Long = totalEntries.getRequired("totalEntries") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetUrl(): String = tweetUrl.getRequired("tweetUrl") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun validEntries(): Long = validEntries.getRequired("validEntries") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun drawnAt(): Optional = drawnAt.getOptional("drawnAt") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [totalEntries]. + * + * Unlike [totalEntries], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("totalEntries") + @ExcludeMissing + fun _totalEntries(): JsonField = totalEntries + + /** + * Returns the raw JSON value of [tweetUrl]. + * + * Unlike [tweetUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tweetUrl") @ExcludeMissing fun _tweetUrl(): JsonField = tweetUrl + + /** + * Returns the raw JSON value of [validEntries]. + * + * Unlike [validEntries], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("validEntries") + @ExcludeMissing + fun _validEntries(): JsonField = validEntries + + /** + * Returns the raw JSON value of [drawnAt]. + * + * Unlike [drawnAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("drawnAt") @ExcludeMissing fun _drawnAt(): JsonField = drawnAt + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Draw]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .status() + * .totalEntries() + * .tweetUrl() + * .validEntries() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Draw]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var status: JsonField? = null + private var totalEntries: JsonField? = null + private var tweetUrl: JsonField? = null + private var validEntries: JsonField? = null + private var drawnAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(draw: Draw) = apply { + id = draw.id + createdAt = draw.createdAt + status = draw.status + totalEntries = draw.totalEntries + tweetUrl = draw.tweetUrl + validEntries = draw.validEntries + drawnAt = draw.drawnAt + additionalProperties = draw.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { + this.createdAt = createdAt + } + + fun status(status: String) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + fun totalEntries(totalEntries: Long) = totalEntries(JsonField.of(totalEntries)) + + /** + * Sets [Builder.totalEntries] to an arbitrary JSON value. + * + * You should usually call [Builder.totalEntries] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun totalEntries(totalEntries: JsonField) = apply { + this.totalEntries = totalEntries + } + + fun tweetUrl(tweetUrl: String) = tweetUrl(JsonField.of(tweetUrl)) + + /** + * Sets [Builder.tweetUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweetUrl(tweetUrl: JsonField) = apply { this.tweetUrl = tweetUrl } + + fun validEntries(validEntries: Long) = validEntries(JsonField.of(validEntries)) + + /** + * Sets [Builder.validEntries] to an arbitrary JSON value. + * + * You should usually call [Builder.validEntries] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun validEntries(validEntries: JsonField) = apply { + this.validEntries = validEntries + } + + fun drawnAt(drawnAt: OffsetDateTime) = drawnAt(JsonField.of(drawnAt)) + + /** + * Sets [Builder.drawnAt] to an arbitrary JSON value. + * + * You should usually call [Builder.drawnAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun drawnAt(drawnAt: JsonField) = apply { this.drawnAt = drawnAt } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Draw]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .status() + * .totalEntries() + * .tweetUrl() + * .validEntries() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Draw = + Draw( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("status", status), + checkRequired("totalEntries", totalEntries), + checkRequired("tweetUrl", tweetUrl), + checkRequired("validEntries", validEntries), + drawnAt, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Draw = apply { + if (validated) { + return@apply + } + + id() + createdAt() + status() + totalEntries() + tweetUrl() + validEntries() + drawnAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (status.asKnown().isPresent) 1 else 0) + + (if (totalEntries.asKnown().isPresent) 1 else 0) + + (if (tweetUrl.asKnown().isPresent) 1 else 0) + + (if (validEntries.asKnown().isPresent) 1 else 0) + + (if (drawnAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Draw && + id == other.id && + createdAt == other.createdAt && + status == other.status && + totalEntries == other.totalEntries && + tweetUrl == other.tweetUrl && + validEntries == other.validEntries && + drawnAt == other.drawnAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + status, + totalEntries, + tweetUrl, + validEntries, + drawnAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Draw{id=$id, createdAt=$createdAt, status=$status, totalEntries=$totalEntries, tweetUrl=$tweetUrl, validEntries=$validEntries, drawnAt=$drawnAt, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawRetrieveResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawRetrieveResponse.kt index 9caec9a..28fe343 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawRetrieveResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawRetrieveResponse.kt @@ -14,21 +14,23 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull class DrawRetrieveResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val draw: JsonField, + private val draw: JsonField, private val winners: JsonField>, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("draw") @ExcludeMissing draw: JsonField = JsonMissing.of(), + @JsonProperty("draw") @ExcludeMissing draw: JsonField = JsonMissing.of(), @JsonProperty("winners") @ExcludeMissing winners: JsonField> = JsonMissing.of(), ) : this(draw, winners, mutableMapOf()) @@ -36,7 +38,7 @@ private constructor( * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun draw(): DrawDetail = draw.getRequired("draw") + fun draw(): Draw = draw.getRequired("draw") /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is @@ -49,7 +51,7 @@ private constructor( * * Unlike [draw], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("draw") @ExcludeMissing fun _draw(): JsonField = draw + @JsonProperty("draw") @ExcludeMissing fun _draw(): JsonField = draw /** * Returns the raw JSON value of [winners]. @@ -87,7 +89,7 @@ private constructor( /** A builder for [DrawRetrieveResponse]. */ class Builder internal constructor() { - private var draw: JsonField? = null + private var draw: JsonField? = null private var winners: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -98,15 +100,15 @@ private constructor( additionalProperties = drawRetrieveResponse.additionalProperties.toMutableMap() } - fun draw(draw: DrawDetail) = draw(JsonField.of(draw)) + fun draw(draw: Draw) = draw(JsonField.of(draw)) /** * Sets [Builder.draw] to an arbitrary JSON value. * - * You should usually call [Builder.draw] with a well-typed [DrawDetail] value instead. This + * You should usually call [Builder.draw] with a well-typed [Draw] value instead. This * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun draw(draw: JsonField) = apply { this.draw = draw } + fun draw(draw: JsonField) = apply { this.draw = draw } fun winners(winners: List) = winners(JsonField.of(winners)) @@ -203,6 +205,992 @@ private constructor( (draw.asKnown().getOrNull()?.validity() ?: 0) + (winners.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class Draw + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val status: JsonField, + private val totalEntries: JsonField, + private val tweetAuthorUsername: JsonField, + private val tweetId: JsonField, + private val tweetLikeCount: JsonField, + private val tweetQuoteCount: JsonField, + private val tweetReplyCount: JsonField, + private val tweetRetweetCount: JsonField, + private val tweetText: JsonField, + private val tweetUrl: JsonField, + private val validEntries: JsonField, + private val drawnAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("totalEntries") + @ExcludeMissing + totalEntries: JsonField = JsonMissing.of(), + @JsonProperty("tweetAuthorUsername") + @ExcludeMissing + tweetAuthorUsername: JsonField = JsonMissing.of(), + @JsonProperty("tweetId") @ExcludeMissing tweetId: JsonField = JsonMissing.of(), + @JsonProperty("tweetLikeCount") + @ExcludeMissing + tweetLikeCount: JsonField = JsonMissing.of(), + @JsonProperty("tweetQuoteCount") + @ExcludeMissing + tweetQuoteCount: JsonField = JsonMissing.of(), + @JsonProperty("tweetReplyCount") + @ExcludeMissing + tweetReplyCount: JsonField = JsonMissing.of(), + @JsonProperty("tweetRetweetCount") + @ExcludeMissing + tweetRetweetCount: JsonField = JsonMissing.of(), + @JsonProperty("tweetText") + @ExcludeMissing + tweetText: JsonField = JsonMissing.of(), + @JsonProperty("tweetUrl") + @ExcludeMissing + tweetUrl: JsonField = JsonMissing.of(), + @JsonProperty("validEntries") + @ExcludeMissing + validEntries: JsonField = JsonMissing.of(), + @JsonProperty("drawnAt") + @ExcludeMissing + drawnAt: JsonField = JsonMissing.of(), + ) : this( + id, + createdAt, + status, + totalEntries, + tweetAuthorUsername, + tweetId, + tweetLikeCount, + tweetQuoteCount, + tweetReplyCount, + tweetRetweetCount, + tweetText, + tweetUrl, + validEntries, + drawnAt, + mutableMapOf(), + ) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun status(): String = status.getRequired("status") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun totalEntries(): Long = totalEntries.getRequired("totalEntries") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetAuthorUsername(): String = tweetAuthorUsername.getRequired("tweetAuthorUsername") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetId(): String = tweetId.getRequired("tweetId") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetLikeCount(): Long = tweetLikeCount.getRequired("tweetLikeCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetQuoteCount(): Long = tweetQuoteCount.getRequired("tweetQuoteCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetReplyCount(): Long = tweetReplyCount.getRequired("tweetReplyCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetRetweetCount(): Long = tweetRetweetCount.getRequired("tweetRetweetCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetText(): String = tweetText.getRequired("tweetText") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetUrl(): String = tweetUrl.getRequired("tweetUrl") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun validEntries(): Long = validEntries.getRequired("validEntries") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun drawnAt(): Optional = drawnAt.getOptional("drawnAt") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [totalEntries]. + * + * Unlike [totalEntries], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("totalEntries") + @ExcludeMissing + fun _totalEntries(): JsonField = totalEntries + + /** + * Returns the raw JSON value of [tweetAuthorUsername]. + * + * Unlike [tweetAuthorUsername], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tweetAuthorUsername") + @ExcludeMissing + fun _tweetAuthorUsername(): JsonField = tweetAuthorUsername + + /** + * Returns the raw JSON value of [tweetId]. + * + * Unlike [tweetId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tweetId") @ExcludeMissing fun _tweetId(): JsonField = tweetId + + /** + * Returns the raw JSON value of [tweetLikeCount]. + * + * Unlike [tweetLikeCount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tweetLikeCount") + @ExcludeMissing + fun _tweetLikeCount(): JsonField = tweetLikeCount + + /** + * Returns the raw JSON value of [tweetQuoteCount]. + * + * Unlike [tweetQuoteCount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tweetQuoteCount") + @ExcludeMissing + fun _tweetQuoteCount(): JsonField = tweetQuoteCount + + /** + * Returns the raw JSON value of [tweetReplyCount]. + * + * Unlike [tweetReplyCount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tweetReplyCount") + @ExcludeMissing + fun _tweetReplyCount(): JsonField = tweetReplyCount + + /** + * Returns the raw JSON value of [tweetRetweetCount]. + * + * Unlike [tweetRetweetCount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tweetRetweetCount") + @ExcludeMissing + fun _tweetRetweetCount(): JsonField = tweetRetweetCount + + /** + * Returns the raw JSON value of [tweetText]. + * + * Unlike [tweetText], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tweetText") @ExcludeMissing fun _tweetText(): JsonField = tweetText + + /** + * Returns the raw JSON value of [tweetUrl]. + * + * Unlike [tweetUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tweetUrl") @ExcludeMissing fun _tweetUrl(): JsonField = tweetUrl + + /** + * Returns the raw JSON value of [validEntries]. + * + * Unlike [validEntries], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("validEntries") + @ExcludeMissing + fun _validEntries(): JsonField = validEntries + + /** + * Returns the raw JSON value of [drawnAt]. + * + * Unlike [drawnAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("drawnAt") @ExcludeMissing fun _drawnAt(): JsonField = drawnAt + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Draw]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .status() + * .totalEntries() + * .tweetAuthorUsername() + * .tweetId() + * .tweetLikeCount() + * .tweetQuoteCount() + * .tweetReplyCount() + * .tweetRetweetCount() + * .tweetText() + * .tweetUrl() + * .validEntries() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Draw]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var status: JsonField? = null + private var totalEntries: JsonField? = null + private var tweetAuthorUsername: JsonField? = null + private var tweetId: JsonField? = null + private var tweetLikeCount: JsonField? = null + private var tweetQuoteCount: JsonField? = null + private var tweetReplyCount: JsonField? = null + private var tweetRetweetCount: JsonField? = null + private var tweetText: JsonField? = null + private var tweetUrl: JsonField? = null + private var validEntries: JsonField? = null + private var drawnAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(draw: Draw) = apply { + id = draw.id + createdAt = draw.createdAt + status = draw.status + totalEntries = draw.totalEntries + tweetAuthorUsername = draw.tweetAuthorUsername + tweetId = draw.tweetId + tweetLikeCount = draw.tweetLikeCount + tweetQuoteCount = draw.tweetQuoteCount + tweetReplyCount = draw.tweetReplyCount + tweetRetweetCount = draw.tweetRetweetCount + tweetText = draw.tweetText + tweetUrl = draw.tweetUrl + validEntries = draw.validEntries + drawnAt = draw.drawnAt + additionalProperties = draw.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { + this.createdAt = createdAt + } + + fun status(status: String) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + fun totalEntries(totalEntries: Long) = totalEntries(JsonField.of(totalEntries)) + + /** + * Sets [Builder.totalEntries] to an arbitrary JSON value. + * + * You should usually call [Builder.totalEntries] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun totalEntries(totalEntries: JsonField) = apply { + this.totalEntries = totalEntries + } + + fun tweetAuthorUsername(tweetAuthorUsername: String) = + tweetAuthorUsername(JsonField.of(tweetAuthorUsername)) + + /** + * Sets [Builder.tweetAuthorUsername] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetAuthorUsername] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun tweetAuthorUsername(tweetAuthorUsername: JsonField) = apply { + this.tweetAuthorUsername = tweetAuthorUsername + } + + fun tweetId(tweetId: String) = tweetId(JsonField.of(tweetId)) + + /** + * Sets [Builder.tweetId] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweetId(tweetId: JsonField) = apply { this.tweetId = tweetId } + + fun tweetLikeCount(tweetLikeCount: Long) = tweetLikeCount(JsonField.of(tweetLikeCount)) + + /** + * Sets [Builder.tweetLikeCount] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetLikeCount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweetLikeCount(tweetLikeCount: JsonField) = apply { + this.tweetLikeCount = tweetLikeCount + } + + fun tweetQuoteCount(tweetQuoteCount: Long) = + tweetQuoteCount(JsonField.of(tweetQuoteCount)) + + /** + * Sets [Builder.tweetQuoteCount] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetQuoteCount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweetQuoteCount(tweetQuoteCount: JsonField) = apply { + this.tweetQuoteCount = tweetQuoteCount + } + + fun tweetReplyCount(tweetReplyCount: Long) = + tweetReplyCount(JsonField.of(tweetReplyCount)) + + /** + * Sets [Builder.tweetReplyCount] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetReplyCount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweetReplyCount(tweetReplyCount: JsonField) = apply { + this.tweetReplyCount = tweetReplyCount + } + + fun tweetRetweetCount(tweetRetweetCount: Long) = + tweetRetweetCount(JsonField.of(tweetRetweetCount)) + + /** + * Sets [Builder.tweetRetweetCount] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetRetweetCount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweetRetweetCount(tweetRetweetCount: JsonField) = apply { + this.tweetRetweetCount = tweetRetweetCount + } + + fun tweetText(tweetText: String) = tweetText(JsonField.of(tweetText)) + + /** + * Sets [Builder.tweetText] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetText] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweetText(tweetText: JsonField) = apply { this.tweetText = tweetText } + + fun tweetUrl(tweetUrl: String) = tweetUrl(JsonField.of(tweetUrl)) + + /** + * Sets [Builder.tweetUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweetUrl(tweetUrl: JsonField) = apply { this.tweetUrl = tweetUrl } + + fun validEntries(validEntries: Long) = validEntries(JsonField.of(validEntries)) + + /** + * Sets [Builder.validEntries] to an arbitrary JSON value. + * + * You should usually call [Builder.validEntries] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun validEntries(validEntries: JsonField) = apply { + this.validEntries = validEntries + } + + fun drawnAt(drawnAt: OffsetDateTime) = drawnAt(JsonField.of(drawnAt)) + + /** + * Sets [Builder.drawnAt] to an arbitrary JSON value. + * + * You should usually call [Builder.drawnAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun drawnAt(drawnAt: JsonField) = apply { this.drawnAt = drawnAt } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Draw]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .status() + * .totalEntries() + * .tweetAuthorUsername() + * .tweetId() + * .tweetLikeCount() + * .tweetQuoteCount() + * .tweetReplyCount() + * .tweetRetweetCount() + * .tweetText() + * .tweetUrl() + * .validEntries() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Draw = + Draw( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("status", status), + checkRequired("totalEntries", totalEntries), + checkRequired("tweetAuthorUsername", tweetAuthorUsername), + checkRequired("tweetId", tweetId), + checkRequired("tweetLikeCount", tweetLikeCount), + checkRequired("tweetQuoteCount", tweetQuoteCount), + checkRequired("tweetReplyCount", tweetReplyCount), + checkRequired("tweetRetweetCount", tweetRetweetCount), + checkRequired("tweetText", tweetText), + checkRequired("tweetUrl", tweetUrl), + checkRequired("validEntries", validEntries), + drawnAt, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Draw = apply { + if (validated) { + return@apply + } + + id() + createdAt() + status() + totalEntries() + tweetAuthorUsername() + tweetId() + tweetLikeCount() + tweetQuoteCount() + tweetReplyCount() + tweetRetweetCount() + tweetText() + tweetUrl() + validEntries() + drawnAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (status.asKnown().isPresent) 1 else 0) + + (if (totalEntries.asKnown().isPresent) 1 else 0) + + (if (tweetAuthorUsername.asKnown().isPresent) 1 else 0) + + (if (tweetId.asKnown().isPresent) 1 else 0) + + (if (tweetLikeCount.asKnown().isPresent) 1 else 0) + + (if (tweetQuoteCount.asKnown().isPresent) 1 else 0) + + (if (tweetReplyCount.asKnown().isPresent) 1 else 0) + + (if (tweetRetweetCount.asKnown().isPresent) 1 else 0) + + (if (tweetText.asKnown().isPresent) 1 else 0) + + (if (tweetUrl.asKnown().isPresent) 1 else 0) + + (if (validEntries.asKnown().isPresent) 1 else 0) + + (if (drawnAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Draw && + id == other.id && + createdAt == other.createdAt && + status == other.status && + totalEntries == other.totalEntries && + tweetAuthorUsername == other.tweetAuthorUsername && + tweetId == other.tweetId && + tweetLikeCount == other.tweetLikeCount && + tweetQuoteCount == other.tweetQuoteCount && + tweetReplyCount == other.tweetReplyCount && + tweetRetweetCount == other.tweetRetweetCount && + tweetText == other.tweetText && + tweetUrl == other.tweetUrl && + validEntries == other.validEntries && + drawnAt == other.drawnAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + status, + totalEntries, + tweetAuthorUsername, + tweetId, + tweetLikeCount, + tweetQuoteCount, + tweetReplyCount, + tweetRetweetCount, + tweetText, + tweetUrl, + validEntries, + drawnAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Draw{id=$id, createdAt=$createdAt, status=$status, totalEntries=$totalEntries, tweetAuthorUsername=$tweetAuthorUsername, tweetId=$tweetId, tweetLikeCount=$tweetLikeCount, tweetQuoteCount=$tweetQuoteCount, tweetReplyCount=$tweetReplyCount, tweetRetweetCount=$tweetRetweetCount, tweetText=$tweetText, tweetUrl=$tweetUrl, validEntries=$validEntries, drawnAt=$drawnAt, additionalProperties=$additionalProperties}" + } + + class Winner + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val authorUsername: JsonField, + private val isBackup: JsonField, + private val position: JsonField, + private val tweetId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("authorUsername") + @ExcludeMissing + authorUsername: JsonField = JsonMissing.of(), + @JsonProperty("isBackup") + @ExcludeMissing + isBackup: JsonField = JsonMissing.of(), + @JsonProperty("position") @ExcludeMissing position: JsonField = JsonMissing.of(), + @JsonProperty("tweetId") @ExcludeMissing tweetId: JsonField = JsonMissing.of(), + ) : this(authorUsername, isBackup, position, tweetId, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun authorUsername(): String = authorUsername.getRequired("authorUsername") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun isBackup(): Boolean = isBackup.getRequired("isBackup") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun position(): Long = position.getRequired("position") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetId(): String = tweetId.getRequired("tweetId") + + /** + * Returns the raw JSON value of [authorUsername]. + * + * Unlike [authorUsername], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("authorUsername") + @ExcludeMissing + fun _authorUsername(): JsonField = authorUsername + + /** + * Returns the raw JSON value of [isBackup]. + * + * Unlike [isBackup], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("isBackup") @ExcludeMissing fun _isBackup(): JsonField = isBackup + + /** + * Returns the raw JSON value of [position]. + * + * Unlike [position], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("position") @ExcludeMissing fun _position(): JsonField = position + + /** + * Returns the raw JSON value of [tweetId]. + * + * Unlike [tweetId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tweetId") @ExcludeMissing fun _tweetId(): JsonField = tweetId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Winner]. + * + * The following fields are required: + * ```java + * .authorUsername() + * .isBackup() + * .position() + * .tweetId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Winner]. */ + class Builder internal constructor() { + + private var authorUsername: JsonField? = null + private var isBackup: JsonField? = null + private var position: JsonField? = null + private var tweetId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(winner: Winner) = apply { + authorUsername = winner.authorUsername + isBackup = winner.isBackup + position = winner.position + tweetId = winner.tweetId + additionalProperties = winner.additionalProperties.toMutableMap() + } + + fun authorUsername(authorUsername: String) = + authorUsername(JsonField.of(authorUsername)) + + /** + * Sets [Builder.authorUsername] to an arbitrary JSON value. + * + * You should usually call [Builder.authorUsername] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun authorUsername(authorUsername: JsonField) = apply { + this.authorUsername = authorUsername + } + + fun isBackup(isBackup: Boolean) = isBackup(JsonField.of(isBackup)) + + /** + * Sets [Builder.isBackup] to an arbitrary JSON value. + * + * You should usually call [Builder.isBackup] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isBackup(isBackup: JsonField) = apply { this.isBackup = isBackup } + + fun position(position: Long) = position(JsonField.of(position)) + + /** + * Sets [Builder.position] to an arbitrary JSON value. + * + * You should usually call [Builder.position] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun position(position: JsonField) = apply { this.position = position } + + fun tweetId(tweetId: String) = tweetId(JsonField.of(tweetId)) + + /** + * Sets [Builder.tweetId] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweetId(tweetId: JsonField) = apply { this.tweetId = tweetId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Winner]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .authorUsername() + * .isBackup() + * .position() + * .tweetId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Winner = + Winner( + checkRequired("authorUsername", authorUsername), + checkRequired("isBackup", isBackup), + checkRequired("position", position), + checkRequired("tweetId", tweetId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Winner = apply { + if (validated) { + return@apply + } + + authorUsername() + isBackup() + position() + tweetId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (authorUsername.asKnown().isPresent) 1 else 0) + + (if (isBackup.asKnown().isPresent) 1 else 0) + + (if (position.asKnown().isPresent) 1 else 0) + + (if (tweetId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Winner && + authorUsername == other.authorUsername && + isBackup == other.isBackup && + position == other.position && + tweetId == other.tweetId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(authorUsername, isBackup, position, tweetId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Winner{authorUsername=$authorUsername, isBackup=$isBackup, position=$position, tweetId=$tweetId, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawRunResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawRunResponse.kt index ae4596e..0c4883f 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawRunResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawRunResponse.kt @@ -309,6 +309,282 @@ private constructor( (if (validEntries.asKnown().isPresent) 1 else 0) + (winners.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class Winner + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val authorUsername: JsonField, + private val isBackup: JsonField, + private val position: JsonField, + private val tweetId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("authorUsername") + @ExcludeMissing + authorUsername: JsonField = JsonMissing.of(), + @JsonProperty("isBackup") + @ExcludeMissing + isBackup: JsonField = JsonMissing.of(), + @JsonProperty("position") @ExcludeMissing position: JsonField = JsonMissing.of(), + @JsonProperty("tweetId") @ExcludeMissing tweetId: JsonField = JsonMissing.of(), + ) : this(authorUsername, isBackup, position, tweetId, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun authorUsername(): String = authorUsername.getRequired("authorUsername") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun isBackup(): Boolean = isBackup.getRequired("isBackup") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun position(): Long = position.getRequired("position") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetId(): String = tweetId.getRequired("tweetId") + + /** + * Returns the raw JSON value of [authorUsername]. + * + * Unlike [authorUsername], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("authorUsername") + @ExcludeMissing + fun _authorUsername(): JsonField = authorUsername + + /** + * Returns the raw JSON value of [isBackup]. + * + * Unlike [isBackup], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("isBackup") @ExcludeMissing fun _isBackup(): JsonField = isBackup + + /** + * Returns the raw JSON value of [position]. + * + * Unlike [position], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("position") @ExcludeMissing fun _position(): JsonField = position + + /** + * Returns the raw JSON value of [tweetId]. + * + * Unlike [tweetId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tweetId") @ExcludeMissing fun _tweetId(): JsonField = tweetId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Winner]. + * + * The following fields are required: + * ```java + * .authorUsername() + * .isBackup() + * .position() + * .tweetId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Winner]. */ + class Builder internal constructor() { + + private var authorUsername: JsonField? = null + private var isBackup: JsonField? = null + private var position: JsonField? = null + private var tweetId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(winner: Winner) = apply { + authorUsername = winner.authorUsername + isBackup = winner.isBackup + position = winner.position + tweetId = winner.tweetId + additionalProperties = winner.additionalProperties.toMutableMap() + } + + fun authorUsername(authorUsername: String) = + authorUsername(JsonField.of(authorUsername)) + + /** + * Sets [Builder.authorUsername] to an arbitrary JSON value. + * + * You should usually call [Builder.authorUsername] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun authorUsername(authorUsername: JsonField) = apply { + this.authorUsername = authorUsername + } + + fun isBackup(isBackup: Boolean) = isBackup(JsonField.of(isBackup)) + + /** + * Sets [Builder.isBackup] to an arbitrary JSON value. + * + * You should usually call [Builder.isBackup] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isBackup(isBackup: JsonField) = apply { this.isBackup = isBackup } + + fun position(position: Long) = position(JsonField.of(position)) + + /** + * Sets [Builder.position] to an arbitrary JSON value. + * + * You should usually call [Builder.position] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun position(position: JsonField) = apply { this.position = position } + + fun tweetId(tweetId: String) = tweetId(JsonField.of(tweetId)) + + /** + * Sets [Builder.tweetId] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweetId(tweetId: JsonField) = apply { this.tweetId = tweetId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Winner]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .authorUsername() + * .isBackup() + * .position() + * .tweetId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Winner = + Winner( + checkRequired("authorUsername", authorUsername), + checkRequired("isBackup", isBackup), + checkRequired("position", position), + checkRequired("tweetId", tweetId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Winner = apply { + if (validated) { + return@apply + } + + authorUsername() + isBackup() + position() + tweetId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (authorUsername.asKnown().isPresent) 1 else 0) + + (if (isBackup.asKnown().isPresent) 1 else 0) + + (if (position.asKnown().isPresent) 1 else 0) + + (if (tweetId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Winner && + authorUsername == other.authorUsername && + isBackup == other.isBackup && + position == other.position && + tweetId == other.tweetId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(authorUsername, isBackup, position, tweetId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Winner{authorUsername=$authorUsername, isBackup=$isBackup, position=$position, tweetId=$tweetId, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/Event.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/Event.kt index 0fdf720..ec20d19 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/Event.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/Event.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum import com.x_twitter_scraper.api.core.ExcludeMissing import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.JsonMissing @@ -13,7 +14,6 @@ import com.x_twitter_scraper.api.core.JsonValue import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException -import com.x_twitter_scraper.api.models.EventType import java.time.OffsetDateTime import java.util.Collections import java.util.Objects @@ -26,7 +26,7 @@ private constructor( private val data: JsonField, private val monitorId: JsonField, private val occurredAt: JsonField, - private val type: JsonField, + private val type: JsonField, private val username: JsonField, private val additionalProperties: MutableMap, ) { @@ -39,7 +39,7 @@ private constructor( @JsonProperty("occurredAt") @ExcludeMissing occurredAt: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), @JsonProperty("username") @ExcludeMissing username: JsonField = JsonMissing.of(), ) : this(id, data, monitorId, occurredAt, type, username, mutableMapOf()) @@ -71,7 +71,7 @@ private constructor( * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun type(): EventType = type.getRequired("type") + fun type(): Type = type.getRequired("type") /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is @@ -114,7 +114,7 @@ private constructor( * * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** * Returns the raw JSON value of [username]. @@ -160,7 +160,7 @@ private constructor( private var data: JsonField? = null private var monitorId: JsonField? = null private var occurredAt: JsonField? = null - private var type: JsonField? = null + private var type: JsonField? = null private var username: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -219,15 +219,15 @@ private constructor( this.occurredAt = occurredAt } - fun type(type: EventType) = type(JsonField.of(type)) + fun type(type: Type) = type(JsonField.of(type)) /** * Sets [Builder.type] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [EventType] value instead. This + * You should usually call [Builder.type] with a well-typed [Type] value instead. This * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun type(type: JsonField) = apply { this.type = type } + fun type(type: JsonField) = apply { this.type = type } fun username(username: String) = username(JsonField.of(username)) @@ -424,6 +424,157 @@ private constructor( override fun toString() = "Data{additionalProperties=$additionalProperties}" } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventDetail.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventDetail.kt index b090e97..c6b2f6b 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventDetail.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventDetail.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum import com.x_twitter_scraper.api.core.ExcludeMissing import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.JsonMissing @@ -13,7 +14,6 @@ import com.x_twitter_scraper.api.core.JsonValue import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException -import com.x_twitter_scraper.api.models.EventType import java.time.OffsetDateTime import java.util.Collections import java.util.Objects @@ -27,7 +27,7 @@ private constructor( private val data: JsonField, private val monitorId: JsonField, private val occurredAt: JsonField, - private val type: JsonField, + private val type: JsonField, private val username: JsonField, private val xEventId: JsonField, private val additionalProperties: MutableMap, @@ -41,7 +41,7 @@ private constructor( @JsonProperty("occurredAt") @ExcludeMissing occurredAt: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), @JsonProperty("username") @ExcludeMissing username: JsonField = JsonMissing.of(), @JsonProperty("xEventId") @ExcludeMissing xEventId: JsonField = JsonMissing.of(), ) : this(id, data, monitorId, occurredAt, type, username, xEventId, mutableMapOf()) @@ -74,7 +74,7 @@ private constructor( * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun type(): EventType = type.getRequired("type") + fun type(): Type = type.getRequired("type") /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is @@ -123,7 +123,7 @@ private constructor( * * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** * Returns the raw JSON value of [username]. @@ -176,7 +176,7 @@ private constructor( private var data: JsonField? = null private var monitorId: JsonField? = null private var occurredAt: JsonField? = null - private var type: JsonField? = null + private var type: JsonField? = null private var username: JsonField? = null private var xEventId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -237,15 +237,15 @@ private constructor( this.occurredAt = occurredAt } - fun type(type: EventType) = type(JsonField.of(type)) + fun type(type: Type) = type(JsonField.of(type)) /** * Sets [Builder.type] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [EventType] value instead. This + * You should usually call [Builder.type] with a well-typed [Type] value instead. This * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun type(type: JsonField) = apply { this.type = type } + fun type(type: JsonField) = apply { this.type = type } fun username(username: String) = username(JsonField.of(username)) @@ -455,6 +455,157 @@ private constructor( override fun toString() = "Data{additionalProperties=$additionalProperties}" } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventListParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventListParams.kt index df67088..f61e383 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventListParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventListParams.kt @@ -2,10 +2,13 @@ package com.x_twitter_scraper.api.models.events +import com.fasterxml.jackson.annotation.JsonCreator +import com.x_twitter_scraper.api.core.Enum +import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.Params import com.x_twitter_scraper.api.core.http.Headers import com.x_twitter_scraper.api.core.http.QueryParams -import com.x_twitter_scraper.api.models.EventType +import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -221,6 +224,159 @@ private constructor( } .build() + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventListResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventListResponse.kt index 7dbcb1c..32fc614 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventListResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventListResponse.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum import com.x_twitter_scraper.api.core.ExcludeMissing import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.JsonMissing @@ -14,6 +15,7 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects import java.util.Optional @@ -235,6 +237,603 @@ private constructor( (if (hasMore.asKnown().isPresent) 1 else 0) + (if (nextCursor.asKnown().isPresent) 1 else 0) + class Event + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val data: JsonField, + private val monitorId: JsonField, + private val occurredAt: JsonField, + private val type: JsonField, + private val username: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("monitorId") + @ExcludeMissing + monitorId: JsonField = JsonMissing.of(), + @JsonProperty("occurredAt") + @ExcludeMissing + occurredAt: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("username") @ExcludeMissing username: JsonField = JsonMissing.of(), + ) : this(id, data, monitorId, occurredAt, type, username, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun data(): Data = data.getRequired("data") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun monitorId(): String = monitorId.getRequired("monitorId") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun occurredAt(): OffsetDateTime = occurredAt.getRequired("occurredAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun type(): Type = type.getRequired("type") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun username(): String = username.getRequired("username") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + + /** + * Returns the raw JSON value of [monitorId]. + * + * Unlike [monitorId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("monitorId") @ExcludeMissing fun _monitorId(): JsonField = monitorId + + /** + * Returns the raw JSON value of [occurredAt]. + * + * Unlike [occurredAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("occurredAt") + @ExcludeMissing + fun _occurredAt(): JsonField = occurredAt + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [username]. + * + * Unlike [username], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("username") @ExcludeMissing fun _username(): JsonField = username + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Event]. + * + * The following fields are required: + * ```java + * .id() + * .data() + * .monitorId() + * .occurredAt() + * .type() + * .username() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Event]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var data: JsonField? = null + private var monitorId: JsonField? = null + private var occurredAt: JsonField? = null + private var type: JsonField? = null + private var username: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(event: Event) = apply { + id = event.id + data = event.data + monitorId = event.monitorId + occurredAt = event.occurredAt + type = event.type + username = event.username + additionalProperties = event.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun data(data: Data) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [Data] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField) = apply { this.data = data } + + fun monitorId(monitorId: String) = monitorId(JsonField.of(monitorId)) + + /** + * Sets [Builder.monitorId] to an arbitrary JSON value. + * + * You should usually call [Builder.monitorId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun monitorId(monitorId: JsonField) = apply { this.monitorId = monitorId } + + fun occurredAt(occurredAt: OffsetDateTime) = occurredAt(JsonField.of(occurredAt)) + + /** + * Sets [Builder.occurredAt] to an arbitrary JSON value. + * + * You should usually call [Builder.occurredAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun occurredAt(occurredAt: JsonField) = apply { + this.occurredAt = occurredAt + } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun username(username: String) = username(JsonField.of(username)) + + /** + * Sets [Builder.username] to an arbitrary JSON value. + * + * You should usually call [Builder.username] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun username(username: JsonField) = apply { this.username = username } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Event]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .data() + * .monitorId() + * .occurredAt() + * .type() + * .username() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Event = + Event( + checkRequired("id", id), + checkRequired("data", data), + checkRequired("monitorId", monitorId), + checkRequired("occurredAt", occurredAt), + checkRequired("type", type), + checkRequired("username", username), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Event = apply { + if (validated) { + return@apply + } + + id() + data().validate() + monitorId() + occurredAt() + type().validate() + username() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (data.asKnown().getOrNull()?.validity() ?: 0) + + (if (monitorId.asKnown().isPresent) 1 else 0) + + (if (occurredAt.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (username.asKnown().isPresent) 1 else 0) + + class Data + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Data]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + additionalProperties = data.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Data = Data(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Data = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Data && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Data{additionalProperties=$additionalProperties}" + } + + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Event && + id == other.id && + data == other.data && + monitorId == other.monitorId && + occurredAt == other.occurredAt && + type == other.type && + username == other.username && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, data, monitorId, occurredAt, type, username, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Event{id=$id, data=$data, monitorId=$monitorId, occurredAt=$occurredAt, type=$type, username=$username, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventRetrieveResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventRetrieveResponse.kt new file mode 100644 index 0000000..e3ccc73 --- /dev/null +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventRetrieveResponse.kt @@ -0,0 +1,642 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.x_twitter_scraper.api.models.events + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum +import com.x_twitter_scraper.api.core.ExcludeMissing +import com.x_twitter_scraper.api.core.JsonField +import com.x_twitter_scraper.api.core.JsonMissing +import com.x_twitter_scraper.api.core.JsonValue +import com.x_twitter_scraper.api.core.checkRequired +import com.x_twitter_scraper.api.core.toImmutable +import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class EventRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val data: JsonField, + private val monitorId: JsonField, + private val occurredAt: JsonField, + private val type: JsonField, + private val username: JsonField, + private val xEventId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("monitorId") @ExcludeMissing monitorId: JsonField = JsonMissing.of(), + @JsonProperty("occurredAt") + @ExcludeMissing + occurredAt: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("username") @ExcludeMissing username: JsonField = JsonMissing.of(), + @JsonProperty("xEventId") @ExcludeMissing xEventId: JsonField = JsonMissing.of(), + ) : this(id, data, monitorId, occurredAt, type, username, xEventId, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): Data = data.getRequired("data") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun monitorId(): String = monitorId.getRequired("monitorId") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun occurredAt(): OffsetDateTime = occurredAt.getRequired("occurredAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun username(): String = username.getRequired("username") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun xEventId(): Optional = xEventId.getOptional("xEventId") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + + /** + * Returns the raw JSON value of [monitorId]. + * + * Unlike [monitorId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("monitorId") @ExcludeMissing fun _monitorId(): JsonField = monitorId + + /** + * Returns the raw JSON value of [occurredAt]. + * + * Unlike [occurredAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("occurredAt") + @ExcludeMissing + fun _occurredAt(): JsonField = occurredAt + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [username]. + * + * Unlike [username], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("username") @ExcludeMissing fun _username(): JsonField = username + + /** + * Returns the raw JSON value of [xEventId]. + * + * Unlike [xEventId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("xEventId") @ExcludeMissing fun _xEventId(): JsonField = xEventId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EventRetrieveResponse]. + * + * The following fields are required: + * ```java + * .id() + * .data() + * .monitorId() + * .occurredAt() + * .type() + * .username() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EventRetrieveResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var data: JsonField? = null + private var monitorId: JsonField? = null + private var occurredAt: JsonField? = null + private var type: JsonField? = null + private var username: JsonField? = null + private var xEventId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(eventRetrieveResponse: EventRetrieveResponse) = apply { + id = eventRetrieveResponse.id + data = eventRetrieveResponse.data + monitorId = eventRetrieveResponse.monitorId + occurredAt = eventRetrieveResponse.occurredAt + type = eventRetrieveResponse.type + username = eventRetrieveResponse.username + xEventId = eventRetrieveResponse.xEventId + additionalProperties = eventRetrieveResponse.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun data(data: Data) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [Data] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField) = apply { this.data = data } + + fun monitorId(monitorId: String) = monitorId(JsonField.of(monitorId)) + + /** + * Sets [Builder.monitorId] to an arbitrary JSON value. + * + * You should usually call [Builder.monitorId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun monitorId(monitorId: JsonField) = apply { this.monitorId = monitorId } + + fun occurredAt(occurredAt: OffsetDateTime) = occurredAt(JsonField.of(occurredAt)) + + /** + * Sets [Builder.occurredAt] to an arbitrary JSON value. + * + * You should usually call [Builder.occurredAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun occurredAt(occurredAt: JsonField) = apply { + this.occurredAt = occurredAt + } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun username(username: String) = username(JsonField.of(username)) + + /** + * Sets [Builder.username] to an arbitrary JSON value. + * + * You should usually call [Builder.username] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun username(username: JsonField) = apply { this.username = username } + + fun xEventId(xEventId: String) = xEventId(JsonField.of(xEventId)) + + /** + * Sets [Builder.xEventId] to an arbitrary JSON value. + * + * You should usually call [Builder.xEventId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun xEventId(xEventId: JsonField) = apply { this.xEventId = xEventId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .data() + * .monitorId() + * .occurredAt() + * .type() + * .username() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventRetrieveResponse = + EventRetrieveResponse( + checkRequired("id", id), + checkRequired("data", data), + checkRequired("monitorId", monitorId), + checkRequired("occurredAt", occurredAt), + checkRequired("type", type), + checkRequired("username", username), + xEventId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventRetrieveResponse = apply { + if (validated) { + return@apply + } + + id() + data().validate() + monitorId() + occurredAt() + type().validate() + username() + xEventId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (data.asKnown().getOrNull()?.validity() ?: 0) + + (if (monitorId.asKnown().isPresent) 1 else 0) + + (if (occurredAt.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (username.asKnown().isPresent) 1 else 0) + + (if (xEventId.asKnown().isPresent) 1 else 0) + + class Data + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Data]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + additionalProperties = data.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Data = Data(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Data = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Data && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Data{additionalProperties=$additionalProperties}" + } + + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventRetrieveResponse && + id == other.id && + data == other.data && + monitorId == other.monitorId && + occurredAt == other.occurredAt && + type == other.type && + username == other.username && + xEventId == other.xEventId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + data, + monitorId, + occurredAt, + type, + username, + xEventId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventRetrieveResponse{id=$id, data=$data, monitorId=$monitorId, occurredAt=$occurredAt, type=$type, username=$username, xEventId=$xEventId, additionalProperties=$additionalProperties}" +} diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionListResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionListResponse.kt index 4c0b10c..86aadc7 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionListResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionListResponse.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum import com.x_twitter_scraper.api.core.ExcludeMissing import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.JsonMissing @@ -14,6 +15,7 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects import java.util.Optional @@ -22,7 +24,7 @@ import kotlin.jvm.optionals.getOrNull class ExtractionListResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val extractions: JsonField>, + private val extractions: JsonField>, private val hasMore: JsonField, private val nextCursor: JsonField, private val additionalProperties: MutableMap, @@ -32,7 +34,7 @@ private constructor( private constructor( @JsonProperty("extractions") @ExcludeMissing - extractions: JsonField> = JsonMissing.of(), + extractions: JsonField> = JsonMissing.of(), @JsonProperty("hasMore") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), @JsonProperty("nextCursor") @ExcludeMissing nextCursor: JsonField = JsonMissing.of(), ) : this(extractions, hasMore, nextCursor, mutableMapOf()) @@ -41,7 +43,7 @@ private constructor( * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun extractions(): List = extractions.getRequired("extractions") + fun extractions(): List = extractions.getRequired("extractions") /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is @@ -62,7 +64,7 @@ private constructor( */ @JsonProperty("extractions") @ExcludeMissing - fun _extractions(): JsonField> = extractions + fun _extractions(): JsonField> = extractions /** * Returns the raw JSON value of [hasMore]. @@ -107,7 +109,7 @@ private constructor( /** A builder for [ExtractionListResponse]. */ class Builder internal constructor() { - private var extractions: JsonField>? = null + private var extractions: JsonField>? = null private var hasMore: JsonField? = null private var nextCursor: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -120,25 +122,25 @@ private constructor( additionalProperties = extractionListResponse.additionalProperties.toMutableMap() } - fun extractions(extractions: List) = extractions(JsonField.of(extractions)) + fun extractions(extractions: List) = extractions(JsonField.of(extractions)) /** * Sets [Builder.extractions] to an arbitrary JSON value. * - * You should usually call [Builder.extractions] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.extractions] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun extractions(extractions: JsonField>) = apply { + fun extractions(extractions: JsonField>) = apply { this.extractions = extractions.map { it.toMutableList() } } /** - * Adds a single [ExtractionJob] to [extractions]. + * Adds a single [Extraction] to [extractions]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addExtraction(extraction: ExtractionJob) = apply { + fun addExtraction(extraction: Extraction) = apply { extractions = (extractions ?: JsonField.of(mutableListOf())).also { checkKnown("extractions", it).add(extraction) @@ -239,6 +241,741 @@ private constructor( (if (hasMore.asKnown().isPresent) 1 else 0) + (if (nextCursor.asKnown().isPresent) 1 else 0) + class Extraction + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val status: JsonField, + private val toolType: JsonField, + private val totalResults: JsonField, + private val completedAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("toolType") + @ExcludeMissing + toolType: JsonField = JsonMissing.of(), + @JsonProperty("totalResults") + @ExcludeMissing + totalResults: JsonField = JsonMissing.of(), + @JsonProperty("completedAt") + @ExcludeMissing + completedAt: JsonField = JsonMissing.of(), + ) : this(id, createdAt, status, toolType, totalResults, completedAt, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun status(): Status = status.getRequired("status") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun toolType(): ToolType = toolType.getRequired("toolType") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun totalResults(): Long = totalResults.getRequired("totalResults") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun completedAt(): Optional = completedAt.getOptional("completedAt") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [toolType]. + * + * Unlike [toolType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("toolType") @ExcludeMissing fun _toolType(): JsonField = toolType + + /** + * Returns the raw JSON value of [totalResults]. + * + * Unlike [totalResults], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("totalResults") + @ExcludeMissing + fun _totalResults(): JsonField = totalResults + + /** + * Returns the raw JSON value of [completedAt]. + * + * Unlike [completedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("completedAt") + @ExcludeMissing + fun _completedAt(): JsonField = completedAt + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Extraction]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .status() + * .toolType() + * .totalResults() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Extraction]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var status: JsonField? = null + private var toolType: JsonField? = null + private var totalResults: JsonField? = null + private var completedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(extraction: Extraction) = apply { + id = extraction.id + createdAt = extraction.createdAt + status = extraction.status + toolType = extraction.toolType + totalResults = extraction.totalResults + completedAt = extraction.completedAt + additionalProperties = extraction.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { + this.createdAt = createdAt + } + + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + fun toolType(toolType: ToolType) = toolType(JsonField.of(toolType)) + + /** + * Sets [Builder.toolType] to an arbitrary JSON value. + * + * You should usually call [Builder.toolType] with a well-typed [ToolType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun toolType(toolType: JsonField) = apply { this.toolType = toolType } + + fun totalResults(totalResults: Long) = totalResults(JsonField.of(totalResults)) + + /** + * Sets [Builder.totalResults] to an arbitrary JSON value. + * + * You should usually call [Builder.totalResults] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun totalResults(totalResults: JsonField) = apply { + this.totalResults = totalResults + } + + fun completedAt(completedAt: OffsetDateTime) = completedAt(JsonField.of(completedAt)) + + /** + * Sets [Builder.completedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.completedAt] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun completedAt(completedAt: JsonField) = apply { + this.completedAt = completedAt + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Extraction]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .status() + * .toolType() + * .totalResults() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Extraction = + Extraction( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("status", status), + checkRequired("toolType", toolType), + checkRequired("totalResults", totalResults), + completedAt, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Extraction = apply { + if (validated) { + return@apply + } + + id() + createdAt() + status().validate() + toolType().validate() + totalResults() + completedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (toolType.asKnown().getOrNull()?.validity() ?: 0) + + (if (totalResults.asKnown().isPresent) 1 else 0) + + (if (completedAt.asKnown().isPresent) 1 else 0) + + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val RUNNING = of("running") + + @JvmField val COMPLETED = of("completed") + + @JvmField val FAILED = of("failed") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + RUNNING, + COMPLETED, + FAILED, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + RUNNING, + COMPLETED, + FAILED, + /** + * An enum member indicating that [Status] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + RUNNING -> Value.RUNNING + COMPLETED -> Value.COMPLETED + FAILED -> Value.FAILED + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + RUNNING -> Known.RUNNING + COMPLETED -> Known.COMPLETED + FAILED -> Known.FAILED + else -> throw XTwitterScraperInvalidDataException("Unknown Status: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Status = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Status && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class ToolType @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ARTICLE_EXTRACTOR = of("article_extractor") + + @JvmField val COMMUNITY_EXTRACTOR = of("community_extractor") + + @JvmField val COMMUNITY_MODERATOR_EXPLORER = of("community_moderator_explorer") + + @JvmField val COMMUNITY_POST_EXTRACTOR = of("community_post_extractor") + + @JvmField val COMMUNITY_SEARCH = of("community_search") + + @JvmField val FOLLOWER_EXPLORER = of("follower_explorer") + + @JvmField val FOLLOWING_EXPLORER = of("following_explorer") + + @JvmField val LIST_FOLLOWER_EXPLORER = of("list_follower_explorer") + + @JvmField val LIST_MEMBER_EXTRACTOR = of("list_member_extractor") + + @JvmField val LIST_POST_EXTRACTOR = of("list_post_extractor") + + @JvmField val MENTION_EXTRACTOR = of("mention_extractor") + + @JvmField val PEOPLE_SEARCH = of("people_search") + + @JvmField val POST_EXTRACTOR = of("post_extractor") + + @JvmField val QUOTE_EXTRACTOR = of("quote_extractor") + + @JvmField val REPLY_EXTRACTOR = of("reply_extractor") + + @JvmField val REPOST_EXTRACTOR = of("repost_extractor") + + @JvmField val SPACE_EXPLORER = of("space_explorer") + + @JvmField val THREAD_EXTRACTOR = of("thread_extractor") + + @JvmField val TWEET_SEARCH_EXTRACTOR = of("tweet_search_extractor") + + @JvmField val VERIFIED_FOLLOWER_EXPLORER = of("verified_follower_explorer") + + @JvmStatic fun of(value: String) = ToolType(JsonField.of(value)) + } + + /** An enum containing [ToolType]'s known values. */ + enum class Known { + ARTICLE_EXTRACTOR, + COMMUNITY_EXTRACTOR, + COMMUNITY_MODERATOR_EXPLORER, + COMMUNITY_POST_EXTRACTOR, + COMMUNITY_SEARCH, + FOLLOWER_EXPLORER, + FOLLOWING_EXPLORER, + LIST_FOLLOWER_EXPLORER, + LIST_MEMBER_EXTRACTOR, + LIST_POST_EXTRACTOR, + MENTION_EXTRACTOR, + PEOPLE_SEARCH, + POST_EXTRACTOR, + QUOTE_EXTRACTOR, + REPLY_EXTRACTOR, + REPOST_EXTRACTOR, + SPACE_EXPLORER, + THREAD_EXTRACTOR, + TWEET_SEARCH_EXTRACTOR, + VERIFIED_FOLLOWER_EXPLORER, + } + + /** + * An enum containing [ToolType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ToolType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ARTICLE_EXTRACTOR, + COMMUNITY_EXTRACTOR, + COMMUNITY_MODERATOR_EXPLORER, + COMMUNITY_POST_EXTRACTOR, + COMMUNITY_SEARCH, + FOLLOWER_EXPLORER, + FOLLOWING_EXPLORER, + LIST_FOLLOWER_EXPLORER, + LIST_MEMBER_EXTRACTOR, + LIST_POST_EXTRACTOR, + MENTION_EXTRACTOR, + PEOPLE_SEARCH, + POST_EXTRACTOR, + QUOTE_EXTRACTOR, + REPLY_EXTRACTOR, + REPOST_EXTRACTOR, + SPACE_EXPLORER, + THREAD_EXTRACTOR, + TWEET_SEARCH_EXTRACTOR, + VERIFIED_FOLLOWER_EXPLORER, + /** + * An enum member indicating that [ToolType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ARTICLE_EXTRACTOR -> Value.ARTICLE_EXTRACTOR + COMMUNITY_EXTRACTOR -> Value.COMMUNITY_EXTRACTOR + COMMUNITY_MODERATOR_EXPLORER -> Value.COMMUNITY_MODERATOR_EXPLORER + COMMUNITY_POST_EXTRACTOR -> Value.COMMUNITY_POST_EXTRACTOR + COMMUNITY_SEARCH -> Value.COMMUNITY_SEARCH + FOLLOWER_EXPLORER -> Value.FOLLOWER_EXPLORER + FOLLOWING_EXPLORER -> Value.FOLLOWING_EXPLORER + LIST_FOLLOWER_EXPLORER -> Value.LIST_FOLLOWER_EXPLORER + LIST_MEMBER_EXTRACTOR -> Value.LIST_MEMBER_EXTRACTOR + LIST_POST_EXTRACTOR -> Value.LIST_POST_EXTRACTOR + MENTION_EXTRACTOR -> Value.MENTION_EXTRACTOR + PEOPLE_SEARCH -> Value.PEOPLE_SEARCH + POST_EXTRACTOR -> Value.POST_EXTRACTOR + QUOTE_EXTRACTOR -> Value.QUOTE_EXTRACTOR + REPLY_EXTRACTOR -> Value.REPLY_EXTRACTOR + REPOST_EXTRACTOR -> Value.REPOST_EXTRACTOR + SPACE_EXPLORER -> Value.SPACE_EXPLORER + THREAD_EXTRACTOR -> Value.THREAD_EXTRACTOR + TWEET_SEARCH_EXTRACTOR -> Value.TWEET_SEARCH_EXTRACTOR + VERIFIED_FOLLOWER_EXPLORER -> Value.VERIFIED_FOLLOWER_EXPLORER + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ARTICLE_EXTRACTOR -> Known.ARTICLE_EXTRACTOR + COMMUNITY_EXTRACTOR -> Known.COMMUNITY_EXTRACTOR + COMMUNITY_MODERATOR_EXPLORER -> Known.COMMUNITY_MODERATOR_EXPLORER + COMMUNITY_POST_EXTRACTOR -> Known.COMMUNITY_POST_EXTRACTOR + COMMUNITY_SEARCH -> Known.COMMUNITY_SEARCH + FOLLOWER_EXPLORER -> Known.FOLLOWER_EXPLORER + FOLLOWING_EXPLORER -> Known.FOLLOWING_EXPLORER + LIST_FOLLOWER_EXPLORER -> Known.LIST_FOLLOWER_EXPLORER + LIST_MEMBER_EXTRACTOR -> Known.LIST_MEMBER_EXTRACTOR + LIST_POST_EXTRACTOR -> Known.LIST_POST_EXTRACTOR + MENTION_EXTRACTOR -> Known.MENTION_EXTRACTOR + PEOPLE_SEARCH -> Known.PEOPLE_SEARCH + POST_EXTRACTOR -> Known.POST_EXTRACTOR + QUOTE_EXTRACTOR -> Known.QUOTE_EXTRACTOR + REPLY_EXTRACTOR -> Known.REPLY_EXTRACTOR + REPOST_EXTRACTOR -> Known.REPOST_EXTRACTOR + SPACE_EXPLORER -> Known.SPACE_EXPLORER + THREAD_EXTRACTOR -> Known.THREAD_EXTRACTOR + TWEET_SEARCH_EXTRACTOR -> Known.TWEET_SEARCH_EXTRACTOR + VERIFIED_FOLLOWER_EXPLORER -> Known.VERIFIED_FOLLOWER_EXPLORER + else -> throw XTwitterScraperInvalidDataException("Unknown ToolType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): ToolType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Extraction && + id == other.id && + createdAt == other.createdAt && + status == other.status && + toolType == other.toolType && + totalResults == other.totalResults && + completedAt == other.completedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + status, + toolType, + totalResults, + completedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Extraction{id=$id, createdAt=$createdAt, status=$status, toolType=$toolType, totalResults=$totalResults, completedAt=$completedAt, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/Integration.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/Integration.kt index bc944b5..d5e93ca 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/Integration.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/Integration.kt @@ -15,7 +15,6 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException -import com.x_twitter_scraper.api.models.EventType import java.time.OffsetDateTime import java.util.Collections import java.util.Objects @@ -629,6 +628,159 @@ private constructor( override fun toString() = "Config{additionalProperties=$additionalProperties}" } + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { /** diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationCreateParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationCreateParams.kt index 1839f8d..da00f53 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationCreateParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationCreateParams.kt @@ -18,7 +18,6 @@ import com.x_twitter_scraper.api.core.http.Headers import com.x_twitter_scraper.api.core.http.QueryParams import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException -import com.x_twitter_scraper.api.models.EventType import java.util.Collections import java.util.Objects import kotlin.jvm.optionals.getOrNull @@ -776,6 +775,159 @@ private constructor( "Config{chatId=$chatId, additionalProperties=$additionalProperties}" } + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { /** diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationCreateResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationCreateResponse.kt new file mode 100644 index 0000000..ce362aa --- /dev/null +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationCreateResponse.kt @@ -0,0 +1,1045 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.x_twitter_scraper.api.models.integrations + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum +import com.x_twitter_scraper.api.core.ExcludeMissing +import com.x_twitter_scraper.api.core.JsonField +import com.x_twitter_scraper.api.core.JsonMissing +import com.x_twitter_scraper.api.core.JsonValue +import com.x_twitter_scraper.api.core.checkKnown +import com.x_twitter_scraper.api.core.checkRequired +import com.x_twitter_scraper.api.core.toImmutable +import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class IntegrationCreateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val config: JsonField, + private val createdAt: JsonField, + private val eventTypes: JsonField>, + private val isActive: JsonField, + private val name: JsonField, + private val type: JsonField, + private val filters: JsonField, + private val messageTemplate: JsonField, + private val scopeAllMonitors: JsonField, + private val silentPush: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("config") @ExcludeMissing config: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("eventTypes") + @ExcludeMissing + eventTypes: JsonField> = JsonMissing.of(), + @JsonProperty("isActive") @ExcludeMissing isActive: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("filters") @ExcludeMissing filters: JsonField = JsonMissing.of(), + @JsonProperty("messageTemplate") + @ExcludeMissing + messageTemplate: JsonField = JsonMissing.of(), + @JsonProperty("scopeAllMonitors") + @ExcludeMissing + scopeAllMonitors: JsonField = JsonMissing.of(), + @JsonProperty("silentPush") + @ExcludeMissing + silentPush: JsonField = JsonMissing.of(), + ) : this( + id, + config, + createdAt, + eventTypes, + isActive, + name, + type, + filters, + messageTemplate, + scopeAllMonitors, + silentPush, + mutableMapOf(), + ) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun config(): Config = config.getRequired("config") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun eventTypes(): List = eventTypes.getRequired("eventTypes") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun isActive(): Boolean = isActive.getRequired("isActive") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun filters(): Optional = filters.getOptional("filters") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun messageTemplate(): Optional = messageTemplate.getOptional("messageTemplate") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun scopeAllMonitors(): Optional = scopeAllMonitors.getOptional("scopeAllMonitors") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun silentPush(): Optional = silentPush.getOptional("silentPush") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [config]. + * + * Unlike [config], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("config") @ExcludeMissing fun _config(): JsonField = config + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [eventTypes]. + * + * Unlike [eventTypes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("eventTypes") + @ExcludeMissing + fun _eventTypes(): JsonField> = eventTypes + + /** + * Returns the raw JSON value of [isActive]. + * + * Unlike [isActive], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("isActive") @ExcludeMissing fun _isActive(): JsonField = isActive + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField = filters + + /** + * Returns the raw JSON value of [messageTemplate]. + * + * Unlike [messageTemplate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("messageTemplate") + @ExcludeMissing + fun _messageTemplate(): JsonField = messageTemplate + + /** + * Returns the raw JSON value of [scopeAllMonitors]. + * + * Unlike [scopeAllMonitors], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scopeAllMonitors") + @ExcludeMissing + fun _scopeAllMonitors(): JsonField = scopeAllMonitors + + /** + * Returns the raw JSON value of [silentPush]. + * + * Unlike [silentPush], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("silentPush") @ExcludeMissing fun _silentPush(): JsonField = silentPush + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [IntegrationCreateResponse]. + * + * The following fields are required: + * ```java + * .id() + * .config() + * .createdAt() + * .eventTypes() + * .isActive() + * .name() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IntegrationCreateResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var config: JsonField? = null + private var createdAt: JsonField? = null + private var eventTypes: JsonField>? = null + private var isActive: JsonField? = null + private var name: JsonField? = null + private var type: JsonField? = null + private var filters: JsonField = JsonMissing.of() + private var messageTemplate: JsonField = JsonMissing.of() + private var scopeAllMonitors: JsonField = JsonMissing.of() + private var silentPush: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(integrationCreateResponse: IntegrationCreateResponse) = apply { + id = integrationCreateResponse.id + config = integrationCreateResponse.config + createdAt = integrationCreateResponse.createdAt + eventTypes = integrationCreateResponse.eventTypes.map { it.toMutableList() } + isActive = integrationCreateResponse.isActive + name = integrationCreateResponse.name + type = integrationCreateResponse.type + filters = integrationCreateResponse.filters + messageTemplate = integrationCreateResponse.messageTemplate + scopeAllMonitors = integrationCreateResponse.scopeAllMonitors + silentPush = integrationCreateResponse.silentPush + additionalProperties = integrationCreateResponse.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun config(config: Config) = config(JsonField.of(config)) + + /** + * Sets [Builder.config] to an arbitrary JSON value. + * + * You should usually call [Builder.config] with a well-typed [Config] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun config(config: JsonField) = apply { this.config = config } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) + + /** + * Sets [Builder.eventTypes] to an arbitrary JSON value. + * + * You should usually call [Builder.eventTypes] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun eventTypes(eventTypes: JsonField>) = apply { + this.eventTypes = eventTypes.map { it.toMutableList() } + } + + /** + * Adds a single [EventType] to [eventTypes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEventType(eventType: EventType) = apply { + eventTypes = + (eventTypes ?: JsonField.of(mutableListOf())).also { + checkKnown("eventTypes", it).add(eventType) + } + } + + fun isActive(isActive: Boolean) = isActive(JsonField.of(isActive)) + + /** + * Sets [Builder.isActive] to an arbitrary JSON value. + * + * You should usually call [Builder.isActive] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun isActive(isActive: JsonField) = apply { this.isActive = isActive } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun filters(filters: Filters) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed [Filters] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField) = apply { this.filters = filters } + + fun messageTemplate(messageTemplate: String) = + messageTemplate(JsonField.of(messageTemplate)) + + /** + * Sets [Builder.messageTemplate] to an arbitrary JSON value. + * + * You should usually call [Builder.messageTemplate] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun messageTemplate(messageTemplate: JsonField) = apply { + this.messageTemplate = messageTemplate + } + + fun scopeAllMonitors(scopeAllMonitors: Boolean) = + scopeAllMonitors(JsonField.of(scopeAllMonitors)) + + /** + * Sets [Builder.scopeAllMonitors] to an arbitrary JSON value. + * + * You should usually call [Builder.scopeAllMonitors] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun scopeAllMonitors(scopeAllMonitors: JsonField) = apply { + this.scopeAllMonitors = scopeAllMonitors + } + + fun silentPush(silentPush: Boolean) = silentPush(JsonField.of(silentPush)) + + /** + * Sets [Builder.silentPush] to an arbitrary JSON value. + * + * You should usually call [Builder.silentPush] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun silentPush(silentPush: JsonField) = apply { this.silentPush = silentPush } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [IntegrationCreateResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .config() + * .createdAt() + * .eventTypes() + * .isActive() + * .name() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): IntegrationCreateResponse = + IntegrationCreateResponse( + checkRequired("id", id), + checkRequired("config", config), + checkRequired("createdAt", createdAt), + checkRequired("eventTypes", eventTypes).map { it.toImmutable() }, + checkRequired("isActive", isActive), + checkRequired("name", name), + checkRequired("type", type), + filters, + messageTemplate, + scopeAllMonitors, + silentPush, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): IntegrationCreateResponse = apply { + if (validated) { + return@apply + } + + id() + config().validate() + createdAt() + eventTypes().forEach { it.validate() } + isActive() + name() + type().validate() + filters().ifPresent { it.validate() } + messageTemplate() + scopeAllMonitors() + silentPush() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (config.asKnown().getOrNull()?.validity() ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (eventTypes.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (isActive.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (filters.asKnown().getOrNull()?.validity() ?: 0) + + (if (messageTemplate.asKnown().isPresent) 1 else 0) + + (if (scopeAllMonitors.asKnown().isPresent) 1 else 0) + + (if (silentPush.asKnown().isPresent) 1 else 0) + + class Config + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Config]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Config]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(config: Config) = apply { + additionalProperties = config.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Config]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Config = Config(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Config = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Config && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Config{additionalProperties=$additionalProperties}" + } + + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TELEGRAM = of("telegram") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TELEGRAM + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TELEGRAM, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TELEGRAM -> Value.TELEGRAM + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TELEGRAM -> Known.TELEGRAM + else -> throw XTwitterScraperInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Filters + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Filters]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Filters]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(filters: Filters) = apply { + additionalProperties = filters.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Filters = Filters(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Filters = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filters && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Filters{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IntegrationCreateResponse && + id == other.id && + config == other.config && + createdAt == other.createdAt && + eventTypes == other.eventTypes && + isActive == other.isActive && + name == other.name && + type == other.type && + filters == other.filters && + messageTemplate == other.messageTemplate && + scopeAllMonitors == other.scopeAllMonitors && + silentPush == other.silentPush && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + config, + createdAt, + eventTypes, + isActive, + name, + type, + filters, + messageTemplate, + scopeAllMonitors, + silentPush, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "IntegrationCreateResponse{id=$id, config=$config, createdAt=$createdAt, eventTypes=$eventTypes, isActive=$isActive, name=$name, type=$type, filters=$filters, messageTemplate=$messageTemplate, scopeAllMonitors=$scopeAllMonitors, silentPush=$silentPush, additionalProperties=$additionalProperties}" +} diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationListDeliveriesResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationListDeliveriesResponse.kt index a56505f..6caf9f4 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationListDeliveriesResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationListDeliveriesResponse.kt @@ -14,14 +14,16 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull class IntegrationListDeliveriesResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val deliveries: JsonField>, + private val deliveries: JsonField>, private val additionalProperties: MutableMap, ) { @@ -29,14 +31,14 @@ private constructor( private constructor( @JsonProperty("deliveries") @ExcludeMissing - deliveries: JsonField> = JsonMissing.of() + deliveries: JsonField> = JsonMissing.of() ) : this(deliveries, mutableMapOf()) /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun deliveries(): List = deliveries.getRequired("deliveries") + fun deliveries(): List = deliveries.getRequired("deliveries") /** * Returns the raw JSON value of [deliveries]. @@ -45,7 +47,7 @@ private constructor( */ @JsonProperty("deliveries") @ExcludeMissing - fun _deliveries(): JsonField> = deliveries + fun _deliveries(): JsonField> = deliveries @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -76,7 +78,7 @@ private constructor( /** A builder for [IntegrationListDeliveriesResponse]. */ class Builder internal constructor() { - private var deliveries: JsonField>? = null + private var deliveries: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -87,25 +89,25 @@ private constructor( integrationListDeliveriesResponse.additionalProperties.toMutableMap() } - fun deliveries(deliveries: List) = deliveries(JsonField.of(deliveries)) + fun deliveries(deliveries: List) = deliveries(JsonField.of(deliveries)) /** * Sets [Builder.deliveries] to an arbitrary JSON value. * - * You should usually call [Builder.deliveries] with a well-typed - * `List` value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. + * You should usually call [Builder.deliveries] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun deliveries(deliveries: JsonField>) = apply { + fun deliveries(deliveries: JsonField>) = apply { this.deliveries = deliveries.map { it.toMutableList() } } /** - * Adds a single [IntegrationDelivery] to [deliveries]. + * Adds a single [Delivery] to [deliveries]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addDelivery(delivery: IntegrationDelivery) = apply { + fun addDelivery(delivery: Delivery) = apply { deliveries = (deliveries ?: JsonField.of(mutableListOf())).also { checkKnown("deliveries", it).add(delivery) @@ -178,6 +180,520 @@ private constructor( internal fun validity(): Int = (deliveries.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class Delivery + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val attempts: JsonField, + private val createdAt: JsonField, + private val eventType: JsonField, + private val status: JsonField, + private val deliveredAt: JsonField, + private val lastError: JsonField, + private val lastStatusCode: JsonField, + private val sourceId: JsonField, + private val sourceType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("attempts") @ExcludeMissing attempts: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("eventType") + @ExcludeMissing + eventType: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("deliveredAt") + @ExcludeMissing + deliveredAt: JsonField = JsonMissing.of(), + @JsonProperty("lastError") + @ExcludeMissing + lastError: JsonField = JsonMissing.of(), + @JsonProperty("lastStatusCode") + @ExcludeMissing + lastStatusCode: JsonField = JsonMissing.of(), + @JsonProperty("sourceId") + @ExcludeMissing + sourceId: JsonField = JsonMissing.of(), + @JsonProperty("sourceType") + @ExcludeMissing + sourceType: JsonField = JsonMissing.of(), + ) : this( + id, + attempts, + createdAt, + eventType, + status, + deliveredAt, + lastError, + lastStatusCode, + sourceId, + sourceType, + mutableMapOf(), + ) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun attempts(): Long = attempts.getRequired("attempts") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventType(): String = eventType.getRequired("eventType") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun status(): String = status.getRequired("status") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun deliveredAt(): Optional = deliveredAt.getOptional("deliveredAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun lastError(): Optional = lastError.getOptional("lastError") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun lastStatusCode(): Optional = lastStatusCode.getOptional("lastStatusCode") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun sourceId(): Optional = sourceId.getOptional("sourceId") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun sourceType(): Optional = sourceType.getOptional("sourceType") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [attempts]. + * + * Unlike [attempts], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("attempts") @ExcludeMissing fun _attempts(): JsonField = attempts + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [eventType]. + * + * Unlike [eventType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("eventType") @ExcludeMissing fun _eventType(): JsonField = eventType + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [deliveredAt]. + * + * Unlike [deliveredAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("deliveredAt") + @ExcludeMissing + fun _deliveredAt(): JsonField = deliveredAt + + /** + * Returns the raw JSON value of [lastError]. + * + * Unlike [lastError], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("lastError") @ExcludeMissing fun _lastError(): JsonField = lastError + + /** + * Returns the raw JSON value of [lastStatusCode]. + * + * Unlike [lastStatusCode], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("lastStatusCode") + @ExcludeMissing + fun _lastStatusCode(): JsonField = lastStatusCode + + /** + * Returns the raw JSON value of [sourceId]. + * + * Unlike [sourceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sourceId") @ExcludeMissing fun _sourceId(): JsonField = sourceId + + /** + * Returns the raw JSON value of [sourceType]. + * + * Unlike [sourceType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sourceType") + @ExcludeMissing + fun _sourceType(): JsonField = sourceType + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Delivery]. + * + * The following fields are required: + * ```java + * .id() + * .attempts() + * .createdAt() + * .eventType() + * .status() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Delivery]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var attempts: JsonField? = null + private var createdAt: JsonField? = null + private var eventType: JsonField? = null + private var status: JsonField? = null + private var deliveredAt: JsonField = JsonMissing.of() + private var lastError: JsonField = JsonMissing.of() + private var lastStatusCode: JsonField = JsonMissing.of() + private var sourceId: JsonField = JsonMissing.of() + private var sourceType: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(delivery: Delivery) = apply { + id = delivery.id + attempts = delivery.attempts + createdAt = delivery.createdAt + eventType = delivery.eventType + status = delivery.status + deliveredAt = delivery.deliveredAt + lastError = delivery.lastError + lastStatusCode = delivery.lastStatusCode + sourceId = delivery.sourceId + sourceType = delivery.sourceType + additionalProperties = delivery.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun attempts(attempts: Long) = attempts(JsonField.of(attempts)) + + /** + * Sets [Builder.attempts] to an arbitrary JSON value. + * + * You should usually call [Builder.attempts] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun attempts(attempts: JsonField) = apply { this.attempts = attempts } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { + this.createdAt = createdAt + } + + fun eventType(eventType: String) = eventType(JsonField.of(eventType)) + + /** + * Sets [Builder.eventType] to an arbitrary JSON value. + * + * You should usually call [Builder.eventType] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun eventType(eventType: JsonField) = apply { this.eventType = eventType } + + fun status(status: String) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + fun deliveredAt(deliveredAt: OffsetDateTime) = deliveredAt(JsonField.of(deliveredAt)) + + /** + * Sets [Builder.deliveredAt] to an arbitrary JSON value. + * + * You should usually call [Builder.deliveredAt] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun deliveredAt(deliveredAt: JsonField) = apply { + this.deliveredAt = deliveredAt + } + + fun lastError(lastError: String) = lastError(JsonField.of(lastError)) + + /** + * Sets [Builder.lastError] to an arbitrary JSON value. + * + * You should usually call [Builder.lastError] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastError(lastError: JsonField) = apply { this.lastError = lastError } + + fun lastStatusCode(lastStatusCode: Long) = lastStatusCode(JsonField.of(lastStatusCode)) + + /** + * Sets [Builder.lastStatusCode] to an arbitrary JSON value. + * + * You should usually call [Builder.lastStatusCode] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastStatusCode(lastStatusCode: JsonField) = apply { + this.lastStatusCode = lastStatusCode + } + + fun sourceId(sourceId: String) = sourceId(JsonField.of(sourceId)) + + /** + * Sets [Builder.sourceId] to an arbitrary JSON value. + * + * You should usually call [Builder.sourceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sourceId(sourceId: JsonField) = apply { this.sourceId = sourceId } + + fun sourceType(sourceType: String) = sourceType(JsonField.of(sourceType)) + + /** + * Sets [Builder.sourceType] to an arbitrary JSON value. + * + * You should usually call [Builder.sourceType] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sourceType(sourceType: JsonField) = apply { this.sourceType = sourceType } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Delivery]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .attempts() + * .createdAt() + * .eventType() + * .status() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Delivery = + Delivery( + checkRequired("id", id), + checkRequired("attempts", attempts), + checkRequired("createdAt", createdAt), + checkRequired("eventType", eventType), + checkRequired("status", status), + deliveredAt, + lastError, + lastStatusCode, + sourceId, + sourceType, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Delivery = apply { + if (validated) { + return@apply + } + + id() + attempts() + createdAt() + eventType() + status() + deliveredAt() + lastError() + lastStatusCode() + sourceId() + sourceType() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (attempts.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (eventType.asKnown().isPresent) 1 else 0) + + (if (status.asKnown().isPresent) 1 else 0) + + (if (deliveredAt.asKnown().isPresent) 1 else 0) + + (if (lastError.asKnown().isPresent) 1 else 0) + + (if (lastStatusCode.asKnown().isPresent) 1 else 0) + + (if (sourceId.asKnown().isPresent) 1 else 0) + + (if (sourceType.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Delivery && + id == other.id && + attempts == other.attempts && + createdAt == other.createdAt && + eventType == other.eventType && + status == other.status && + deliveredAt == other.deliveredAt && + lastError == other.lastError && + lastStatusCode == other.lastStatusCode && + sourceId == other.sourceId && + sourceType == other.sourceType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + attempts, + createdAt, + eventType, + status, + deliveredAt, + lastError, + lastStatusCode, + sourceId, + sourceType, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Delivery{id=$id, attempts=$attempts, createdAt=$createdAt, eventType=$eventType, status=$status, deliveredAt=$deliveredAt, lastError=$lastError, lastStatusCode=$lastStatusCode, sourceId=$sourceId, sourceType=$sourceType, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationListResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationListResponse.kt index 9a9f4a2..c75b31a 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationListResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationListResponse.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum import com.x_twitter_scraper.api.core.ExcludeMissing import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.JsonMissing @@ -14,8 +15,10 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull class IntegrationListResponse @@ -175,6 +178,1057 @@ private constructor( internal fun validity(): Int = (integrations.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class Integration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val config: JsonField, + private val createdAt: JsonField, + private val eventTypes: JsonField>, + private val isActive: JsonField, + private val name: JsonField, + private val type: JsonField, + private val filters: JsonField, + private val messageTemplate: JsonField, + private val scopeAllMonitors: JsonField, + private val silentPush: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("config") @ExcludeMissing config: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("eventTypes") + @ExcludeMissing + eventTypes: JsonField> = JsonMissing.of(), + @JsonProperty("isActive") + @ExcludeMissing + isActive: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("filters") @ExcludeMissing filters: JsonField = JsonMissing.of(), + @JsonProperty("messageTemplate") + @ExcludeMissing + messageTemplate: JsonField = JsonMissing.of(), + @JsonProperty("scopeAllMonitors") + @ExcludeMissing + scopeAllMonitors: JsonField = JsonMissing.of(), + @JsonProperty("silentPush") + @ExcludeMissing + silentPush: JsonField = JsonMissing.of(), + ) : this( + id, + config, + createdAt, + eventTypes, + isActive, + name, + type, + filters, + messageTemplate, + scopeAllMonitors, + silentPush, + mutableMapOf(), + ) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun config(): Config = config.getRequired("config") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventTypes(): List = eventTypes.getRequired("eventTypes") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun isActive(): Boolean = isActive.getRequired("isActive") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun name(): String = name.getRequired("name") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun type(): Type = type.getRequired("type") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun filters(): Optional = filters.getOptional("filters") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun messageTemplate(): Optional = messageTemplate.getOptional("messageTemplate") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun scopeAllMonitors(): Optional = scopeAllMonitors.getOptional("scopeAllMonitors") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun silentPush(): Optional = silentPush.getOptional("silentPush") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [config]. + * + * Unlike [config], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("config") @ExcludeMissing fun _config(): JsonField = config + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [eventTypes]. + * + * Unlike [eventTypes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("eventTypes") + @ExcludeMissing + fun _eventTypes(): JsonField> = eventTypes + + /** + * Returns the raw JSON value of [isActive]. + * + * Unlike [isActive], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("isActive") @ExcludeMissing fun _isActive(): JsonField = isActive + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField = filters + + /** + * Returns the raw JSON value of [messageTemplate]. + * + * Unlike [messageTemplate], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("messageTemplate") + @ExcludeMissing + fun _messageTemplate(): JsonField = messageTemplate + + /** + * Returns the raw JSON value of [scopeAllMonitors]. + * + * Unlike [scopeAllMonitors], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scopeAllMonitors") + @ExcludeMissing + fun _scopeAllMonitors(): JsonField = scopeAllMonitors + + /** + * Returns the raw JSON value of [silentPush]. + * + * Unlike [silentPush], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("silentPush") + @ExcludeMissing + fun _silentPush(): JsonField = silentPush + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Integration]. + * + * The following fields are required: + * ```java + * .id() + * .config() + * .createdAt() + * .eventTypes() + * .isActive() + * .name() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Integration]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var config: JsonField? = null + private var createdAt: JsonField? = null + private var eventTypes: JsonField>? = null + private var isActive: JsonField? = null + private var name: JsonField? = null + private var type: JsonField? = null + private var filters: JsonField = JsonMissing.of() + private var messageTemplate: JsonField = JsonMissing.of() + private var scopeAllMonitors: JsonField = JsonMissing.of() + private var silentPush: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(integration: Integration) = apply { + id = integration.id + config = integration.config + createdAt = integration.createdAt + eventTypes = integration.eventTypes.map { it.toMutableList() } + isActive = integration.isActive + name = integration.name + type = integration.type + filters = integration.filters + messageTemplate = integration.messageTemplate + scopeAllMonitors = integration.scopeAllMonitors + silentPush = integration.silentPush + additionalProperties = integration.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun config(config: Config) = config(JsonField.of(config)) + + /** + * Sets [Builder.config] to an arbitrary JSON value. + * + * You should usually call [Builder.config] with a well-typed [Config] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun config(config: JsonField) = apply { this.config = config } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { + this.createdAt = createdAt + } + + fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) + + /** + * Sets [Builder.eventTypes] to an arbitrary JSON value. + * + * You should usually call [Builder.eventTypes] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun eventTypes(eventTypes: JsonField>) = apply { + this.eventTypes = eventTypes.map { it.toMutableList() } + } + + /** + * Adds a single [EventType] to [eventTypes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEventType(eventType: EventType) = apply { + eventTypes = + (eventTypes ?: JsonField.of(mutableListOf())).also { + checkKnown("eventTypes", it).add(eventType) + } + } + + fun isActive(isActive: Boolean) = isActive(JsonField.of(isActive)) + + /** + * Sets [Builder.isActive] to an arbitrary JSON value. + * + * You should usually call [Builder.isActive] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isActive(isActive: JsonField) = apply { this.isActive = isActive } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun filters(filters: Filters) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed [Filters] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun filters(filters: JsonField) = apply { this.filters = filters } + + fun messageTemplate(messageTemplate: String) = + messageTemplate(JsonField.of(messageTemplate)) + + /** + * Sets [Builder.messageTemplate] to an arbitrary JSON value. + * + * You should usually call [Builder.messageTemplate] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun messageTemplate(messageTemplate: JsonField) = apply { + this.messageTemplate = messageTemplate + } + + fun scopeAllMonitors(scopeAllMonitors: Boolean) = + scopeAllMonitors(JsonField.of(scopeAllMonitors)) + + /** + * Sets [Builder.scopeAllMonitors] to an arbitrary JSON value. + * + * You should usually call [Builder.scopeAllMonitors] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun scopeAllMonitors(scopeAllMonitors: JsonField) = apply { + this.scopeAllMonitors = scopeAllMonitors + } + + fun silentPush(silentPush: Boolean) = silentPush(JsonField.of(silentPush)) + + /** + * Sets [Builder.silentPush] to an arbitrary JSON value. + * + * You should usually call [Builder.silentPush] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun silentPush(silentPush: JsonField) = apply { this.silentPush = silentPush } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Integration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .config() + * .createdAt() + * .eventTypes() + * .isActive() + * .name() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Integration = + Integration( + checkRequired("id", id), + checkRequired("config", config), + checkRequired("createdAt", createdAt), + checkRequired("eventTypes", eventTypes).map { it.toImmutable() }, + checkRequired("isActive", isActive), + checkRequired("name", name), + checkRequired("type", type), + filters, + messageTemplate, + scopeAllMonitors, + silentPush, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Integration = apply { + if (validated) { + return@apply + } + + id() + config().validate() + createdAt() + eventTypes().forEach { it.validate() } + isActive() + name() + type().validate() + filters().ifPresent { it.validate() } + messageTemplate() + scopeAllMonitors() + silentPush() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (config.asKnown().getOrNull()?.validity() ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (eventTypes.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (isActive.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (filters.asKnown().getOrNull()?.validity() ?: 0) + + (if (messageTemplate.asKnown().isPresent) 1 else 0) + + (if (scopeAllMonitors.asKnown().isPresent) 1 else 0) + + (if (silentPush.asKnown().isPresent) 1 else 0) + + class Config + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Config]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Config]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(config: Config) = apply { + additionalProperties = config.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Config]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Config = Config(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Config = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Config && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Config{additionalProperties=$additionalProperties}" + } + + class EventType @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TELEGRAM = of("telegram") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TELEGRAM + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TELEGRAM, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TELEGRAM -> Value.TELEGRAM + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TELEGRAM -> Known.TELEGRAM + else -> throw XTwitterScraperInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Filters + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Filters]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Filters]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(filters: Filters) = apply { + additionalProperties = filters.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Filters = Filters(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Filters = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filters && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Filters{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Integration && + id == other.id && + config == other.config && + createdAt == other.createdAt && + eventTypes == other.eventTypes && + isActive == other.isActive && + name == other.name && + type == other.type && + filters == other.filters && + messageTemplate == other.messageTemplate && + scopeAllMonitors == other.scopeAllMonitors && + silentPush == other.silentPush && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + config, + createdAt, + eventTypes, + isActive, + name, + type, + filters, + messageTemplate, + scopeAllMonitors, + silentPush, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Integration{id=$id, config=$config, createdAt=$createdAt, eventTypes=$eventTypes, isActive=$isActive, name=$name, type=$type, filters=$filters, messageTemplate=$messageTemplate, scopeAllMonitors=$scopeAllMonitors, silentPush=$silentPush, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationRetrieveResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationRetrieveResponse.kt new file mode 100644 index 0000000..fa24dc8 --- /dev/null +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationRetrieveResponse.kt @@ -0,0 +1,1045 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.x_twitter_scraper.api.models.integrations + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum +import com.x_twitter_scraper.api.core.ExcludeMissing +import com.x_twitter_scraper.api.core.JsonField +import com.x_twitter_scraper.api.core.JsonMissing +import com.x_twitter_scraper.api.core.JsonValue +import com.x_twitter_scraper.api.core.checkKnown +import com.x_twitter_scraper.api.core.checkRequired +import com.x_twitter_scraper.api.core.toImmutable +import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class IntegrationRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val config: JsonField, + private val createdAt: JsonField, + private val eventTypes: JsonField>, + private val isActive: JsonField, + private val name: JsonField, + private val type: JsonField, + private val filters: JsonField, + private val messageTemplate: JsonField, + private val scopeAllMonitors: JsonField, + private val silentPush: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("config") @ExcludeMissing config: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("eventTypes") + @ExcludeMissing + eventTypes: JsonField> = JsonMissing.of(), + @JsonProperty("isActive") @ExcludeMissing isActive: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("filters") @ExcludeMissing filters: JsonField = JsonMissing.of(), + @JsonProperty("messageTemplate") + @ExcludeMissing + messageTemplate: JsonField = JsonMissing.of(), + @JsonProperty("scopeAllMonitors") + @ExcludeMissing + scopeAllMonitors: JsonField = JsonMissing.of(), + @JsonProperty("silentPush") + @ExcludeMissing + silentPush: JsonField = JsonMissing.of(), + ) : this( + id, + config, + createdAt, + eventTypes, + isActive, + name, + type, + filters, + messageTemplate, + scopeAllMonitors, + silentPush, + mutableMapOf(), + ) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun config(): Config = config.getRequired("config") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun eventTypes(): List = eventTypes.getRequired("eventTypes") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun isActive(): Boolean = isActive.getRequired("isActive") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun filters(): Optional = filters.getOptional("filters") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun messageTemplate(): Optional = messageTemplate.getOptional("messageTemplate") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun scopeAllMonitors(): Optional = scopeAllMonitors.getOptional("scopeAllMonitors") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun silentPush(): Optional = silentPush.getOptional("silentPush") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [config]. + * + * Unlike [config], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("config") @ExcludeMissing fun _config(): JsonField = config + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [eventTypes]. + * + * Unlike [eventTypes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("eventTypes") + @ExcludeMissing + fun _eventTypes(): JsonField> = eventTypes + + /** + * Returns the raw JSON value of [isActive]. + * + * Unlike [isActive], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("isActive") @ExcludeMissing fun _isActive(): JsonField = isActive + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField = filters + + /** + * Returns the raw JSON value of [messageTemplate]. + * + * Unlike [messageTemplate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("messageTemplate") + @ExcludeMissing + fun _messageTemplate(): JsonField = messageTemplate + + /** + * Returns the raw JSON value of [scopeAllMonitors]. + * + * Unlike [scopeAllMonitors], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scopeAllMonitors") + @ExcludeMissing + fun _scopeAllMonitors(): JsonField = scopeAllMonitors + + /** + * Returns the raw JSON value of [silentPush]. + * + * Unlike [silentPush], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("silentPush") @ExcludeMissing fun _silentPush(): JsonField = silentPush + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [IntegrationRetrieveResponse]. + * + * The following fields are required: + * ```java + * .id() + * .config() + * .createdAt() + * .eventTypes() + * .isActive() + * .name() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IntegrationRetrieveResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var config: JsonField? = null + private var createdAt: JsonField? = null + private var eventTypes: JsonField>? = null + private var isActive: JsonField? = null + private var name: JsonField? = null + private var type: JsonField? = null + private var filters: JsonField = JsonMissing.of() + private var messageTemplate: JsonField = JsonMissing.of() + private var scopeAllMonitors: JsonField = JsonMissing.of() + private var silentPush: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(integrationRetrieveResponse: IntegrationRetrieveResponse) = apply { + id = integrationRetrieveResponse.id + config = integrationRetrieveResponse.config + createdAt = integrationRetrieveResponse.createdAt + eventTypes = integrationRetrieveResponse.eventTypes.map { it.toMutableList() } + isActive = integrationRetrieveResponse.isActive + name = integrationRetrieveResponse.name + type = integrationRetrieveResponse.type + filters = integrationRetrieveResponse.filters + messageTemplate = integrationRetrieveResponse.messageTemplate + scopeAllMonitors = integrationRetrieveResponse.scopeAllMonitors + silentPush = integrationRetrieveResponse.silentPush + additionalProperties = integrationRetrieveResponse.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun config(config: Config) = config(JsonField.of(config)) + + /** + * Sets [Builder.config] to an arbitrary JSON value. + * + * You should usually call [Builder.config] with a well-typed [Config] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun config(config: JsonField) = apply { this.config = config } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) + + /** + * Sets [Builder.eventTypes] to an arbitrary JSON value. + * + * You should usually call [Builder.eventTypes] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun eventTypes(eventTypes: JsonField>) = apply { + this.eventTypes = eventTypes.map { it.toMutableList() } + } + + /** + * Adds a single [EventType] to [eventTypes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEventType(eventType: EventType) = apply { + eventTypes = + (eventTypes ?: JsonField.of(mutableListOf())).also { + checkKnown("eventTypes", it).add(eventType) + } + } + + fun isActive(isActive: Boolean) = isActive(JsonField.of(isActive)) + + /** + * Sets [Builder.isActive] to an arbitrary JSON value. + * + * You should usually call [Builder.isActive] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun isActive(isActive: JsonField) = apply { this.isActive = isActive } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun filters(filters: Filters) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed [Filters] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField) = apply { this.filters = filters } + + fun messageTemplate(messageTemplate: String) = + messageTemplate(JsonField.of(messageTemplate)) + + /** + * Sets [Builder.messageTemplate] to an arbitrary JSON value. + * + * You should usually call [Builder.messageTemplate] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun messageTemplate(messageTemplate: JsonField) = apply { + this.messageTemplate = messageTemplate + } + + fun scopeAllMonitors(scopeAllMonitors: Boolean) = + scopeAllMonitors(JsonField.of(scopeAllMonitors)) + + /** + * Sets [Builder.scopeAllMonitors] to an arbitrary JSON value. + * + * You should usually call [Builder.scopeAllMonitors] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun scopeAllMonitors(scopeAllMonitors: JsonField) = apply { + this.scopeAllMonitors = scopeAllMonitors + } + + fun silentPush(silentPush: Boolean) = silentPush(JsonField.of(silentPush)) + + /** + * Sets [Builder.silentPush] to an arbitrary JSON value. + * + * You should usually call [Builder.silentPush] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun silentPush(silentPush: JsonField) = apply { this.silentPush = silentPush } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [IntegrationRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .config() + * .createdAt() + * .eventTypes() + * .isActive() + * .name() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): IntegrationRetrieveResponse = + IntegrationRetrieveResponse( + checkRequired("id", id), + checkRequired("config", config), + checkRequired("createdAt", createdAt), + checkRequired("eventTypes", eventTypes).map { it.toImmutable() }, + checkRequired("isActive", isActive), + checkRequired("name", name), + checkRequired("type", type), + filters, + messageTemplate, + scopeAllMonitors, + silentPush, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): IntegrationRetrieveResponse = apply { + if (validated) { + return@apply + } + + id() + config().validate() + createdAt() + eventTypes().forEach { it.validate() } + isActive() + name() + type().validate() + filters().ifPresent { it.validate() } + messageTemplate() + scopeAllMonitors() + silentPush() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (config.asKnown().getOrNull()?.validity() ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (eventTypes.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (isActive.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (filters.asKnown().getOrNull()?.validity() ?: 0) + + (if (messageTemplate.asKnown().isPresent) 1 else 0) + + (if (scopeAllMonitors.asKnown().isPresent) 1 else 0) + + (if (silentPush.asKnown().isPresent) 1 else 0) + + class Config + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Config]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Config]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(config: Config) = apply { + additionalProperties = config.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Config]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Config = Config(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Config = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Config && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Config{additionalProperties=$additionalProperties}" + } + + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TELEGRAM = of("telegram") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TELEGRAM + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TELEGRAM, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TELEGRAM -> Value.TELEGRAM + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TELEGRAM -> Known.TELEGRAM + else -> throw XTwitterScraperInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Filters + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Filters]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Filters]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(filters: Filters) = apply { + additionalProperties = filters.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Filters = Filters(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Filters = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filters && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Filters{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IntegrationRetrieveResponse && + id == other.id && + config == other.config && + createdAt == other.createdAt && + eventTypes == other.eventTypes && + isActive == other.isActive && + name == other.name && + type == other.type && + filters == other.filters && + messageTemplate == other.messageTemplate && + scopeAllMonitors == other.scopeAllMonitors && + silentPush == other.silentPush && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + config, + createdAt, + eventTypes, + isActive, + name, + type, + filters, + messageTemplate, + scopeAllMonitors, + silentPush, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "IntegrationRetrieveResponse{id=$id, config=$config, createdAt=$createdAt, eventTypes=$eventTypes, isActive=$isActive, name=$name, type=$type, filters=$filters, messageTemplate=$messageTemplate, scopeAllMonitors=$scopeAllMonitors, silentPush=$silentPush, additionalProperties=$additionalProperties}" +} diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationUpdateParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationUpdateParams.kt index aec890f..ed6d8cb 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationUpdateParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationUpdateParams.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum import com.x_twitter_scraper.api.core.ExcludeMissing import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.JsonMissing @@ -16,7 +17,6 @@ import com.x_twitter_scraper.api.core.http.Headers import com.x_twitter_scraper.api.core.http.QueryParams import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException -import com.x_twitter_scraper.api.models.EventType import java.util.Collections import java.util.Objects import java.util.Optional @@ -810,6 +810,159 @@ private constructor( "Body{eventTypes=$eventTypes, filters=$filters, isActive=$isActive, messageTemplate=$messageTemplate, name=$name, scopeAllMonitors=$scopeAllMonitors, silentPush=$silentPush, additionalProperties=$additionalProperties}" } + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Filters @JsonCreator private constructor( diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationUpdateResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationUpdateResponse.kt new file mode 100644 index 0000000..46c510e --- /dev/null +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationUpdateResponse.kt @@ -0,0 +1,1045 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.x_twitter_scraper.api.models.integrations + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum +import com.x_twitter_scraper.api.core.ExcludeMissing +import com.x_twitter_scraper.api.core.JsonField +import com.x_twitter_scraper.api.core.JsonMissing +import com.x_twitter_scraper.api.core.JsonValue +import com.x_twitter_scraper.api.core.checkKnown +import com.x_twitter_scraper.api.core.checkRequired +import com.x_twitter_scraper.api.core.toImmutable +import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class IntegrationUpdateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val config: JsonField, + private val createdAt: JsonField, + private val eventTypes: JsonField>, + private val isActive: JsonField, + private val name: JsonField, + private val type: JsonField, + private val filters: JsonField, + private val messageTemplate: JsonField, + private val scopeAllMonitors: JsonField, + private val silentPush: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("config") @ExcludeMissing config: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("eventTypes") + @ExcludeMissing + eventTypes: JsonField> = JsonMissing.of(), + @JsonProperty("isActive") @ExcludeMissing isActive: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("filters") @ExcludeMissing filters: JsonField = JsonMissing.of(), + @JsonProperty("messageTemplate") + @ExcludeMissing + messageTemplate: JsonField = JsonMissing.of(), + @JsonProperty("scopeAllMonitors") + @ExcludeMissing + scopeAllMonitors: JsonField = JsonMissing.of(), + @JsonProperty("silentPush") + @ExcludeMissing + silentPush: JsonField = JsonMissing.of(), + ) : this( + id, + config, + createdAt, + eventTypes, + isActive, + name, + type, + filters, + messageTemplate, + scopeAllMonitors, + silentPush, + mutableMapOf(), + ) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun config(): Config = config.getRequired("config") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun eventTypes(): List = eventTypes.getRequired("eventTypes") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun isActive(): Boolean = isActive.getRequired("isActive") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun filters(): Optional = filters.getOptional("filters") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun messageTemplate(): Optional = messageTemplate.getOptional("messageTemplate") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun scopeAllMonitors(): Optional = scopeAllMonitors.getOptional("scopeAllMonitors") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun silentPush(): Optional = silentPush.getOptional("silentPush") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [config]. + * + * Unlike [config], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("config") @ExcludeMissing fun _config(): JsonField = config + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [eventTypes]. + * + * Unlike [eventTypes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("eventTypes") + @ExcludeMissing + fun _eventTypes(): JsonField> = eventTypes + + /** + * Returns the raw JSON value of [isActive]. + * + * Unlike [isActive], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("isActive") @ExcludeMissing fun _isActive(): JsonField = isActive + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField = filters + + /** + * Returns the raw JSON value of [messageTemplate]. + * + * Unlike [messageTemplate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("messageTemplate") + @ExcludeMissing + fun _messageTemplate(): JsonField = messageTemplate + + /** + * Returns the raw JSON value of [scopeAllMonitors]. + * + * Unlike [scopeAllMonitors], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scopeAllMonitors") + @ExcludeMissing + fun _scopeAllMonitors(): JsonField = scopeAllMonitors + + /** + * Returns the raw JSON value of [silentPush]. + * + * Unlike [silentPush], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("silentPush") @ExcludeMissing fun _silentPush(): JsonField = silentPush + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [IntegrationUpdateResponse]. + * + * The following fields are required: + * ```java + * .id() + * .config() + * .createdAt() + * .eventTypes() + * .isActive() + * .name() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IntegrationUpdateResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var config: JsonField? = null + private var createdAt: JsonField? = null + private var eventTypes: JsonField>? = null + private var isActive: JsonField? = null + private var name: JsonField? = null + private var type: JsonField? = null + private var filters: JsonField = JsonMissing.of() + private var messageTemplate: JsonField = JsonMissing.of() + private var scopeAllMonitors: JsonField = JsonMissing.of() + private var silentPush: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(integrationUpdateResponse: IntegrationUpdateResponse) = apply { + id = integrationUpdateResponse.id + config = integrationUpdateResponse.config + createdAt = integrationUpdateResponse.createdAt + eventTypes = integrationUpdateResponse.eventTypes.map { it.toMutableList() } + isActive = integrationUpdateResponse.isActive + name = integrationUpdateResponse.name + type = integrationUpdateResponse.type + filters = integrationUpdateResponse.filters + messageTemplate = integrationUpdateResponse.messageTemplate + scopeAllMonitors = integrationUpdateResponse.scopeAllMonitors + silentPush = integrationUpdateResponse.silentPush + additionalProperties = integrationUpdateResponse.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun config(config: Config) = config(JsonField.of(config)) + + /** + * Sets [Builder.config] to an arbitrary JSON value. + * + * You should usually call [Builder.config] with a well-typed [Config] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun config(config: JsonField) = apply { this.config = config } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) + + /** + * Sets [Builder.eventTypes] to an arbitrary JSON value. + * + * You should usually call [Builder.eventTypes] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun eventTypes(eventTypes: JsonField>) = apply { + this.eventTypes = eventTypes.map { it.toMutableList() } + } + + /** + * Adds a single [EventType] to [eventTypes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEventType(eventType: EventType) = apply { + eventTypes = + (eventTypes ?: JsonField.of(mutableListOf())).also { + checkKnown("eventTypes", it).add(eventType) + } + } + + fun isActive(isActive: Boolean) = isActive(JsonField.of(isActive)) + + /** + * Sets [Builder.isActive] to an arbitrary JSON value. + * + * You should usually call [Builder.isActive] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun isActive(isActive: JsonField) = apply { this.isActive = isActive } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun filters(filters: Filters) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed [Filters] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField) = apply { this.filters = filters } + + fun messageTemplate(messageTemplate: String) = + messageTemplate(JsonField.of(messageTemplate)) + + /** + * Sets [Builder.messageTemplate] to an arbitrary JSON value. + * + * You should usually call [Builder.messageTemplate] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun messageTemplate(messageTemplate: JsonField) = apply { + this.messageTemplate = messageTemplate + } + + fun scopeAllMonitors(scopeAllMonitors: Boolean) = + scopeAllMonitors(JsonField.of(scopeAllMonitors)) + + /** + * Sets [Builder.scopeAllMonitors] to an arbitrary JSON value. + * + * You should usually call [Builder.scopeAllMonitors] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun scopeAllMonitors(scopeAllMonitors: JsonField) = apply { + this.scopeAllMonitors = scopeAllMonitors + } + + fun silentPush(silentPush: Boolean) = silentPush(JsonField.of(silentPush)) + + /** + * Sets [Builder.silentPush] to an arbitrary JSON value. + * + * You should usually call [Builder.silentPush] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun silentPush(silentPush: JsonField) = apply { this.silentPush = silentPush } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [IntegrationUpdateResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .config() + * .createdAt() + * .eventTypes() + * .isActive() + * .name() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): IntegrationUpdateResponse = + IntegrationUpdateResponse( + checkRequired("id", id), + checkRequired("config", config), + checkRequired("createdAt", createdAt), + checkRequired("eventTypes", eventTypes).map { it.toImmutable() }, + checkRequired("isActive", isActive), + checkRequired("name", name), + checkRequired("type", type), + filters, + messageTemplate, + scopeAllMonitors, + silentPush, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): IntegrationUpdateResponse = apply { + if (validated) { + return@apply + } + + id() + config().validate() + createdAt() + eventTypes().forEach { it.validate() } + isActive() + name() + type().validate() + filters().ifPresent { it.validate() } + messageTemplate() + scopeAllMonitors() + silentPush() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (config.asKnown().getOrNull()?.validity() ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (eventTypes.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (isActive.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (filters.asKnown().getOrNull()?.validity() ?: 0) + + (if (messageTemplate.asKnown().isPresent) 1 else 0) + + (if (scopeAllMonitors.asKnown().isPresent) 1 else 0) + + (if (silentPush.asKnown().isPresent) 1 else 0) + + class Config + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Config]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Config]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(config: Config) = apply { + additionalProperties = config.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Config]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Config = Config(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Config = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Config && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Config{additionalProperties=$additionalProperties}" + } + + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TELEGRAM = of("telegram") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TELEGRAM + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TELEGRAM, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TELEGRAM -> Value.TELEGRAM + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TELEGRAM -> Known.TELEGRAM + else -> throw XTwitterScraperInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Filters + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Filters]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Filters]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(filters: Filters) = apply { + additionalProperties = filters.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Filters = Filters(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Filters = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filters && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Filters{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IntegrationUpdateResponse && + id == other.id && + config == other.config && + createdAt == other.createdAt && + eventTypes == other.eventTypes && + isActive == other.isActive && + name == other.name && + type == other.type && + filters == other.filters && + messageTemplate == other.messageTemplate && + scopeAllMonitors == other.scopeAllMonitors && + silentPush == other.silentPush && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + config, + createdAt, + eventTypes, + isActive, + name, + type, + filters, + messageTemplate, + scopeAllMonitors, + silentPush, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "IntegrationUpdateResponse{id=$id, config=$config, createdAt=$createdAt, eventTypes=$eventTypes, isActive=$isActive, name=$name, type=$type, filters=$filters, messageTemplate=$messageTemplate, scopeAllMonitors=$scopeAllMonitors, silentPush=$silentPush, additionalProperties=$additionalProperties}" +} diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/Monitor.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/Monitor.kt index c6034a0..264356a 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/Monitor.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/Monitor.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum import com.x_twitter_scraper.api.core.ExcludeMissing import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.JsonMissing @@ -14,7 +15,6 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException -import com.x_twitter_scraper.api.models.EventType import java.time.OffsetDateTime import java.util.Collections import java.util.Objects @@ -343,6 +343,159 @@ private constructor( (if (username.asKnown().isPresent) 1 else 0) + (if (xUserId.asKnown().isPresent) 1 else 0) + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorCreateParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorCreateParams.kt index 2c9f2b9..7afdf68 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorCreateParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorCreateParams.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum import com.x_twitter_scraper.api.core.ExcludeMissing import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.JsonMissing @@ -17,7 +18,6 @@ import com.x_twitter_scraper.api.core.http.Headers import com.x_twitter_scraper.api.core.http.QueryParams import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException -import com.x_twitter_scraper.api.models.EventType import java.util.Collections import java.util.Objects import kotlin.jvm.optionals.getOrNull @@ -498,6 +498,159 @@ private constructor( "Body{eventTypes=$eventTypes, username=$username, additionalProperties=$additionalProperties}" } + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorCreateResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorCreateResponse.kt index 4e9bfd2..97199ba 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorCreateResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorCreateResponse.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum import com.x_twitter_scraper.api.core.ExcludeMissing import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.JsonMissing @@ -14,7 +15,6 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException -import com.x_twitter_scraper.api.models.EventType import java.time.OffsetDateTime import java.util.Collections import java.util.Objects @@ -310,6 +310,159 @@ private constructor( (if (username.asKnown().isPresent) 1 else 0) + (if (xUserId.asKnown().isPresent) 1 else 0) + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorListResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorListResponse.kt index e714d7d..74fb015 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorListResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorListResponse.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum import com.x_twitter_scraper.api.core.ExcludeMissing import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.JsonMissing @@ -14,6 +15,7 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects import kotlin.jvm.optionals.getOrNull @@ -205,6 +207,533 @@ private constructor( (monitors.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (total.asKnown().isPresent) 1 else 0) + class Monitor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val eventTypes: JsonField>, + private val isActive: JsonField, + private val username: JsonField, + private val xUserId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("eventTypes") + @ExcludeMissing + eventTypes: JsonField> = JsonMissing.of(), + @JsonProperty("isActive") + @ExcludeMissing + isActive: JsonField = JsonMissing.of(), + @JsonProperty("username") + @ExcludeMissing + username: JsonField = JsonMissing.of(), + @JsonProperty("xUserId") @ExcludeMissing xUserId: JsonField = JsonMissing.of(), + ) : this(id, createdAt, eventTypes, isActive, username, xUserId, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventTypes(): List = eventTypes.getRequired("eventTypes") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun isActive(): Boolean = isActive.getRequired("isActive") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun username(): String = username.getRequired("username") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun xUserId(): String = xUserId.getRequired("xUserId") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [eventTypes]. + * + * Unlike [eventTypes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("eventTypes") + @ExcludeMissing + fun _eventTypes(): JsonField> = eventTypes + + /** + * Returns the raw JSON value of [isActive]. + * + * Unlike [isActive], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("isActive") @ExcludeMissing fun _isActive(): JsonField = isActive + + /** + * Returns the raw JSON value of [username]. + * + * Unlike [username], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("username") @ExcludeMissing fun _username(): JsonField = username + + /** + * Returns the raw JSON value of [xUserId]. + * + * Unlike [xUserId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("xUserId") @ExcludeMissing fun _xUserId(): JsonField = xUserId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Monitor]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .eventTypes() + * .isActive() + * .username() + * .xUserId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Monitor]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var eventTypes: JsonField>? = null + private var isActive: JsonField? = null + private var username: JsonField? = null + private var xUserId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(monitor: Monitor) = apply { + id = monitor.id + createdAt = monitor.createdAt + eventTypes = monitor.eventTypes.map { it.toMutableList() } + isActive = monitor.isActive + username = monitor.username + xUserId = monitor.xUserId + additionalProperties = monitor.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { + this.createdAt = createdAt + } + + fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) + + /** + * Sets [Builder.eventTypes] to an arbitrary JSON value. + * + * You should usually call [Builder.eventTypes] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun eventTypes(eventTypes: JsonField>) = apply { + this.eventTypes = eventTypes.map { it.toMutableList() } + } + + /** + * Adds a single [EventType] to [eventTypes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEventType(eventType: EventType) = apply { + eventTypes = + (eventTypes ?: JsonField.of(mutableListOf())).also { + checkKnown("eventTypes", it).add(eventType) + } + } + + fun isActive(isActive: Boolean) = isActive(JsonField.of(isActive)) + + /** + * Sets [Builder.isActive] to an arbitrary JSON value. + * + * You should usually call [Builder.isActive] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isActive(isActive: JsonField) = apply { this.isActive = isActive } + + fun username(username: String) = username(JsonField.of(username)) + + /** + * Sets [Builder.username] to an arbitrary JSON value. + * + * You should usually call [Builder.username] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun username(username: JsonField) = apply { this.username = username } + + fun xUserId(xUserId: String) = xUserId(JsonField.of(xUserId)) + + /** + * Sets [Builder.xUserId] to an arbitrary JSON value. + * + * You should usually call [Builder.xUserId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun xUserId(xUserId: JsonField) = apply { this.xUserId = xUserId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Monitor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .eventTypes() + * .isActive() + * .username() + * .xUserId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Monitor = + Monitor( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("eventTypes", eventTypes).map { it.toImmutable() }, + checkRequired("isActive", isActive), + checkRequired("username", username), + checkRequired("xUserId", xUserId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Monitor = apply { + if (validated) { + return@apply + } + + id() + createdAt() + eventTypes().forEach { it.validate() } + isActive() + username() + xUserId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (eventTypes.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (isActive.asKnown().isPresent) 1 else 0) + + (if (username.asKnown().isPresent) 1 else 0) + + (if (xUserId.asKnown().isPresent) 1 else 0) + + class EventType @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Monitor && + id == other.id && + createdAt == other.createdAt && + eventTypes == other.eventTypes && + isActive == other.isActive && + username == other.username && + xUserId == other.xUserId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + eventTypes, + isActive, + username, + xUserId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Monitor{id=$id, createdAt=$createdAt, eventTypes=$eventTypes, isActive=$isActive, username=$username, xUserId=$xUserId, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorRetrieveResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorRetrieveResponse.kt new file mode 100644 index 0000000..43a9471 --- /dev/null +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorRetrieveResponse.kt @@ -0,0 +1,522 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.x_twitter_scraper.api.models.monitors + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum +import com.x_twitter_scraper.api.core.ExcludeMissing +import com.x_twitter_scraper.api.core.JsonField +import com.x_twitter_scraper.api.core.JsonMissing +import com.x_twitter_scraper.api.core.JsonValue +import com.x_twitter_scraper.api.core.checkKnown +import com.x_twitter_scraper.api.core.checkRequired +import com.x_twitter_scraper.api.core.toImmutable +import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class MonitorRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val eventTypes: JsonField>, + private val isActive: JsonField, + private val username: JsonField, + private val xUserId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("eventTypes") + @ExcludeMissing + eventTypes: JsonField> = JsonMissing.of(), + @JsonProperty("isActive") @ExcludeMissing isActive: JsonField = JsonMissing.of(), + @JsonProperty("username") @ExcludeMissing username: JsonField = JsonMissing.of(), + @JsonProperty("xUserId") @ExcludeMissing xUserId: JsonField = JsonMissing.of(), + ) : this(id, createdAt, eventTypes, isActive, username, xUserId, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun eventTypes(): List = eventTypes.getRequired("eventTypes") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun isActive(): Boolean = isActive.getRequired("isActive") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun username(): String = username.getRequired("username") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun xUserId(): String = xUserId.getRequired("xUserId") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [eventTypes]. + * + * Unlike [eventTypes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("eventTypes") + @ExcludeMissing + fun _eventTypes(): JsonField> = eventTypes + + /** + * Returns the raw JSON value of [isActive]. + * + * Unlike [isActive], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("isActive") @ExcludeMissing fun _isActive(): JsonField = isActive + + /** + * Returns the raw JSON value of [username]. + * + * Unlike [username], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("username") @ExcludeMissing fun _username(): JsonField = username + + /** + * Returns the raw JSON value of [xUserId]. + * + * Unlike [xUserId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("xUserId") @ExcludeMissing fun _xUserId(): JsonField = xUserId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [MonitorRetrieveResponse]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .eventTypes() + * .isActive() + * .username() + * .xUserId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MonitorRetrieveResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var eventTypes: JsonField>? = null + private var isActive: JsonField? = null + private var username: JsonField? = null + private var xUserId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(monitorRetrieveResponse: MonitorRetrieveResponse) = apply { + id = monitorRetrieveResponse.id + createdAt = monitorRetrieveResponse.createdAt + eventTypes = monitorRetrieveResponse.eventTypes.map { it.toMutableList() } + isActive = monitorRetrieveResponse.isActive + username = monitorRetrieveResponse.username + xUserId = monitorRetrieveResponse.xUserId + additionalProperties = monitorRetrieveResponse.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) + + /** + * Sets [Builder.eventTypes] to an arbitrary JSON value. + * + * You should usually call [Builder.eventTypes] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun eventTypes(eventTypes: JsonField>) = apply { + this.eventTypes = eventTypes.map { it.toMutableList() } + } + + /** + * Adds a single [EventType] to [eventTypes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEventType(eventType: EventType) = apply { + eventTypes = + (eventTypes ?: JsonField.of(mutableListOf())).also { + checkKnown("eventTypes", it).add(eventType) + } + } + + fun isActive(isActive: Boolean) = isActive(JsonField.of(isActive)) + + /** + * Sets [Builder.isActive] to an arbitrary JSON value. + * + * You should usually call [Builder.isActive] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun isActive(isActive: JsonField) = apply { this.isActive = isActive } + + fun username(username: String) = username(JsonField.of(username)) + + /** + * Sets [Builder.username] to an arbitrary JSON value. + * + * You should usually call [Builder.username] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun username(username: JsonField) = apply { this.username = username } + + fun xUserId(xUserId: String) = xUserId(JsonField.of(xUserId)) + + /** + * Sets [Builder.xUserId] to an arbitrary JSON value. + * + * You should usually call [Builder.xUserId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun xUserId(xUserId: JsonField) = apply { this.xUserId = xUserId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [MonitorRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .eventTypes() + * .isActive() + * .username() + * .xUserId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MonitorRetrieveResponse = + MonitorRetrieveResponse( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("eventTypes", eventTypes).map { it.toImmutable() }, + checkRequired("isActive", isActive), + checkRequired("username", username), + checkRequired("xUserId", xUserId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MonitorRetrieveResponse = apply { + if (validated) { + return@apply + } + + id() + createdAt() + eventTypes().forEach { it.validate() } + isActive() + username() + xUserId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (eventTypes.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (isActive.asKnown().isPresent) 1 else 0) + + (if (username.asKnown().isPresent) 1 else 0) + + (if (xUserId.asKnown().isPresent) 1 else 0) + + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MonitorRetrieveResponse && + id == other.id && + createdAt == other.createdAt && + eventTypes == other.eventTypes && + isActive == other.isActive && + username == other.username && + xUserId == other.xUserId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, eventTypes, isActive, username, xUserId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MonitorRetrieveResponse{id=$id, createdAt=$createdAt, eventTypes=$eventTypes, isActive=$isActive, username=$username, xUserId=$xUserId, additionalProperties=$additionalProperties}" +} diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorUpdateParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorUpdateParams.kt index 5eeca70..03f85bf 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorUpdateParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorUpdateParams.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum import com.x_twitter_scraper.api.core.ExcludeMissing import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.JsonMissing @@ -16,7 +17,6 @@ import com.x_twitter_scraper.api.core.http.Headers import com.x_twitter_scraper.api.core.http.QueryParams import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException -import com.x_twitter_scraper.api.models.EventType import java.util.Collections import java.util.Objects import java.util.Optional @@ -480,6 +480,159 @@ private constructor( "Body{eventTypes=$eventTypes, isActive=$isActive, additionalProperties=$additionalProperties}" } + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorUpdateResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorUpdateResponse.kt new file mode 100644 index 0000000..84a791c --- /dev/null +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorUpdateResponse.kt @@ -0,0 +1,522 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.x_twitter_scraper.api.models.monitors + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.Enum +import com.x_twitter_scraper.api.core.ExcludeMissing +import com.x_twitter_scraper.api.core.JsonField +import com.x_twitter_scraper.api.core.JsonMissing +import com.x_twitter_scraper.api.core.JsonValue +import com.x_twitter_scraper.api.core.checkKnown +import com.x_twitter_scraper.api.core.checkRequired +import com.x_twitter_scraper.api.core.toImmutable +import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class MonitorUpdateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val eventTypes: JsonField>, + private val isActive: JsonField, + private val username: JsonField, + private val xUserId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("eventTypes") + @ExcludeMissing + eventTypes: JsonField> = JsonMissing.of(), + @JsonProperty("isActive") @ExcludeMissing isActive: JsonField = JsonMissing.of(), + @JsonProperty("username") @ExcludeMissing username: JsonField = JsonMissing.of(), + @JsonProperty("xUserId") @ExcludeMissing xUserId: JsonField = JsonMissing.of(), + ) : this(id, createdAt, eventTypes, isActive, username, xUserId, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun eventTypes(): List = eventTypes.getRequired("eventTypes") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun isActive(): Boolean = isActive.getRequired("isActive") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun username(): String = username.getRequired("username") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun xUserId(): String = xUserId.getRequired("xUserId") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [eventTypes]. + * + * Unlike [eventTypes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("eventTypes") + @ExcludeMissing + fun _eventTypes(): JsonField> = eventTypes + + /** + * Returns the raw JSON value of [isActive]. + * + * Unlike [isActive], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("isActive") @ExcludeMissing fun _isActive(): JsonField = isActive + + /** + * Returns the raw JSON value of [username]. + * + * Unlike [username], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("username") @ExcludeMissing fun _username(): JsonField = username + + /** + * Returns the raw JSON value of [xUserId]. + * + * Unlike [xUserId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("xUserId") @ExcludeMissing fun _xUserId(): JsonField = xUserId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [MonitorUpdateResponse]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .eventTypes() + * .isActive() + * .username() + * .xUserId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MonitorUpdateResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var eventTypes: JsonField>? = null + private var isActive: JsonField? = null + private var username: JsonField? = null + private var xUserId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(monitorUpdateResponse: MonitorUpdateResponse) = apply { + id = monitorUpdateResponse.id + createdAt = monitorUpdateResponse.createdAt + eventTypes = monitorUpdateResponse.eventTypes.map { it.toMutableList() } + isActive = monitorUpdateResponse.isActive + username = monitorUpdateResponse.username + xUserId = monitorUpdateResponse.xUserId + additionalProperties = monitorUpdateResponse.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) + + /** + * Sets [Builder.eventTypes] to an arbitrary JSON value. + * + * You should usually call [Builder.eventTypes] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun eventTypes(eventTypes: JsonField>) = apply { + this.eventTypes = eventTypes.map { it.toMutableList() } + } + + /** + * Adds a single [EventType] to [eventTypes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEventType(eventType: EventType) = apply { + eventTypes = + (eventTypes ?: JsonField.of(mutableListOf())).also { + checkKnown("eventTypes", it).add(eventType) + } + } + + fun isActive(isActive: Boolean) = isActive(JsonField.of(isActive)) + + /** + * Sets [Builder.isActive] to an arbitrary JSON value. + * + * You should usually call [Builder.isActive] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun isActive(isActive: JsonField) = apply { this.isActive = isActive } + + fun username(username: String) = username(JsonField.of(username)) + + /** + * Sets [Builder.username] to an arbitrary JSON value. + * + * You should usually call [Builder.username] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun username(username: JsonField) = apply { this.username = username } + + fun xUserId(xUserId: String) = xUserId(JsonField.of(xUserId)) + + /** + * Sets [Builder.xUserId] to an arbitrary JSON value. + * + * You should usually call [Builder.xUserId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun xUserId(xUserId: JsonField) = apply { this.xUserId = xUserId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [MonitorUpdateResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .eventTypes() + * .isActive() + * .username() + * .xUserId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MonitorUpdateResponse = + MonitorUpdateResponse( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("eventTypes", eventTypes).map { it.toImmutable() }, + checkRequired("isActive", isActive), + checkRequired("username", username), + checkRequired("xUserId", xUserId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MonitorUpdateResponse = apply { + if (validated) { + return@apply + } + + id() + createdAt() + eventTypes().forEach { it.validate() } + isActive() + username() + xUserId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (eventTypes.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (isActive.asKnown().isPresent) 1 else 0) + + (if (username.asKnown().isPresent) 1 else 0) + + (if (xUserId.asKnown().isPresent) 1 else 0) + + class EventType @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TWEET_NEW = of("tweet.new") + + @JvmField val TWEET_REPLY = of("tweet.reply") + + @JvmField val TWEET_RETWEET = of("tweet.retweet") + + @JvmField val TWEET_QUOTE = of("tweet.quote") + + @JvmField val FOLLOWER_GAINED = of("follower.gained") + + @JvmField val FOLLOWER_LOST = of("follower.lost") + + @JvmStatic fun of(value: String) = EventType(JsonField.of(value)) + } + + /** An enum containing [EventType]'s known values. */ + enum class Known { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + } + + /** + * An enum containing [EventType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TWEET_NEW, + TWEET_REPLY, + TWEET_RETWEET, + TWEET_QUOTE, + FOLLOWER_GAINED, + FOLLOWER_LOST, + /** + * An enum member indicating that [EventType] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TWEET_NEW -> Value.TWEET_NEW + TWEET_REPLY -> Value.TWEET_REPLY + TWEET_RETWEET -> Value.TWEET_RETWEET + TWEET_QUOTE -> Value.TWEET_QUOTE + FOLLOWER_GAINED -> Value.FOLLOWER_GAINED + FOLLOWER_LOST -> Value.FOLLOWER_LOST + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TWEET_NEW -> Known.TWEET_NEW + TWEET_REPLY -> Known.TWEET_REPLY + TWEET_RETWEET -> Known.TWEET_RETWEET + TWEET_QUOTE -> Known.TWEET_QUOTE + FOLLOWER_GAINED -> Known.FOLLOWER_GAINED + FOLLOWER_LOST -> Known.FOLLOWER_LOST + else -> throw XTwitterScraperInvalidDataException("Unknown EventType: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws XTwitterScraperInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + XTwitterScraperInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MonitorUpdateResponse && + id == other.id && + createdAt == other.createdAt && + eventTypes == other.eventTypes && + isActive == other.isActive && + username == other.username && + xUserId == other.xUserId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, eventTypes, isActive, username, xUserId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MonitorUpdateResponse{id=$id, createdAt=$createdAt, eventTypes=$eventTypes, isActive=$isActive, username=$username, xUserId=$xUserId, additionalProperties=$additionalProperties}" +} diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/radar/RadarRetrieveTrendingTopicsResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/radar/RadarRetrieveTrendingTopicsResponse.kt index 5f17e52..ee848b7 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/radar/RadarRetrieveTrendingTopicsResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/radar/RadarRetrieveTrendingTopicsResponse.kt @@ -14,21 +14,23 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull class RadarRetrieveTrendingTopicsResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val items: JsonField>, + private val items: JsonField>, private val total: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("items") @ExcludeMissing items: JsonField> = JsonMissing.of(), + @JsonProperty("items") @ExcludeMissing items: JsonField> = JsonMissing.of(), @JsonProperty("total") @ExcludeMissing total: JsonField = JsonMissing.of(), ) : this(items, total, mutableMapOf()) @@ -36,7 +38,7 @@ private constructor( * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun items(): List = items.getRequired("items") + fun items(): List = items.getRequired("items") /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is @@ -49,7 +51,7 @@ private constructor( * * Unlike [items], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("items") @ExcludeMissing fun _items(): JsonField> = items + @JsonProperty("items") @ExcludeMissing fun _items(): JsonField> = items /** * Returns the raw JSON value of [total]. @@ -88,7 +90,7 @@ private constructor( /** A builder for [RadarRetrieveTrendingTopicsResponse]. */ class Builder internal constructor() { - private var items: JsonField>? = null + private var items: JsonField>? = null private var total: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -102,25 +104,25 @@ private constructor( radarRetrieveTrendingTopicsResponse.additionalProperties.toMutableMap() } - fun items(items: List) = items(JsonField.of(items)) + fun items(items: List) = items(JsonField.of(items)) /** * Sets [Builder.items] to an arbitrary JSON value. * - * You should usually call [Builder.items] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * You should usually call [Builder.items] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun items(items: JsonField>) = apply { + fun items(items: JsonField>) = apply { this.items = items.map { it.toMutableList() } } /** - * Adds a single [RadarItem] to [items]. + * Adds a single [Item] to [items]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addItem(item: RadarItem) = apply { + fun addItem(item: Item) = apply { items = (items ?: JsonField.of(mutableListOf())).also { checkKnown("items", it).add(item) } } @@ -205,6 +207,476 @@ private constructor( (items.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (total.asKnown().isPresent) 1 else 0) + class Item + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val category: JsonField, + private val publishedAt: JsonField, + private val region: JsonField, + private val score: JsonField, + private val source: JsonField, + private val title: JsonField, + private val description: JsonField, + private val imageUrl: JsonField, + private val url: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("category") + @ExcludeMissing + category: JsonField = JsonMissing.of(), + @JsonProperty("publishedAt") + @ExcludeMissing + publishedAt: JsonField = JsonMissing.of(), + @JsonProperty("region") @ExcludeMissing region: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField = JsonMissing.of(), + @JsonProperty("title") @ExcludeMissing title: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("imageUrl") + @ExcludeMissing + imageUrl: JsonField = JsonMissing.of(), + @JsonProperty("url") @ExcludeMissing url: JsonField = JsonMissing.of(), + ) : this( + category, + publishedAt, + region, + score, + source, + title, + description, + imageUrl, + url, + mutableMapOf(), + ) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun category(): String = category.getRequired("category") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun publishedAt(): OffsetDateTime = publishedAt.getRequired("publishedAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun region(): String = region.getRequired("region") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun score(): Double = score.getRequired("score") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun source(): String = source.getRequired("source") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun title(): String = title.getRequired("title") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun imageUrl(): Optional = imageUrl.getOptional("imageUrl") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun url(): Optional = url.getOptional("url") + + /** + * Returns the raw JSON value of [category]. + * + * Unlike [category], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("category") @ExcludeMissing fun _category(): JsonField = category + + /** + * Returns the raw JSON value of [publishedAt]. + * + * Unlike [publishedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("publishedAt") + @ExcludeMissing + fun _publishedAt(): JsonField = publishedAt + + /** + * Returns the raw JSON value of [region]. + * + * Unlike [region], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("region") @ExcludeMissing fun _region(): JsonField = region + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + /** + * Returns the raw JSON value of [title]. + * + * Unlike [title], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("title") @ExcludeMissing fun _title(): JsonField = title + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [imageUrl]. + * + * Unlike [imageUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("imageUrl") @ExcludeMissing fun _imageUrl(): JsonField = imageUrl + + /** + * Returns the raw JSON value of [url]. + * + * Unlike [url], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Item]. + * + * The following fields are required: + * ```java + * .category() + * .publishedAt() + * .region() + * .score() + * .source() + * .title() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Item]. */ + class Builder internal constructor() { + + private var category: JsonField? = null + private var publishedAt: JsonField? = null + private var region: JsonField? = null + private var score: JsonField? = null + private var source: JsonField? = null + private var title: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var imageUrl: JsonField = JsonMissing.of() + private var url: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(item: Item) = apply { + category = item.category + publishedAt = item.publishedAt + region = item.region + score = item.score + source = item.source + title = item.title + description = item.description + imageUrl = item.imageUrl + url = item.url + additionalProperties = item.additionalProperties.toMutableMap() + } + + fun category(category: String) = category(JsonField.of(category)) + + /** + * Sets [Builder.category] to an arbitrary JSON value. + * + * You should usually call [Builder.category] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun category(category: JsonField) = apply { this.category = category } + + fun publishedAt(publishedAt: OffsetDateTime) = publishedAt(JsonField.of(publishedAt)) + + /** + * Sets [Builder.publishedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.publishedAt] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun publishedAt(publishedAt: JsonField) = apply { + this.publishedAt = publishedAt + } + + fun region(region: String) = region(JsonField.of(region)) + + /** + * Sets [Builder.region] to an arbitrary JSON value. + * + * You should usually call [Builder.region] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun region(region: JsonField) = apply { this.region = region } + + fun score(score: Double) = score(JsonField.of(score)) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + fun source(source: String) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + fun title(title: String) = title(JsonField.of(title)) + + /** + * Sets [Builder.title] to an arbitrary JSON value. + * + * You should usually call [Builder.title] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun title(title: JsonField) = apply { this.title = title } + + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + fun imageUrl(imageUrl: String) = imageUrl(JsonField.of(imageUrl)) + + /** + * Sets [Builder.imageUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.imageUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun imageUrl(imageUrl: JsonField) = apply { this.imageUrl = imageUrl } + + fun url(url: String) = url(JsonField.of(url)) + + /** + * Sets [Builder.url] to an arbitrary JSON value. + * + * You should usually call [Builder.url] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun url(url: JsonField) = apply { this.url = url } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Item]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .category() + * .publishedAt() + * .region() + * .score() + * .source() + * .title() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Item = + Item( + checkRequired("category", category), + checkRequired("publishedAt", publishedAt), + checkRequired("region", region), + checkRequired("score", score), + checkRequired("source", source), + checkRequired("title", title), + description, + imageUrl, + url, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Item = apply { + if (validated) { + return@apply + } + + category() + publishedAt() + region() + score() + source() + title() + description() + imageUrl() + url() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (category.asKnown().isPresent) 1 else 0) + + (if (publishedAt.asKnown().isPresent) 1 else 0) + + (if (region.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + (if (source.asKnown().isPresent) 1 else 0) + + (if (title.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (imageUrl.asKnown().isPresent) 1 else 0) + + (if (url.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Item && + category == other.category && + publishedAt == other.publishedAt && + region == other.region && + score == other.score && + source == other.source && + title == other.title && + description == other.description && + imageUrl == other.imageUrl && + url == other.url && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + category, + publishedAt, + region, + score, + source, + title, + description, + imageUrl, + url, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Item{category=$category, publishedAt=$publishedAt, region=$region, score=$score, source=$source, title=$title, description=$description, imageUrl=$imageUrl, url=$url, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleAnalyzeResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleAnalyzeResponse.kt new file mode 100644 index 0000000..8f7c1c5 --- /dev/null +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleAnalyzeResponse.kt @@ -0,0 +1,609 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.x_twitter_scraper.api.models.styles + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.x_twitter_scraper.api.core.ExcludeMissing +import com.x_twitter_scraper.api.core.JsonField +import com.x_twitter_scraper.api.core.JsonMissing +import com.x_twitter_scraper.api.core.JsonValue +import com.x_twitter_scraper.api.core.checkKnown +import com.x_twitter_scraper.api.core.checkRequired +import com.x_twitter_scraper.api.core.toImmutable +import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class StyleAnalyzeResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val fetchedAt: JsonField, + private val isOwnAccount: JsonField, + private val tweetCount: JsonField, + private val tweets: JsonField>, + private val xUsername: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("fetchedAt") + @ExcludeMissing + fetchedAt: JsonField = JsonMissing.of(), + @JsonProperty("isOwnAccount") + @ExcludeMissing + isOwnAccount: JsonField = JsonMissing.of(), + @JsonProperty("tweetCount") @ExcludeMissing tweetCount: JsonField = JsonMissing.of(), + @JsonProperty("tweets") @ExcludeMissing tweets: JsonField> = JsonMissing.of(), + @JsonProperty("xUsername") @ExcludeMissing xUsername: JsonField = JsonMissing.of(), + ) : this(fetchedAt, isOwnAccount, tweetCount, tweets, xUsername, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun fetchedAt(): OffsetDateTime = fetchedAt.getRequired("fetchedAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun isOwnAccount(): Boolean = isOwnAccount.getRequired("isOwnAccount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tweetCount(): Long = tweetCount.getRequired("tweetCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tweets(): List = tweets.getRequired("tweets") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun xUsername(): String = xUsername.getRequired("xUsername") + + /** + * Returns the raw JSON value of [fetchedAt]. + * + * Unlike [fetchedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("fetchedAt") + @ExcludeMissing + fun _fetchedAt(): JsonField = fetchedAt + + /** + * Returns the raw JSON value of [isOwnAccount]. + * + * Unlike [isOwnAccount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("isOwnAccount") + @ExcludeMissing + fun _isOwnAccount(): JsonField = isOwnAccount + + /** + * Returns the raw JSON value of [tweetCount]. + * + * Unlike [tweetCount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tweetCount") @ExcludeMissing fun _tweetCount(): JsonField = tweetCount + + /** + * Returns the raw JSON value of [tweets]. + * + * Unlike [tweets], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tweets") @ExcludeMissing fun _tweets(): JsonField> = tweets + + /** + * Returns the raw JSON value of [xUsername]. + * + * Unlike [xUsername], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("xUsername") @ExcludeMissing fun _xUsername(): JsonField = xUsername + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [StyleAnalyzeResponse]. + * + * The following fields are required: + * ```java + * .fetchedAt() + * .isOwnAccount() + * .tweetCount() + * .tweets() + * .xUsername() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StyleAnalyzeResponse]. */ + class Builder internal constructor() { + + private var fetchedAt: JsonField? = null + private var isOwnAccount: JsonField? = null + private var tweetCount: JsonField? = null + private var tweets: JsonField>? = null + private var xUsername: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(styleAnalyzeResponse: StyleAnalyzeResponse) = apply { + fetchedAt = styleAnalyzeResponse.fetchedAt + isOwnAccount = styleAnalyzeResponse.isOwnAccount + tweetCount = styleAnalyzeResponse.tweetCount + tweets = styleAnalyzeResponse.tweets.map { it.toMutableList() } + xUsername = styleAnalyzeResponse.xUsername + additionalProperties = styleAnalyzeResponse.additionalProperties.toMutableMap() + } + + fun fetchedAt(fetchedAt: OffsetDateTime) = fetchedAt(JsonField.of(fetchedAt)) + + /** + * Sets [Builder.fetchedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.fetchedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fetchedAt(fetchedAt: JsonField) = apply { this.fetchedAt = fetchedAt } + + fun isOwnAccount(isOwnAccount: Boolean) = isOwnAccount(JsonField.of(isOwnAccount)) + + /** + * Sets [Builder.isOwnAccount] to an arbitrary JSON value. + * + * You should usually call [Builder.isOwnAccount] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun isOwnAccount(isOwnAccount: JsonField) = apply { + this.isOwnAccount = isOwnAccount + } + + fun tweetCount(tweetCount: Long) = tweetCount(JsonField.of(tweetCount)) + + /** + * Sets [Builder.tweetCount] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetCount] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun tweetCount(tweetCount: JsonField) = apply { this.tweetCount = tweetCount } + + fun tweets(tweets: List) = tweets(JsonField.of(tweets)) + + /** + * Sets [Builder.tweets] to an arbitrary JSON value. + * + * You should usually call [Builder.tweets] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tweets(tweets: JsonField>) = apply { + this.tweets = tweets.map { it.toMutableList() } + } + + /** + * Adds a single [Tweet] to [tweets]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTweet(tweet: Tweet) = apply { + tweets = + (tweets ?: JsonField.of(mutableListOf())).also { + checkKnown("tweets", it).add(tweet) + } + } + + fun xUsername(xUsername: String) = xUsername(JsonField.of(xUsername)) + + /** + * Sets [Builder.xUsername] to an arbitrary JSON value. + * + * You should usually call [Builder.xUsername] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun xUsername(xUsername: JsonField) = apply { this.xUsername = xUsername } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [StyleAnalyzeResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fetchedAt() + * .isOwnAccount() + * .tweetCount() + * .tweets() + * .xUsername() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): StyleAnalyzeResponse = + StyleAnalyzeResponse( + checkRequired("fetchedAt", fetchedAt), + checkRequired("isOwnAccount", isOwnAccount), + checkRequired("tweetCount", tweetCount), + checkRequired("tweets", tweets).map { it.toImmutable() }, + checkRequired("xUsername", xUsername), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): StyleAnalyzeResponse = apply { + if (validated) { + return@apply + } + + fetchedAt() + isOwnAccount() + tweetCount() + tweets().forEach { it.validate() } + xUsername() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (fetchedAt.asKnown().isPresent) 1 else 0) + + (if (isOwnAccount.asKnown().isPresent) 1 else 0) + + (if (tweetCount.asKnown().isPresent) 1 else 0) + + (tweets.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (xUsername.asKnown().isPresent) 1 else 0) + + class Tweet + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val text: JsonField, + private val authorUsername: JsonField, + private val createdAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("authorUsername") + @ExcludeMissing + authorUsername: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + ) : this(id, text, authorUsername, createdAt, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun text(): String = text.getRequired("text") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun authorUsername(): Optional = authorUsername.getOptional("authorUsername") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("createdAt") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + /** + * Returns the raw JSON value of [authorUsername]. + * + * Unlike [authorUsername], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("authorUsername") + @ExcludeMissing + fun _authorUsername(): JsonField = authorUsername + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Tweet]. + * + * The following fields are required: + * ```java + * .id() + * .text() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Tweet]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var text: JsonField? = null + private var authorUsername: JsonField = JsonMissing.of() + private var createdAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(tweet: Tweet) = apply { + id = tweet.id + text = tweet.text + authorUsername = tweet.authorUsername + createdAt = tweet.createdAt + additionalProperties = tweet.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun text(text: JsonField) = apply { this.text = text } + + fun authorUsername(authorUsername: String) = + authorUsername(JsonField.of(authorUsername)) + + /** + * Sets [Builder.authorUsername] to an arbitrary JSON value. + * + * You should usually call [Builder.authorUsername] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun authorUsername(authorUsername: JsonField) = apply { + this.authorUsername = authorUsername + } + + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Tweet]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .text() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tweet = + Tweet( + checkRequired("id", id), + checkRequired("text", text), + authorUsername, + createdAt, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tweet = apply { + if (validated) { + return@apply + } + + id() + text() + authorUsername() + createdAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (text.asKnown().isPresent) 1 else 0) + + (if (authorUsername.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tweet && + id == other.id && + text == other.text && + authorUsername == other.authorUsername && + createdAt == other.createdAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, text, authorUsername, createdAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tweet{id=$id, text=$text, authorUsername=$authorUsername, createdAt=$createdAt, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StyleAnalyzeResponse && + fetchedAt == other.fetchedAt && + isOwnAccount == other.isOwnAccount && + tweetCount == other.tweetCount && + tweets == other.tweets && + xUsername == other.xUsername && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(fetchedAt, isOwnAccount, tweetCount, tweets, xUsername, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "StyleAnalyzeResponse{fetchedAt=$fetchedAt, isOwnAccount=$isOwnAccount, tweetCount=$tweetCount, tweets=$tweets, xUsername=$xUsername, additionalProperties=$additionalProperties}" +} diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleCompareResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleCompareResponse.kt index bb86c01..e42856e 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleCompareResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleCompareResponse.kt @@ -10,51 +10,55 @@ import com.x_twitter_scraper.api.core.ExcludeMissing import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.core.JsonMissing import com.x_twitter_scraper.api.core.JsonValue +import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired +import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull class StyleCompareResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val style1: JsonField, - private val style2: JsonField, + private val style1: JsonField, + private val style2: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("style1") @ExcludeMissing style1: JsonField = JsonMissing.of(), - @JsonProperty("style2") @ExcludeMissing style2: JsonField = JsonMissing.of(), + @JsonProperty("style1") @ExcludeMissing style1: JsonField = JsonMissing.of(), + @JsonProperty("style2") @ExcludeMissing style2: JsonField = JsonMissing.of(), ) : this(style1, style2, mutableMapOf()) /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun style1(): StyleProfile = style1.getRequired("style1") + fun style1(): Style1 = style1.getRequired("style1") /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun style2(): StyleProfile = style2.getRequired("style2") + fun style2(): Style2 = style2.getRequired("style2") /** * Returns the raw JSON value of [style1]. * * Unlike [style1], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("style1") @ExcludeMissing fun _style1(): JsonField = style1 + @JsonProperty("style1") @ExcludeMissing fun _style1(): JsonField = style1 /** * Returns the raw JSON value of [style2]. * * Unlike [style2], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("style2") @ExcludeMissing fun _style2(): JsonField = style2 + @JsonProperty("style2") @ExcludeMissing fun _style2(): JsonField = style2 @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -85,8 +89,8 @@ private constructor( /** A builder for [StyleCompareResponse]. */ class Builder internal constructor() { - private var style1: JsonField? = null - private var style2: JsonField? = null + private var style1: JsonField? = null + private var style2: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -96,27 +100,25 @@ private constructor( additionalProperties = styleCompareResponse.additionalProperties.toMutableMap() } - fun style1(style1: StyleProfile) = style1(JsonField.of(style1)) + fun style1(style1: Style1) = style1(JsonField.of(style1)) /** * Sets [Builder.style1] to an arbitrary JSON value. * - * You should usually call [Builder.style1] with a well-typed [StyleProfile] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * You should usually call [Builder.style1] with a well-typed [Style1] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun style1(style1: JsonField) = apply { this.style1 = style1 } + fun style1(style1: JsonField) = apply { this.style1 = style1 } - fun style2(style2: StyleProfile) = style2(JsonField.of(style2)) + fun style2(style2: Style2) = style2(JsonField.of(style2)) /** * Sets [Builder.style2] to an arbitrary JSON value. * - * You should usually call [Builder.style2] with a well-typed [StyleProfile] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * You should usually call [Builder.style2] with a well-typed [Style2] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun style2(style2: JsonField) = apply { this.style2 = style2 } + fun style2(style2: JsonField) = apply { this.style2 = style2 } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -188,6 +190,1240 @@ private constructor( (style1.asKnown().getOrNull()?.validity() ?: 0) + (style2.asKnown().getOrNull()?.validity() ?: 0) + class Style1 + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val fetchedAt: JsonField, + private val isOwnAccount: JsonField, + private val tweetCount: JsonField, + private val tweets: JsonField>, + private val xUsername: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("fetchedAt") + @ExcludeMissing + fetchedAt: JsonField = JsonMissing.of(), + @JsonProperty("isOwnAccount") + @ExcludeMissing + isOwnAccount: JsonField = JsonMissing.of(), + @JsonProperty("tweetCount") + @ExcludeMissing + tweetCount: JsonField = JsonMissing.of(), + @JsonProperty("tweets") + @ExcludeMissing + tweets: JsonField> = JsonMissing.of(), + @JsonProperty("xUsername") + @ExcludeMissing + xUsername: JsonField = JsonMissing.of(), + ) : this(fetchedAt, isOwnAccount, tweetCount, tweets, xUsername, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun fetchedAt(): OffsetDateTime = fetchedAt.getRequired("fetchedAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun isOwnAccount(): Boolean = isOwnAccount.getRequired("isOwnAccount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetCount(): Long = tweetCount.getRequired("tweetCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweets(): List = tweets.getRequired("tweets") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun xUsername(): String = xUsername.getRequired("xUsername") + + /** + * Returns the raw JSON value of [fetchedAt]. + * + * Unlike [fetchedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("fetchedAt") + @ExcludeMissing + fun _fetchedAt(): JsonField = fetchedAt + + /** + * Returns the raw JSON value of [isOwnAccount]. + * + * Unlike [isOwnAccount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("isOwnAccount") + @ExcludeMissing + fun _isOwnAccount(): JsonField = isOwnAccount + + /** + * Returns the raw JSON value of [tweetCount]. + * + * Unlike [tweetCount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tweetCount") @ExcludeMissing fun _tweetCount(): JsonField = tweetCount + + /** + * Returns the raw JSON value of [tweets]. + * + * Unlike [tweets], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tweets") @ExcludeMissing fun _tweets(): JsonField> = tweets + + /** + * Returns the raw JSON value of [xUsername]. + * + * Unlike [xUsername], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("xUsername") @ExcludeMissing fun _xUsername(): JsonField = xUsername + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Style1]. + * + * The following fields are required: + * ```java + * .fetchedAt() + * .isOwnAccount() + * .tweetCount() + * .tweets() + * .xUsername() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Style1]. */ + class Builder internal constructor() { + + private var fetchedAt: JsonField? = null + private var isOwnAccount: JsonField? = null + private var tweetCount: JsonField? = null + private var tweets: JsonField>? = null + private var xUsername: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(style1: Style1) = apply { + fetchedAt = style1.fetchedAt + isOwnAccount = style1.isOwnAccount + tweetCount = style1.tweetCount + tweets = style1.tweets.map { it.toMutableList() } + xUsername = style1.xUsername + additionalProperties = style1.additionalProperties.toMutableMap() + } + + fun fetchedAt(fetchedAt: OffsetDateTime) = fetchedAt(JsonField.of(fetchedAt)) + + /** + * Sets [Builder.fetchedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.fetchedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fetchedAt(fetchedAt: JsonField) = apply { + this.fetchedAt = fetchedAt + } + + fun isOwnAccount(isOwnAccount: Boolean) = isOwnAccount(JsonField.of(isOwnAccount)) + + /** + * Sets [Builder.isOwnAccount] to an arbitrary JSON value. + * + * You should usually call [Builder.isOwnAccount] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isOwnAccount(isOwnAccount: JsonField) = apply { + this.isOwnAccount = isOwnAccount + } + + fun tweetCount(tweetCount: Long) = tweetCount(JsonField.of(tweetCount)) + + /** + * Sets [Builder.tweetCount] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetCount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweetCount(tweetCount: JsonField) = apply { this.tweetCount = tweetCount } + + fun tweets(tweets: List) = tweets(JsonField.of(tweets)) + + /** + * Sets [Builder.tweets] to an arbitrary JSON value. + * + * You should usually call [Builder.tweets] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweets(tweets: JsonField>) = apply { + this.tweets = tweets.map { it.toMutableList() } + } + + /** + * Adds a single [Tweet] to [tweets]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTweet(tweet: Tweet) = apply { + tweets = + (tweets ?: JsonField.of(mutableListOf())).also { + checkKnown("tweets", it).add(tweet) + } + } + + fun xUsername(xUsername: String) = xUsername(JsonField.of(xUsername)) + + /** + * Sets [Builder.xUsername] to an arbitrary JSON value. + * + * You should usually call [Builder.xUsername] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun xUsername(xUsername: JsonField) = apply { this.xUsername = xUsername } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Style1]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fetchedAt() + * .isOwnAccount() + * .tweetCount() + * .tweets() + * .xUsername() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Style1 = + Style1( + checkRequired("fetchedAt", fetchedAt), + checkRequired("isOwnAccount", isOwnAccount), + checkRequired("tweetCount", tweetCount), + checkRequired("tweets", tweets).map { it.toImmutable() }, + checkRequired("xUsername", xUsername), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Style1 = apply { + if (validated) { + return@apply + } + + fetchedAt() + isOwnAccount() + tweetCount() + tweets().forEach { it.validate() } + xUsername() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (fetchedAt.asKnown().isPresent) 1 else 0) + + (if (isOwnAccount.asKnown().isPresent) 1 else 0) + + (if (tweetCount.asKnown().isPresent) 1 else 0) + + (tweets.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (xUsername.asKnown().isPresent) 1 else 0) + + class Tweet + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val text: JsonField, + private val authorUsername: JsonField, + private val createdAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("authorUsername") + @ExcludeMissing + authorUsername: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + ) : this(id, text, authorUsername, createdAt, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun text(): String = text.getRequired("text") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun authorUsername(): Optional = authorUsername.getOptional("authorUsername") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("createdAt") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + /** + * Returns the raw JSON value of [authorUsername]. + * + * Unlike [authorUsername], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("authorUsername") + @ExcludeMissing + fun _authorUsername(): JsonField = authorUsername + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Tweet]. + * + * The following fields are required: + * ```java + * .id() + * .text() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Tweet]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var text: JsonField? = null + private var authorUsername: JsonField = JsonMissing.of() + private var createdAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(tweet: Tweet) = apply { + id = tweet.id + text = tweet.text + authorUsername = tweet.authorUsername + createdAt = tweet.createdAt + additionalProperties = tweet.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + fun authorUsername(authorUsername: String) = + authorUsername(JsonField.of(authorUsername)) + + /** + * Sets [Builder.authorUsername] to an arbitrary JSON value. + * + * You should usually call [Builder.authorUsername] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun authorUsername(authorUsername: JsonField) = apply { + this.authorUsername = authorUsername + } + + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Tweet]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .text() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tweet = + Tweet( + checkRequired("id", id), + checkRequired("text", text), + authorUsername, + createdAt, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tweet = apply { + if (validated) { + return@apply + } + + id() + text() + authorUsername() + createdAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (text.asKnown().isPresent) 1 else 0) + + (if (authorUsername.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tweet && + id == other.id && + text == other.text && + authorUsername == other.authorUsername && + createdAt == other.createdAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, text, authorUsername, createdAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tweet{id=$id, text=$text, authorUsername=$authorUsername, createdAt=$createdAt, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Style1 && + fetchedAt == other.fetchedAt && + isOwnAccount == other.isOwnAccount && + tweetCount == other.tweetCount && + tweets == other.tweets && + xUsername == other.xUsername && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + fetchedAt, + isOwnAccount, + tweetCount, + tweets, + xUsername, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Style1{fetchedAt=$fetchedAt, isOwnAccount=$isOwnAccount, tweetCount=$tweetCount, tweets=$tweets, xUsername=$xUsername, additionalProperties=$additionalProperties}" + } + + class Style2 + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val fetchedAt: JsonField, + private val isOwnAccount: JsonField, + private val tweetCount: JsonField, + private val tweets: JsonField>, + private val xUsername: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("fetchedAt") + @ExcludeMissing + fetchedAt: JsonField = JsonMissing.of(), + @JsonProperty("isOwnAccount") + @ExcludeMissing + isOwnAccount: JsonField = JsonMissing.of(), + @JsonProperty("tweetCount") + @ExcludeMissing + tweetCount: JsonField = JsonMissing.of(), + @JsonProperty("tweets") + @ExcludeMissing + tweets: JsonField> = JsonMissing.of(), + @JsonProperty("xUsername") + @ExcludeMissing + xUsername: JsonField = JsonMissing.of(), + ) : this(fetchedAt, isOwnAccount, tweetCount, tweets, xUsername, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun fetchedAt(): OffsetDateTime = fetchedAt.getRequired("fetchedAt") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun isOwnAccount(): Boolean = isOwnAccount.getRequired("isOwnAccount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweetCount(): Long = tweetCount.getRequired("tweetCount") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tweets(): List = tweets.getRequired("tweets") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun xUsername(): String = xUsername.getRequired("xUsername") + + /** + * Returns the raw JSON value of [fetchedAt]. + * + * Unlike [fetchedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("fetchedAt") + @ExcludeMissing + fun _fetchedAt(): JsonField = fetchedAt + + /** + * Returns the raw JSON value of [isOwnAccount]. + * + * Unlike [isOwnAccount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("isOwnAccount") + @ExcludeMissing + fun _isOwnAccount(): JsonField = isOwnAccount + + /** + * Returns the raw JSON value of [tweetCount]. + * + * Unlike [tweetCount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tweetCount") @ExcludeMissing fun _tweetCount(): JsonField = tweetCount + + /** + * Returns the raw JSON value of [tweets]. + * + * Unlike [tweets], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tweets") @ExcludeMissing fun _tweets(): JsonField> = tweets + + /** + * Returns the raw JSON value of [xUsername]. + * + * Unlike [xUsername], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("xUsername") @ExcludeMissing fun _xUsername(): JsonField = xUsername + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Style2]. + * + * The following fields are required: + * ```java + * .fetchedAt() + * .isOwnAccount() + * .tweetCount() + * .tweets() + * .xUsername() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Style2]. */ + class Builder internal constructor() { + + private var fetchedAt: JsonField? = null + private var isOwnAccount: JsonField? = null + private var tweetCount: JsonField? = null + private var tweets: JsonField>? = null + private var xUsername: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(style2: Style2) = apply { + fetchedAt = style2.fetchedAt + isOwnAccount = style2.isOwnAccount + tweetCount = style2.tweetCount + tweets = style2.tweets.map { it.toMutableList() } + xUsername = style2.xUsername + additionalProperties = style2.additionalProperties.toMutableMap() + } + + fun fetchedAt(fetchedAt: OffsetDateTime) = fetchedAt(JsonField.of(fetchedAt)) + + /** + * Sets [Builder.fetchedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.fetchedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fetchedAt(fetchedAt: JsonField) = apply { + this.fetchedAt = fetchedAt + } + + fun isOwnAccount(isOwnAccount: Boolean) = isOwnAccount(JsonField.of(isOwnAccount)) + + /** + * Sets [Builder.isOwnAccount] to an arbitrary JSON value. + * + * You should usually call [Builder.isOwnAccount] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isOwnAccount(isOwnAccount: JsonField) = apply { + this.isOwnAccount = isOwnAccount + } + + fun tweetCount(tweetCount: Long) = tweetCount(JsonField.of(tweetCount)) + + /** + * Sets [Builder.tweetCount] to an arbitrary JSON value. + * + * You should usually call [Builder.tweetCount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweetCount(tweetCount: JsonField) = apply { this.tweetCount = tweetCount } + + fun tweets(tweets: List) = tweets(JsonField.of(tweets)) + + /** + * Sets [Builder.tweets] to an arbitrary JSON value. + * + * You should usually call [Builder.tweets] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tweets(tweets: JsonField>) = apply { + this.tweets = tweets.map { it.toMutableList() } + } + + /** + * Adds a single [Tweet] to [tweets]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTweet(tweet: Tweet) = apply { + tweets = + (tweets ?: JsonField.of(mutableListOf())).also { + checkKnown("tweets", it).add(tweet) + } + } + + fun xUsername(xUsername: String) = xUsername(JsonField.of(xUsername)) + + /** + * Sets [Builder.xUsername] to an arbitrary JSON value. + * + * You should usually call [Builder.xUsername] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun xUsername(xUsername: JsonField) = apply { this.xUsername = xUsername } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Style2]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fetchedAt() + * .isOwnAccount() + * .tweetCount() + * .tweets() + * .xUsername() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Style2 = + Style2( + checkRequired("fetchedAt", fetchedAt), + checkRequired("isOwnAccount", isOwnAccount), + checkRequired("tweetCount", tweetCount), + checkRequired("tweets", tweets).map { it.toImmutable() }, + checkRequired("xUsername", xUsername), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Style2 = apply { + if (validated) { + return@apply + } + + fetchedAt() + isOwnAccount() + tweetCount() + tweets().forEach { it.validate() } + xUsername() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (fetchedAt.asKnown().isPresent) 1 else 0) + + (if (isOwnAccount.asKnown().isPresent) 1 else 0) + + (if (tweetCount.asKnown().isPresent) 1 else 0) + + (tweets.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (xUsername.asKnown().isPresent) 1 else 0) + + class Tweet + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val text: JsonField, + private val authorUsername: JsonField, + private val createdAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("authorUsername") + @ExcludeMissing + authorUsername: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + ) : this(id, text, authorUsername, createdAt, mutableMapOf()) + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun text(): String = text.getRequired("text") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun authorUsername(): Optional = authorUsername.getOptional("authorUsername") + + /** + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("createdAt") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + /** + * Returns the raw JSON value of [authorUsername]. + * + * Unlike [authorUsername], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("authorUsername") + @ExcludeMissing + fun _authorUsername(): JsonField = authorUsername + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Tweet]. + * + * The following fields are required: + * ```java + * .id() + * .text() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Tweet]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var text: JsonField? = null + private var authorUsername: JsonField = JsonMissing.of() + private var createdAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(tweet: Tweet) = apply { + id = tweet.id + text = tweet.text + authorUsername = tweet.authorUsername + createdAt = tweet.createdAt + additionalProperties = tweet.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + fun authorUsername(authorUsername: String) = + authorUsername(JsonField.of(authorUsername)) + + /** + * Sets [Builder.authorUsername] to an arbitrary JSON value. + * + * You should usually call [Builder.authorUsername] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun authorUsername(authorUsername: JsonField) = apply { + this.authorUsername = authorUsername + } + + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Tweet]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .text() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tweet = + Tweet( + checkRequired("id", id), + checkRequired("text", text), + authorUsername, + createdAt, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tweet = apply { + if (validated) { + return@apply + } + + id() + text() + authorUsername() + createdAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: XTwitterScraperInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (text.asKnown().isPresent) 1 else 0) + + (if (authorUsername.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tweet && + id == other.id && + text == other.text && + authorUsername == other.authorUsername && + createdAt == other.createdAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, text, authorUsername, createdAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tweet{id=$id, text=$text, authorUsername=$authorUsername, createdAt=$createdAt, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Style2 && + fetchedAt == other.fetchedAt && + isOwnAccount == other.isOwnAccount && + tweetCount == other.tweetCount && + tweets == other.tweets && + xUsername == other.xUsername && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + fetchedAt, + isOwnAccount, + tweetCount, + tweets, + xUsername, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Style2{fetchedAt=$fetchedAt, isOwnAccount=$isOwnAccount, tweetCount=$tweetCount, tweets=$tweets, xUsername=$xUsername, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleListResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleListResponse.kt index 909ab03..0b2a049 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleListResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleListResponse.kt @@ -14,6 +14,7 @@ import com.x_twitter_scraper.api.core.checkKnown import com.x_twitter_scraper.api.core.checkRequired import com.x_twitter_scraper.api.core.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects import kotlin.jvm.optionals.getOrNull @@ -21,31 +22,27 @@ import kotlin.jvm.optionals.getOrNull class StyleListResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val styles: JsonField>, + private val styles: JsonField>, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("styles") - @ExcludeMissing - styles: JsonField> = JsonMissing.of() + @JsonProperty("styles") @ExcludeMissing styles: JsonField> = JsonMissing.of() ) : this(styles, mutableMapOf()) /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun styles(): List = styles.getRequired("styles") + fun styles(): List