Search in sources :

Example 1 with GiphyResponse

use of org.thoughtcrime.securesms.giph.model.GiphyResponse in project Signal-Android by WhisperSystems.

the class GiphyLoader method loadPage.

@NonNull
public List<GiphyImage> loadPage(int offset) {
    try {
        String url;
        if (TextUtils.isEmpty(searchString))
            url = String.format(getTrendingUrl(), offset);
        else
            url = String.format(getSearchUrl(), offset, Uri.encode(searchString));
        Request request = new Request.Builder().url(url).build();
        Response response = client.newCall(request).execute();
        if (!response.isSuccessful()) {
            throw new IOException("Unexpected code " + response);
        }
        GiphyResponse giphyResponse = JsonUtils.fromJson(response.body().byteStream(), GiphyResponse.class);
        List<GiphyImage> results = giphyResponse.getData();
        if (results == null)
            return new LinkedList<>();
        else
            return results;
    } catch (IOException e) {
        Log.w(TAG, e);
        return new LinkedList<>();
    }
}
Also used : GiphyResponse(org.thoughtcrime.securesms.giph.model.GiphyResponse) Response(okhttp3.Response) GiphyResponse(org.thoughtcrime.securesms.giph.model.GiphyResponse) GiphyImage(org.thoughtcrime.securesms.giph.model.GiphyImage) Request(okhttp3.Request) IOException(java.io.IOException) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)1 IOException (java.io.IOException)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 GiphyImage (org.thoughtcrime.securesms.giph.model.GiphyImage)1 GiphyResponse (org.thoughtcrime.securesms.giph.model.GiphyResponse)1