public void updateInformation(ApiClient client) throws IOException, ApiException { serverInformation = client.getServerInformation(); } }
@Override public ServerInformation getServerInformation() throws IOException, ApiException { return get("/information", CacheControl.FORCE_NETWORK, ServerInformation.class); }
@Override public void run() { try { plugin.getApiClient().deleteCoupon(code); sender.sendMessage(ChatColor.GREEN + plugin.getI18n().get("coupon_deleted")); } catch (ApiException | IOException e) { sender.sendMessage(ChatColor.RED + e.getMessage()); return; } } });
Platform() { super(new ProductionApiClient(apiKey, new OkHttpClient.Builder() .connectTimeout(1, TimeUnit.SECONDS) .writeTimeout(3, TimeUnit.SECONDS) .readTimeout(3, TimeUnit.SECONDS) .build()), executorService); }
@Override public void run() { try { plugin.getApiClient().createCoupon(coupon); sender.sendMessage(ChatColor.GREEN + plugin.getI18n().get("coupon_creation_success", coupon.getCode())); } catch (ApiException | IOException e) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("generic_api_operation_error")); } } });
@Override public void deleteCoupon(String id) throws IOException, ApiException { Request request = getBuilder("/coupons/" + id + "/code") .delete() .build(); Response response = httpClient.newCall(request).execute(); try (ResponseBody rspBody = response.body()) { if (!response.isSuccessful()) { throw handleError(response, rspBody); } } }
public void flush() { if (!completed.isEmpty()) { for (List<Integer> list : Lists.partition(new ArrayList<>(completed), MAXIMUM_COMMANDS_TO_POST)) { try { platform.getApiClient().deleteCommand(list); } catch (IOException | ApiException e) { platform.log(Level.SEVERE, "Unable to mark commands as completed", e); break; } } } } }
public void updateInformation(ApiClient client) throws IOException, ApiException { serverInformation = client.getServerInformation(); } }
@Override public void run() { try { plugin.getApiClient().deleteCoupon(code); sender.sendMessage(ChatColor.GREEN + plugin.getI18n().get("coupon_deleted")); } catch (ApiException | IOException e) { sender.sendMessage(ChatColor.RED + e.getMessage()); return; } } });
@Override public DueQueueInformation retrieveDueQueue() throws IOException, ApiException { return get("/queue", CacheControl.FORCE_NETWORK, DueQueueInformation.class); }
@Override public void deleteCoupon(int id) throws IOException, ApiException { Request request = getBuilder("/coupons/" + id) .delete() .build(); Response response = httpClient.newCall(request).execute(); try (ResponseBody rspBody = response.body()) { if (!response.isSuccessful()) { throw handleError(response, rspBody); } } }
public void initializeTasks() { try { serverInformation = platform.getApiClient().getServerInformation(); } catch (IOException | ApiException e) { throw new RuntimeException("Can't fetch account information", e); } executorService.schedule(playerFetcher = new DuePlayerFetcher(platform, verbose), 1, TimeUnit.SECONDS); }
@Override public void run() { try { plugin.getApiClient().deleteCoupon(code); sender.sendMessage(TextFormat.GREEN + plugin.getI18n().get("coupon_deleted")); } catch (ApiException | IOException e) { sender.sendMessage(TextFormat.RED + e.getMessage()); return; } } });
@Override public QueueInformation getPlayerQueue(int id) throws IOException, ApiException { return get("/queue/online-commands/" + id, CacheControl.FORCE_NETWORK, QueueInformation.class); }
@Override public QueueInformation retrieveOfflineQueue() throws IOException, ApiException { return get("/queue/offline-commands", CacheControl.FORCE_NETWORK, QueueInformation.class); }
private <T> T get(String endpoint, Type type) throws IOException, ApiException { return get(endpoint, null, type); }
@Override public Listing retrieveListing() throws IOException, ApiException { Listing listing = get("/listing", CacheControl.FORCE_NETWORK, Listing.class); if(listing != null) listing.order(); return listing; }
@Override public List<Coupon> getAllCoupons() throws IOException, ApiException { CouponListing listing = get("/coupons", CouponListing.class); if(listing == null){ return null; } return listing.getData(); }
@Override public Coupon getCoupon(int id) throws IOException, ApiException { CouponSingleListing listing = get("/coupons/" + id, CouponSingleListing.class); return listing.getData(); }