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

com.lajospolya.spotifyapiwrapper.client.service.SpotifyApiClientService Maven / Gradle / Ivy

Go to download

This project wraps the Spotify public API in order to allow users to intuitively use it

There is a newer version: 3.0.RELEASE
Show newest version
package com.lajospolya.spotifyapiwrapper.client.service;

import com.lajospolya.spotifyapiwrapper.internal.*;
import com.lajospolya.spotifyapiwrapper.spotifyexception.SpotifyResponseException;

import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class SpotifyApiClientService implements ISpotifyApiClientService
{
    private ISpotifyClient client;

    public SpotifyApiClientService()
    {
        this.client = new Java11HttpClient();
    }

    @Override
    public  T sendRequestAndFetchResponse(ISpotifyRequest request, Type typeOfReturnValue) throws SpotifyResponseException
    {
        ISpotifyResponse response = client.send(request, typeOfReturnValue);
        return response.body();
    }

    @Override
    public  ISpotifyAsyncResponse sendRequestAndFetchResponseAsync(ISpotifyRequest request, Type typeOfReturnValue) throws SpotifyResponseException
    {
        ISpotifyAsyncResponse asyncResponse = client.sendAsync(request, typeOfReturnValue);
        return  asyncResponse;
    }

    @Override
    public String getBase64EncodedAuthorizationKey(String clientId, String clientSecret)
    {
        byte[] authorizationKey = (clientId + ":" + clientSecret).getBytes(StandardCharsets.UTF_8);
        return Base64.getEncoder().encodeToString(authorizationKey);
    }

    @Override
    public Boolean hasTokenExpired(Long timeOfAuthorization, Integer expiredIn)
    {
        return (System.currentTimeMillis() - timeOfAuthorization) / 1000L > expiredIn;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy