diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 10f3091..6b7b74c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.2.0" + ".": "0.3.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 58aca93..db87955 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-3b2c6c771ad1da0bbfeb0af115972929ed2c7fcd5e47a79556d66cd21431b224.yml -openapi_spec_hash: de2890233b68387bf5f9b6d19e7d87dc -config_hash: 8894c96caeb6df84c9394518810221bd +configured_endpoints: 117 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/xquik%2Fx-twitter-scraper-d40c57a05527faf060d21c0e013729f371d88017b10680cea7c8fd6780ffaef5.yml +openapi_spec_hash: 597ebc460cf86740b9f6f7c95478dece +config_hash: 30ce23c9cfbf8fb8be9e5dd28a2124fa diff --git a/CHANGELOG.md b/CHANGELOG.md index 2239e78..8ee5e83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # Changelog +## 0.3.0 (2026-04-08) + +Full Changelog: [v0.2.0...v0.3.0](https://github.com/Xquik-dev/x-twitter-scraper-java/compare/v0.2.0...v0.3.0) + +### Features + +* **api:** api update ([c190c61](https://github.com/Xquik-dev/x-twitter-scraper-java/commit/c190c61c7ec6d8edd03874f8bcaac3ca9bce5fae)) +* **api:** api update ([d3ad9b3](https://github.com/Xquik-dev/x-twitter-scraper-java/commit/d3ad9b3b176efa1edd42d9500965287b714acef5)) +* **api:** api update ([91fe731](https://github.com/Xquik-dev/x-twitter-scraper-java/commit/91fe7314ce8e6e9db863a4bc4863333ffb94fc5c)) +* **api:** api update ([85f6788](https://github.com/Xquik-dev/x-twitter-scraper-java/commit/85f67881300bb5cdb912fe7c59edcd0af640a14f)) +* **api:** api update ([d4be9ff](https://github.com/Xquik-dev/x-twitter-scraper-java/commit/d4be9ff16190320b7cdaffae495057ee2ceda50c)) +* **api:** api update ([f8f5138](https://github.com/Xquik-dev/x-twitter-scraper-java/commit/f8f51380d7cb3d07a0be410e69492edf9fba07cc)) +* **api:** api update ([be5b4f9](https://github.com/Xquik-dev/x-twitter-scraper-java/commit/be5b4f9f89ea2e7606d57cb7f0ea809c17c4096f)) +* **api:** api update ([a4e0acd](https://github.com/Xquik-dev/x-twitter-scraper-java/commit/a4e0acdd9e95507a2d69d05b50c5b8c114c7cd0b)) + + +### Chores + +* update SDK settings ([0a6a774](https://github.com/Xquik-dev/x-twitter-scraper-java/commit/0a6a774604e8868c1a286b2235433829a46ebe92)) + ## 0.2.0 (2026-04-01) Full Changelog: [v0.1.0...v0.2.0](https://github.com/Xquik-dev/x-twitter-scraper-java/compare/v0.1.0...v0.2.0) diff --git a/README.md b/README.md index 39d4d2e..c3a3578 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![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.2.0) -[![javadoc](https://javadoc.io/badge2/com.x_twitter_scraper.api/x-twitter-scraper-java/0.2.0/javadoc.svg)](https://javadoc.io/doc/com.x_twitter_scraper.api/x-twitter-scraper-java/0.2.0) +[![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.3.0) +[![javadoc](https://javadoc.io/badge2/com.x_twitter_scraper.api/x-twitter-scraper-java/0.3.0/javadoc.svg)](https://javadoc.io/doc/com.x_twitter_scraper.api/x-twitter-scraper-java/0.3.0) @@ -15,7 +15,7 @@ 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.2.0). +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.3.0). @@ -26,7 +26,7 @@ The REST API documentation can be found on [xquik.com](https://xquik.com). Javad ### Gradle ```kotlin -implementation("com.x_twitter_scraper.api:x-twitter-scraper-java:0.2.0") +implementation("com.x_twitter_scraper.api:x-twitter-scraper-java:0.3.0") ``` ### Maven @@ -35,7 +35,7 @@ implementation("com.x_twitter_scraper.api:x-twitter-scraper-java:0.2.0") com.x_twitter_scraper.api x-twitter-scraper-java - 0.2.0 + 0.3.0 ``` @@ -50,8 +50,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 @@ -61,7 +61,7 @@ TweetSearchParams params = TweetSearchParams.builder() .q("from:elonmusk") .limit(10L) .build(); -TweetSearchResponse response = client.x().tweets().search(params); +PaginatedTweets paginatedTweets = client.x().tweets().search(params); ``` ## Client configuration @@ -136,7 +136,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 `TweetSearchResponse`. +For example, `client.x().tweets().search(...)` should be called with an instance of `TweetSearchParams`, and it will return an instance of `PaginatedTweets`. ## Immutability @@ -153,8 +153,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 @@ -165,7 +165,7 @@ TweetSearchParams params = TweetSearchParams.builder() .q("from:elonmusk") .limit(10L) .build(); -CompletableFuture response = client.async().x().tweets().search(params); +CompletableFuture paginatedTweets = client.async().x().tweets().search(params); ``` Or create an asynchronous client from the beginning: @@ -173,8 +173,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 @@ -185,7 +185,7 @@ TweetSearchParams params = TweetSearchParams.builder() .q("from:elonmusk") .limit(10L) .build(); -CompletableFuture response = client.x().tweets().search(params); +CompletableFuture paginatedTweets = client.x().tweets().search(params); ``` The asynchronous client supports the same options as the synchronous one, except most methods return `CompletableFuture`s. @@ -202,7 +202,7 @@ import com.x_twitter_scraper.api.models.x.media.MediaUploadResponse; import java.nio.file.Paths; MediaUploadParams params = MediaUploadParams.builder() - .account("account") + .account("@elonmusk") .file(Paths.get("/path/to/file")) .build(); MediaUploadResponse response = client.x().media().upload(params); @@ -216,7 +216,7 @@ import com.x_twitter_scraper.api.models.x.media.MediaUploadResponse; import java.net.URL; MediaUploadParams params = MediaUploadParams.builder() - .account("account") + .account("@elonmusk") .file(new URL("https://example.com//path/to/file").openStream()) .build(); MediaUploadResponse response = client.x().media().upload(params); @@ -229,7 +229,7 @@ import com.x_twitter_scraper.api.models.x.media.MediaUploadParams; import com.x_twitter_scraper.api.models.x.media.MediaUploadResponse; MediaUploadParams params = MediaUploadParams.builder() - .account("account") + .account("@elonmusk") .file("content".getBytes()) .build(); MediaUploadResponse response = client.x().media().upload(params); @@ -245,7 +245,7 @@ import java.io.InputStream; import java.net.URL; MediaUploadParams params = MediaUploadParams.builder() - .account("account") + .account("@elonmusk") .file(MultipartField.builder() .value(new URL("https://example.com//path/to/file").openStream()) .filename("/path/to/file") @@ -311,25 +311,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 response = client.x().tweets().withRawResponse().search(params); +HttpResponseFor paginatedTweets = client.x().tweets().withRawResponse().search(params); -int statusCode = response.statusCode(); -Headers headers = response.headers(); +int statusCode = paginatedTweets.statusCode(); +Headers headers = paginatedTweets.headers(); ``` You can still deserialize the response into an instance of a Java class if needed: ```java -import com.x_twitter_scraper.api.models.x.tweets.TweetSearchResponse; +import com.x_twitter_scraper.api.models.PaginatedTweets; -TweetSearchResponse parsedResponse = response.parse(); +PaginatedTweets parsedPaginatedTweets = paginatedTweets.parse(); ``` ## Error handling @@ -427,9 +427,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.x.tweets.TweetSearchResponse; +import com.x_twitter_scraper.api.models.PaginatedTweets; -TweetSearchResponse response = client.x().tweets().search( +PaginatedTweets paginatedTweets = client.x().tweets().search( params, RequestOptions.builder().timeout(Duration.ofSeconds(30)).build() ); ``` @@ -705,17 +705,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.x.tweets.TweetSearchResponse; +import com.x_twitter_scraper.api.models.PaginatedTweets; -TweetSearchResponse response = client.x().tweets().search(params).validate(); +PaginatedTweets paginatedTweets = 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.x.tweets.TweetSearchResponse; +import com.x_twitter_scraper.api.models.PaginatedTweets; -TweetSearchResponse response = client.x().tweets().search( +PaginatedTweets paginatedTweets = client.x().tweets().search( params, RequestOptions.builder().responseValidation(true).build() ); ``` diff --git a/build.gradle.kts b/build.gradle.kts index 81f4172..93d1d37 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.x_twitter_scraper.api" - version = "0.2.0" // x-release-please-version + version = "0.3.0" // x-release-please-version } subprojects { 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 b0ad2e8..c59ccf8 100644 --- a/buildSrc/src/main/kotlin/x-twitter-scraper.publish.gradle.kts +++ b/buildSrc/src/main/kotlin/x-twitter-scraper.publish.gradle.kts @@ -43,7 +43,7 @@ configure { pom { name.set("Xquik API") - description.set("X real-time data platform — extractions, giveaway draws, monitoring, webhooks.") + description.set("Xquik is an all-in-one X (Twitter) automation API with 40+ endpoints for\nreading, writing, and monitoring X data. **Read endpoints** let you look up\ntweets, search tweets, fetch user profiles, list followers & following, browse\ntimelines, bookmarks, notifications, communities, lists, trending topics, and\ndownload media. **Write endpoints** let you post tweets, reply, like, unlike,\nretweet, unretweet, follow, unfollow, send DMs, upload media, update profiles,\nand manage communities. **Automation endpoints** power bulk data extractions (20\ntool types), giveaway draws from tweet replies, real-time account monitoring\nwith webhooks & Telegram integrations, tweet composition with AI, and writing\nstyle analysis. Authenticate with an API key or OAuth 2.1 bearer token.\nPay-per-use endpoints are also available without an account.") url.set("https://xquik.com") licenses { diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/Error.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/Error.kt index cb6ccba..6356b08 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/Error.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/Error.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects import kotlin.jvm.optionals.getOrNull +/** Error response containing a machine-readable error code. */ class Error @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/EventType.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/EventType.kt index 4f21ed7..fad6c19 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/EventType.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/EventType.kt @@ -7,6 +7,7 @@ import com.x_twitter_scraper.api.core.Enum import com.x_twitter_scraper.api.core.JsonField import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +/** Type of monitor event fired when account activity occurs. */ class EventType @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/PaginatedTweets.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/PaginatedTweets.kt index 2880aa9..2817a3e 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,17 +14,18 @@ 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 +/** Paginated list of tweets with cursor-based navigation. */ class PaginatedTweets @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val hasNextPage: JsonField, private val nextCursor: JsonField, - private val tweets: JsonField>, + private val tweets: JsonField>, private val additionalProperties: MutableMap, ) { @@ -36,7 +37,9 @@ 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()) /** @@ -55,7 +58,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]. @@ -78,7 +81,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) { @@ -112,7 +115,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 @@ -145,25 +148,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 [Tweet] to [tweets]. + * Adds a single [SearchTweet] to [tweets]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addTweet(tweet: Tweet) = apply { + fun addTweet(tweet: SearchTweet) = apply { tweets = (tweets ?: JsonField.of(mutableListOf())).also { checkKnown("tweets", it).add(tweet) @@ -244,776 +247,6 @@ 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 c3e969c..f7a0acf 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,17 +14,18 @@ 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 +/** Paginated list of user profiles with cursor-based navigation. */ class PaginatedUsers @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val hasNextPage: JsonField, private val nextCursor: JsonField, - private val users: JsonField>, + private val users: JsonField>, private val additionalProperties: MutableMap, ) { @@ -36,7 +37,9 @@ 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()) /** @@ -55,7 +58,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]. @@ -78,7 +81,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) { @@ -112,7 +115,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 @@ -145,25 +148,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 [User] to [users]. + * Adds a single [UserProfile] to [users]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addUser(user: User) = apply { + fun addUser(user: UserProfile) = apply { users = (users ?: JsonField.of(mutableListOf())).also { checkKnown("users", it).add(user) } } @@ -242,552 +245,6 @@ 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/ApiKey.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/apikeys/ApiKey.kt index f4edb41..f7477af 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/apikeys/ApiKey.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/apikeys/ApiKey.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects import java.util.Optional +/** API key metadata returned when listing keys. */ class ApiKey @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( 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 cc46a86..dc1a8f1 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,36 +14,34 @@ 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) { @@ -73,7 +71,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 @@ -82,22 +80,25 @@ 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 [Key] to [keys]. + * Adds a single [ApiKey] to [keys]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addKey(key: Key) = apply { + fun addKey(key: ApiKey) = apply { keys = (keys ?: JsonField.of(mutableListOf())).also { checkKnown("keys", it).add(key) } } @@ -167,353 +168,6 @@ 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/compose/ComposeCreateResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/compose/ComposeCreateResponse.kt index 2687153..34478fb 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/compose/ComposeCreateResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/compose/ComposeCreateResponse.kt @@ -3,23 +3,112 @@ package com.x_twitter_scraper.api.models.compose 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.toImmutable import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException +import java.util.Collections import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull class ComposeCreateResponse -@JsonCreator +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val feedback: JsonField, + private val score: JsonField, + private val suggestions: JsonField>, + private val text: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("feedback") @ExcludeMissing feedback: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + @JsonProperty("suggestions") + @ExcludeMissing + suggestions: JsonField> = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + ) : this(feedback, score, suggestions, text, mutableMapOf()) + + /** + * AI feedback on the draft + * + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun feedback(): Optional = feedback.getOptional("feedback") + + /** + * Engagement score (0-100) + * + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Improvement suggestions + * + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun suggestions(): Optional> = suggestions.getOptional("suggestions") + + /** + * Generated or refined tweet text + * + * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun text(): Optional = text.getOptional("text") + + /** + * Returns the raw JSON value of [feedback]. + * + * Unlike [feedback], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("feedback") @ExcludeMissing fun _feedback(): JsonField = feedback + + /** + * 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 [suggestions]. + * + * Unlike [suggestions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("suggestions") + @ExcludeMissing + fun _suggestions(): JsonField> = suggestions + + /** + * 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 + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -32,13 +121,80 @@ private constructor( /** A builder for [ComposeCreateResponse]. */ class Builder internal constructor() { + private var feedback: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var suggestions: JsonField>? = null + private var text: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(composeCreateResponse: ComposeCreateResponse) = apply { + feedback = composeCreateResponse.feedback + score = composeCreateResponse.score + suggestions = composeCreateResponse.suggestions.map { it.toMutableList() } + text = composeCreateResponse.text additionalProperties = composeCreateResponse.additionalProperties.toMutableMap() } + /** AI feedback on the draft */ + fun feedback(feedback: String) = feedback(JsonField.of(feedback)) + + /** + * Sets [Builder.feedback] to an arbitrary JSON value. + * + * You should usually call [Builder.feedback] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun feedback(feedback: JsonField) = apply { this.feedback = feedback } + + /** Engagement score (0-100) */ + 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 } + + /** Improvement suggestions */ + fun suggestions(suggestions: List) = suggestions(JsonField.of(suggestions)) + + /** + * Sets [Builder.suggestions] to an arbitrary JSON value. + * + * You should usually call [Builder.suggestions] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun suggestions(suggestions: JsonField>) = apply { + this.suggestions = suggestions.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [suggestions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSuggestion(suggestion: String) = apply { + suggestions = + (suggestions ?: JsonField.of(mutableListOf())).also { + checkKnown("suggestions", it).add(suggestion) + } + } + + /** Generated or refined tweet text */ + 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 additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -64,7 +220,13 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): ComposeCreateResponse = - ComposeCreateResponse(additionalProperties.toImmutable()) + ComposeCreateResponse( + feedback, + score, + (suggestions ?: JsonMissing.of()).map { it.toImmutable() }, + text, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -74,6 +236,10 @@ private constructor( return@apply } + feedback() + score() + suggestions() + text() validated = true } @@ -92,19 +258,30 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (feedback.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + (suggestions.asKnown().getOrNull()?.size ?: 0) + + (if (text.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is ComposeCreateResponse && additionalProperties == other.additionalProperties + return other is ComposeCreateResponse && + feedback == other.feedback && + score == other.score && + suggestions == other.suggestions && + text == other.text && + additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + private val hashCode: Int by lazy { + Objects.hash(feedback, score, suggestions, text, additionalProperties) + } override fun hashCode(): Int = hashCode - override fun toString() = "ComposeCreateResponse{additionalProperties=$additionalProperties}" + override fun toString() = + "ComposeCreateResponse{feedback=$feedback, score=$score, suggestions=$suggestions, text=$text, additionalProperties=$additionalProperties}" } diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/Draft.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/Draft.kt index 40c2080..81ebb82 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/Draft.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/Draft.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects import java.util.Optional +/** Saved tweet draft with optional topic and goal. */ class Draft @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( 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 deleted file mode 100644 index 37fd934..0000000 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftCreateResponse.kt +++ /dev/null @@ -1,347 +0,0 @@ -// 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/DraftDetail.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftDetail.kt index 3a80f3d..e4c8ebd 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftDetail.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftDetail.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects import java.util.Optional +/** Full tweet draft including update timestamp. */ class DraftDetail @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftListParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftListParams.kt index 727ae92..791ebf8 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftListParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftListParams.kt @@ -21,6 +21,7 @@ private constructor( /** Cursor for pagination */ fun afterCursor(): Optional = Optional.ofNullable(afterCursor) + /** Maximum number of items to return (1-100, default 50) */ fun limit(): Optional = Optional.ofNullable(limit) /** Additional headers to send with the request. */ @@ -61,6 +62,7 @@ private constructor( /** Alias for calling [Builder.afterCursor] with `afterCursor.orElse(null)`. */ fun afterCursor(afterCursor: Optional) = afterCursor(afterCursor.getOrNull()) + /** Maximum number of items to return (1-100, default 50) */ fun limit(limit: Long?) = apply { this.limit = limit } /** 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 da62295..ee471eb 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,7 +14,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 java.time.OffsetDateTime import java.util.Collections import java.util.Objects import java.util.Optional @@ -236,307 +235,6 @@ 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 deleted file mode 100644 index 45f2c57..0000000 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/drafts/DraftRetrieveResponse.kt +++ /dev/null @@ -1,347 +0,0 @@ -// 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/DrawDetail.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawDetail.kt index 330c1b4..ee79d40 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawDetail.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawDetail.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects import java.util.Optional +/** Full giveaway draw with tweet metrics, entries, and timing. */ class DrawDetail @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawExportParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawExportParams.kt index 9071e39..d37a0b7 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawExportParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawExportParams.kt @@ -25,6 +25,7 @@ private constructor( fun id(): Optional = Optional.ofNullable(id) + /** Export output format */ fun format(): Optional = Optional.ofNullable(format) /** Export winners or all entries */ @@ -69,6 +70,7 @@ private constructor( /** Alias for calling [Builder.id] with `id.orElse(null)`. */ fun id(id: Optional) = id(id.getOrNull()) + /** Export output format */ fun format(format: Format?) = apply { this.format = format } /** Alias for calling [Builder.format] with `format.orElse(null)`. */ @@ -210,6 +212,7 @@ private constructor( } .build() + /** Export output format */ class Format @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/draws/DrawListItem.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawListItem.kt index 3297fd6..050b004 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawListItem.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawListItem.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects import java.util.Optional +/** Giveaway draw summary with entry counts and status. */ class DrawListItem @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawListParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawListParams.kt index 1676adb..ab4f65a 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawListParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/DrawListParams.kt @@ -18,9 +18,10 @@ private constructor( private val additionalQueryParams: QueryParams, ) : Params { - /** Cursor for pagination */ + /** Cursor for keyset pagination */ fun after(): Optional = Optional.ofNullable(after) + /** Maximum number of items to return (1-100, default 50) */ fun limit(): Optional = Optional.ofNullable(limit) /** Additional headers to send with the request. */ @@ -55,12 +56,13 @@ private constructor( additionalQueryParams = drawListParams.additionalQueryParams.toBuilder() } - /** Cursor for pagination */ + /** Cursor for keyset pagination */ fun after(after: String?) = apply { this.after = after } /** Alias for calling [Builder.after] with `after.orElse(null)`. */ fun after(after: Optional) = after(after.getOrNull()) + /** Maximum number of items to return (1-100, default 50) */ fun limit(limit: Long?) = apply { this.limit = limit } /** 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 fd73ddd..0dd6e51 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,7 +14,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 java.time.OffsetDateTime import java.util.Collections import java.util.Objects import java.util.Optional @@ -23,7 +22,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, @@ -31,7 +30,9 @@ 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()) @@ -40,7 +41,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 @@ -59,7 +60,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]. @@ -104,7 +105,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() @@ -117,25 +118,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 [Draw] to [draws]. + * Adds a single [DrawListItem] to [draws]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addDraw(draw: Draw) = apply { + fun addDraw(draw: DrawListItem) = apply { draws = (draws ?: JsonField.of(mutableListOf())).also { checkKnown("draws", it).add(draw) } } @@ -234,416 +235,6 @@ 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 28fe343..0d99841 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,31 +14,31 @@ 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()) /** + * Full giveaway draw with tweet metrics, entries, and timing. + * * @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(): Draw = draw.getRequired("draw") + fun draw(): DrawDetail = draw.getRequired("draw") /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is @@ -51,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]. @@ -89,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() @@ -100,15 +100,16 @@ private constructor( additionalProperties = drawRetrieveResponse.additionalProperties.toMutableMap() } - fun draw(draw: Draw) = draw(JsonField.of(draw)) + /** Full giveaway draw with tweet metrics, entries, and timing. */ + fun draw(draw: DrawDetail) = draw(JsonField.of(draw)) /** * Sets [Builder.draw] to an arbitrary JSON value. * - * You should usually call [Builder.draw] with a well-typed [Draw] value instead. This + * You should usually call [Builder.draw] with a well-typed [DrawDetail] 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)) @@ -205,992 +206,6 @@ 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 0c4883f..ae4596e 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,282 +309,6 @@ 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/draws/Winner.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/Winner.kt index 186f724..f2b9e45 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/Winner.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/draws/Winner.kt @@ -15,6 +15,7 @@ import com.x_twitter_scraper.api.errors.XTwitterScraperInvalidDataException import java.util.Collections import java.util.Objects +/** Giveaway draw winner with position and backup flag. */ class Winner @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( 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 ec20d19..e633e17 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,7 +6,6 @@ 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,11 +13,13 @@ 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 import kotlin.jvm.optionals.getOrNull +/** Monitor event summary with type, username, and occurrence time. */ class Event @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( @@ -26,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 additionalProperties: MutableMap, ) { @@ -39,7 +40,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()) @@ -68,10 +69,12 @@ private constructor( fun occurredAt(): OffsetDateTime = occurredAt.getRequired("occurredAt") /** + * Type of monitor event fired when account activity occurs. + * * @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") + fun type(): EventType = type.getRequired("type") /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is @@ -114,7 +117,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 +163,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 +222,16 @@ private constructor( this.occurredAt = occurredAt } - fun type(type: Type) = type(JsonField.of(type)) + /** Type of monitor event fired when account activity occurs. */ + fun type(type: EventType) = 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 + * You should usually call [Builder.type] with a well-typed [EventType] 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,157 +428,6 @@ 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 c6b2f6b..eec6aec 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,7 +6,6 @@ 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,12 +13,14 @@ 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 import java.util.Optional import kotlin.jvm.optionals.getOrNull +/** Full monitor event including payload data and optional X event ID. */ class EventDetail @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( @@ -27,7 +28,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 +42,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()) @@ -53,6 +54,8 @@ private constructor( fun id(): String = id.getRequired("id") /** + * Event payload — shape varies by event type (JSON) + * * @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). */ @@ -71,10 +74,12 @@ private constructor( fun occurredAt(): OffsetDateTime = occurredAt.getRequired("occurredAt") /** + * Type of monitor event fired when account activity occurs. + * * @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") + fun type(): EventType = type.getRequired("type") /** * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type or is @@ -123,7 +128,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 +181,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() @@ -203,6 +208,7 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } + /** Event payload — shape varies by event type (JSON) */ fun data(data: Data) = data(JsonField.of(data)) /** @@ -237,15 +243,16 @@ private constructor( this.occurredAt = occurredAt } - fun type(type: Type) = type(JsonField.of(type)) + /** Type of monitor event fired when account activity occurs. */ + fun type(type: EventType) = 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 + * You should usually call [Builder.type] with a well-typed [EventType] 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)) @@ -356,6 +363,7 @@ private constructor( (if (username.asKnown().isPresent) 1 else 0) + (if (xEventId.asKnown().isPresent) 1 else 0) + /** Event payload — shape varies by event type (JSON) */ class Data @JsonCreator private constructor( @@ -455,157 +463,6 @@ 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 f61e383..d194443 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,13 +2,10 @@ 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.errors.XTwitterScraperInvalidDataException +import com.x_twitter_scraper.api.models.EventType import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -24,13 +21,16 @@ private constructor( private val additionalQueryParams: QueryParams, ) : Params { - /** Cursor for pagination */ + /** Cursor for keyset pagination */ fun after(): Optional = Optional.ofNullable(after) + /** Filter events by type */ fun eventType(): Optional = Optional.ofNullable(eventType) + /** Maximum number of items to return (1-100, default 50) */ fun limit(): Optional = Optional.ofNullable(limit) + /** Filter events by monitor ID */ fun monitorId(): Optional = Optional.ofNullable(monitorId) /** Additional headers to send with the request. */ @@ -69,17 +69,19 @@ private constructor( additionalQueryParams = eventListParams.additionalQueryParams.toBuilder() } - /** Cursor for pagination */ + /** Cursor for keyset pagination */ fun after(after: String?) = apply { this.after = after } /** Alias for calling [Builder.after] with `after.orElse(null)`. */ fun after(after: Optional) = after(after.getOrNull()) + /** Filter events by type */ fun eventType(eventType: EventType?) = apply { this.eventType = eventType } /** Alias for calling [Builder.eventType] with `eventType.orElse(null)`. */ fun eventType(eventType: Optional) = eventType(eventType.getOrNull()) + /** Maximum number of items to return (1-100, default 50) */ fun limit(limit: Long?) = apply { this.limit = limit } /** @@ -92,6 +94,7 @@ private constructor( /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ fun limit(limit: Optional) = limit(limit.getOrNull()) + /** Filter events by monitor ID */ fun monitorId(monitorId: String?) = apply { this.monitorId = monitorId } /** Alias for calling [Builder.monitorId] with `monitorId.orElse(null)`. */ @@ -224,159 +227,6 @@ 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 32fc614..7dbcb1c 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,7 +6,6 @@ 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 @@ -15,7 +14,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 java.time.OffsetDateTime import java.util.Collections import java.util.Objects import java.util.Optional @@ -237,603 +235,6 @@ 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 deleted file mode 100644 index e3ccc73..0000000 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/events/EventRetrieveResponse.kt +++ /dev/null @@ -1,642 +0,0 @@ -// 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/ExtractionEstimateCostParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionEstimateCostParams.kt index 5dbf9e1..de3f924 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionEstimateCostParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionEstimateCostParams.kt @@ -30,13 +30,15 @@ private constructor( ) : Params { /** + * Identifier for the extraction tool used to run a job. + * * @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 = body.toolType() /** - * Raw advanced search query appended as-is (tweet_search_extractor) + * Raw advanced query string appended to the estimate (tweet_search_extractor) * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). @@ -44,7 +46,7 @@ private constructor( fun advancedQuery(): Optional = body.advancedQuery() /** - * Exact phrase to match (tweet_search_extractor) + * Exact phrase filter for search estimation * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). @@ -52,7 +54,7 @@ private constructor( fun exactPhrase(): Optional = body.exactPhrase() /** - * Words to exclude from results (tweet_search_extractor) + * Words excluded from estimated search results * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). @@ -217,6 +219,7 @@ private constructor( */ fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Identifier for the extraction tool used to run a job. */ fun toolType(toolType: ToolType) = apply { body.toolType(toolType) } /** @@ -228,7 +231,7 @@ private constructor( */ fun toolType(toolType: JsonField) = apply { body.toolType(toolType) } - /** Raw advanced search query appended as-is (tweet_search_extractor) */ + /** Raw advanced query string appended to the estimate (tweet_search_extractor) */ fun advancedQuery(advancedQuery: String) = apply { body.advancedQuery(advancedQuery) } /** @@ -242,7 +245,7 @@ private constructor( body.advancedQuery(advancedQuery) } - /** Exact phrase to match (tweet_search_extractor) */ + /** Exact phrase filter for search estimation */ fun exactPhrase(exactPhrase: String) = apply { body.exactPhrase(exactPhrase) } /** @@ -254,7 +257,7 @@ private constructor( */ fun exactPhrase(exactPhrase: JsonField) = apply { body.exactPhrase(exactPhrase) } - /** Words to exclude from results (tweet_search_extractor) */ + /** Words excluded from estimated search results */ fun excludeWords(excludeWords: String) = apply { body.excludeWords(excludeWords) } /** @@ -552,6 +555,8 @@ private constructor( ) /** + * Identifier for the extraction tool used to run a job. + * * @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). @@ -559,7 +564,7 @@ private constructor( fun toolType(): ToolType = toolType.getRequired("toolType") /** - * Raw advanced search query appended as-is (tweet_search_extractor) + * Raw advanced query string appended to the estimate (tweet_search_extractor) * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type * (e.g. if the server responded with an unexpected value). @@ -567,7 +572,7 @@ private constructor( fun advancedQuery(): Optional = advancedQuery.getOptional("advancedQuery") /** - * Exact phrase to match (tweet_search_extractor) + * Exact phrase filter for search estimation * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type * (e.g. if the server responded with an unexpected value). @@ -575,7 +580,7 @@ private constructor( fun exactPhrase(): Optional = exactPhrase.getOptional("exactPhrase") /** - * Words to exclude from results (tweet_search_extractor) + * Words excluded from estimated search results * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type * (e.g. if the server responded with an unexpected value). @@ -769,6 +774,7 @@ private constructor( additionalProperties = body.additionalProperties.toMutableMap() } + /** Identifier for the extraction tool used to run a job. */ fun toolType(toolType: ToolType) = toolType(JsonField.of(toolType)) /** @@ -780,7 +786,7 @@ private constructor( */ fun toolType(toolType: JsonField) = apply { this.toolType = toolType } - /** Raw advanced search query appended as-is (tweet_search_extractor) */ + /** Raw advanced query string appended to the estimate (tweet_search_extractor) */ fun advancedQuery(advancedQuery: String) = advancedQuery(JsonField.of(advancedQuery)) /** @@ -794,7 +800,7 @@ private constructor( this.advancedQuery = advancedQuery } - /** Exact phrase to match (tweet_search_extractor) */ + /** Exact phrase filter for search estimation */ fun exactPhrase(exactPhrase: String) = exactPhrase(JsonField.of(exactPhrase)) /** @@ -808,7 +814,7 @@ private constructor( this.exactPhrase = exactPhrase } - /** Words to exclude from results (tweet_search_extractor) */ + /** Words excluded from estimated search results */ fun excludeWords(excludeWords: String) = excludeWords(JsonField.of(excludeWords)) /** @@ -1037,6 +1043,7 @@ private constructor( "Body{toolType=$toolType, advancedQuery=$advancedQuery, exactPhrase=$exactPhrase, excludeWords=$excludeWords, searchQuery=$searchQuery, targetCommunityId=$targetCommunityId, targetListId=$targetListId, targetSpaceId=$targetSpaceId, targetTweetId=$targetTweetId, targetUsername=$targetUsername, additionalProperties=$additionalProperties}" } + /** Identifier for the extraction tool used to run a job. */ class ToolType @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/extractions/ExtractionExportResultsParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionExportResultsParams.kt index b43fdda..15900b3 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionExportResultsParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionExportResultsParams.kt @@ -24,6 +24,7 @@ private constructor( fun id(): Optional = Optional.ofNullable(id) + /** Export file format */ fun format(): Optional = Optional.ofNullable(format) /** Additional headers to send with the request. */ @@ -66,6 +67,7 @@ private constructor( /** Alias for calling [Builder.id] with `id.orElse(null)`. */ fun id(id: Optional) = id(id.getOrNull()) + /** Export file format */ fun format(format: Format?) = apply { this.format = format } /** Alias for calling [Builder.format] with `format.orElse(null)`. */ @@ -199,6 +201,7 @@ private constructor( } .build() + /** Export file format */ class Format @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/extractions/ExtractionJob.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionJob.kt index fa48bb8..eb6d678 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionJob.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionJob.kt @@ -19,6 +19,7 @@ import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull +/** Extraction job tracking status, tool type, and result count. */ class ExtractionJob @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( @@ -66,6 +67,8 @@ private constructor( fun status(): Status = status.getRequired("status") /** + * Identifier for the extraction tool used to run a job. + * * @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). */ @@ -213,6 +216,7 @@ private constructor( */ fun status(status: JsonField) = apply { this.status = status } + /** Identifier for the extraction tool used to run a job. */ fun toolType(toolType: ToolType) = toolType(JsonField.of(toolType)) /** @@ -466,6 +470,7 @@ private constructor( override fun toString() = value.toString() } + /** Identifier for the extraction tool used to run a job. */ class ToolType @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/extractions/ExtractionListParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionListParams.kt index c0769c4..2c0627e 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionListParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionListParams.kt @@ -24,13 +24,16 @@ private constructor( private val additionalQueryParams: QueryParams, ) : Params { - /** Cursor for pagination */ + /** Cursor for keyset pagination */ fun after(): Optional = Optional.ofNullable(after) + /** Maximum number of items to return (1-100, default 50) */ fun limit(): Optional = Optional.ofNullable(limit) + /** Filter by job status */ fun status(): Optional = Optional.ofNullable(status) + /** Filter by extraction tool type */ fun toolType(): Optional = Optional.ofNullable(toolType) /** Additional headers to send with the request. */ @@ -69,12 +72,13 @@ private constructor( additionalQueryParams = extractionListParams.additionalQueryParams.toBuilder() } - /** Cursor for pagination */ + /** Cursor for keyset pagination */ fun after(after: String?) = apply { this.after = after } /** Alias for calling [Builder.after] with `after.orElse(null)`. */ fun after(after: Optional) = after(after.getOrNull()) + /** Maximum number of items to return (1-100, default 50) */ fun limit(limit: Long?) = apply { this.limit = limit } /** @@ -87,11 +91,13 @@ private constructor( /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ fun limit(limit: Optional) = limit(limit.getOrNull()) + /** Filter by job status */ fun status(status: Status?) = apply { this.status = status } /** Alias for calling [Builder.status] with `status.orElse(null)`. */ fun status(status: Optional) = status(status.getOrNull()) + /** Filter by extraction tool type */ fun toolType(toolType: ToolType?) = apply { this.toolType = toolType } /** Alias for calling [Builder.toolType] with `toolType.orElse(null)`. */ @@ -224,6 +230,7 @@ private constructor( } .build() + /** Filter by job status */ class Status @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -357,6 +364,7 @@ private constructor( override fun toString() = value.toString() } + /** Filter by extraction tool type */ class ToolType @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/extractions/ExtractionListResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionListResponse.kt index 86aadc7..4c0b10c 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,7 +6,6 @@ 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 @@ -15,7 +14,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 java.time.OffsetDateTime import java.util.Collections import java.util.Objects import java.util.Optional @@ -24,7 +22,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, @@ -34,7 +32,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()) @@ -43,7 +41,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 @@ -64,7 +62,7 @@ private constructor( */ @JsonProperty("extractions") @ExcludeMissing - fun _extractions(): JsonField> = extractions + fun _extractions(): JsonField> = extractions /** * Returns the raw JSON value of [hasMore]. @@ -109,7 +107,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() @@ -122,25 +120,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 [Extraction] to [extractions]. + * Adds a single [ExtractionJob] to [extractions]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addExtraction(extraction: Extraction) = apply { + fun addExtraction(extraction: ExtractionJob) = apply { extractions = (extractions ?: JsonField.of(mutableListOf())).also { checkKnown("extractions", it).add(extraction) @@ -241,741 +239,6 @@ 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/extractions/ExtractionRetrieveParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRetrieveParams.kt index 4daafbd..7b4c2c3 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRetrieveParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRetrieveParams.kt @@ -21,9 +21,10 @@ private constructor( fun id(): Optional = Optional.ofNullable(id) - /** Cursor for pagination */ + /** Cursor for keyset pagination */ fun after(): Optional = Optional.ofNullable(after) + /** Maximum number of results to return (1-1000, default 100) */ fun limit(): Optional = Optional.ofNullable(limit) /** Additional headers to send with the request. */ @@ -65,12 +66,13 @@ private constructor( /** Alias for calling [Builder.id] with `id.orElse(null)`. */ fun id(id: Optional) = id(id.getOrNull()) - /** Cursor for pagination */ + /** Cursor for keyset pagination */ fun after(after: String?) = apply { this.after = after } /** Alias for calling [Builder.after] with `after.orElse(null)`. */ fun after(after: Optional) = after(after.getOrNull()) + /** Maximum number of results to return (1-1000, default 100) */ fun limit(limit: Long?) = apply { this.limit = limit } /** diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRetrieveResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRetrieveResponse.kt index c5b275d..488f5a1 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRetrieveResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRetrieveResponse.kt @@ -46,6 +46,8 @@ private constructor( fun hasMore(): Boolean = hasMore.getRequired("hasMore") /** + * Extraction job metadata — shape varies by tool type (JSON) + * * @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). */ @@ -146,6 +148,7 @@ private constructor( */ fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + /** Extraction job metadata — shape varies by tool type (JSON) */ fun job(job: Job) = job(JsonField.of(job)) /** @@ -269,6 +272,7 @@ private constructor( (results.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (nextCursor.asKnown().isPresent) 1 else 0) + /** Extraction job metadata — shape varies by tool type (JSON) */ class Job @JsonCreator private constructor( diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRunParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRunParams.kt index 96d2335..ff38946 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRunParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRunParams.kt @@ -30,6 +30,8 @@ private constructor( ) : Params { /** + * Identifier for the extraction tool used to run a job. + * * @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). */ @@ -217,6 +219,7 @@ private constructor( */ fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Identifier for the extraction tool used to run a job. */ fun toolType(toolType: ToolType) = apply { body.toolType(toolType) } /** @@ -552,6 +555,8 @@ private constructor( ) /** + * Identifier for the extraction tool used to run a job. + * * @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). @@ -769,6 +774,7 @@ private constructor( additionalProperties = body.additionalProperties.toMutableMap() } + /** Identifier for the extraction tool used to run a job. */ fun toolType(toolType: ToolType) = toolType(JsonField.of(toolType)) /** @@ -1037,6 +1043,7 @@ private constructor( "Body{toolType=$toolType, advancedQuery=$advancedQuery, exactPhrase=$exactPhrase, excludeWords=$excludeWords, searchQuery=$searchQuery, targetCommunityId=$targetCommunityId, targetListId=$targetListId, targetSpaceId=$targetSpaceId, targetTweetId=$targetTweetId, targetUsername=$targetUsername, additionalProperties=$additionalProperties}" } + /** Identifier for the extraction tool used to run a job. */ class ToolType @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/extractions/ExtractionRunResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRunResponse.kt index efcace5..655f3eb 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRunResponse.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/extractions/ExtractionRunResponse.kt @@ -21,7 +21,7 @@ class ExtractionRunResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, - private val status: JsonField, + private val status: JsonValue, private val toolType: JsonField, private val additionalProperties: MutableMap, ) { @@ -29,7 +29,7 @@ private constructor( @JsonCreator private constructor( @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), - @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonValue = JsonMissing.of(), @JsonProperty("toolType") @ExcludeMissing toolType: JsonField = JsonMissing.of(), ) : this(id, status, toolType, mutableMapOf()) @@ -40,12 +40,19 @@ private constructor( 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). + * Expected to always return the following: + * ```java + * JsonValue.from("running") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). */ - fun status(): Status = status.getRequired("status") + @JsonProperty("status") @ExcludeMissing fun _status(): JsonValue = status /** + * Identifier for the extraction tool used to run a job. + * * @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). */ @@ -58,13 +65,6 @@ private constructor( */ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - /** - * 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]. * @@ -92,7 +92,6 @@ private constructor( * The following fields are required: * ```java * .id() - * .status() * .toolType() * ``` */ @@ -103,7 +102,7 @@ private constructor( class Builder internal constructor() { private var id: JsonField? = null - private var status: JsonField? = null + private var status: JsonValue = JsonValue.from("running") private var toolType: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -125,16 +124,21 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } - fun status(status: Status) = status(JsonField.of(status)) - /** - * Sets [Builder.status] to an arbitrary JSON value. + * Sets the field 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. + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("running") + * ``` + * + * 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 status(status: JsonValue) = apply { this.status = status } + /** Identifier for the extraction tool used to run a job. */ fun toolType(toolType: ToolType) = toolType(JsonField.of(toolType)) /** @@ -173,7 +177,6 @@ private constructor( * The following fields are required: * ```java * .id() - * .status() * .toolType() * ``` * @@ -182,7 +185,7 @@ private constructor( fun build(): ExtractionRunResponse = ExtractionRunResponse( checkRequired("id", id), - checkRequired("status", status), + status, checkRequired("toolType", toolType), additionalProperties.toMutableMap(), ) @@ -196,7 +199,11 @@ private constructor( } id() - status().validate() + _status().let { + if (it != JsonValue.from("running")) { + throw XTwitterScraperInvalidDataException("'status' is invalid, received $it") + } + } toolType().validate() validated = true } @@ -217,130 +224,10 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) + - (status.asKnown().getOrNull()?.validity() ?: 0) + + status.let { if (it == JsonValue.from("running")) 1 else 0 } + (toolType.asKnown().getOrNull()?.validity() ?: 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") - - @JvmStatic fun of(value: String) = Status(JsonField.of(value)) - } - - /** An enum containing [Status]'s known values. */ - enum class Known { - RUNNING - } - - /** - * 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, - /** 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 - 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 - 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() - } - + /** Identifier for the extraction tool used to run a job. */ class ToolType @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/Integration.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/Integration.kt index d5e93ca..2e88a37 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 @@ -6,7 +6,6 @@ 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 @@ -15,12 +14,14 @@ 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 import java.util.Optional import kotlin.jvm.optionals.getOrNull +/** Third-party integration (e.g. Telegram) subscribed to monitor events. */ class Integration @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( @@ -30,7 +31,7 @@ private constructor( private val eventTypes: JsonField>, private val isActive: JsonField, private val name: JsonField, - private val type: JsonField, + private val type: JsonValue, private val filters: JsonField, private val messageTemplate: JsonField, private val scopeAllMonitors: JsonField, @@ -50,7 +51,7 @@ private constructor( 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("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing filters: JsonField = JsonMissing.of(), @JsonProperty("messageTemplate") @ExcludeMissing @@ -83,6 +84,8 @@ private constructor( fun id(): String = id.getRequired("id") /** + * Integration config — shape varies by type (JSON) + * * @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). */ @@ -95,6 +98,8 @@ private constructor( fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") /** + * Array of event types to subscribe to. + * * @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). */ @@ -113,12 +118,19 @@ private constructor( 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). + * Expected to always return the following: + * ```java + * JsonValue.from("telegram") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). */ - fun type(): Type = type.getRequired("type") + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type /** + * Event filter rules (JSON) + * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ @@ -188,13 +200,6 @@ private constructor( */ @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]. * @@ -253,7 +258,6 @@ private constructor( * .eventTypes() * .isActive() * .name() - * .type() * ``` */ @JvmStatic fun builder() = Builder() @@ -268,7 +272,7 @@ private constructor( private var eventTypes: JsonField>? = null private var isActive: JsonField? = null private var name: JsonField? = null - private var type: JsonField? = null + private var type: JsonValue = JsonValue.from("telegram") private var filters: JsonField = JsonMissing.of() private var messageTemplate: JsonField = JsonMissing.of() private var scopeAllMonitors: JsonField = JsonMissing.of() @@ -301,6 +305,7 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } + /** Integration config — shape varies by type (JSON) */ fun config(config: Config) = config(JsonField.of(config)) /** @@ -322,6 +327,7 @@ private constructor( */ fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + /** Array of event types to subscribe to. */ fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) /** @@ -368,16 +374,21 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } - fun type(type: Type) = type(JsonField.of(type)) - /** - * Sets [Builder.type] to an arbitrary JSON value. + * Sets the field 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. + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("telegram") + * ``` + * + * 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: JsonValue) = apply { this.type = type } + /** Event filter rules (JSON) */ fun filters(filters: Filters) = filters(JsonField.of(filters)) /** @@ -459,7 +470,6 @@ private constructor( * .eventTypes() * .isActive() * .name() - * .type() * ``` * * @throws IllegalStateException if any required field is unset. @@ -472,7 +482,7 @@ private constructor( checkRequired("eventTypes", eventTypes).map { it.toImmutable() }, checkRequired("isActive", isActive), checkRequired("name", name), - checkRequired("type", type), + type, filters, messageTemplate, scopeAllMonitors, @@ -494,7 +504,11 @@ private constructor( eventTypes().forEach { it.validate() } isActive() name() - type().validate() + _type().let { + if (it != JsonValue.from("telegram")) { + throw XTwitterScraperInvalidDataException("'type' is invalid, received $it") + } + } filters().ifPresent { it.validate() } messageTemplate() scopeAllMonitors() @@ -523,12 +537,13 @@ private constructor( (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) + + type.let { if (it == JsonValue.from("telegram")) 1 else 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) + /** Integration config — shape varies by type (JSON) */ class Config @JsonCreator private constructor( @@ -628,280 +643,7 @@ 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 { - - /** - * 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() - } - + /** Event filter rules (JSON) */ class Filters @JsonCreator private constructor( 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 da00f53..e1b81b6 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 @@ -6,7 +6,6 @@ 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 @@ -18,6 +17,7 @@ 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 @@ -39,6 +39,8 @@ private constructor( fun config(): Config = body.config() /** + * Array of event types to subscribe to. + * * @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). */ @@ -51,10 +53,15 @@ private constructor( fun name(): String = body.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). + * Expected to always return the following: + * ```java + * JsonValue.from("telegram") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). */ - fun type(): Type = body.type() + fun _type(): JsonValue = body._type() /** * Returns the raw JSON value of [config]. @@ -77,13 +84,6 @@ private constructor( */ fun _name(): JsonField = body._name() - /** - * Returns the raw JSON value of [type]. - * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _type(): JsonField = body._type() - fun _additionalBodyProperties(): Map = body._additionalProperties() /** Additional headers to send with the request. */ @@ -104,7 +104,6 @@ private constructor( * .config() * .eventTypes() * .name() - * .type() * ``` */ @JvmStatic fun builder() = Builder() @@ -147,6 +146,7 @@ private constructor( */ fun config(config: JsonField) = apply { body.config(config) } + /** Array of event types to subscribe to. */ fun eventTypes(eventTypes: List) = apply { body.eventTypes(eventTypes) } /** @@ -177,15 +177,19 @@ private constructor( */ fun name(name: JsonField) = apply { body.name(name) } - fun type(type: Type) = apply { body.type(type) } - /** - * Sets [Builder.type] to an arbitrary JSON value. + * Sets the field 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. + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("telegram") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun type(type: JsonField) = apply { body.type(type) } + fun type(type: JsonValue) = apply { body.type(type) } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { body.additionalProperties(additionalBodyProperties) @@ -314,7 +318,6 @@ private constructor( * .config() * .eventTypes() * .name() - * .type() * ``` * * @throws IllegalStateException if any required field is unset. @@ -339,7 +342,7 @@ private constructor( private val config: JsonField, private val eventTypes: JsonField>, private val name: JsonField, - private val type: JsonField, + private val type: JsonValue, private val additionalProperties: MutableMap, ) { @@ -350,7 +353,7 @@ private constructor( @ExcludeMissing eventTypes: JsonField> = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), ) : this(config, eventTypes, name, type, mutableMapOf()) /** @@ -363,6 +366,8 @@ private constructor( fun config(): Config = config.getRequired("config") /** + * Array of event types to subscribe to. + * * @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). @@ -377,11 +382,15 @@ private constructor( 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). + * Expected to always return the following: + * ```java + * JsonValue.from("telegram") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). */ - fun type(): Type = type.getRequired("type") + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type /** * Returns the raw JSON value of [config]. @@ -406,13 +415,6 @@ private constructor( */ @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 - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -435,7 +437,6 @@ private constructor( * .config() * .eventTypes() * .name() - * .type() * ``` */ @JvmStatic fun builder() = Builder() @@ -447,7 +448,7 @@ private constructor( private var config: JsonField? = null private var eventTypes: JsonField>? = null private var name: JsonField? = null - private var type: JsonField? = null + private var type: JsonValue = JsonValue.from("telegram") private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -471,6 +472,7 @@ private constructor( */ fun config(config: JsonField) = apply { this.config = config } + /** Array of event types to subscribe to. */ fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) /** @@ -507,16 +509,19 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } - fun type(type: Type) = type(JsonField.of(type)) - /** - * Sets [Builder.type] to an arbitrary JSON value. + * Sets the field 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. + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("telegram") + * ``` + * + * 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: JsonValue) = apply { this.type = type } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -547,7 +552,6 @@ private constructor( * .config() * .eventTypes() * .name() - * .type() * ``` * * @throws IllegalStateException if any required field is unset. @@ -557,7 +561,7 @@ private constructor( checkRequired("config", config), checkRequired("eventTypes", eventTypes).map { it.toImmutable() }, checkRequired("name", name), - checkRequired("type", type), + type, additionalProperties.toMutableMap(), ) } @@ -572,7 +576,11 @@ private constructor( config().validate() eventTypes().forEach { it.validate() } name() - type().validate() + _type().let { + if (it != JsonValue.from("telegram")) { + throw XTwitterScraperInvalidDataException("'type' is invalid, received $it") + } + } validated = true } @@ -595,7 +603,7 @@ private constructor( (config.asKnown().getOrNull()?.validity() ?: 0) + (eventTypes.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + type.let { if (it == JsonValue.from("telegram")) 1 else 0 } override fun equals(other: Any?): Boolean { if (this === other) { @@ -775,280 +783,6 @@ 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 { - - /** - * 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() - } - 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/IntegrationCreateResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationCreateResponse.kt deleted file mode 100644 index ce362aa..0000000 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationCreateResponse.kt +++ /dev/null @@ -1,1045 +0,0 @@ -// 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/IntegrationDelivery.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationDelivery.kt index ae1dcc6..9fc6c54 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationDelivery.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationDelivery.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects import java.util.Optional +/** Integration delivery attempt record with status and retry count. */ class IntegrationDelivery @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationListDeliveriesParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationListDeliveriesParams.kt index b5eee15..be7b04c 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationListDeliveriesParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationListDeliveriesParams.kt @@ -20,6 +20,7 @@ private constructor( fun id(): Optional = Optional.ofNullable(id) + /** Maximum number of items to return (1-100, default 50) */ fun limit(): Optional = Optional.ofNullable(limit) /** Additional headers to send with the request. */ @@ -64,6 +65,7 @@ private constructor( /** Alias for calling [Builder.id] with `id.orElse(null)`. */ fun id(id: Optional) = id(id.getOrNull()) + /** Maximum number of items to return (1-100, default 50) */ fun limit(limit: Long?) = apply { this.limit = limit } /** 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 6caf9f4..a56505f 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,16 +14,14 @@ 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, ) { @@ -31,14 +29,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]. @@ -47,7 +45,7 @@ private constructor( */ @JsonProperty("deliveries") @ExcludeMissing - fun _deliveries(): JsonField> = deliveries + fun _deliveries(): JsonField> = deliveries @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -78,7 +76,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 @@ -89,25 +87,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 [Delivery] to [deliveries]. + * Adds a single [IntegrationDelivery] to [deliveries]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addDelivery(delivery: Delivery) = apply { + fun addDelivery(delivery: IntegrationDelivery) = apply { deliveries = (deliveries ?: JsonField.of(mutableListOf())).also { checkKnown("deliveries", it).add(delivery) @@ -180,520 +178,6 @@ 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 c75b31a..9a9f4a2 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,7 +6,6 @@ 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 @@ -15,10 +14,8 @@ 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 @@ -178,1057 +175,6 @@ 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 deleted file mode 100644 index fa24dc8..0000000 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationRetrieveResponse.kt +++ /dev/null @@ -1,1045 +0,0 @@ -// 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 ed6d8cb..9da8486 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,7 +6,6 @@ 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,6 +16,7 @@ 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 @@ -34,12 +34,16 @@ private constructor( fun id(): Optional = Optional.ofNullable(id) /** + * Array of event types to subscribe to. + * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ fun eventTypes(): Optional> = body.eventTypes() /** + * Event filter rules (JSON) + * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ @@ -52,6 +56,8 @@ private constructor( fun isActive(): Optional = body.isActive() /** + * Custom message template (JSON) + * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ @@ -178,6 +184,7 @@ private constructor( */ fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Array of event types to subscribe to. */ fun eventTypes(eventTypes: List) = apply { body.eventTypes(eventTypes) } /** @@ -198,6 +205,7 @@ private constructor( */ fun addEventType(eventType: EventType) = apply { body.addEventType(eventType) } + /** Event filter rules (JSON) */ fun filters(filters: Filters) = apply { body.filters(filters) } /** @@ -219,6 +227,7 @@ private constructor( */ fun isActive(isActive: JsonField) = apply { body.isActive(isActive) } + /** Custom message template (JSON) */ fun messageTemplate(messageTemplate: MessageTemplate) = apply { body.messageTemplate(messageTemplate) } @@ -457,12 +466,16 @@ private constructor( ) /** + * Array of event types to subscribe to. + * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type * (e.g. if the server responded with an unexpected value). */ fun eventTypes(): Optional> = eventTypes.getOptional("eventTypes") /** + * Event filter rules (JSON) + * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type * (e.g. if the server responded with an unexpected value). */ @@ -475,6 +488,8 @@ private constructor( fun isActive(): Optional = isActive.getOptional("isActive") /** + * Custom message template (JSON) + * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type * (e.g. if the server responded with an unexpected value). */ @@ -600,6 +615,7 @@ private constructor( additionalProperties = body.additionalProperties.toMutableMap() } + /** Array of event types to subscribe to. */ fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) /** @@ -625,6 +641,7 @@ private constructor( } } + /** Event filter rules (JSON) */ fun filters(filters: Filters) = filters(JsonField.of(filters)) /** @@ -647,6 +664,7 @@ private constructor( */ fun isActive(isActive: JsonField) = apply { this.isActive = isActive } + /** Custom message template (JSON) */ fun messageTemplate(messageTemplate: MessageTemplate) = messageTemplate(JsonField.of(messageTemplate)) @@ -810,159 +828,7 @@ 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() - } - + /** Event filter rules (JSON) */ class Filters @JsonCreator private constructor( @@ -1062,6 +928,7 @@ private constructor( override fun toString() = "Filters{additionalProperties=$additionalProperties}" } + /** Custom message template (JSON) */ class MessageTemplate @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 deleted file mode 100644 index 46c510e..0000000 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/integrations/IntegrationUpdateResponse.kt +++ /dev/null @@ -1,1045 +0,0 @@ -// 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 264356a..09d619d 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,7 +6,6 @@ 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 @@ -15,11 +14,13 @@ 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 import kotlin.jvm.optionals.getOrNull +/** Account monitor that tracks activity for a given X user. */ class Monitor @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( @@ -59,6 +60,8 @@ private constructor( fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") /** + * Array of event types to subscribe to. + * * @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). */ @@ -201,6 +204,7 @@ private constructor( */ fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + /** Array of event types to subscribe to. */ fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) /** @@ -343,159 +347,6 @@ 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 7afdf68..02bff00 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,7 +6,6 @@ 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 @@ -18,6 +17,7 @@ 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 @@ -31,6 +31,8 @@ private constructor( ) : Params { /** + * Array of event types to subscribe to. + * * @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). */ @@ -106,6 +108,7 @@ private constructor( */ fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Array of event types to subscribe to. */ fun eventTypes(eventTypes: List) = apply { body.eventTypes(eventTypes) } /** @@ -298,6 +301,8 @@ private constructor( ) : this(eventTypes, username, mutableMapOf()) /** + * Array of event types to subscribe to. + * * @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). @@ -369,6 +374,7 @@ private constructor( additionalProperties = body.additionalProperties.toMutableMap() } + /** Array of event types to subscribe to. */ fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) /** @@ -498,159 +504,6 @@ 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 97199ba..258d721 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,7 +6,6 @@ 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 @@ -15,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 com.x_twitter_scraper.api.models.EventType import java.time.OffsetDateTime import java.util.Collections import java.util.Objects @@ -57,6 +57,8 @@ private constructor( fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") /** + * Array of event types to subscribe to. + * * @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). */ @@ -183,6 +185,7 @@ private constructor( */ fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + /** Array of event types to subscribe to. */ fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) /** @@ -310,159 +313,6 @@ 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 74fb015..e714d7d 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,7 +6,6 @@ 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 @@ -15,7 +14,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 java.time.OffsetDateTime import java.util.Collections import java.util.Objects import kotlin.jvm.optionals.getOrNull @@ -207,533 +205,6 @@ 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 deleted file mode 100644 index 43a9471..0000000 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorRetrieveResponse.kt +++ /dev/null @@ -1,522 +0,0 @@ -// 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 03f85bf..0804303 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,7 +6,6 @@ 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,6 +16,7 @@ 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 @@ -34,6 +34,8 @@ private constructor( fun id(): Optional = Optional.ofNullable(id) /** + * Array of event types to subscribe to. + * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ @@ -108,6 +110,7 @@ private constructor( */ fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Array of event types to subscribe to. */ fun eventTypes(eventTypes: List) = apply { body.eventTypes(eventTypes) } /** @@ -301,6 +304,8 @@ private constructor( ) : this(eventTypes, isActive, mutableMapOf()) /** + * Array of event types to subscribe to. + * * @throws XTwitterScraperInvalidDataException if the JSON field has an unexpected type * (e.g. if the server responded with an unexpected value). */ @@ -360,6 +365,7 @@ private constructor( additionalProperties = body.additionalProperties.toMutableMap() } + /** Array of event types to subscribe to. */ fun eventTypes(eventTypes: List) = eventTypes(JsonField.of(eventTypes)) /** @@ -480,159 +486,6 @@ 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 deleted file mode 100644 index 84a791c..0000000 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/monitors/MonitorUpdateResponse.kt +++ /dev/null @@ -1,522 +0,0 @@ -// 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/RadarItem.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/radar/RadarItem.kt index 153dea2..7231e8e 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/radar/RadarItem.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/radar/RadarItem.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects import java.util.Optional +/** Trending topic with score, category, source, and region. */ class RadarItem @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/radar/RadarRetrieveTrendingTopicsParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/radar/RadarRetrieveTrendingTopicsParams.kt index 9c74f5c..a00f5fb 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/radar/RadarRetrieveTrendingTopicsParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/radar/RadarRetrieveTrendingTopicsParams.kt @@ -2,9 +2,13 @@ package com.x_twitter_scraper.api.models.radar +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.errors.XTwitterScraperInvalidDataException import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -16,7 +20,7 @@ private constructor( private val count: Long?, private val hours: Long?, private val region: String?, - private val source: String?, + private val source: Source?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { @@ -37,7 +41,7 @@ private constructor( * Source filter. One of: github, google_trends, hacker_news, polymarket, reddit, trustmrr, * wikipedia */ - fun source(): Optional = Optional.ofNullable(source) + fun source(): Optional = Optional.ofNullable(source) /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders @@ -65,7 +69,7 @@ private constructor( private var count: Long? = null private var hours: Long? = null private var region: String? = null - private var source: String? = null + private var source: Source? = null private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @@ -124,10 +128,10 @@ private constructor( * Source filter. One of: github, google_trends, hacker_news, polymarket, reddit, trustmrr, * wikipedia */ - fun source(source: String?) = apply { this.source = source } + fun source(source: Source?) = apply { this.source = source } /** Alias for calling [Builder.source] with `source.orElse(null)`. */ - fun source(source: Optional) = source(source.getOrNull()) + fun source(source: Optional) = source(source.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -253,11 +257,172 @@ private constructor( count?.let { put("count", it.toString()) } hours?.let { put("hours", it.toString()) } region?.let { put("region", it) } - source?.let { put("source", it) } + source?.let { put("source", it.toString()) } putAll(additionalQueryParams) } .build() + /** + * Source filter. One of: github, google_trends, hacker_news, polymarket, reddit, trustmrr, + * wikipedia + */ + class Source @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 GITHUB = of("github") + + @JvmField val GOOGLE_TRENDS = of("google_trends") + + @JvmField val HACKER_NEWS = of("hacker_news") + + @JvmField val POLYMARKET = of("polymarket") + + @JvmField val REDDIT = of("reddit") + + @JvmField val TRUSTMRR = of("trustmrr") + + @JvmField val WIKIPEDIA = of("wikipedia") + + @JvmStatic fun of(value: String) = Source(JsonField.of(value)) + } + + /** An enum containing [Source]'s known values. */ + enum class Known { + GITHUB, + GOOGLE_TRENDS, + HACKER_NEWS, + POLYMARKET, + REDDIT, + TRUSTMRR, + WIKIPEDIA, + } + + /** + * An enum containing [Source]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Source] 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 { + GITHUB, + GOOGLE_TRENDS, + HACKER_NEWS, + POLYMARKET, + REDDIT, + TRUSTMRR, + WIKIPEDIA, + /** An enum member indicating that [Source] 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) { + GITHUB -> Value.GITHUB + GOOGLE_TRENDS -> Value.GOOGLE_TRENDS + HACKER_NEWS -> Value.HACKER_NEWS + POLYMARKET -> Value.POLYMARKET + REDDIT -> Value.REDDIT + TRUSTMRR -> Value.TRUSTMRR + WIKIPEDIA -> Value.WIKIPEDIA + 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) { + GITHUB -> Known.GITHUB + GOOGLE_TRENDS -> Known.GOOGLE_TRENDS + HACKER_NEWS -> Known.HACKER_NEWS + POLYMARKET -> Known.POLYMARKET + REDDIT -> Known.REDDIT + TRUSTMRR -> Known.TRUSTMRR + WIKIPEDIA -> Known.WIKIPEDIA + else -> throw XTwitterScraperInvalidDataException("Unknown Source: $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(): Source = 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 Source && 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/radar/RadarRetrieveTrendingTopicsResponse.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/radar/RadarRetrieveTrendingTopicsResponse.kt index ee848b7..5f17e52 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,23 +14,21 @@ 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()) @@ -38,7 +36,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 @@ -51,7 +49,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]. @@ -90,7 +88,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() @@ -104,25 +102,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 [Item] to [items]. + * Adds a single [RadarItem] to [items]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addItem(item: Item) = apply { + fun addItem(item: RadarItem) = apply { items = (items ?: JsonField.of(mutableListOf())).also { checkKnown("items", it).add(item) } } @@ -207,476 +205,6 @@ 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 deleted file mode 100644 index 8f7c1c5..0000000 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleAnalyzeResponse.kt +++ /dev/null @@ -1,609 +0,0 @@ -// 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 e42856e..b064f3e 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,55 +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()) /** + * Full style profile with sampled tweets used for tone analysis. + * * @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(): Style1 = style1.getRequired("style1") + fun style1(): StyleProfile = style1.getRequired("style1") /** + * Full style profile with sampled tweets used for tone analysis. + * * @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(): Style2 = style2.getRequired("style2") + fun style2(): StyleProfile = 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) { @@ -89,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 @@ -100,25 +100,29 @@ private constructor( additionalProperties = styleCompareResponse.additionalProperties.toMutableMap() } - fun style1(style1: Style1) = style1(JsonField.of(style1)) + /** Full style profile with sampled tweets used for tone analysis. */ + fun style1(style1: StyleProfile) = style1(JsonField.of(style1)) /** * Sets [Builder.style1] to an arbitrary JSON 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. + * 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. */ - fun style1(style1: JsonField) = apply { this.style1 = style1 } + fun style1(style1: JsonField) = apply { this.style1 = style1 } - fun style2(style2: Style2) = style2(JsonField.of(style2)) + /** Full style profile with sampled tweets used for tone analysis. */ + fun style2(style2: StyleProfile) = style2(JsonField.of(style2)) /** * Sets [Builder.style2] to an arbitrary JSON 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. + * 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. */ - fun style2(style2: JsonField) = apply { this.style2 = style2 } + fun style2(style2: JsonField) = apply { this.style2 = style2 } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -190,1240 +194,6 @@ 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/StyleDeleteParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleDeleteParams.kt index 73c092b..d913500 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleDeleteParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleDeleteParams.kt @@ -14,13 +14,13 @@ import kotlin.jvm.optionals.getOrNull /** Delete a style profile */ class StyleDeleteParams private constructor( - private val username: String?, + private val id: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { - fun username(): Optional = Optional.ofNullable(username) + fun id(): Optional = Optional.ofNullable(id) /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties @@ -44,23 +44,23 @@ private constructor( /** A builder for [StyleDeleteParams]. */ class Builder internal constructor() { - private var username: String? = null + private var id: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() private var additionalBodyProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(styleDeleteParams: StyleDeleteParams) = apply { - username = styleDeleteParams.username + id = styleDeleteParams.id additionalHeaders = styleDeleteParams.additionalHeaders.toBuilder() additionalQueryParams = styleDeleteParams.additionalQueryParams.toBuilder() additionalBodyProperties = styleDeleteParams.additionalBodyProperties.toMutableMap() } - fun username(username: String?) = apply { this.username = username } + fun id(id: String?) = apply { this.id = id } - /** Alias for calling [Builder.username] with `username.orElse(null)`. */ - fun username(username: Optional) = username(username.getOrNull()) + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -189,7 +189,7 @@ private constructor( */ fun build(): StyleDeleteParams = StyleDeleteParams( - username, + id, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -201,7 +201,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> username ?: "" + 0 -> id ?: "" else -> "" } @@ -215,15 +215,15 @@ private constructor( } return other is StyleDeleteParams && - username == other.username && + id == other.id && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties } override fun hashCode(): Int = - Objects.hash(username, additionalHeaders, additionalQueryParams, additionalBodyProperties) + Objects.hash(id, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = - "StyleDeleteParams{username=$username, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" + "StyleDeleteParams{id=$id, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" } diff --git a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleGetPerformanceParams.kt b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleGetPerformanceParams.kt index 4194c20..573cb0e 100644 --- a/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleGetPerformanceParams.kt +++ b/x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/models/styles/StyleGetPerformanceParams.kt @@ -12,12 +12,12 @@ import kotlin.jvm.optionals.getOrNull /** Get engagement metrics for style tweets */ class StyleGetPerformanceParams private constructor( - private val username: String?, + private val id: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun username(): Optional = Optional.ofNullable(username) + fun id(): Optional = Optional.ofNullable(id) /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders @@ -40,21 +40,21 @@ private constructor( /** A builder for [StyleGetPerformanceParams]. */ class Builder internal constructor() { - private var username: String? = null + private var id: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(styleGetPerformanceParams: StyleGetPerformanceParams) = apply { - username = styleGetPerformanceParams.username + id = styleGetPerformanceParams.id additionalHeaders = styleGetPerformanceParams.additionalHeaders.toBuilder() additionalQueryParams = styleGetPerformanceParams.additionalQueryParams.toBuilder() } - fun username(username: String?) = apply { this.username = username } + fun id(id: String?) = apply { this.id = id } - /** Alias for calling [Builder.username] with `username.orElse(null)`. */ - fun username(username: Optional) = username(username.getOrNull()) + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -160,16 +160,12 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): StyleGetPerformanceParams = - StyleGetPerformanceParams( - username, - additionalHeaders.build(), - additionalQueryParams.build(), - ) + StyleGetPerformanceParams(id, additionalHeaders.build(), additionalQueryParams.build()) } fun _pathParam(index: Int): String = when (index) { - 0 -> username ?: "" + 0 -> id ?: "" else -> "" } @@ -183,13 +179,13 @@ private constructor( } return other is StyleGetPerformanceParams && - username == other.username && + id == other.id && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = Objects.hash(username, additionalHeaders, additionalQueryParams) + override fun hashCode(): Int = Objects.hash(id, additionalHeaders, additionalQueryParams) override fun toString() = - "StyleGetPerformanceParams{username=$username, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "StyleGetPerformanceParams{id=$id, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } 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 0b2a049..909ab03 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,7 +14,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 java.time.OffsetDateTime import java.util.Collections import java.util.Objects import kotlin.jvm.optionals.getOrNull @@ -22,27 +21,31 @@ 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