Search in sources :

Example 1 with TwitchUserDataResponse

use of com.discordbolt.boltbot.system.twitch.objects.TwitchUserDataResponse in project BoltBot by DiscordBolt.

the class TwitchUser method getUserData.

public Optional<TwitchUserData> getUserData(String username) throws IOException {
    HttpUrl userURL = HttpUrl.parse(USER_INFO_URL).newBuilder().addQueryParameter("login", username).build();
    Request request = new Request.Builder().url(userURL).addHeader("Client-ID", api.getClientID()).addHeader("Accept", "application/vnd.twitchtv.v5+json").build();
    try (Response response = api.getClient().newCall(request).execute()) {
        TwitchUserDataResponse users = api.getGson().fromJson(response.body().string(), TwitchUserDataResponse.class);
        return users.getUsers().stream().findFirst();
    }
}
Also used : TwitchUserDataResponse(com.discordbolt.boltbot.system.twitch.objects.TwitchUserDataResponse) Response(okhttp3.Response) Request(okhttp3.Request) TwitchUserDataResponse(com.discordbolt.boltbot.system.twitch.objects.TwitchUserDataResponse) HttpUrl(okhttp3.HttpUrl)

Aggregations

TwitchUserDataResponse (com.discordbolt.boltbot.system.twitch.objects.TwitchUserDataResponse)1 HttpUrl (okhttp3.HttpUrl)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1