Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class mQubeQueriesImpl implements mQubeQueries {
- private XStream xStream;
- public mQubeQueriesImpl() {
- this.xStream = new XStream();
- this.xStream.setMode(XStream.ID_REFERENCES);
- }
- @Override
- public List getPlayers(Integer serviceId, Date from, Date to) throws UnirestException, XStreamException {
- GetRequest response = Unirest.get("http://server.com/" + "get-players" + "/" + serviceId +
- "/" + new DateFormatter().formatQubeDateTimezone(from) +
- "/" + new DateFormatter().formatQubeDateTimezone(to)).basicAuth("login", "password");
- if (response.asString().getStatus() == 403) {
- throw new UnirestException("No authorized");
- }
- if (response.asString().getStatus() != 200) {
- throw new UnirestException("Unexpected response with code : " + response.asString().getStatus());
- }
- String body = response.asString().getBody();
- if (body == null) {
- throw new UnirestException("Response from server is null");
- } else {
- try {
- return (List) xStream.fromXML(body);
- } catch (Exception e) {
- throw new XStreamException(e.getMessage());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement