use of com.spotify.apollo.Client in project apollo by spotify.
the class EnvironmentModule method environmentFactory.
@Provides
@Singleton
EnvironmentFactory environmentFactory(Config configNode, ApolloConfig apolloConfig, Closer closer, Injector injector, IncomingRequestAwareClient incomingRequestAwareClient) {
final String backend = apolloConfig.backend();
final Client unawareClient = incomingRequestAwareClient.asUnawareClient();
return EnvironmentFactoryBuilder.newBuilder(backend, unawareClient, closer, injector::getInstance).withStaticConfig(configNode).build();
}
use of com.spotify.apollo.Client in project apollo by spotify.
the class ClientDecoratorTest method shouldBindDecoratedClient.
@Test
public void shouldBindDecoratedClient() throws Exception {
try (Service.Instance i = service.build().start()) {
Client client = ApolloEnvironmentModule.environment(i).environment().client();
Request request = Request.forUri("http://example.com/");
Request withService = request.withService("ping");
client.send(request);
verify(mockClient).send(eq(withService), eq(empty()));
} catch (IOException e) {
fail();
}
}
use of com.spotify.apollo.Client in project apollo by spotify.
the class AlbumResource method getAlbums.
CompletionStage<Response<ArrayList<Album>>> getAlbums(RequestContext requestContext, String tag) {
// We need to first query the search API, parse the result, then query the album API.
Request searchRequest = Request.forUri(SEARCH_API + "?type=album&q=tag%3A" + tag);
Client client = requestContext.requestScopedClient();
return client.send(searchRequest).thenComposeAsync(response -> {
String ids = parseResponseAlbumIds(response.payload().get().utf8());
return client.send(Request.forUri(ALBUM_API + "?ids=" + ids));
}).thenApplyAsync(response -> Response.ok().withPayload(parseAlbumData(response.payload().get().utf8())));
}
use of com.spotify.apollo.Client in project apollo by spotify.
the class ArtistResource method getArtistTopTracks.
CompletionStage<Response<ArrayList<Track>>> getArtistTopTracks(RequestContext requestContext) {
// Validate request
Optional<String> query = requestContext.request().parameter("q");
if (!query.isPresent()) {
return CompletableFuture.completedFuture(Response.forStatus(Status.BAD_REQUEST.withReasonPhrase("No search query")));
}
String country = requestContext.pathArgs().get("country");
// We need to first query the search API, parse the result, then query top-tracks.
Request searchRequest = Request.forUri(SEARCH_API + "?type=artist&q=" + query.get());
Client client = requestContext.requestScopedClient();
return client.send(searchRequest).thenComposeAsync(response -> {
String topArtistId = parseFirstArtistId(response.payload().get().utf8());
Request topTracksRequest = Request.forUri(String.format("%s/%s/top-tracks?country=%s", ARTIST_API, topArtistId, country));
return client.send(topTracksRequest);
}).thenApplyAsync(response -> Response.ok().withPayload(parseTopTracks(response.payload().get().utf8()))).exceptionally(throwable -> Response.forStatus(Status.INTERNAL_SERVER_ERROR.withReasonPhrase("Something failed")));
}
use of com.spotify.apollo.Client in project apollo by spotify.
the class RequestHandlerImpl method handleEndpointMatch.
/**
* Continuation for the {@link RequestRunnableFactory}
*
* @param request request being processed
* @param match the match that was made
*/
private void handleEndpointMatch(OngoingRequest request, RuleMatch<Endpoint> match) {
final Endpoint endpoint = match.getRule().getTarget();
final Map<String, String> parsedPathArguments = match.parsedPathArguments();
final Client requestScopedClient = client.wrapRequest(request.request());
final RequestContext requestContext = RequestContexts.create(request.request(), requestScopedClient, parsedPathArguments, request.arrivalTimeNanos(), request.metadata());
erf.create(request, requestContext, endpoint).run();
}
Aggregations