aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/cowtipper/cowlection/chestTracker/HyBazaarData.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/cowtipper/cowlection/chestTracker/HyBazaarData.java')
-rw-r--r--src/main/java/de/cowtipper/cowlection/chestTracker/HyBazaarData.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/chestTracker/HyBazaarData.java b/src/main/java/de/cowtipper/cowlection/chestTracker/HyBazaarData.java
new file mode 100644
index 0000000..6480244
--- /dev/null
+++ b/src/main/java/de/cowtipper/cowlection/chestTracker/HyBazaarData.java
@@ -0,0 +1,61 @@
+package de.cowtipper.cowlection.chestTracker;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.util.Map;
+
+@SuppressWarnings("unused")
+public class HyBazaarData {
+ private boolean success;
+ private long lastUpdated;
+ @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
+ private Map<String, Product> products;
+
+ public boolean isSuccess() {
+ return success;
+ }
+
+ /**
+ * Returns {@link Product} from bazaar reply.
+ * Returns null if product does not exist
+ *
+ * @param productId product in bazaar
+ * @return instance of Product
+ */
+ public Product getProduct(String productId) {
+ return products.get(productId);
+ }
+
+ /**
+ * Refresh only allowed once per minute
+ */
+ public boolean allowRefreshData() {
+ return (System.currentTimeMillis() - lastUpdated) > 60000;
+ }
+
+ public static class Product {
+ @SerializedName("quick_status")
+ private Status quickStatus;
+
+ public double getInstantSellPrice() {
+ return quickStatus.getSellPrice();
+ }
+
+ public double getSellOfferPrice() {
+ return quickStatus.getBuyPrice();
+ }
+
+ public static class Status {
+ private double sellPrice;
+ private double buyPrice;
+
+ public double getSellPrice() {
+ return sellPrice;
+ }
+
+ public double getBuyPrice() {
+ return buyPrice;
+ }
+ }
+ }
+}