Skip to content

Commit

Permalink
Formatted code. Added javadoc. Upgraded artifacts.
Browse files Browse the repository at this point in the history
  • Loading branch information
yvasyliev committed Jan 23, 2023
1 parent 7ce7125 commit 6df1c87
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 24 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.github.yvasyliev</groupId>
<artifactId>deezer-api</artifactId>
<packaging>jar</packaging>
<version>1.1.4</version>
<version>1.2.0</version>
<name>Deezer API Java Library</name>
<description>A Java implementation of Deezer API.</description>
<url>https://github.com/yvasyliev/deezer-api</url>
Expand All @@ -30,17 +30,17 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.5</version>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.1</version>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -169,12 +169,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<version>3.0.0-M8</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
<version>5.9.2</version>
</dependency>
</dependencies>
</plugin>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/api/deezer/http/HttpClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api.deezer.http;

import java.io.IOException;
import java.io.OutputStream;

/**
* Executes HTTP requests.
Expand All @@ -15,5 +14,4 @@ public interface HttpClient {
* @throws IOException if errors occur.
*/
HttpResponse execute(HttpRequest httpRequest) throws IOException;

}
3 changes: 1 addition & 2 deletions src/main/java/api/deezer/http/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public interface HttpRequest {
/**
* File as bytes.
*
* @return the file as bytes
* @return the file as bytes.
*/
HttpRequestFilePart[] getFileParts();

}
41 changes: 34 additions & 7 deletions src/main/java/api/deezer/http/HttpRequestFilePart.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
package api.deezer.http;

/**
* A file to upload as {@code multipart/form-data}.
*/
public class HttpRequestFilePart {
/**
* Form field name.
*/
private final String name;

private String name = null;
private String filename = null;
private String contentType = null;
private String contentTransferEncoding = null;
private byte[] value = null;
/**
* File data.
*/
private final byte[] value;

/**
* Filename.
*/
private String filename;

/**
* Form field content type.
*/
private String contentType;

/**
* Content encoding.
*/
private String contentTransferEncoding;

public HttpRequestFilePart(final String name, final byte[] value) {
this.name = name;
this.value = value;
}

public static HttpRequestFilePart image(final String name, final byte[] value){
/**
* Creates an instance of {@link HttpRequestFilePart} with a PNG image as a value.
*
* @param name form field name.
* @param value image data.
* @return instance of {@link HttpRequestFilePart}.
*/
public static HttpRequestFilePart png(final String name, final byte[] value) {
HttpRequestFilePart image = new HttpRequestFilePart(name, value);
image.setContentType("image/png");
image.setFilename("image.png");
Expand Down Expand Up @@ -51,5 +79,4 @@ public void setContentTransferEncoding(String contentTransferEncoding) {
public byte[] getValue() {
return value;
}

}
2 changes: 1 addition & 1 deletion src/main/java/api/deezer/http/impl/DeezerRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class DeezerRequest<Response> implements HttpRequest {
private final Map<String, String> params;

/**
* File
* File.
*/
private final HttpRequestFilePart[] parts;

Expand Down
23 changes: 18 additions & 5 deletions src/main/java/api/deezer/http/impl/DefaultHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
Expand Down Expand Up @@ -60,6 +63,13 @@ public HttpResponse execute(HttpRequest httpRequest) throws IOException {
}
}

/**
* Creates GET request.
*
* @param httpRequest request data.
* @return {@link HttpURLConnection}.
* @throws IOException if errors occur.
*/
private static HttpURLConnection prepareRegularRequest(HttpRequest httpRequest) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(httpRequest.getUrl()).openConnection();
connection.setRequestMethod(httpRequest.getRequestMethod());
Expand All @@ -74,7 +84,13 @@ private static HttpURLConnection prepareRegularRequest(HttpRequest httpRequest)
return connection;
}


/**
* Creates POST request.
*
* @param httpRequest request data.
* @return {@link HttpURLConnection}.
* @throws IOException if errors occur.
*/
private static HttpURLConnection prepareMultipartRequest(HttpRequest httpRequest) throws IOException {
Map<String, String> params = httpRequest.getParams();
String urlParams = "";
Expand Down Expand Up @@ -109,7 +125,4 @@ private static HttpURLConnection prepareMultipartRequest(HttpRequest httpRequest
}
return connection;
}



}
2 changes: 1 addition & 1 deletion src/main/java/api/deezer/requests/PlaylistRequests.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public DeezerRequest<Boolean> uploadPicture(long playlistId, final String upload
property("playlist.picture", playlistId),
params,
Boolean.class,
new HttpRequestFilePart[]{ HttpRequestFilePart.image("file", image) }
new HttpRequestFilePart[]{ HttpRequestFilePart.png("file", image) }
);
}

Expand Down

0 comments on commit 6df1c87

Please sign in to comment.