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

de.aipark.api.webservice.AiparkApi Maven / Gradle / Ivy

Go to download

AIPARK offers detailed parking information for more than 1.8 Mio parking areas in Germany with nationwide coverage. Additionally, accurate occupancy predictions are derived using data from a network of more than 5 million smartphones. Use the AIPARK API Explorer application to try out and test the interface. Please send a request via email if you are a developer and require an API key. We'll be in touch with you shortly. This application is provided via a demo backend environment. Please note that API load tests do not reflect the performance of the productive system. Mail: [email protected]

There is a newer version: 30.06
Show newest version
package de.aipark.api.webservice;

import com.bedatadriven.jackson.datatype.jts.JtsModule;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.aipark.api.livedata.spot.LiveSpot;
import de.aipark.api.parkevent.ParkEventLiveLeaving;
import de.aipark.api.requestsResponse.getChargingStationsForPosition.GetChargingStationsForPositionRequest;
import de.aipark.api.requestsResponse.getChargingStationsForPosition.GetChargingStationsForPositionResponse;
import de.aipark.api.requestsResponse.getChargingStationsForTile.GetChargingStationsForTileRequest;
import de.aipark.api.requestsResponse.getChargingStationsForTile.GetChargingStationsForTileResponse;
import de.aipark.api.requestsResponse.getCostsForArea.GetCostsForAreaRequest;
import de.aipark.api.requestsResponse.getCostsForArea.GetCostsForAreaResponse;
import de.aipark.api.requestsResponse.getLiveParkEvents.GetLiveParkEventsRequest;
import de.aipark.api.requestsResponse.getLiveSpots.GetLiveSpotsForTileRequest;
import de.aipark.api.requestsResponse.getOccupancyForParkingAreas.GetOccupancyForParkingAreasRequest;
import de.aipark.api.requestsResponse.getOccupancyForParkingAreas.GetOccupancyForParkingAreasResponse;
import de.aipark.api.requestsResponse.getOptimalTrip.GetOptimalTripRequest;
import de.aipark.api.requestsResponse.getOptimalTrip.GetOptimalTripResponse;
import de.aipark.api.requestsResponse.getParkingAreasForPosition.GetParkingAreasForPositionRequest;
import de.aipark.api.requestsResponse.getParkingAreasForPosition.GetParkingAreasForPositionResponse;
import de.aipark.api.requestsResponse.getParkingAreasForPositionWithOccupancy.GetParkingAreasForPositionWithOccupancyRequest;
import de.aipark.api.requestsResponse.getParkingAreasForPositionWithOccupancy.GetParkingAreasForPositionWithOccupancyResponse;
import de.aipark.api.requestsResponse.getParkingAreasForPositionWithOccupancyForDeparture.GetParkingAreasForPositionWithOccupancyForDepartureRequest;
import de.aipark.api.requestsResponse.getParkingAreasForTile.GetParkingAreasForTileRequest;
import de.aipark.api.requestsResponse.getParkingAreasForTile.GetParkingAreasForTileResponse;
import de.aipark.api.requestsResponse.getParkingAreasForTileWithOccupancy.GetParkingAreasForTileWithOccupancyRequest;
import de.aipark.api.requestsResponse.getParkingAreasForTileWithOccupancy.GetParkingAreasForTileWithOccupancyResponse;
import de.aipark.api.requestsResponse.getParkingAreasForTileWithOccupancyForDeparture.GetParkingAreasForTileWithOccupancyForDepartureRequest;
import de.aipark.api.webservice.jsonConverter.aiparkapi.AiparkApiModule;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.jackson.JacksonConverterFactory;
import rx.Observable;

import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.io.Serializable;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.List;

/**
 * Communicate with AiPark API.
 */

public class AiparkApi implements AiparkApiEndpointInterface, Serializable {
    private AiparkApiEndpointInterface mApiEndpoint;

    public AiparkApi(String urlApi, final String apiKey) {
        Retrofit mApiRetrofit = null;

        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JtsModule());
        objectMapper.registerModule(new AiparkApiModule());
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        try {
            OkHttpClient.Builder httpClient = new OkHttpClient.Builder().sslSocketFactory(createSSLContex().getSocketFactory());
            httpClient.addInterceptor(new Interceptor() {
                @Override
                public Response intercept(Chain chain) throws IOException {
                    Request original = chain.request();
                    Request request = original.newBuilder()
                            .header("User-Agent", "AIPARK")
                            .header("apikey", apiKey)
                            .method(original.method(), original.body())
                            .build();
                    return chain.proceed(request);
                }
            });
            // logging
            /*HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
            interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            httpClient.addInterceptor(interceptor);*/

            mApiRetrofit = new Retrofit.Builder()
                    .client(httpClient.build())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .baseUrl(urlApi)
                    .addConverterFactory(JacksonConverterFactory.create(objectMapper))
                    .build();

        } catch (Exception e) {
            e.printStackTrace();
        }
        mApiEndpoint = mApiRetrofit.create(AiparkApiEndpointInterface.class);


    }

    @Override
    public Observable getParkingAreasForTile(GetParkingAreasForTileRequest tileParkingAreasRequest) {
        return mApiEndpoint.getParkingAreasForTile(tileParkingAreasRequest);
    }

    @Override
    public Observable getOccupancyForParkingAreas(GetOccupancyForParkingAreasRequest getOccupancyForParkingAreasRequest) {
        return mApiEndpoint.getOccupancyForParkingAreas(getOccupancyForParkingAreasRequest);
    }

    @Override
    public Observable getParkingAreasForTileWithOccupancy(GetParkingAreasForTileWithOccupancyRequest getParkingAreasForTileWithOccupancyRequest) {
        return mApiEndpoint.getParkingAreasForTileWithOccupancy(getParkingAreasForTileWithOccupancyRequest);
    }

    @Override
    public Observable getParkingAreasForTileWithOccupancyForPosition(GetParkingAreasForTileWithOccupancyForDepartureRequest getParkingAreasForTileWithOccupancyForPositionRequest) {
        return mApiEndpoint.getParkingAreasForTileWithOccupancyForPosition(getParkingAreasForTileWithOccupancyForPositionRequest);
    }

    @Override
    public Observable getParkingAreasForPosition(GetParkingAreasForPositionRequest getParkingAreasForPositionRequest) {
        return mApiEndpoint.getParkingAreasForPosition(getParkingAreasForPositionRequest);
    }

    @Override
    public Observable getParkingAreasForPositionWithOccupancy(GetParkingAreasForPositionWithOccupancyRequest getParkingAreasForPositionRequest) {
        return mApiEndpoint.getParkingAreasForPositionWithOccupancy(getParkingAreasForPositionRequest);
    }

    @Override
    public Observable getParkingAreasForPositionWithOccupancyForPosition(GetParkingAreasForPositionWithOccupancyForDepartureRequest getParkingAreasForPositionRequest) {
        return mApiEndpoint.getParkingAreasForPositionWithOccupancyForPosition(getParkingAreasForPositionRequest);
    }

    @Override
    public Observable getOptimalTrip(GetOptimalTripRequest getOptimalTripRequest) {
        return mApiEndpoint.getOptimalTrip(getOptimalTripRequest);
    }

    @Override
    public Observable> getLiveParkEvents(GetLiveParkEventsRequest getLiveParkEventsRequest) {
        return mApiEndpoint.getLiveParkEvents(getLiveParkEventsRequest);
    }

    @Override
    public Observable getCostsForArea(GetCostsForAreaRequest getCostsForAreaRequest) {
        return mApiEndpoint.getCostsForArea(getCostsForAreaRequest);
    }

    @Override
    public Observable getChargingStationsForTile(GetChargingStationsForTileRequest getChargingStationsForTileRequest) {
        return mApiEndpoint.getChargingStationsForTile(getChargingStationsForTileRequest);
    }

    @Override
    public Observable getChargingStationsForPosition(GetChargingStationsForPositionRequest getChargingStationsForPositionRequest) {
        return mApiEndpoint.getChargingStationsForPosition(getChargingStationsForPositionRequest);
    }

    @Override
    public Observable> getLiveSpotsForTile(GetLiveSpotsForTileRequest getLiveSpotsForTileRequest) {
        return mApiEndpoint.getLiveSpotsForTile(getLiveSpotsForTileRequest);
    }

    public static SSLContext createSSLContex() throws NoSuchAlgorithmException, IOException, KeyStoreException, CertificateException, UnrecoverableKeyException, KeyManagementException {
        SSLContext sslContext = SSLContext.getInstance("SSL");
        sslContext.init(null,null,null);
        return sslContext;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy