private ProfileResponse getAvailableProfiles() throws IOException, BankException, LoginException { HttpResponse httpResponse = urlopen.openAsHttpResponse(getResourceUri("profile/"), false); if (httpResponse.getStatusLine().getStatusCode() == 200) { ProfileResponse response = readJsonValue(httpResponse.getEntity().getContent(), ProfileResponse.class); if (response.getBanks().isEmpty()) { String provider = response.isSwedbankProfile() ? "Swedbank" : response.isSavingbankProfile() ? "Sparbankerna" : null; if (provider != null) { throw new LoginException( "You are trying to connect an account from " + provider + " to the " + NAME + " bank. Please use the " + provider + " bank instead."); } else { throw new BankException("No profiles available."); } } return response; } throw new BankException("Could not fetch available profiles."); }
@Override public void update() throws BankException, LoginException, BankChoiceException, IOException { super.update(); if (getUsername().isEmpty() || getPassword().isEmpty()) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } urlopen = login(); ProfileResponse profileResponse = getAvailableProfiles(); setDefaultProfile(getBankId(profileResponse.getBanks())); HttpResponse httpResponse = urlopen.openAsHttpResponse(getResourceUri("engagement/overview"), false); if (httpResponse.getStatusLine().getStatusCode() != 200) { throw new BankException(httpResponse.getStatusLine().toString()); } OverviewResponse overviewResponse = readJsonValue(httpResponse.getEntity().getContent(), OverviewResponse.class); addAccounts(overviewResponse.getTransactionAccounts(), Account.REGULAR); addAccounts(overviewResponse.getSavingAccounts(), Account.REGULAR); addAccounts(overviewResponse.getTransactionDisposalAccounts(), Account.REGULAR); addAccounts(overviewResponse.getSavingDisposalAccounts(), Account.REGULAR); addCardAccounts(overviewResponse.getCardAccounts()); addAccounts(overviewResponse.getLoanAccounts(), Account.LOANS); if (this.accounts.isEmpty()) { throw new BankException(res.getText(R.string.no_accounts_found).toString()); } updateComplete(); }