Commit 73a20d75 authored by Benjamin Beeker's avatar Benjamin Beeker

twitch api accept header v5

parent 182ac51e
Pipeline #11213065 passed with stages
in 1 minute and 43 seconds
......@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.comhix.twitch</groupId>
<version>0.1.2</version>
<version>0.1.3</version>
<artifactId>twitch-api</artifactId>
<name>Twitch API</name>
<url>https://nozomibk.gitlab.io/twitch-api</url>
......
......@@ -14,6 +14,8 @@ import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStream;
import java.io.InputStreamReader;
......@@ -26,6 +28,8 @@ import static com.google.common.collect.Maps.newHashMap;
* Main entry-point to use the Twitch-Api
*/
public class TwitchApi {
private static final Logger log = LoggerFactory.getLogger(TwitchApi.class);
private final ClientInformation clientInformation;
private final String oauthToken;
......@@ -111,7 +115,8 @@ public class TwitchApi {
return Observable.fromCallable(() -> {
Request.Builder request = new Request.Builder().url("https://api.twitch.tv/kraken/user")
.addHeader("Client-ID", clientInformation.getClientId())
.addHeader("Authorization", "OAuth " + oauthToken);
.addHeader("Authorization", "OAuth " + oauthToken)
.addHeader("Accept", "application/vnd.twitchtv.v5+json");
InputStream body = client.newCall(request.build()).execute().body().byteStream();
return new Gson().fromJson(new InputStreamReader(body), DetailedUser.class);
}).observeOn(Schedulers.io());
......@@ -122,10 +127,14 @@ public class TwitchApi {
*/
public static Observable<List<User>> getUsers(ClientInformation clientInformation, List<String> loginNames) {
return Observable.fromCallable(() -> {
Request.Builder request = new Request.Builder().url("https://api.twitch.tv/kraken/users?login=" + Joiner.on(",").join(loginNames))
.addHeader("Client-ID", clientInformation.getClientId());
InputStream body = client.newCall(request.build()).execute().body().byteStream();
return new Gson().fromJson(new InputStreamReader(body), UsersResponse.class).users;
String url = "https://api.twitch.tv/kraken/users?login=" + Joiner.on(",").join(loginNames);
log.debug("calling {}", url);
Request.Builder request = new Request.Builder().url(url)
.addHeader("Client-ID", clientInformation.getClientId())
.addHeader("Accept", "application/vnd.twitchtv.v5+json");
String json = client.newCall(request.build()).execute().body().string();
log.debug("response json: {}", json);
return new Gson().fromJson(json, UsersResponse.class).users;
}).observeOn(Schedulers.io());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment