Search in sources :

Example 41 with NetworkResponse

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());
}
Also used : Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 42 with NetworkResponse

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());
}
Also used : Matcher(java.util.regex.Matcher) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 43 with NetworkResponse

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;
}
Also used : Brand(forpdateam.ru.forpda.api.devdb.models.Brand) Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 44 with NetworkResponse

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;
}
Also used : Matcher(java.util.regex.Matcher) Brands(forpdateam.ru.forpda.api.devdb.models.Brands) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) ArrayList(java.util.ArrayList)

Aggregations

NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)44 Matcher (java.util.regex.Matcher)27 NetworkRequest (forpdateam.ru.forpda.api.NetworkRequest)25 ArrayList (java.util.ArrayList)8 AttachmentItem (forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)6 Bundle (android.os.Bundle)3 RequestFile (forpdateam.ru.forpda.api.RequestFile)3 Context (android.content.Context)2 Uri (android.net.Uri)2 App (forpdateam.ru.forpda.App)2 R (forpdateam.ru.forpda.R)2 QmsMessage (forpdateam.ru.forpda.api.qms.models.QmsMessage)2 Client (forpdateam.ru.forpda.client.Client)2 Observable (io.reactivex.Observable)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 Schedulers (io.reactivex.schedulers.Schedulers)2 Activity (android.app.Activity)1 DownloadManager (android.app.DownloadManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1