Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Commit

Permalink
Fix MAL API block due "new security measures".
Browse files Browse the repository at this point in the history
  • Loading branch information
ratan12 committed Jul 1, 2017
1 parent 814ff03 commit f4357d8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 58 deletions.
16 changes: 8 additions & 8 deletions Atarashii/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ android {
productFlavors {
Production {
applicationId 'net.somethingdreadful.MAL'
versionCode 39
versionName '2.4'
versionCode 40
versionName '2.4.1'
}
FLOSSProduction {
applicationId 'net.somethingdreadful.MAL'
versionCode 39
versionName '2.4'
versionCode 40
versionName '2.4.1'
}
Beta {
applicationId 'net.somethingdreadful.MAL.beta'
versionCode 82
versionName '2.4'
versionCode 83
versionName '2.4.1'
}
FLOSSBeta {
applicationId 'net.somethingdreadful.MAL.beta'
versionCode 82
versionName '2.4'
versionCode 83
versionName '2.4.1'
}
}

Expand Down
84 changes: 43 additions & 41 deletions Atarashii/src/main/java/net/somethingdreadful/MAL/api/MALApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@

public class MALApi {
// Use version 2.1 of the API interface
private static final String API_HOST = "https://api.atarashiiapp.com/2.1/";
private static final String API_HOST = "https://malapi.atarashiiapp.com/2.1/";
private static final String MAL_HOST = "https://myanimelist.net/";
private Activity activity = null;

private MALInterface service;
private MALInterface APIservice;
private MALInterface MALservice;

public MALApi() {
setupRESTService(AccountService.getUsername(), AccountService.getPassword());
Expand All @@ -50,26 +51,27 @@ public MALApi(Activity activity) {
* Only use for verifying.
*/
public MALApi(String username, String password) {
service = APIHelper.createClient(MAL_HOST, MALInterface.class, Credentials.basic(username, password));
setupRESTService(username, password);
}

public static String getListTypeString(ListType type) {
return type.name().toLowerCase();
}

private void setupRESTService(String username, String password) {
service = APIHelper.createClient(API_HOST, MALInterface.class, Credentials.basic(username, password));
APIservice = APIHelper.createClient(API_HOST, MALInterface.class, Credentials.basic(username, password));
MALservice = APIHelper.createClient(MAL_HOST, MALInterface.class, Credentials.basic(username, password));
}

public boolean isAuth() {
return APIHelper.isOK(service.verifyAuthentication(), "isAuth");
return APIHelper.isOK(MALservice.verifyAuthentication(), "isAuth");
}

public ArrayList<Anime> searchAnime(String query, int page) {
if (PrefManager.getNSFWEnabled()) {
Response<ArrayList<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Anime>> response = null;
try {
response = service.searchAnime(query, page).execute();
response = APIservice.searchAnime(query, page).execute();
return AnimeList.convertBaseArray(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "searchAnime", e);
Expand All @@ -89,7 +91,7 @@ public ArrayList<Manga> searchManga(String query, int page) {
if (PrefManager.getNSFWEnabled()) {
Response<ArrayList<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Manga>> response = null;
try {
response = service.searchManga(query, page).execute();
response = APIservice.searchManga(query, page).execute();
return MangaList.convertBaseArray(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "searchManga", e);
Expand All @@ -108,7 +110,7 @@ public ArrayList<Manga> searchManga(String query, int page) {
public UserList getAnimeList(String username) {
Response<AnimeList> response = null;
try {
response = service.getAnimeList(username).execute();
response = APIservice.getAnimeList(username).execute();
return AnimeList.createBaseModel(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getAnimeList", e);
Expand All @@ -119,7 +121,7 @@ public UserList getAnimeList(String username) {
public UserList getMangaList(String username) {
Response<MangaList> response = null;
try {
response = service.getMangaList(username).execute();
response = APIservice.getMangaList(username).execute();
return MangaList.createBaseModel(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getMangaList", e);
Expand All @@ -130,7 +132,7 @@ public UserList getMangaList(String username) {
public Anime getAnime(int id, int mine) {
Response<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Anime> response = null;
try {
response = service.getAnime(id, mine).execute();
response = APIservice.getAnime(id, mine).execute();
return response.body().createBaseModel();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getAnime", e);
Expand All @@ -141,7 +143,7 @@ public Anime getAnime(int id, int mine) {
public Manga getManga(int id, int mine) {
Response<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Manga> response = null;
try {
response = service.getManga(id, mine).execute();
response = APIservice.getManga(id, mine).execute();
return response.body().createBaseModel();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getManga", e);
Expand All @@ -151,7 +153,7 @@ public Manga getManga(int id, int mine) {

public boolean addOrUpdateAnime(Anime anime) {
if (anime.getCreateFlag())
return APIHelper.isOK(service.addAnime(anime.getId(), anime.getWatchedStatus(), anime.getWatchedEpisodes(), anime.getScore()), "addOrUpdateAnime");
return APIHelper.isOK(APIservice.addAnime(anime.getId(), anime.getWatchedStatus(), anime.getWatchedEpisodes(), anime.getScore()), "addOrUpdateAnime");
else {
if (anime.isDirty()) {
// map anime property names to api field names
Expand Down Expand Up @@ -182,15 +184,15 @@ public boolean addOrUpdateAnime(Anime anime) {
}
}
}
return APIHelper.isOK(service.updateAnime(anime.getId(), fieldMap), "addOrUpdateAnime");
return APIHelper.isOK(APIservice.updateAnime(anime.getId(), fieldMap), "addOrUpdateAnime");
}
}
return false;
}

public boolean addOrUpdateManga(Manga manga) {
if (manga.getCreateFlag())
return APIHelper.isOK(service.addManga(manga.getId(), manga.getReadStatus(), manga.getChaptersRead(), manga.getVolumesRead(), manga.getScore()), "addOrUpdateManga");
return APIHelper.isOK(APIservice.addManga(manga.getId(), manga.getReadStatus(), manga.getChaptersRead(), manga.getVolumesRead(), manga.getScore()), "addOrUpdateManga");
else {
if (manga.isDirty()) {
// map manga property names to api field names
Expand Down Expand Up @@ -218,25 +220,25 @@ public boolean addOrUpdateManga(Manga manga) {
}
}
}
return APIHelper.isOK(service.updateManga(manga.getId(), fieldMap), "addOrUpdateManga");
return APIHelper.isOK(APIservice.updateManga(manga.getId(), fieldMap), "addOrUpdateManga");
}
}
return false;
}

public boolean deleteAnimeFromList(int id) {
return APIHelper.isOK(service.deleteAnime(id), "deleteAnimeFromList");
return APIHelper.isOK(APIservice.deleteAnime(id), "deleteAnimeFromList");
}

public boolean deleteMangaFromList(int id) {
return APIHelper.isOK(service.deleteManga(id), "deleteMangaFromList");
return APIHelper.isOK(APIservice.deleteManga(id), "deleteMangaFromList");
}

public ArrayList<Anime> getBrowseAnime(Map<String, String> queries) {
retrofit2.Response<ArrayList<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Anime>> response = null;
AppLog.log(Log.INFO, "Atarashii", "MALApi.getBrowseAnime(): queries=" + queries.toString());
try {
response = service.getBrowseAnime(queries).execute();
response = APIservice.getBrowseAnime(queries).execute();
return AnimeList.convertBaseArray(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getBrowseAnime: " + queries.toString(), e);
Expand All @@ -248,7 +250,7 @@ public ArrayList<Manga> getBrowseManga(Map<String, String> queries) {
retrofit2.Response<ArrayList<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Manga>> response = null;
AppLog.log(Log.INFO, "Atarashii", "MALApi.getBrowseManga(): queries=" + queries.toString());
try {
response = service.getBrowseManga(queries).execute();
response = APIservice.getBrowseManga(queries).execute();
return MangaList.convertBaseArray(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getBrowseManga: " + queries.toString(), e);
Expand All @@ -267,7 +269,7 @@ private HashMap<String, String> checkNSFW(HashMap<String, String> map) {
public ArrayList<Anime> getMostPopularAnime(int page) {
Response<ArrayList<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Anime>> response = null;
try {
response = service.getPopularAnime(page).execute();
response = APIservice.getPopularAnime(page).execute();
return AnimeList.convertBaseArray(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getMostPopularAnime: page =" + page, e);
Expand All @@ -278,7 +280,7 @@ public ArrayList<Anime> getMostPopularAnime(int page) {
public ArrayList<Manga> getMostPopularManga(int page) {
Response<ArrayList<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Manga>> response = null;
try {
response = service.getPopularManga(page).execute();
response = APIservice.getPopularManga(page).execute();
return MangaList.convertBaseArray(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getMostPopularManga: page =" + page, e);
Expand All @@ -289,7 +291,7 @@ public ArrayList<Manga> getMostPopularManga(int page) {
public ArrayList<Anime> getTopRatedAnime(int page) {
Response<ArrayList<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Anime>> response = null;
try {
response = service.getTopRatedAnime(page).execute();
response = APIservice.getTopRatedAnime(page).execute();
return AnimeList.convertBaseArray(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getTopRatedAnime: page =" + page, e);
Expand All @@ -300,7 +302,7 @@ public ArrayList<Anime> getTopRatedAnime(int page) {
public ArrayList<Manga> getTopRatedManga(int page) {
Response<ArrayList<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Manga>> response = null;
try {
response = service.getTopRatedManga(page).execute();
response = APIservice.getTopRatedManga(page).execute();
return MangaList.convertBaseArray(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getTopRatedManga: page =" + page, e);
Expand Down Expand Up @@ -347,7 +349,7 @@ public ArrayList<Manga> getUpcomingManga(int page) {
public Profile getProfile(String user) {
Response<net.somethingdreadful.MAL.api.MALModels.Profile> response = null;
try {
response = service.getProfile(user).execute();
response = APIservice.getProfile(user).execute();
return response.body().createBaseModel();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getProfile", e);
Expand All @@ -358,7 +360,7 @@ public Profile getProfile(String user) {
public ArrayList<Profile> getFriends(String user) {
Response<ArrayList<Friend>> response = null;
try {
response = service.getFriends(user).execute();
response = APIservice.getFriends(user).execute();
return Friend.convertBaseFriendList(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getFriends", e);
Expand All @@ -369,7 +371,7 @@ public ArrayList<Profile> getFriends(String user) {
public ForumMain getForum() {
Response<ForumMain> response = null;
try {
response = service.getForum().execute();
response = APIservice.getForum().execute();
return response.body();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getForum", e);
Expand All @@ -380,7 +382,7 @@ public ForumMain getForum() {
public ForumMain getCategoryTopics(int id, int page) {
Response<ForumMain> response = null;
try {
response = service.getCategoryTopics(id, page).execute();
response = APIservice.getCategoryTopics(id, page).execute();
return response.body();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getCategoryTopics", e);
Expand All @@ -391,7 +393,7 @@ public ForumMain getCategoryTopics(int id, int page) {
public ForumMain getForumAnime(int id, int page) {
Response<ForumMain> response = null;
try {
response = service.getForumAnime(id, page).execute();
response = APIservice.getForumAnime(id, page).execute();
return response.body();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getForumAnime", e);
Expand All @@ -402,7 +404,7 @@ public ForumMain getForumAnime(int id, int page) {
public ForumMain getForumManga(int id, int page) {
Response<ForumMain> response = null;
try {
response = service.getForumManga(id, page).execute();
response = APIservice.getForumManga(id, page).execute();
return response.body();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getForumManga", e);
Expand All @@ -413,7 +415,7 @@ public ForumMain getForumManga(int id, int page) {
public ForumMain getPosts(int id, int page) {
Response<ForumMain> response = null;
try {
response = service.getPosts(id, page).execute();
response = APIservice.getPosts(id, page).execute();
return response.body();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getPosts", e);
Expand All @@ -424,7 +426,7 @@ public ForumMain getPosts(int id, int page) {
public ForumMain getSubBoards(int id, int page) {
Response<ForumMain> response = null;
try {
response = service.getSubBoards(id, page).execute();
response = APIservice.getSubBoards(id, page).execute();
return response.body();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getSubBoards", e);
Expand All @@ -433,21 +435,21 @@ public ForumMain getSubBoards(int id, int page) {
}

public boolean addComment(int id, String message) {
return APIHelper.isOK(service.addComment(id, message), "addComment");
return APIHelper.isOK(APIservice.addComment(id, message), "addComment");
}

public boolean updateComment(int id, String message) {
return APIHelper.isOK(service.updateComment(id, message), "updateComment");
return APIHelper.isOK(APIservice.updateComment(id, message), "updateComment");
}

public boolean addTopic(int id, String title, String message) {
return APIHelper.isOK(service.addTopic(id, title, message), "addTopic");
return APIHelper.isOK(APIservice.addTopic(id, title, message), "addTopic");
}

public ForumMain search(String query) {
Response<ForumMain> response = null;
try {
response = service.search(query).execute();
response = APIservice.search(query).execute();
return response.body();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "search", e);
Expand All @@ -458,7 +460,7 @@ public ForumMain search(String query) {
public ArrayList<Reviews> getAnimeReviews(int id, int page) {
Response<ArrayList<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Reviews>> response = null;
try {
response = service.getAnimeReviews(id, page).execute();
response = APIservice.getAnimeReviews(id, page).execute();
return net.somethingdreadful.MAL.api.MALModels.AnimeManga.Reviews.convertBaseArray(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getAnimeReviews", e);
Expand All @@ -469,7 +471,7 @@ public ArrayList<Reviews> getAnimeReviews(int id, int page) {
public ArrayList<Reviews> getMangaReviews(int id, int page) {
Response<ArrayList<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Reviews>> response = null;
try {
response = service.getMangaReviews(id, page).execute();
response = APIservice.getMangaReviews(id, page).execute();
return net.somethingdreadful.MAL.api.MALModels.AnimeManga.Reviews.convertBaseArray(response.body());
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getMangaReviews", e);
Expand All @@ -480,7 +482,7 @@ public ArrayList<Reviews> getMangaReviews(int id, int page) {
public ArrayList<net.somethingdreadful.MAL.api.BaseModels.History> getActivity(String username) {
Response<ArrayList<History>> response = null;
try {
response = service.getActivity(username).execute();
response = APIservice.getActivity(username).execute();
return History.convertBaseHistoryList(response.body(), username);
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getActivity", e);
Expand All @@ -491,7 +493,7 @@ public ArrayList<net.somethingdreadful.MAL.api.BaseModels.History> getActivity(S
public ArrayList<Recommendations> getAnimeRecs(int id) {
Response<ArrayList<Recommendations>> response = null;
try {
response = service.getAnimeRecs(id).execute();
response = APIservice.getAnimeRecs(id).execute();
return response.body();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getAnimeRecs", e);
Expand All @@ -502,7 +504,7 @@ public ArrayList<Recommendations> getAnimeRecs(int id) {
public ArrayList<Recommendations> getMangaRecs(int id) {
Response<ArrayList<Recommendations>> response = null;
try {
response = service.getMangaRecs(id).execute();
response = APIservice.getMangaRecs(id).execute();
return response.body();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getMangaRecs", e);
Expand All @@ -513,7 +515,7 @@ public ArrayList<Recommendations> getMangaRecs(int id) {
public Schedule getSchedule() {
Response<net.somethingdreadful.MAL.api.MALModels.AnimeManga.Schedule> response = null;
try {
response = service.getSchedule().execute();
response = APIservice.getSchedule().execute();
return response.body().convertBaseSchedule();
} catch (Exception e) {
APIHelper.logE(activity, response, "MALApi", "getSchedule", e);
Expand Down
Loading

0 comments on commit f4357d8

Please sign in to comment.