Skip to content

Commit

Permalink
Merge pull request #62 from redouane59/develop
Browse files Browse the repository at this point in the history
1.9
  • Loading branch information
redouane59 authored Sep 8, 2020
2 parents 66cfb8c + 71adf30 commit 892528c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ In your pom.xml, add the following dependency :
<dependency>
<groupId>com.github.redouane59.twitter</groupId>
<artifactId>twittered</artifactId>
<version>1.8</version>
<version>1.9</version>
</dependency>
```
In order to use your own developer credentials, you have several options :
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.redouane59.twitter</groupId>
<artifactId>twittered</artifactId>
<version>1.8</version>
<version>1.9</version>

<name>twittered</name>
<description>java client for twitter API</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public String getBearerToken() {
params.put("Authorization", "Basic " + cryptedValue);
params.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
String body = "grant_type=client_credentials";
BearerToken result = this.requestHelperV2
BearerToken result = requestHelperV2
.postRequestWithHeader(url, params, body, BearerToken.class).orElseThrow(NoSuchElementException::new);
return result.getAccessToken();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public <T> Optional<T> getRequestWithParameters(String url, Map<String, String>
.get()
.headers(Headers.of("Authorization", "Bearer " + bearerToken))
.build();
String newUrl = httpBuilder.build().url().toString();
Response response = this.getHttpClient(newUrl).newCall(request).execute();
String stringResponse = response.body().string();
OkHttpClient client = this.getHttpClient(httpBuilder.build().url().toString());
Response response = client.newCall(request).execute();
String stringResponse = response.body().string();
if (response.code() == 429) {
this.wait(stringResponse, url);
return this.getRequestWithParameters(url, parameters, classType);
Expand Down Expand Up @@ -83,9 +83,12 @@ public void onResponse(Call call, final Response response) throws IOException {
Buffer buffer = new Buffer();
while (!response.body().source().exhausted()) {
response.body().source().read(buffer, 8192);
String content = new String(buffer.readByteArray());
TweetV2 tweet = TwitterClient.OBJECT_MAPPER.readValue(content, TweetV2.class);
consumer.accept(tweet);
String content = new String(buffer.readByteArray());
try {
TweetV2 tweet = TwitterClient.OBJECT_MAPPER.readValue(content, TweetV2.class);
consumer.accept(tweet);
} catch (Exception e) {
}
}
}
});
Expand Down Expand Up @@ -119,12 +122,14 @@ public static <T> Optional<T> postRequestWithHeader(String url, Map<String, Stri
.method("POST", RequestBody.create(MediaType.parse("application/x-www-form-urlencoded"), body))
.headers(Headers.of(headersMap))
.build();
Response response = new OkHttpClient.Builder().build().newCall(request).execute();
OkHttpClient client = new OkHttpClient.Builder().build();
Response response = client.newCall(request).execute();
if (response.code() < 200 || response.code() > 299) {
LOGGER.error("(POST) Error calling " + url + " " + response.message() + " - " + response.code());
}
String stringResponse = response.body().string();
result = TwitterClient.OBJECT_MAPPER.readValue(stringResponse, classType);
client.connectionPool().evictAll();
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
Expand Down

0 comments on commit 892528c

Please sign in to comment.