-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
96 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
package io.github.yvasyliev.deezer.http; | ||
|
||
import io.github.yvasyliev.deezer.helpers.QueryParams; | ||
|
||
import java.io.IOException; | ||
|
||
public interface HttpClient { | ||
HttpResponse get(String url, QueryParams queryParams) throws IOException; | ||
HttpResponse send(HttpRequest request) throws IOException; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/io/github/yvasyliev/deezer/http/HttpMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.github.yvasyliev.deezer.http; | ||
|
||
public enum HttpMethod { | ||
GET | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/io/github/yvasyliev/deezer/http/HttpRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.github.yvasyliev.deezer.http; | ||
|
||
import java.net.URL; | ||
|
||
public interface HttpRequest { | ||
HttpMethod getMethod(); | ||
URL getUrl(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/io/github/yvasyliev/deezer/http/InterceptingHttpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.github.yvasyliev.deezer.http; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.io.IOException; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
public class InterceptingHttpClient implements HttpClient { | ||
private HttpClient origHttpClient; | ||
private Interceptor<HttpRequest> requestInterceptor; | ||
private Interceptor<HttpResponse> responseInterceptor; | ||
|
||
public InterceptingHttpClient() { | ||
this( | ||
new DefaultHttpClient(), | ||
request -> { | ||
System.out.println(request); | ||
return request; | ||
}, | ||
response -> { | ||
System.out.println(response); | ||
return response; | ||
} | ||
); | ||
} | ||
|
||
@Override | ||
public HttpResponse send(HttpRequest request) throws IOException { | ||
return responseInterceptor.intercept(origHttpClient.send(requestInterceptor.intercept(request))); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/io/github/yvasyliev/deezer/http/Interceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.github.yvasyliev.deezer.http; | ||
|
||
import java.io.IOException; | ||
|
||
@FunctionalInterface | ||
public interface Interceptor<T> { | ||
T intercept(T t) throws IOException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters