1
0
mirror of https://github.com/Rogiel/httpchannel synced 2025-12-06 07:32:50 +00:00

Implement AccountDetails object that provides account information

This commit is contained in:
2012-01-22 19:27:33 -02:00
parent 885de35de5
commit 3b06f0b9e6
33 changed files with 598 additions and 121 deletions

View File

@@ -26,10 +26,13 @@ import java.util.regex.Pattern;
import com.rogiel.httpchannel.captcha.ImageCaptcha;
import com.rogiel.httpchannel.captcha.ReCaptchaExtractor;
import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -191,7 +194,12 @@ public class UploadHereService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>();
return new CapabilityMatrix<AuthenticatorCapability>(AuthenticatorCapability.ACCOUNT_DETAILS);
}
@Override
public AccountDetails getAccountDetails() {
return account;
}
protected class UploaderImpl extends
@@ -300,14 +308,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
}
@Override
public void login() throws IOException {
public AccountDetails login() throws IOException {
final HTMLPage page = post("http://www.uploadhere.com/login")
.parameter("do", "login")
.parameter("username", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
if (page.contains(INVALID_LOGIN_STRING))
throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -317,4 +325,21 @@ public class UploadHereService extends AbstractHttpService implements Service,
// TODO check logout status
}
}
private class AccountDetailsImpl extends AbstractAccountDetails implements
PremiumAccountDetails {
/**
* @param username
* the username
*/
public AccountDetailsImpl(String username) {
super(UploadHereService.this, username);
}
@Override
public boolean isPremium() {
// TODO implement this
return false;
}
}
}