Example usage for com.squareup.okhttp Response isSuccessful

List of usage examples for com.squareup.okhttp Response isSuccessful

Introduction

In this page you can find the example usage for com.squareup.okhttp Response isSuccessful.

Prototype

public boolean isSuccessful() 

Source Link

Document

Returns true if the code is in [200..300), which means the request was successfully received, understood, and accepted.

Usage

From source file:com.miz.apis.trakt.Trakt.java

License:Apache License

public static boolean performMovieCheckin(String tmdbId, Context c) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    String username = settings.getString(TRAKT_USERNAME, "").trim();
    String password = settings.getString(TRAKT_PASSWORD, "");

    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password))
        return false;

    try {//from   w  ww.  ja  v  a 2 s  . co  m
        // Cancel any current check-in
        Request request = MizLib.getTraktAuthenticationRequest(
                "http://api.trakt.tv/movie/cancelcheckin/" + getApiKey(c), username, password);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();
        if (!response.isSuccessful())
            return false;
    } catch (Exception e) {
        return false;
    }

    try {
        // Perform the new check-in
        JSONObject holder = new JSONObject();
        holder.put("username", username);
        holder.put("password", password);
        holder.put("tmdb_id", tmdbId);
        holder.put("app_version", c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName);
        holder.put("app_date", c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName);

        Request request = MizLib.getJsonPostRequest("http://api.trakt.tv/movie/checkin/" + getApiKey(c),
                holder);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();
        return response.isSuccessful();
    } catch (Exception e) {
        return false;
    }
}

From source file:com.miz.apis.trakt.Trakt.java

License:Apache License

public static boolean performMovieCheckin(Movie movie, Context c) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    String username = settings.getString(TRAKT_USERNAME, "").trim();
    String password = settings.getString(TRAKT_PASSWORD, "");

    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password))
        return false;

    try {//from   w ww  . jav a  2s  .  c  o  m
        // Cancel any current check-in
        Request request = MizLib.getTraktAuthenticationRequest(
                "http://api.trakt.tv/movie/cancelcheckin/" + getApiKey(c), username, password);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();
        if (!response.isSuccessful())
            return false;
    } catch (Exception e) {
        return false;
    }

    try {
        // Perform the new check-in
        JSONObject holder = new JSONObject();
        holder.put("username", username);
        holder.put("password", password);
        holder.put("imdb_id", movie.getImdbId());
        holder.put("tmdb_id", movie.getImdbId());
        holder.put("title", movie.getTitle());
        holder.put("year", movie.getReleaseYear().replace("(", "").replace(")", ""));
        holder.put("app_version", c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName);
        holder.put("app_date", c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName);

        Request request = MizLib.getJsonPostRequest("http://api.trakt.tv/movie/checkin/" + getApiKey(c),
                holder);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();
        return response.isSuccessful();
    } catch (Exception e) {
        return false;
    }
}

From source file:com.miz.apis.trakt.Trakt.java

License:Apache License

public static boolean performEpisodeCheckin(TvShowEpisode episode, Context c) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    String username = settings.getString(TRAKT_USERNAME, "").trim();
    String password = settings.getString(TRAKT_PASSWORD, "");

    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password))
        return false;

    try {//from  w w w.  j a  v a 2 s  .com
        // Cancel any current check-in
        Request request = MizLib.getTraktAuthenticationRequest(
                "http://api.trakt.tv/show/cancelcheckin/" + getApiKey(c), username, password);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();
        if (!response.isSuccessful())
            return false;
    } catch (Exception e) {
        return false;
    }

    try {
        // Perform the new check-in
        JSONObject holder = new JSONObject();
        holder.put("username", username);
        holder.put("password", password);
        holder.put("tvdb_id", episode.getShowId());
        holder.put("title", "");
        holder.put("year", "");
        holder.put("season", episode.getSeason());
        holder.put("episode", episode.getEpisode());
        holder.put("app_version", c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName);
        holder.put("app_date", c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName);

        Request request = MizLib.getJsonPostRequest("http://api.trakt.tv/show/checkin/" + getApiKey(c), holder);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();
        return response.isSuccessful();
    } catch (Exception e) {
        return false;
    }
}

From source file:com.miz.apis.trakt.Trakt.java

License:Apache License

public static boolean markMovieAsWatched(List<Movie> movies, Context c) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    String username = settings.getString(TRAKT_USERNAME, "").trim();
    String password = settings.getString(TRAKT_PASSWORD, "");

    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password) || movies.size() == 0)
        return false;

    try {//www  . j  av  a 2 s.c  o  m
        JSONObject holder = new JSONObject();
        holder.put("username", username);
        holder.put("password", password);

        JSONArray array = new JSONArray();
        int count = movies.size();
        for (int i = 0; i < count; i++) {
            JSONObject jsonMovie = new JSONObject();
            jsonMovie.put("imdb_id", movies.get(i).getImdbId());
            jsonMovie.put("tmdb_id", movies.get(i).getTmdbId());
            jsonMovie.put("year", movies.get(i).getReleaseYear());
            jsonMovie.put("title", movies.get(i).getTitle());
            array.put(jsonMovie);
        }
        holder.put("movies", array);

        Request request = MizLib
                .getJsonPostRequest((movies.get(0).hasWatched() ? "http://api.trakt.tv/movie/seen/"
                        : "http://api.trakt.tv/movie/unseen/") + getApiKey(c), holder);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();
        return response.isSuccessful();
    } catch (Exception e) {
        return false;
    }
}

From source file:com.miz.apis.trakt.Trakt.java

License:Apache License

public static boolean markMoviesAsWatched(List<MediumMovie> movies, Context c) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    String username = settings.getString(TRAKT_USERNAME, "").trim();
    String password = settings.getString(TRAKT_PASSWORD, "");

    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password) || movies.size() == 0)
        return false;

    try {//from  ww  w .  j  a va  2 s .  c  om
        JSONObject holder = new JSONObject();
        holder.put("username", username);
        holder.put("password", password);

        JSONArray array = new JSONArray();
        int count = movies.size();
        for (int i = 0; i < count; i++) {
            JSONObject jsonMovie = new JSONObject();
            jsonMovie.put("tmdb_id", movies.get(i).getTmdbId());
            jsonMovie.put("year", movies.get(i).getReleaseYear());
            jsonMovie.put("title", movies.get(i).getTitle());
            array.put(jsonMovie);
        }
        holder.put("movies", array);

        Request request = MizLib
                .getJsonPostRequest((movies.get(0).hasWatched() ? "http://api.trakt.tv/movie/seen/"
                        : "http://api.trakt.tv/movie/unseen/") + getApiKey(c), holder);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();
        return response.isSuccessful();
    } catch (Exception e) {
        return false;
    }
}

From source file:com.miz.apis.trakt.Trakt.java

License:Apache License

public static boolean changeSeasonWatchedStatus(String showId, int season, Context c, boolean watched) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    String username = settings.getString(TRAKT_USERNAME, "").trim();
    String password = settings.getString(TRAKT_PASSWORD, "");

    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password))
        return false;

    try {// w w w.  j av  a 2 s .c  o m
        JSONObject holder = new JSONObject();
        holder.put("username", username);
        holder.put("password", password);
        holder.put("imdb_id", "");
        holder.put("tvdb_id", showId);
        holder.put("title", "");
        holder.put("year", "");
        holder.put("season", season);

        Request request = MizLib.getJsonPostRequest(
                "http://api.trakt.tv/show/season/" + (!watched ? "un" : "") + "seen/" + getApiKey(c), holder);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();
        return response.isSuccessful();
    } catch (Exception e) {
        return false;
    }
}

From source file:com.miz.apis.trakt.Trakt.java

License:Apache License

public static boolean markEpisodeAsWatched(String showId, List<com.miz.functions.TvShowEpisode> episodes,
        Context c, boolean watched) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    String username = settings.getString(TRAKT_USERNAME, "").trim();
    String password = settings.getString(TRAKT_PASSWORD, "");

    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)
            || !settings.getBoolean(SYNC_WITH_TRAKT, false) || episodes.size() == 0)
        return false;

    try {//ww w.  j av a 2 s  .co  m
        JSONObject holder = new JSONObject();
        holder.put("username", username);
        holder.put("password", password);
        holder.put("imdb_id", "");
        holder.put("tvdb_id", showId);
        holder.put("title", "");
        holder.put("year", "");

        JSONArray array = new JSONArray();
        int count = episodes.size();
        for (int i = 0; i < count; i++) {
            JSONObject jsonMovie = new JSONObject();
            jsonMovie.put("season", episodes.get(i).getSeason());
            jsonMovie.put("episode", episodes.get(i).getEpisode());
            array.put(jsonMovie);
        }
        holder.put("episodes", array);

        Request request = MizLib.getJsonPostRequest(
                "http://api.trakt.tv/show/episode/" + (!watched ? "un" : "") + "seen/" + getApiKey(c), holder);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();

        return response.isSuccessful();
    } catch (Exception e) {
        return false;
    }
}

From source file:com.miz.apis.trakt.Trakt.java

License:Apache License

public static boolean markTvShowAsWatched(TraktTvShow show, Context c) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    String username = settings.getString(TRAKT_USERNAME, "").trim();
    String password = settings.getString(TRAKT_PASSWORD, "");

    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password))
        return false;

    try {/*w  w  w  .j ava2s  . co m*/
        JSONObject json = new JSONObject();
        json.put("username", username);
        json.put("password", password);
        json.put("tvdb_id", show.getId());
        json.put("title", show.getTitle());

        JSONArray array = new JSONArray();
        for (String season : show.getSeasons().keySet()) {
            Collection<String> episodes = show.getSeasons().get(season);
            for (String episode : episodes) {
                JSONObject jsonShow = new JSONObject();
                jsonShow.put("season", season);
                jsonShow.put("episode", episode);
                array.put(jsonShow);
            }
        }
        json.put("episodes", array);

        Request request = MizLib.getJsonPostRequest("http://api.trakt.tv/show/episode/seen/" + getApiKey(c),
                json);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();
        return response.isSuccessful();
    } catch (Exception e) {
        return false;
    }
}

From source file:com.miz.apis.trakt.Trakt.java

License:Apache License

public static boolean addMoviesToLibrary(List<Movie> movies, Context c) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    String username = settings.getString(TRAKT_USERNAME, "").trim();
    String password = settings.getString(TRAKT_PASSWORD, "");

    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password) || movies.size() == 0)
        return false;

    try {/* w  w w  .  java2s  .  c o m*/
        JSONObject json = new JSONObject();
        json.put("username", username);
        json.put("password", password);

        JSONArray array = new JSONArray();
        int count = movies.size();
        for (int i = 0; i < count; i++) {
            JSONObject jsonMovie = new JSONObject();
            jsonMovie.put("imdb_id", movies.get(i).getImdbId());
            jsonMovie.put("tmdb_id", movies.get(i).getTmdbId());
            jsonMovie.put("year", movies.get(i).getReleaseYear());
            jsonMovie.put("title", movies.get(i).getTitle());
            array.put(jsonMovie);
        }
        json.put("movies", array);

        Request request = MizLib.getJsonPostRequest("http://api.trakt.tv/movie/library/" + getApiKey(c), json);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();
        return response.isSuccessful();
    } catch (Exception e) {
        return false;
    }
}

From source file:com.miz.apis.trakt.Trakt.java

License:Apache License

public static boolean movieWatchlist(List<Movie> movies, Context c) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    String username = settings.getString(TRAKT_USERNAME, "").trim();
    String password = settings.getString(TRAKT_PASSWORD, "");

    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password) || movies.size() == 0)
        return false;

    try {/*from  w w  w. ja v  a2  s.  c  om*/
        JSONObject json = new JSONObject();
        json.put("username", username);
        json.put("password", password);

        JSONArray array = new JSONArray();
        int count = movies.size();
        for (int i = 0; i < count; i++) {
            JSONObject jsonMovie = new JSONObject();
            jsonMovie.put("imdb_id", movies.get(i).getImdbId());
            jsonMovie.put("tmdb_id", movies.get(i).getTmdbId());
            jsonMovie.put("year", movies.get(i).getReleaseYear());
            jsonMovie.put("title", movies.get(i).getTitle());
            array.put(jsonMovie);
        }
        json.put("movies", array);

        Request request = MizLib
                .getJsonPostRequest((movies.get(0).toWatch() ? "http://api.trakt.tv/movie/watchlist/"
                        : "http://api.trakt.tv/movie/unwatchlist/") + getApiKey(c), json);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();
        return response.isSuccessful();
    } catch (Exception e) {
        return false;
    }
}