All Downloads are FREE. Search and download functionalities are using the official Maven repository.

global.maplink.place.async.PlaceAsyncApiImpl Maven / Gradle / Ivy

There is a newer version: 1.5.15
Show newest version
package global.maplink.place.async;

import global.maplink.credentials.MapLinkCredentials;
import global.maplink.env.Environment;
import global.maplink.http.HttpAsyncEngine;
import global.maplink.json.JsonMapper;
import global.maplink.place.schema.PlaceRouteRequest;
import global.maplink.place.schema.PlaceRouteResponse;
import global.maplink.token.TokenProvider;
import lombok.RequiredArgsConstructor;
import lombok.val;

import java.util.concurrent.CompletableFuture;

@RequiredArgsConstructor
public class PlaceAsyncApiImpl implements PlaceAsyncAPI {
    private final Environment environment;

    private final HttpAsyncEngine http;

    private final JsonMapper mapper;

    private final TokenProvider tokenProvider;

    private final MapLinkCredentials credentials;

    @Override
    public CompletableFuture calculate(PlaceRouteRequest request) {
        val httpRequest = request.asHttpRequest(environment, mapper);
        return credentials.fetchToken(tokenProvider)
                .thenCompose(token -> http.run(token.applyOn(httpRequest)))
                .thenApply(r -> r.parseBodyObject(mapper, PlaceRouteResponse.class));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy