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

javastrava.service.impl.RouteServiceImpl Maven / Gradle / Ivy

The newest version!
package javastrava.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;

import javastrava.auth.model.Token;
import javastrava.model.StravaRoute;
import javastrava.service.RouteService;
import javastrava.service.exception.NotFoundException;
import javastrava.service.exception.UnauthorizedException;

/**
 * 

* Routes are manually-created paths made up of sections called legs. Currently it is only possible to create routes using the Routebuilder web interface. *

* * @author Dan Shannon * */ public class RouteServiceImpl extends StravaServiceImpl implements RouteService { /** *

* Returns an instance of {@link RouteService route services} *

* *

* Instances are cached so that if 2 requests are made for the same token, the same instance is returned *

* * @param token * The Strava access token to be used in requests to the Strava API * @return An instance of the stream services */ public static RouteService instance(final Token token) { // Get the service from the token's cache RouteService service = token.getService(RouteService.class); // If it's not already there, create a new one and put it in the token if (service == null) { service = new RouteServiceImpl(token); token.addService(RouteService.class, service); } return service; } /** *

* Private constructor prevents anyone from getting an instance without a valid access token *

* * @param token * The access token to be used to authenticate to the Strava API */ private RouteServiceImpl(final Token token) { super(token); } @Override public void clearCache() { // Nothing to do - not cached } @Override public StravaRoute getRoute(Integer routeId) { if (routeId == null) { return null; } try { return this.api.getRoute(routeId); } catch (final NotFoundException e) { return null; } } @Override public CompletableFuture getRouteAsync(Integer routeId) { return StravaServiceImpl.future(() -> getRoute(routeId)); } @Override public List listAthleteRoutes(Integer id) { try { return Arrays.asList(this.api.listAthleteRoutes(id, null, null)); } catch (final NotFoundException e) { return null; } catch (final UnauthorizedException e) { return new ArrayList(); } } @Override public CompletableFuture> listAthleteRoutesAsync(Integer id) { return StravaServiceImpl.future(() -> listAthleteRoutes(id)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy