use of org.mediawiki.api.ApiResult in project apps-android-commons by commons-app.
the class MediaDataExtractor method fetch.
/**
* Actually fetch the data over the network.
* todo: use local caching?
*
* Warning: synchronous i/o, call on a background thread
*/
public void fetch() throws IOException {
if (fetched) {
throw new IllegalStateException("Tried to call MediaDataExtractor.fetch() again.");
}
MWApi api = CommonsApplication.getInstance().getMWApi();
ApiResult result = api.action("query").param("prop", "revisions").param("titles", filename).param("rvprop", "content").param("rvlimit", 1).param("rvgeneratexml", 1).get();
processResult(result);
fetched = true;
}
use of org.mediawiki.api.ApiResult in project apps-android-commons by commons-app.
the class MethodAUpdater method doInBackground.
@Override
protected ArrayList<String> doInBackground(Void... voids) {
//otherwise if user has typed something in that isn't in cache, search API for matching categories
MWApi api = CommonsApplication.getInstance().getMWApi();
ApiResult result;
ArrayList<String> categories = new ArrayList<>();
//URL https://commons.wikimedia.org/w/api.php?action=query&format=xml&list=search&srwhat=text&srenablerewrites=1&srnamespace=14&srlimit=10&srsearch=
try {
result = api.action("query").param("format", "xml").param("list", "search").param("srwhat", "text").param("srnamespace", "14").param("srlimit", catFragment.SEARCH_CATS_LIMIT).param("srsearch", filter).get();
Timber.d("Method A URL filter %s", result);
} catch (IOException e) {
Timber.e(e, "IO Exception: ");
//Return empty arraylist
return categories;
}
ArrayList<ApiResult> categoryNodes = result.getNodes("/api/query/search/p/@title");
for (ApiResult categoryNode : categoryNodes) {
String cat = categoryNode.getDocument().getTextContent();
String catString = cat.replace("Category:", "");
categories.add(catString);
}
Timber.d("Found categories from Method A search, waiting for filter");
return new ArrayList<>(filterYears(categories));
}
use of org.mediawiki.api.ApiResult in project apps-android-commons by commons-app.
the class PrefixUpdater method doInBackground.
@Override
protected ArrayList<String> doInBackground(Void... voids) {
//If user hasn't typed anything in yet, get GPS and recent items
if (TextUtils.isEmpty(filter)) {
ArrayList<String> mergedItems = new ArrayList<>(catFragment.mergeItems());
Timber.d("Merged items, waiting for filter");
return new ArrayList<>(filterYears(mergedItems));
}
//if user types in something that is in cache, return cached category
if (catFragment.categoriesCache.containsKey(filter)) {
ArrayList<String> cachedItems = new ArrayList<>(catFragment.categoriesCache.get(filter));
Timber.d("Found cache items, waiting for filter");
return new ArrayList<>(filterYears(cachedItems));
}
//otherwise if user has typed something in that isn't in cache, search API for matching categories
//URL: https://commons.wikimedia.org/w/api.php?action=query&list=allcategories&acprefix=filter&aclimit=25
MWApi api = CommonsApplication.getInstance().getMWApi();
ApiResult result;
ArrayList<String> categories = new ArrayList<>();
try {
result = api.action("query").param("list", "allcategories").param("acprefix", filter).param("aclimit", catFragment.SEARCH_CATS_LIMIT).get();
Timber.d("Prefix URL filter %s", result);
} catch (IOException e) {
Timber.e(e, "IO Exception: ");
//Return empty arraylist
return categories;
}
ArrayList<ApiResult> categoryNodes = result.getNodes("/api/query/allcategories/c");
for (ApiResult categoryNode : categoryNodes) {
categories.add(categoryNode.getDocument().getTextContent());
}
Timber.d("Found categories from Prefix search, waiting for filter");
return new ArrayList<>(filterYears(categories));
}
use of org.mediawiki.api.ApiResult in project apps-android-commons by commons-app.
the class TitleCategories method doInBackground.
@Override
protected ArrayList<String> doInBackground(Void... voids) {
MWApi api = CommonsApplication.getInstance().getMWApi();
ApiResult result;
ArrayList<String> items = new ArrayList<>();
//URL https://commons.wikimedia.org/w/api.php?action=query&format=xml&list=search&srwhat=text&srenablerewrites=1&srnamespace=14&srlimit=10&srsearch=
try {
result = api.action("query").param("format", "xml").param("list", "search").param("srwhat", "text").param("srnamespace", "14").param("srlimit", SEARCH_CATS_LIMIT).param("srsearch", title).get();
Timber.d("Searching for cats for title: %s", result);
} catch (IOException e) {
Timber.e(e, "IO Exception: ");
//Return empty arraylist
return items;
}
ArrayList<ApiResult> categoryNodes = result.getNodes("/api/query/search/p/@title");
for (ApiResult categoryNode : categoryNodes) {
String cat = categoryNode.getDocument().getTextContent();
String catString = cat.replace("Category:", "");
items.add(catString);
}
Timber.d("Title cat query results: %s", items);
return items;
}
use of org.mediawiki.api.ApiResult in project apps-android-commons by commons-app.
the class MediaThumbnailFetchTask method doInBackground.
@Override
protected String doInBackground(String... params) {
try {
MWApi api = CommonsApplication.getInstance().getMWApi();
ApiResult result = api.action("query").param("format", "xml").param("prop", "imageinfo").param("iiprop", "url").param("iiurlwidth", THUMB_SIZE).param("titles", params[0]).get();
return result.getString("/api/query/pages/page/imageinfo/ii/@thumburl");
} catch (Exception e) {
// Do something better!
}
return null;
}
Aggregations