Search in sources :

Example 1 with AuthSessionParser

use of com.github.hakko.musiccabinet.parser.lastfm.AuthSessionParser in project musiccabinet by hakko.

the class LastFmService method identifyLastFmUser.

public LastFmUser identifyLastFmUser(String token) throws ApplicationException {
    LOG.debug("identifyLastFmUser(" + token + ")");
    WSResponse wsResponse = authSessionClient.getAuthSession(token);
    if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
        StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
        AuthSessionParser authSessionParser = new AuthSessionParserImpl(stringUtil.getInputStream());
        return authSessionParser.getLastFmUser();
    } else {
        LOG.debug("wsResponse: " + wsResponse.getResponseBody());
        throw new ApplicationException("Could not get session key for user! (code " + wsResponse.getErrorCode() + ", " + wsResponse.getErrorMessage() + ")");
    }
}
Also used : AuthSessionParser(com.github.hakko.musiccabinet.parser.lastfm.AuthSessionParser) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) AuthSessionParserImpl(com.github.hakko.musiccabinet.parser.lastfm.AuthSessionParserImpl) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Aggregations

ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 AuthSessionParser (com.github.hakko.musiccabinet.parser.lastfm.AuthSessionParser)1 AuthSessionParserImpl (com.github.hakko.musiccabinet.parser.lastfm.AuthSessionParserImpl)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1