Example usage for com.squareup.okhttp Request.Builder tag

List of usage examples for com.squareup.okhttp Request.Builder tag

Introduction

In this page you can find the example usage for com.squareup.okhttp Request.Builder tag.

Prototype

Object tag

To view the source code for com.squareup.okhttp Request.Builder tag.

Click Source Link

Usage

From source file:net.yatomiya.nicherry.services.bbs.ModelUpdateHandler.java

License:Open Source License

protected Request.Builder createRequestBuilder() {
    MBBSModel model = getModel();/*from  w ww  .  ja  v a 2 s.  co  m*/
    HttpUrl url = HttpUrl.parse(createRequestUrl());
    Request.Builder builder = HttpUtils.createRequestBuilder(url,
            isForceUpdate ? null : new Date(model.getLastModifiedInResponseHeader()));
    builder.tag(this);

    return builder;
}

From source file:pct.droid.base.providers.media.EZTVProvider.java

License:Open Source License

@Override
public Call getList(final ArrayList<Media> existingList, Filters filters, final Callback callback) {
    final ArrayList<Media> currentList;
    if (existingList == null) {
        currentList = new ArrayList<>();
    } else {/*from w ww.j a  v  a  2 s  . com*/
        currentList = (ArrayList<Media>) existingList.clone();
    }

    ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("limit", "30"));

    if (filters == null) {
        filters = new Filters();
    }

    if (filters.keywords != null) {
        params.add(new NameValuePair("keywords", filters.keywords));
    }

    if (filters.genre != null) {
        params.add(new NameValuePair("genre", filters.genre));
    }

    if (filters.order == Filters.Order.ASC) {
        params.add(new NameValuePair("order", "asc"));
    } else {
        params.add(new NameValuePair("order", "desc"));
    }

    String sort = "";
    switch (filters.sort) {
    default:
    case POPULARITY:
        sort = "popularity";
        break;
    case TRENDING:
        sort = "trending";
        break;
    case YEAR:
        sort = "year";
        break;
    case DATE:
        sort = "updated";
        break;
    case RATING:
        sort = "rating";
        break;
    case ALPHABET:
        sort = "name";
        break;
    }

    params.add(new NameValuePair("sort", sort));

    String url = API_URL + "shows/";
    if (filters.page != null) {
        url += filters.page;
    } else {
        url += "1";
    }

    Request.Builder requestBuilder = new Request.Builder();
    String query = buildQuery(params);
    requestBuilder.url(url + "?" + query);
    requestBuilder.tag(MEDIA_CALL);

    return fetchList(currentList, requestBuilder, filters, callback);
}

From source file:pct.droid.base.providers.media.EZTVProvider.java

License:Open Source License

@Override
public Call getDetail(String videoId, final Callback callback) {
    Request.Builder requestBuilder = new Request.Builder();
    requestBuilder.url(API_URL + "show/" + videoId);
    requestBuilder.tag(MEDIA_CALL);

    return enqueue(requestBuilder.build(), new com.squareup.okhttp.Callback() {
        @Override// w  w w .  ja v a  2 s . c  o m
        public void onFailure(Request request, IOException e) {
            callback.onFailure(e);
        }

        @Override
        public void onResponse(Response response) throws IOException {
            if (response.isSuccessful()) {
                String responseStr = response.body().string();
                LinkedTreeMap<String, Object> map = mGson.fromJson(responseStr, LinkedTreeMap.class);
                EZTVReponse result = new EZTVReponse(map);
                if (map == null) {
                    callback.onFailure(new NetworkErrorException("Empty response"));
                } else {
                    ArrayList<Media> formattedData = result.formatDetailForPopcorn();

                    if (formattedData.size() > 0) {
                        callback.onSuccess(null, formattedData, true);
                        return;
                    }
                    callback.onFailure(new IllegalStateException("Empty list"));
                    return;
                }
            }
            callback.onFailure(new NetworkErrorException("Couldn't connect to EZTVAPI"));
        }
    });
}

From source file:pct.droid.base.providers.media.HaruProvider.java

License:Open Source License

@Override
public Call getList(final ArrayList<Media> existingList, Filters filters, final Callback callback) {
    final ArrayList<Media> currentList;
    if (existingList == null) {
        currentList = new ArrayList<>();
    } else {//from  w  w w.j a  v a  2s  .com
        currentList = (ArrayList<Media>) existingList.clone();
    }

    ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("limit", "30"));

    if (filters == null) {
        filters = new Filters();
    }

    if (filters.keywords != null) {
        params.add(new NameValuePair("search", filters.keywords));
    }

    if (filters.genre != null) {
        params.add(new NameValuePair("genres", filters.genre));
    }

    if (filters.order == Filters.Order.DESC) {
        params.add(new NameValuePair("order", "desc"));
    } else {
        params.add(new NameValuePair("order", "asc"));
    }

    String sort = "";
    switch (filters.sort) {
    default:
    case POPULARITY:
        sort = "popularity";
        break;
    case YEAR:
        sort = "year";
        break;
    case DATE:
        sort = "updated";
        break;
    case RATING:
        sort = "rating";
        break;
    case ALPHABET:
        sort = "name";
        break;
    }

    params.add(new NameValuePair("sort", sort));

    String url = API_URL + "list.php";
    if (filters.page != null) {
        params.add(new NameValuePair("page", Integer.toString(filters.page - 1)));
    } else {
        params.add(new NameValuePair("page", "0"));
    }

    Request.Builder requestBuilder = new Request.Builder();
    String query = buildQuery(params);
    requestBuilder.url(url + "?" + query);
    requestBuilder.tag(MEDIA_CALL);

    return fetchList(currentList, requestBuilder, filters, callback);
}

From source file:pct.droid.base.providers.media.HaruProvider.java

License:Open Source License

@Override
public Call getDetail(String videoId, final Callback callback) {
    Request.Builder requestBuilder = new Request.Builder();
    requestBuilder.url(API_URL + "anime.php?id=" + videoId);
    requestBuilder.tag(MEDIA_CALL);

    return enqueue(requestBuilder.build(), new com.squareup.okhttp.Callback() {
        @Override/*ww w .  j  av a  2 s .com*/
        public void onFailure(Request request, IOException e) {
            callback.onFailure(e);
        }

        @Override
        public void onResponse(Response response) throws IOException {
            if (response.isSuccessful()) {
                String responseStr = response.body().string();
                LinkedTreeMap<String, Object> map = mGson.fromJson(responseStr, LinkedTreeMap.class);
                HaruResponse result = new HaruResponse(map);
                if (map == null) {
                    callback.onFailure(new NetworkErrorException("Empty response"));
                } else {
                    ArrayList<Media> formattedData = result.formatDetailForPopcorn();

                    if (formattedData.size() > 0) {
                        callback.onSuccess(null, formattedData, true);
                        return;
                    }
                    callback.onFailure(new IllegalStateException("Empty list"));
                    return;
                }
            }
            callback.onFailure(new NetworkErrorException("Couldn't connect to Haruhichan API"));
        }
    });
}

From source file:pct.droid.base.providers.media.YTSProvider.java

License:Open Source License

@Override
public Call getList(final ArrayList<Media> existingList, Filters filters, final Callback callback) {
    sFilters = filters;/*www.j ava  2 s  . c o m*/

    final ArrayList<Media> currentList;
    if (existingList == null) {
        currentList = new ArrayList<>();
    } else {
        currentList = (ArrayList<Media>) existingList.clone();
    }

    ArrayList<NameValuePair> params = new ArrayList<>();
    params.add(new NameValuePair("limit", "30"));

    if (filters == null) {
        filters = new Filters();
    }

    if (filters.keywords != null) {
        params.add(new NameValuePair("query_term", filters.keywords));
    }

    if (filters.genre != null) {
        params.add(new NameValuePair("genre", filters.genre));
    }

    if (filters.order == Filters.Order.ASC) {
        params.add(new NameValuePair("order_by", "asc"));
    } else {
        params.add(new NameValuePair("order_by", "desc"));
    }

    if (filters.langCode != null) {
        params.add(new NameValuePair("lang", filters.langCode));
    }

    String sort;
    switch (filters.sort) {
    default:
    case POPULARITY:
        sort = "seeds";
        break;
    case YEAR:
        sort = "year";
        break;
    case DATE:
        sort = "date_added";
        break;
    case RATING:
        sort = "rating";
        break;
    case ALPHABET:
        sort = "title";
        break;
    }

    params.add(new NameValuePair("sort_by", sort));

    if (filters.page != null) {
        params.add(new NameValuePair("page", Integer.toString(filters.page)));
    }

    Request.Builder requestBuilder = new Request.Builder();
    String query = buildQuery(params);
    requestBuilder.url(CURRENT_URL + "list_movies_pct.json?" + query);
    requestBuilder.tag(MEDIA_CALL);

    return fetchList(currentList, requestBuilder, filters, callback);
}

From source file:pct.droid.base.providers.media.YTSProvider.java

License:Open Source License

@Override
public Call getDetail(String videoId, Callback callback) {
    Request.Builder requestBuilder = new Request.Builder();
    requestBuilder// ww w .jav a 2 s. c o  m
            .url(API_URL + "list_movies_pct.json?query_term=" + videoId + "&limit=1&lang=" + sFilters.langCode);
    requestBuilder.addHeader("Host", "xor.image.yt");
    requestBuilder.tag(MEDIA_CALL);

    return fetchDetail(requestBuilder, callback);
}