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

com.github.alex1304.jdash.client.GDSongInfoRequest Maven / Gradle / Ivy

There is a newer version: 3.3.10
Show newest version
package com.github.alex1304.jdash.client;

import java.util.Map;

import com.github.alex1304.jdash.entity.GDSong;
import com.github.alex1304.jdash.exception.GDClientException;
import com.github.alex1304.jdash.exception.MissingAccessException;
import com.github.alex1304.jdash.exception.SongNotAllowedForUseException;
import com.github.alex1304.jdash.util.ParseUtils;
import com.github.alex1304.jdash.util.Routes;

class GDSongInfoRequest extends AbstractGDRequest {
	
	private final long songId;
	
	GDSongInfoRequest(AbstractGDClient client, long songId) {
		super(client);
		this.songId = songId;
	}

	@Override
	public String getPath() {
		return Routes.GET_SONG_INFO;
	}

	@Override
	void putParams(Map params) {
		params.put("songID", "" + songId);
	}

	@Override
	GDSong parseResponse0(String response) throws GDClientException {
		if (response.equals("-2")) {
			throw new SongNotAllowedForUseException();
		}
		Map songInfo = ParseUtils.structureSongsInfo(response);
		if (!songInfo.containsKey(songId)) {
			throw new MissingAccessException();
		}
		return songInfo.get(songId);
	}
	
	@Override
	public boolean equals(Object obj) {
		return obj instanceof GDSongInfoRequest && ((GDSongInfoRequest) obj).songId == songId;
	}
	
	@Override
	public int hashCode() {
		return Long.hashCode(songId);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy