use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Auth method logout.
public boolean logout() throws Exception {
NetworkResponse response = Api.getWebClient().get("https://4pda.ru/forum/index.php?act=logout&CODE=03&k=".concat(Api.getWebClient().getAuthKey()));
Matcher matcher = Pattern.compile("wr va-m text").matcher(response.getBody());
if (matcher.find())
throw new Exception("You already logout");
Api.getWebClient().clearCookies();
App.get().getPreferences().edit().remove("cookie_member_id").remove("cookie_pass_hash").apply();
ClientHelper.setAuthState(ClientHelper.AUTH_STATE_LOGOUT);
return !checkLogin(Api.getWebClient().get(IWebClient.MINIMAL_PAGE).getBody());
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Auth method login.
public Boolean login(final AuthForm form) throws Exception {
NetworkRequest.Builder builder = new NetworkRequest.Builder().url(AUTH_BASE_URL).formHeader("captcha-time", form.getCaptchaTime()).formHeader("captcha-sig", form.getCaptchaSig()).formHeader("captcha", form.getCaptcha()).formHeader("return", form.getReturnField()).formHeader("login", URLEncoder.encode(form.getNick(), "windows-1251"), true).formHeader("password", URLEncoder.encode(form.getPassword(), "windows-1251"), true).formHeader("remember", form.getRememberField()).formHeader("hidden", form.isHidden() ? "1" : "0");
NetworkResponse response = Api.getWebClient().request(builder.build());
Matcher matcher = errorPattern.matcher(response.getBody());
if (matcher.find()) {
throw new Exception(ApiUtils.fromHtml(matcher.group(1)).replaceAll("\\.", ".\n").trim());
}
form.setBody(response.getBody());
return checkLogin(response.getBody());
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class DevDb method getBrand.
public Brand getBrand(String catId, String brandId) throws Exception {
Brand data = new Brand();
NetworkResponse response = Api.getWebClient().get("https://4pda.ru/devdb/" + catId + "/" + brandId + "/all");
Matcher matcher = Brand.DEVICES_PATTERN.matcher(response.getBody());
while (matcher.find()) {
Brand.DeviceItem item = new Brand.DeviceItem();
item.setImageSrc(matcher.group(1));
item.setId(matcher.group(2));
item.setTitle(ApiUtils.fromHtml(matcher.group(3)));
Matcher specsMatcher = SPECS_PATTERN.matcher(matcher.group(4));
if (specsMatcher.find()) {
item.addSpec(specsMatcher.group(1), specsMatcher.group(2));
}
if (matcher.group(5) != null)
item.setPrice(matcher.group(5));
if (matcher.group(7) != null) {
item.setRating(Integer.parseInt(matcher.group(7)));
}
data.addDevice(item);
}
matcher = MAIN_PATTERN.matcher(response.getBody());
if (matcher.find()) {
Matcher bcMatcher = BREADCRUMB_PATTERN.matcher(matcher.group(1));
while (bcMatcher.find()) {
if (bcMatcher.group(2) == null) {
data.setCatId(bcMatcher.group(1));
data.setCatTitle(bcMatcher.group(3));
} else {
data.setId(bcMatcher.group(2));
data.setTitle(bcMatcher.group(3));
}
}
data.setTitle(matcher.group(4));
data.setActual(Integer.parseInt(matcher.group(5)));
data.setAll(Integer.parseInt(matcher.group(6)));
}
return data;
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class DevDb method getBrands.
public Brands getBrands(String catId) throws Exception {
Brands data = new Brands();
NetworkResponse response = Api.getWebClient().get("https://4pda.ru/devdb/" + catId + "/all");
Matcher matcher = Brands.LETTERS_PATTERN.matcher(response.getBody());
while (matcher.find()) {
String letter = matcher.group(1);
ArrayList<Brands.Item> items = new ArrayList<>();
Matcher itemsMatcher = Brands.ITEMS_IN_LETTER_PATTERN.matcher(matcher.group(2));
while (itemsMatcher.find()) {
Brands.Item item = new Brands.Item();
item.setId(itemsMatcher.group(1));
item.setTitle(ApiUtils.fromHtml(itemsMatcher.group(2)));
item.setCount(Integer.parseInt(itemsMatcher.group(3)));
items.add(item);
}
data.putItems(letter, items);
}
matcher = MAIN_PATTERN.matcher(response.getBody());
if (matcher.find()) {
Matcher bcMatcher = BREADCRUMB_PATTERN.matcher(matcher.group(1));
while (bcMatcher.find()) {
if (bcMatcher.group(2) == null) {
data.setCatId(bcMatcher.group(1));
data.setCatTitle(bcMatcher.group(3));
}
}
data.setActual(Integer.parseInt(matcher.group(5)));
data.setAll(Integer.parseInt(matcher.group(6)));
}
return data;
}
Aggregations