use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.
the class ScrobbleServiceTest method createTestData.
@Before
public void createTestData() throws ApplicationException {
scrobbleService = new ScrobbleService();
UpdateNowPlayingClient nowPlayinglient = mock(UpdateNowPlayingClient.class);
when(nowPlayinglient.updateNowPlaying(Mockito.any(Scrobble.class))).thenReturn(new WSResponse(false, 404, "Not found"));
scrobbleService.setUpdateNowPlayingClient(nowPlayinglient);
ScrobbleClient scrobbleClient = mock(ScrobbleClient.class);
when(scrobbleClient.scrobble(Mockito.any(Scrobble.class))).thenReturn(new WSResponse("<lfm status=\"ok\"></lfm>"));
scrobbleService.setScrobbleClient(scrobbleClient);
PlayCountDao playCountDao = mock(PlayCountDao.class);
scrobbleService.setPlayCountDao(playCountDao);
MetaData metaData1 = new MetaData();
metaData1.setArtist("artist 1");
metaData1.setArtistId(artist1Id);
metaData1.setAlbum("album 1");
metaData1.setAlbumId(album1Id);
track1 = new Track(track1Id, "track 1", metaData1);
track2 = new Track(track2Id, "track 2", metaData1);
user1 = new LastFmUser(username1, sessionKey1);
user2 = new LastFmUser(username2, sessionKey2);
}
use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.
the class TagUpdateServiceTest method createTestData.
@Before
public void createTestData() throws ApplicationException {
responseOK = new WSResponse("<lfm status=\"ok\"></lfm>");
responseFail = new WSResponse(false, 404, "Not found");
}
use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.
the class JdbcUserRecommendedArtistsDaoTest method loadFunctionDependency.
@Before
public void loadFunctionDependency() throws ApplicationException {
PostgreSQLUtil.loadFunction(dao, UPDATE_USER_RECOMMENDED_ARTISTS);
joanRec = new UserRecommendedArtists(joan, new UserRecommendedArtistsParserImpl(new ResourceUtil(JOAN_FILE).getInputStream()).getArtists());
rjRec = new UserRecommendedArtists(rj, new UserRecommendedArtistsParserImpl(new ResourceUtil(RJ_FILE).getInputStream()).getArtists());
String body = new WSResponse(new ResourceUtil(FTPAREA_FILE).getContent()).getResponseBody();
ftpareaRec = new UserRecommendedArtists(ftparea, new UserRecommendedArtistsParserImpl(new StringUtil(body).getInputStream()).getArtists());
createArtistMetaData();
}
use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse 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() + ")");
}
}
use of com.github.hakko.musiccabinet.ws.lastfm.WSResponse in project musiccabinet by hakko.
the class ScrobbleService method scrobbleTracks.
protected void scrobbleTracks() throws ApplicationException {
scrobbleFailedTracks();
Scrobble head;
for (LastFmUser lastFmUser : userScrobbles.keySet()) {
ConcurrentLinkedDeque<Scrobble> deque = userScrobbles.get(lastFmUser);
while ((head = deque.peekFirst()) != null && !tooClose(head, new DateTime())) {
playCountDao.addPlayCount(head.getLastFmUser(), head.getTrack());
WSResponse wsResponse = scrobbleClient.scrobble(head);
if (!wsResponse.wasCallSuccessful()) {
LOG.warn("scrobbling " + head + " failed! Add for re-sending.");
LOG.debug("Scrobble response: " + wsResponse);
failedScrobbles.add(head);
}
deque.pollFirst();
}
}
}
Aggregations