Advertisement
Guest User

GarciaPL

a guest
Mar 14th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. public class mQubeQueriesImpl implements mQubeQueries {
  2.     private XStream xStream;
  3.  
  4.     public mQubeQueriesImpl() {
  5.         this.xStream = new XStream();
  6.         this.xStream.setMode(XStream.ID_REFERENCES);
  7.     }
  8.  
  9.     @Override
  10.     public List getPlayers(Integer serviceId, Date from, Date to) throws UnirestException, XStreamException {
  11.         GetRequest response = Unirest.get("http://server.com/" + "get-players" + "/" + serviceId +
  12.                 "/" + new DateFormatter().formatQubeDateTimezone(from) +
  13.                 "/" + new DateFormatter().formatQubeDateTimezone(to)).basicAuth("login", "password");
  14.  
  15.         if (response.asString().getStatus() == 403) {
  16.             throw new UnirestException("No authorized");
  17.         }
  18.  
  19.         if (response.asString().getStatus() != 200) {
  20.             throw new UnirestException("Unexpected response with code : " + response.asString().getStatus());
  21.         }
  22.  
  23.         String body = response.asString().getBody();
  24.         if (body == null) {
  25.             throw new UnirestException("Response from server is null");
  26.         } else {
  27.             try {
  28.                 return (List) xStream.fromXML(body);
  29.             } catch (Exception e) {
  30.                 throw new XStreamException(e.getMessage());
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement