Search in sources :

Example 1 with DeviceSearch

use of forpdateam.ru.forpda.api.devdb.models.DeviceSearch in project ForPDA by RadiationX.

the class DevDb method search.

public DeviceSearch search(String query) throws Exception {
    DeviceSearch searchResult = new DeviceSearch();
    try {
        query = URLDecoder.decode(query, "windows-1251");
    } catch (Exception ignore) {
    }
    NetworkResponse response = Api.getWebClient().get("http://4pda.ru/devdb/search?s=" + query);
    Matcher matcher = SEARCH_PATTERN.matcher(response.getBody());
    while (matcher.find()) {
        DeviceSearch.DeviceItem item = new DeviceSearch.DeviceItem();
        item.setImageSrc(matcher.group(1));
        item.setId(matcher.group(2));
        item.setTitle(ApiUtils.fromHtml(matcher.group(3)));
        searchResult.addDevice(item);
    }
    searchResult.setAll(searchResult.getDevices().size());
    searchResult.setActual(searchResult.getAll());
    return searchResult;
}
Also used : DeviceSearch(forpdateam.ru.forpda.api.devdb.models.DeviceSearch) Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Aggregations

NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)1 DeviceSearch (forpdateam.ru.forpda.api.devdb.models.DeviceSearch)1 Matcher (java.util.regex.Matcher)1