|
| 1 | +package pl.stachu540; |
| 2 | + |
| 3 | +import com.sun.istack.internal.NotNull; |
| 4 | +import pl.stachu540.hirezstudios.Paladins; |
| 5 | +import pl.stachu540.hirezstudios.Smite; |
| 6 | + |
| 7 | +import java.io.*; |
| 8 | +import java.nio.file.Paths; |
| 9 | +import java.util.Properties; |
| 10 | + |
| 11 | +public class HiRezAPI { |
| 12 | + private static final File filesession = Paths.get(System.getProperty("java.io.tmpdir"), ".hirezsessions").toFile(); |
| 13 | + |
| 14 | + /** |
| 15 | + * Session keys for specific base API url type |
| 16 | + */ |
| 17 | + public static final Properties sessions = new Properties() { |
| 18 | + @Override |
| 19 | + public synchronized String setProperty(String key, String value) { |
| 20 | + put(key, value); |
| 21 | + try { |
| 22 | + HiRezAPI.store(); |
| 23 | + } catch (IOException ex) { |
| 24 | + ex.printStackTrace(); |
| 25 | + } |
| 26 | + return value; |
| 27 | + } |
| 28 | + }; |
| 29 | + |
| 30 | + /** |
| 31 | + * Developer ID (DevId) |
| 32 | + * @see HiRezAPI#HiRezAPI(String, String) |
| 33 | + */ |
| 34 | + private final String devId; |
| 35 | + |
| 36 | + /** |
| 37 | + * Authorization Key (AuthKey) |
| 38 | + * @see HiRezAPI#HiRezAPI(String, String) |
| 39 | + */ |
| 40 | + private final String authKey; |
| 41 | + |
| 42 | + public Smite smite; |
| 43 | + public Paladins paladins; |
| 44 | + |
| 45 | + /** |
| 46 | + * <p>Initialize Hi-Rez API. All stuff will delivered by Hi-Rez employer via E-Mail.<br /> |
| 47 | + * Please fill <a href="https://fs12.formsite.com/HiRez/form48/secure_index.html">this form first</a> to using script.<br /> |
| 48 | + * After acceptation your request, you can proceed to action.</p> |
| 49 | + * @param devId Developer ID (DevId) |
| 50 | + * @param authKey Authorization Key (AuthKey) |
| 51 | + */ |
| 52 | + public HiRezAPI(@NotNull String devId, @NotNull String authKey) { |
| 53 | + this.devId = devId; |
| 54 | + this.authKey = authKey; |
| 55 | + try { |
| 56 | + initialize(); |
| 57 | + } catch (Exception ex) { |
| 58 | + ex.printStackTrace(); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + private static void store() throws IOException { |
| 63 | + Writer writer = new FileWriter(filesession); |
| 64 | + sessions.store(writer, ""); |
| 65 | + } |
| 66 | + |
| 67 | + private void initialize() throws IOException { |
| 68 | + if (!filesession.exists()) { |
| 69 | + filesession.createNewFile(); |
| 70 | + } |
| 71 | + Reader reader = new FileReader(filesession); |
| 72 | + sessions.load(reader); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Smite API |
| 77 | + * @param platform Platform |
| 78 | + * @see Smite |
| 79 | + */ |
| 80 | + public Smite smite(Smite.Platform platform) { |
| 81 | + return new Smite(platform, devId, authKey); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Paladins API |
| 86 | + * @param platform Platform |
| 87 | + * @see Paladins |
| 88 | + */ |
| 89 | + public Paladins paladins(Paladins.Platform platform) { |
| 90 | + return new Paladins(platform, devId, authKey); |
| 91 | + } |
| 92 | + |
| 93 | +} |
0 commit comments