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

org.craftercms.profile.services.impl.AccessTokenServiceRestClient Maven / Gradle / Ivy

There is a newer version: 4.3.1
Show newest version
package org.craftercms.profile.services.impl;

import java.util.List;

import org.craftercms.profile.api.AccessToken;
import org.craftercms.profile.api.exceptions.ProfileException;
import org.craftercms.profile.api.services.AccessTokenService;
import org.springframework.core.ParameterizedTypeReference;

import static org.craftercms.profile.api.ProfileConstants.BASE_URL_ACCESS_TOKEN;
import static org.craftercms.profile.api.ProfileConstants.URL_ACCESS_TOKEN_CREATE;
import static org.craftercms.profile.api.ProfileConstants.URL_ACCESS_TOKEN_DELETE;
import static org.craftercms.profile.api.ProfileConstants.URL_ACCESS_TOKEN_GET;
import static org.craftercms.profile.api.ProfileConstants.URL_ACCESS_TOKEN_GET_ALL;

/**
 * REST client implementation of {@link org.craftercms.profile.api.services.AccessTokenService}.
 *
 * @author avasquez
 */
public class AccessTokenServiceRestClient extends AbstractProfileRestClientBase implements AccessTokenService {

    public static final ParameterizedTypeReference> accessTokenListTypeRef =
        new ParameterizedTypeReference>() {};

    @Override
    public AccessToken createToken(AccessToken token) throws ProfileException {
        String url = getAbsoluteUrlWithAccessTokenIdParam(BASE_URL_ACCESS_TOKEN + URL_ACCESS_TOKEN_CREATE);

        return doPostForObject(url, token, AccessToken.class);
    }

    @Override
    public AccessToken getToken(String id) throws ProfileException {
        String url = getAbsoluteUrlWithAccessTokenIdParam(BASE_URL_ACCESS_TOKEN + URL_ACCESS_TOKEN_GET);

        return doGetForObject(url, AccessToken.class, id);
    }

    @Override
    public List getAllTokens() throws ProfileException {
        String url = getAbsoluteUrlWithAccessTokenIdParam(BASE_URL_ACCESS_TOKEN + URL_ACCESS_TOKEN_GET_ALL);

        return doGetForObject(url, accessTokenListTypeRef);
    }

    @Override
    public void deleteToken(String id) throws ProfileException {
        String url = getAbsoluteUrl(BASE_URL_ACCESS_TOKEN + URL_ACCESS_TOKEN_DELETE);

        doPostForLocation(url, createBaseParams(), id);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy