Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package com.rhidlor;
  2.  
  3. import java.io.IOException;
  4. import com.google.gson.Gson;
  5. import json.RuneScapeAPI;
  6. import okhttp3.OkHttpClient;
  7. import okhttp3.Request;
  8. import okhttp3.Response;
  9.  
  10. public class Main {
  11.  
  12. //https://apps.runescape.com/runemetrics/profile/profile?user=Rhidlor
  13.  
  14. private static OkHttpClient client = new OkHttpClient();
  15.  
  16. public static void main(String[] args) {
  17. for(String str: getUserData("Rhidlor")) {
  18. System.out.println(str);
  19. }
  20. }
  21.  
  22. public static String run(String url) throws IOException {
  23. Request request = new Request.Builder()
  24. .url(url)
  25. .build();
  26.  
  27. Response response = client.newCall(request).execute();
  28. return response.body().string();
  29. }
  30.  
  31. public static String[] getUserData(String username) {
  32. String json = null;
  33. try {
  34. json = getJSON("https://apps.runescape.com/runemetrics/profile/profile?user=" + username);
  35. }catch(Exception e) {
  36. e.printStackTrace();
  37. }
  38.  
  39. Gson gson = new Gson();
  40.  
  41. RuneScapeAPI runescapeAPI = gson.fromJson(json, RuneScapeAPI.class);
  42.  
  43. return new String[] {
  44. "Name: " + runescapeAPI.getName(),
  45. "Rank: " + runescapeAPI.getRank()
  46. };
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement