Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Collection<Carte> donneCartesDepuisInternet() throws UnirestException {
- // requête synchrone pour obtenir une carte par son nom
- HttpResponse<String> reponseSpell = Unirest.get("https://omgvamp-hearthstone-v1.p.mashape.com/cards/types/Spell")
- .header("X-Mashape-Key", "CpPfoW8xR0mshYN8aeZjsMvBiXF7p1gzHJJjsn2XHwZg8OYZQy")
- .asString();
- HttpResponse<String> reponseMinion = Unirest.get("https://omgvamp-hearthstone-v1.p.mashape.com/cards/types/Minion")
- .header("X-Mashape-Key", "CpPfoW8xR0mshYN8aeZjsMvBiXF7p1gzHJJjsn2XHwZg8OYZQy")
- .asString();
- HttpResponse<String> reponseWeapon = Unirest.get("https://omgvamp-hearthstone-v1.p.mashape.com/cards/types/Weapon")
- .header("X-Mashape-Key", "CpPfoW8xR0mshYN8aeZjsMvBiXF7p1gzHJJjsn2XHwZg8OYZQy")
- .asString();
- // si on obtient une réponse valide
- if (reponseSpell != null && reponseSpell.getStatus() == 200 || reponseMinion != null && reponseMinion.getStatus() == 200 || reponseWeapon != null && reponseWeapon.getStatus() == 200) {
- return deserialiseJson(reponseSpell.getBody(), reponseMinion.getBody(), reponseWeapon.getBody());
- } else {
- throw new UnirestException("Erreur lors de la recup�ration des cartes sur le web");
- }
- }
- public static Collection<Carte> deserialiseJson(String spell, String minion, String weapon) {
- // DéSérialisation
- Collection<Carte> cartes = donneGson().fromJson(spell, new TypeToken<List<Carte>>(){}.getType());
- cartes.addAll(donneGson().fromJson(minion, new TypeToken<List<Carte>>(){}.getType()));
- cartes.addAll(donneGson().fromJson(weapon, new TypeToken<List<Carte>>(){}.getType()));
- // élimination des cartes à coup sûr avec une image non existante
- for (Iterator<Carte> ic = cartes.iterator(); ic.hasNext(); ) {
- Carte curr = ic.next();
- curr.verifie();
- if (curr.urlImage().contains("wow.zamimg.com"))
- ic.remove();
- }
- return cartes;
- }
Add Comment
Please, Sign In to add comment