Skip to content

Add support for Likes Firehose #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>twitter-api-java-sdk</artifactId>
<packaging>jar</packaging>
<name>twitter-api-java-sdk</name>
<version>2.0.3</version>
<version>2.1.0</version>
<url>https://github.com/twitterdev/twitter-api-java-sdk</url>
<description>Twitter API v2 available endpoints</description>
<scm>
Expand Down
338 changes: 338 additions & 0 deletions src/main/java/com/twitter/clientlib/api/LikesApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,338 @@
/*
Copyright 2020 Twitter, Inc.
SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
https://openapi-generator.tech
Do not edit the class manually.
*/


package com.twitter.clientlib.api;

import com.google.gson.reflect.TypeToken;
import com.twitter.clientlib.ApiCallback;
import com.twitter.clientlib.ApiException;
import com.twitter.clientlib.ApiResponse;
import com.twitter.clientlib.Pair;
import com.twitter.clientlib.model.*;

import java.io.InputStream;
import java.lang.reflect.Type;
import java.time.OffsetDateTime;
import java.util.*;
public class LikesApi extends ApiCommon {


private okhttp3.Call getLikesFirehoseStreamCall(Integer backfillMinutes, Integer partition, OffsetDateTime startTime, OffsetDateTime endTime, Set<String> likeFields ,Set<String> tweetFields, Set<String> expansions, Set<String> userFields, final ApiCallback _callback) throws ApiException {
Object localVarPostBody = null;

// create path and map variables
String localVarPath = "/2/likes/firehose/stream";

List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

if (backfillMinutes != null) {
localVarQueryParams.addAll(localVarApiClient.parameterToPair("backfill_minutes", backfillMinutes));
}

if (partition != null) {
localVarQueryParams.addAll(localVarApiClient.parameterToPair("partition", partition));
}

if (startTime != null) {
localVarQueryParams.addAll(localVarApiClient.parameterToPair("start_time", startTime));
}

if (endTime != null) {
localVarQueryParams.addAll(localVarApiClient.parameterToPair("end_time", endTime));
}

if (tweetFields != null) {
localVarCollectionQueryParams.addAll(localVarApiClient.parameterToPairs("csv", "tweet.fields", tweetFields));
}

if (likeFields != null) {
localVarCollectionQueryParams.addAll(localVarApiClient.parameterToPairs("csv", "like.fields", likeFields));
}

if (expansions != null) {
localVarCollectionQueryParams.addAll(localVarApiClient.parameterToPairs("csv", "expansions", expansions));
}

if (userFields != null) {
localVarCollectionQueryParams.addAll(localVarApiClient.parameterToPairs("csv", "user.fields", userFields));
}

final String[] localVarAccepts = {
"application/json", "application/problem+json"
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}

final String[] localVarContentTypes = {

};
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
if (localVarContentType != null) {
localVarHeaderParams.put("Content-Type", localVarContentType);
}

String[] localVarAuthNames = new String[]{"BearerToken"};
return localVarApiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, reduceAuthNames(localVarAuthNames), _callback);
}

@SuppressWarnings("rawtypes")
private okhttp3.Call getLikesFirehoseStreamValidateBeforeCall(Integer backfillMinutes, Integer partition, OffsetDateTime startTime, OffsetDateTime endTime, Set<String> likeFields, Set<String> tweetFields, Set<String> expansions, Set<String> userFields, final ApiCallback _callback) throws ApiException {

// verify the required parameter 'partition' is set
if (partition == null) {
throw new ApiException("Missing the required parameter 'partition' when calling getLikesFirehoseStream(Async)");
}


okhttp3.Call localVarCall = getLikesFirehoseStreamCall(backfillMinutes, partition, startTime, endTime, likeFields, tweetFields, expansions, userFields, _callback);
return localVarCall;

}


private InputStream getLikesFirehoseStreamWithHttpInfo(Integer backfillMinutes, Integer partition, OffsetDateTime startTime, OffsetDateTime endTime, Set<String> likeFields, Set<String> tweetFields, Set<String> expansions, Set<String> userFields) throws ApiException {
okhttp3.Call localVarCall = getLikesFirehoseStreamValidateBeforeCall(backfillMinutes, partition, startTime, endTime, likeFields, tweetFields, expansions, userFields, null);
try {
Type localVarReturnType = new TypeToken<StreamingTweetResponse>() {
}.getType();
return localVarApiClient.executeStream(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<com.twitter.clientlib.model.ProblemOrError>() {
}.getType()));
throw e;
}
}

private okhttp3.Call getLikesFirehoseStreamAsync(Integer backfillMinutes, Integer partition, OffsetDateTime startTime, OffsetDateTime endTime, Set<String> likeFields, Set<String> tweetFields, Set<String> expansions, Set<String> userFields, final ApiCallback<StreamingTweetResponse> _callback) throws ApiException {

okhttp3.Call localVarCall = getLikesFirehoseStreamValidateBeforeCall(backfillMinutes, partition, startTime, endTime, likeFields, tweetFields, expansions, userFields, _callback);
Type localVarReturnType = new TypeToken<StreamingTweetResponse>() {
}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}

public class APIgetLikesFirehoseStreamRequest {
private final Integer partition;
private Integer backfillMinutes;
private OffsetDateTime startTime;
private OffsetDateTime endTime;
private Set<String> likeFields;
private Set<String> tweetFields;
private Set<String> expansions;
private Set<String> userFields;
private final Set<String> likeFieldsAll = new HashSet<>(Arrays.asList("created_at", "id", "liked_tweet_id", "liking_user_id", "timestamp_ms"));
private final Set<String> tweetFieldsAll = new HashSet<>(Arrays.asList("attachments", "author_id", "card_uri", "context_annotations", "conversation_id", "created_at", "edit_controls", "edit_history_tweet_ids", "entities", "geo", "id", "in_reply_to_user_id", "lang", "non_public_metrics", "note_tweet", "organic_metrics", "possibly_sensitive", "promoted_metrics", "public_metrics", "referenced_tweets", "reply_settings", "source", "text", "withheld"));
private final Set<String> expansionsAll = new HashSet<>(Arrays.asList("liked_tweet_id", "liking_user_id"));
private final Set<String> userFieldsAll = new HashSet<>(Arrays.asList("connection_status", "created_at", "description", "entities", "id", "location", "most_recent_tweet_id", "name", "pinned_tweet_id", "profile_image_url", "protected", "public_metrics", "receives_your_dm", "subscription_type", "url", "username", "verified", "verified_type", "withheld"));

private boolean isExclude = false;

public APIgetLikesFirehoseStreamRequest excludeInputFields() {
isExclude = true;
return this;
}

private APIgetLikesFirehoseStreamRequest(Integer partition) {
this.partition = partition;
}

/**
* Set backfillMinutes
*
* @param backfillMinutes The number of minutes of backfill requested. (optional)
* @return APIgetLikesFirehoseStreamRequest
*/
public APIgetLikesFirehoseStreamRequest backfillMinutes(Integer backfillMinutes) {
this.backfillMinutes = backfillMinutes;
return this;
}

/**
* Set startTime
*
* @param startTime YYYY-MM-DDTHH:mm:ssZ. The earliest UTC timestamp to which the Tweets will be provided. (optional)
* @return APIgetLikesFirehoseStreamRequest
*/
public APIgetLikesFirehoseStreamRequest startTime(OffsetDateTime startTime) {
this.startTime = startTime;
return this;
}

/**
* Set endTime
*
* @param endTime YYYY-MM-DDTHH:mm:ssZ. The latest UTC timestamp to which the Tweets will be provided. (optional)
* @return APIgetLikesFirehoseStreamRequest
*/
public APIgetLikesFirehoseStreamRequest endTime(OffsetDateTime endTime) {
this.endTime = endTime;
return this;
}

/**
* Set likeFields
*
* @param likeFields A comma separated list of Tweet fields to display. (optional)
* @return APIgetLikesFirehoseStreamRequest
*/
public APIgetLikesFirehoseStreamRequest likeFields(Set<String> likeFields) {
this.likeFields = likeFields;
return this;
}

/**
* Set tweetFields
*
* @param tweetFields A comma separated list of Tweet fields to display. (optional)
* @return APIgetLikesFirehoseStreamRequest
*/
public APIgetLikesFirehoseStreamRequest tweetFields(Set<String> tweetFields) {
this.tweetFields = tweetFields;
return this;
}

/**
* Set expansions
*
* @param expansions A comma separated list of fields to expand. (optional)
* @return APIgetLikesFirehoseStreamRequest
*/
public APIgetLikesFirehoseStreamRequest expansions(Set<String> expansions) {
this.expansions = expansions;
return this;
}

/**
* Set userFields
*
* @param userFields A comma separated list of User fields to display. (optional)
* @return APIgetLikesFirehoseStreamRequest
*/
public APIgetLikesFirehoseStreamRequest userFields(Set<String> userFields) {
this.userFields = userFields;
return this;
}

/**
* Build call for getLikesFirehoseStream
*
* @param _callback ApiCallback API callback
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
* @http.response.details <table summary="Response Details" border="1">
* <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
* <tr><td> 200 </td><td> The request has succeeded. </td><td> - </td></tr>
* <tr><td> 0 </td><td> The request has failed. </td><td> - </td></tr>
* </table>
*/
public okhttp3.Call buildCall(final ApiCallback _callback) throws ApiException {
return getLikesFirehoseStreamCall(backfillMinutes, partition, startTime, endTime, likeFields, tweetFields, expansions, userFields, _callback);
}

/**
* Execute getLikesFirehoseStream request
*
* @return StreamingTweetResponse
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details <table summary="Response Details" border="1">
* <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
* <tr><td> 200 </td><td> The request has succeeded. </td><td> - </td></tr>
* <tr><td> 0 </td><td> The request has failed. </td><td> - </td></tr>
* </table>
*/
public InputStream execute() throws ApiException {
return getLikesFirehoseStreamWithHttpInfo(backfillMinutes, partition, startTime, endTime, likeFields, tweetFields, expansions, userFields);
}

/**
* Calls the API using a retry mechanism to handle rate limits errors.
*/
public InputStream execute(Integer retries) throws ApiException {
InputStream localVarResp;
try {
localVarResp = execute();
} catch (ApiException e) {
if (handleRateLimit(e, retries)) {
return execute(retries - 1);
} else {
throw e;
}
}
return localVarResp;
}

/**
* Execute getLikesFirehoseStream request with HTTP info returned
*
* @return ApiResponse&lt;StreamingTweetResponse&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details <table summary="Response Details" border="1">
* <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
* <tr><td> 200 </td><td> The request has succeeded. </td><td> - </td></tr>
* <tr><td> 0 </td><td> The request has failed. </td><td> - </td></tr>
* </table>
*/

public InputStream executeWithHttpInfo() throws ApiException {
return getLikesFirehoseStreamWithHttpInfo(backfillMinutes, partition, startTime, endTime, likeFields, tweetFields, expansions, userFields);
}

/**
* Execute getLikesFirehoseStream request (asynchronously)
*
* @param _callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
* @http.response.details <table summary="Response Details" border="1">
* <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
* <tr><td> 200 </td><td> The request has succeeded. </td><td> - </td></tr>
* <tr><td> 0 </td><td> The request has failed. </td><td> - </td></tr>
* </table>
*/
public okhttp3.Call executeAsync(final ApiCallback<StreamingTweetResponse> _callback) throws ApiException {
return getLikesFirehoseStreamAsync(backfillMinutes, partition, startTime, endTime, likeFields, tweetFields, expansions, userFields, _callback);
}
}

/**
* Firehose stream
* Streams 100% of public Likes.
*
* @param partition The partition number. (required)
* @return APIgetLikesFirehoseStreamRequest
* @http.response.details <table summary="Response Details" border="1">
* <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
* <tr><td> 200 </td><td> The request has succeeded. </td><td> - </td></tr>
* <tr><td> 0 </td><td> The request has failed. </td><td> - </td></tr>
* </table>
*/
public APIgetLikesFirehoseStreamRequest getLikesFirehoseStream(Integer partition) {
return new APIgetLikesFirehoseStreamRequest(partition);
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/twitter/clientlib/api/TwitterApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class TwitterApi {
private final ListsApi lists = new ListsApi();
private final SpacesApi spaces = new SpacesApi();
private final TweetsApi tweets = new TweetsApi();
private final LikesApi likes = new LikesApi();
private final UsersApi users = new UsersApi();
private ApiClient localVarApiClient = new ApiClient();

Expand Down Expand Up @@ -83,6 +84,7 @@ private void initApis() {
lists.setClient(localVarApiClient);
spaces.setClient(localVarApiClient);
tweets.setClient(localVarApiClient);
likes.setClient(localVarApiClient);
users.setClient(localVarApiClient);
}

Expand All @@ -107,6 +109,9 @@ public TweetsApi tweets() {
public UsersApi users() {
return users;
}
public LikesApi likes() {
return likes;
}

public OAuth2AccessToken refreshToken() throws ApiException {
return localVarApiClient.refreshToken();
Expand Down
Loading