added make get request method
This commit is contained in:
parent
6defe67767
commit
ade7211ea8
@ -10,6 +10,8 @@ import sarsoo.fmframework.music.Track.TrackBuilder;
|
|||||||
import sarsoo.fmframework.music.Wiki;
|
import sarsoo.fmframework.music.Wiki;
|
||||||
import sarsoo.fmframework.util.ConsoleHandler;
|
import sarsoo.fmframework.util.ConsoleHandler;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@ -165,6 +167,7 @@ public class FmNetwork {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an artist from Last.FM
|
* Get an artist from Last.FM
|
||||||
|
*
|
||||||
* @param name Artist Name
|
* @param name Artist Name
|
||||||
* @return Artist
|
* @return Artist
|
||||||
*/
|
*/
|
||||||
@ -392,7 +395,8 @@ public class FmNetwork {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (ConsoleHandler.isVerbose())
|
if (ConsoleHandler.isVerbose())
|
||||||
ConsoleHandler.getConsole().write("ERROR (getTrack): " + name + " " + artist + " HTTP REQUEST ERROR");
|
ConsoleHandler.getConsole()
|
||||||
|
.write("ERROR (getTrack): " + name + " " + artist + " HTTP REQUEST ERROR");
|
||||||
else
|
else
|
||||||
System.err.println("ERROR (getTrack): " + name + " " + artist + " HTTP REQUEST ERROR");
|
System.err.println("ERROR (getTrack): " + name + " " + artist + " HTTP REQUEST ERROR");
|
||||||
return null;
|
return null;
|
||||||
@ -449,8 +453,7 @@ public class FmNetwork {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Catch-all refresh method to update an FMObj
|
* Catch-all refresh method to update an FMObj by routing based on object class
|
||||||
* by routing based on object class
|
|
||||||
*
|
*
|
||||||
* @param obj FMObj for refreshing
|
* @param obj FMObj for refreshing
|
||||||
* @return Updated FMObj
|
* @return Updated FMObj
|
||||||
@ -464,4 +467,35 @@ public class FmNetwork {
|
|||||||
return refresh((Artist) obj);
|
return refresh((Artist) obj);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected JSONObject makeGetRequest(String method, HashMap<String, String> parameters) {
|
||||||
|
|
||||||
|
HttpRequest request;
|
||||||
|
try {
|
||||||
|
request = Unirest.get("http://ws.audioscrobbler.com/2.0/").header("Accept", "application/json")
|
||||||
|
.header("User-Agent", "fmframework").queryString("api_key", key).queryString("format", "json");
|
||||||
|
|
||||||
|
for (String key : parameters.keySet()) {
|
||||||
|
request = request.queryString(key, parameters.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpResponse<JsonNode> response = request.asJson();
|
||||||
|
|
||||||
|
if (response.getStatus() == 200) {
|
||||||
|
|
||||||
|
return new JSONObject(response.getBody().toString());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (ConsoleHandler.isVerbose())
|
||||||
|
ConsoleHandler.getConsole().write("ERROR (getAlbum): HTTP REQUEST ERROR");
|
||||||
|
else
|
||||||
|
System.err.println("ERROR (getAlbum): HTTP REQUEST ERROR");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (UnirestException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user