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

@@ -27,10 +27,13 @@ import java.util.regex.Pattern;
import org.apache.http.client.ClientProtocolException;
import org.htmlparser.Tag;
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;
@@ -186,7 +189,12 @@ public class HotFileService 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
@@ -273,7 +281,8 @@ public class HotFileService extends AbstractHttpService implements Service,
}
@Override
public void login() throws ClientProtocolException, IOException {
public AccountDetails login() throws ClientProtocolException,
IOException {
logger.debug("Authenticating hotfile.com");
HTMLPage page = post("http://www.hotfile.com/login.php")
.parameter("returnto", "/index.php")
@@ -283,7 +292,7 @@ public class HotFileService extends AbstractHttpService implements Service,
final Tag accountTag = page.getTagByID("account");
if (accountTag == null)
throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -294,6 +303,23 @@ public class HotFileService extends AbstractHttpService implements Service,
}
}
private class AccountDetailsImpl extends AbstractAccountDetails implements
PremiumAccountDetails {
/**
* @param username
* the username
*/
public AccountDetailsImpl(String username) {
super(HotFileService.this, username);
}
@Override
public boolean isPremium() {
// TODO implement this
return false;
}
}
@Override
public String toString() {
return this.getClass().getSimpleName() + " " + getMajorVersion() + "."