mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-06 07:32:50 +00:00
Adds -SNAPSHOT to Maven version parameter and few modifications to API
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>httpchannel-service</artifactId>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>httpchannel-service-filesonic</artifactId>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package com.rogiel.httpchannel.filesonic;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
@@ -16,7 +16,7 @@ import com.rogiel.httpchannel.filesonic.xml.FSUpload;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class FileSonicAPI {
|
||||
private static final String BASE_URL = "http://api.filesonic.com/";
|
||||
private static final String BASE_URI = "http://api.filesonic.com/";
|
||||
|
||||
private String email;
|
||||
private String password;
|
||||
@@ -25,10 +25,10 @@ public class FileSonicAPI {
|
||||
return id;
|
||||
}
|
||||
|
||||
public URL getUploadURL() throws IOException {
|
||||
return new URL(((FSGetUploadURL) execute(FSUpload.class,
|
||||
public URI getUploadURI() throws IOException {
|
||||
return URI.create((((FSGetUploadURL) execute(FSUpload.class,
|
||||
"upload?method=getUploadUrl").getResponse()).getResponse()
|
||||
.getUploadURL());
|
||||
.getUploadURI()));
|
||||
}
|
||||
|
||||
public long getMaxFilesize() throws IOException {
|
||||
@@ -47,10 +47,10 @@ public class FileSonicAPI {
|
||||
this.password = null;
|
||||
}
|
||||
|
||||
private <T extends FSAPI> T execute(Class<T> type, String requestURL)
|
||||
private <T extends FSAPI> T execute(Class<T> type, String requestURI)
|
||||
throws IOException {
|
||||
final URL url = new URL(BASE_URL + requestURL + "&u=" + email + "&p="
|
||||
+ password + "&format=xml");
|
||||
return JAXB.unmarshal(url.openStream(), type);
|
||||
final URI uri = URI.create(BASE_URI + requestURI + "&u=" + email
|
||||
+ "&p=" + password + "&format=xml");
|
||||
return JAXB.unmarshal(uri.toURL().openStream(), type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ public class FSGetUploadURL extends FSResponse {
|
||||
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public static class FSGetUploadURLResponse {
|
||||
@XmlElement(name = "url")
|
||||
private String uploadURL;
|
||||
@XmlElement(name = "uri")
|
||||
private String uploadURI;
|
||||
@XmlElement(name = "max-filesize")
|
||||
private long maxFilesize;
|
||||
|
||||
public String getUploadURL() {
|
||||
return uploadURL;
|
||||
public String getUploadURI() {
|
||||
return uploadURI;
|
||||
}
|
||||
|
||||
public long getMaxFilesize() {
|
||||
|
||||
@@ -57,9 +57,9 @@ public class FileSonicService extends AbstractHttpService implements Service,
|
||||
public static final ServiceID SERVICE_ID = ServiceID.create("megaupload");
|
||||
|
||||
/**
|
||||
* The download URL pattern
|
||||
* The download URI pattern
|
||||
*/
|
||||
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
|
||||
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
|
||||
.compile("http://www.filesonic.com/file/[0-9A-z]*");
|
||||
/**
|
||||
* The FileSonic API
|
||||
@@ -67,7 +67,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
|
||||
private final FileSonicAPI api = new FileSonicAPI();
|
||||
|
||||
@Override
|
||||
public ServiceID getID() {
|
||||
public ServiceID getServiceID() {
|
||||
return SERVICE_ID;
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
|
||||
public UploadChannel openChannel() throws IOException {
|
||||
logger.debug("Starting upload to filesonic.com");
|
||||
final LinkedUploadChannel channel = createLinkedChannel(this);
|
||||
uploadFuture = multipartPost(api.getUploadURL().toString())
|
||||
uploadFuture = multipartPost(api.getUploadURI().toString())
|
||||
.parameter("files[]", channel).asStringAsync();
|
||||
return waitChannelLink(channel, uploadFuture);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
|
||||
@Override
|
||||
public String finish() throws IOException {
|
||||
try {
|
||||
return PatternUtils.find(DOWNLOAD_URL_PATTERN,
|
||||
return PatternUtils.find(DOWNLOAD_URI_PATTERN,
|
||||
uploadFuture.get());
|
||||
} catch (InterruptedException e) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user