-
Notifications
You must be signed in to change notification settings - Fork 14
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
52 changed files
with
1,410 additions
and
1,029 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
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,44 @@ | ||
package com.gocardless.http; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.google.common.collect.ImmutableListMultimap; | ||
import com.google.common.collect.Multimap; | ||
|
||
/** | ||
* Base class for API responses. | ||
* | ||
* @param <T> the type of the resource within this response. | ||
*/ | ||
public class ApiResponse<T> { | ||
private final T resource; | ||
private final int statusCode; | ||
private final Multimap<String, String> headers; | ||
|
||
public ApiResponse(T resource, int statusCode, Map<String, List<String>> headers) { | ||
this.resource = resource; | ||
this.statusCode = statusCode; | ||
this.headers = buildHeaderMap(headers); | ||
} | ||
|
||
public T getResource() { | ||
return resource; | ||
} | ||
|
||
public int getStatusCode() { | ||
return statusCode; | ||
} | ||
|
||
public Multimap<String, String> getHeaders() { | ||
return headers; | ||
} | ||
|
||
private static Multimap<String, String> buildHeaderMap(Map<String, List<String>> headers) { | ||
ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder(); | ||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) { | ||
builder.putAll(entry.getKey(), entry.getValue()); | ||
} | ||
return builder.build(); | ||
} | ||
} |
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
Oops, something went wrong.