From e364fe678fec81a095b19379d54f2cfd135616f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius?= Date: Thu, 20 Jul 2017 16:37:16 -0300 Subject: [PATCH] Adding docs and some tests for a few API handler classes (GetRequiredFees, ListAssets, LookupAccounts, LookupAssetSymbols and SubscriptionMessagesHub --- .../graphenej/api/GetRequiredFees.java | 3 +- .../graphenej/api/ListAssets.java | 5 ++- .../graphenej/api/LookupAccounts.java | 44 ++++++++++++++++++- .../graphenej/api/LookupAssetSymbols.java | 29 +++++++++++- .../api/SubscriptionMessagesHub.java | 44 +------------------ 5 files changed, 77 insertions(+), 48 deletions(-) diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java index 418c51d..3c9fd54 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java @@ -29,7 +29,7 @@ import java.util.Map; * * @see get_required_fees API doc */ -public class GetRequiredFees extends WebSocketAdapter { +public class GetRequiredFees extends BaseGrapheneHandler { private WitnessResponseListener mListener; private List operations; @@ -49,6 +49,7 @@ public class GetRequiredFees extends WebSocketAdapter { * of the transaction broadcast operation. */ public GetRequiredFees(List operations, Asset asset, boolean oneTime, WitnessResponseListener listener){ + super(listener); this.operations = operations; this.asset = asset; this.mOneTime = oneTime; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/ListAssets.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/ListAssets.java index ba2e5ef..cd3f1a6 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/ListAssets.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/ListAssets.java @@ -26,7 +26,6 @@ import java.util.Map; * constructor. Internally we are going to perform multiple calls in order to satisfy the user's * request. * - * Created by nelson on 1/5/17. */ public class ListAssets extends BaseGrapheneHandler { /** @@ -49,6 +48,7 @@ public class ListAssets extends BaseGrapheneHandler { /** * Constructor + * * @param lowerBoundSymbol: Lower bound of symbol names to retrieve * @param limit: Maximum number of assets to fetch, if the constant LIST_ALL * is passed, all existing assets will be retrieved. @@ -61,7 +61,8 @@ public class ListAssets extends BaseGrapheneHandler { } /** - * Constructor with oneTime = true for compatibility issue. + * Using this constructor the WebSocket connection closes after the response. + * * @param lowerBoundSymbol: Lower bound of symbol names to retrieve * @param limit: Maximum number of assets to fetch, if the constant LIST_ALL * is passed, all existing assets will be retrieved. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java index 7a34162..2ca951f 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java @@ -18,7 +18,13 @@ import de.bitsharesmunich.graphenej.models.ApiCall; import de.bitsharesmunich.graphenej.models.WitnessResponse; /** - * Created by henry on 07/12/16. + * Class that implements lookup_accounts request handler. + * + * Get names and IDs for registered accounts. + * + * The request returns a map of account names to corresponding IDs. + * + * @see lookup_accounts API doc */ public class LookupAccounts extends BaseGrapheneHandler { @@ -29,6 +35,16 @@ public class LookupAccounts extends BaseGrapheneHandler { private boolean mOneTime; + /** + * Constructor + * + * @param accountName account name used at the query + * @param oneTime boolean value indicating if websocket must be closed (true) or not (false) + * after the response + * @param listener A class implementing the WitnessResponseListener interface. This should + * be implemented by the party interested in being notified about the success/failure + * of the transaction broadcast operation. + */ public LookupAccounts(String accountName, boolean oneTime, WitnessResponseListener listener){ super(listener); this.accountName = accountName; @@ -37,6 +53,17 @@ public class LookupAccounts extends BaseGrapheneHandler { this.mListener = listener; } + /** + * Constructor with maxAccounts + * + * @param accountName account name used at the query + * @param maxAccounts maximum number of results to return (must not exceed 1000) + * @param oneTime boolean value indicating if websocket must be closed (true) or not (false) + * after the response + * @param listener A class implementing the WitnessResponseListener interface. This should + * be implemented by the party interested in being notified about the success/failure + * of the transaction broadcast operation. + */ public LookupAccounts(String accountName, int maxAccounts, boolean oneTime, WitnessResponseListener listener){ super(listener); this.accountName = accountName; @@ -45,10 +72,25 @@ public class LookupAccounts extends BaseGrapheneHandler { this.mListener = listener; } + /** + * Using this constructor the WebSocket connection closes after the response. + * + * @param accountName account name used at the query + * @param listener A class implementing the WitnessResponseListener interface. This should + * be implemented by the party interested in being notified about the success/failure + * of the transaction broadcast operation. + */ public LookupAccounts(String accountName, WitnessResponseListener listener){ this(accountName, true, listener); } + /** + * Using this constructor the WebSocket connection closes after the response. + * + * @param accountName account name used at the query + * @param maxAccounts maximum number of results to return (must not exceed 1000) + * @param listener + */ public LookupAccounts(String accountName, int maxAccounts, WitnessResponseListener listener){ this(accountName, maxAccounts, true, listener); } diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAssetSymbols.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAssetSymbols.java index 770f851..186a74e 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAssetSymbols.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAssetSymbols.java @@ -18,7 +18,13 @@ import de.bitsharesmunich.graphenej.models.ApiCall; import de.bitsharesmunich.graphenej.models.WitnessResponse; /** - * Created by nelson on 12/12/16. + * Class that implements lookup_asset_symbols request handler. + * + * Get the assets corresponding to the provided IDs. + * + * The request returns the assets corresponding to the provided symbols or IDs. + * + * @see lookup_asset_symbols API doc */ public class LookupAssetSymbols extends BaseGrapheneHandler { private WitnessResponseListener mListener; @@ -26,6 +32,16 @@ public class LookupAssetSymbols extends BaseGrapheneHandler { private boolean mOneTime; + /** + * Constructor + * + * @param assets list of the assets to retrieve + * @param oneTime boolean value indicating if websocket must be closed (true) or not (false) + * after the response + * @param listener A class implementing the WitnessResponseListener interface. This should + * be implemented by the party interested in being notified about the success/failure + * of the transaction broadcast operation. + */ public LookupAssetSymbols(List assets, boolean oneTime, WitnessResponseListener listener){ super(listener); this.assets = assets; @@ -33,6 +49,14 @@ public class LookupAssetSymbols extends BaseGrapheneHandler { this.mListener = listener; } + /** + * Using this constructor the WebSocket connection closes after the response. + * + * @param assets list of the assets to retrieve + * @param listener A class implementing the WitnessResponseListener interface. This should + * be implemented by the party interested in being notified about the success/failure + * of the transaction broadcast operation. + */ public LookupAssetSymbols(List assets, WitnessResponseListener listener){ this(assets, true, listener); } @@ -58,6 +82,9 @@ public class LookupAssetSymbols extends BaseGrapheneHandler { gsonBuilder.registerTypeAdapter(Asset.class, new Asset.AssetDeserializer()); WitnessResponse> witnessResponse = gsonBuilder.create().fromJson(response, LookupAssetSymbolsResponse); mListener.onSuccess(witnessResponse); + if(mOneTime){ + websocket.disconnect(); + } } @Override diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/SubscriptionMessagesHub.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/SubscriptionMessagesHub.java index 747d01b..780564d 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/SubscriptionMessagesHub.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/SubscriptionMessagesHub.java @@ -30,7 +30,7 @@ import de.bitsharesmunich.graphenej.operations.LimitOrderCreateOperation; import de.bitsharesmunich.graphenej.operations.TransferOperation; /** - * A websocket adapter prepared to be used as a basic dispatch hub for subscription messages. + * A WebSocket adapter prepared to be used as a basic dispatch hub for subscription messages. * * Created by nelson on 1/26/17. */ @@ -66,48 +66,6 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs private boolean isUnsubscribing; private boolean isSubscribed; - /** - * Constructor used to create a subscription message hub that will call the set_subscribe_callback - * API with the clear_filter parameter set to false, meaning that it will only receive automatic updates - * from objects we register. - * - * A list of ObjectTypes must be provided, otherwise we won't get any update. - * - * @param user: User name, in case the node to which we're going to connect to requires authentication - * @param password: Password, same as above - * @param clearFilter: Whether to automatically subscribe of not to the notification feed. - * @param errorListener: Callback that will be fired in case there is an error. - */ - public SubscriptionMessagesHub(String user, String password, boolean clearFilter, WitnessResponseListener errorListener){ - super(errorListener); - this.user = user; - this.password = password; - this.clearFilter = clearFilter; - this.mSubscriptionDeserializer = new SubscriptionResponse.SubscriptionResponseDeserializer(); - GsonBuilder builder = new GsonBuilder(); - builder.registerTypeAdapter(SubscriptionResponse.class, mSubscriptionDeserializer); - builder.registerTypeAdapter(Transaction.class, new Transaction.TransactionDeserializer()); - builder.registerTypeAdapter(TransferOperation.class, new TransferOperation.TransferDeserializer()); - builder.registerTypeAdapter(LimitOrderCreateOperation.class, new LimitOrderCreateOperation.LimitOrderCreateDeserializer()); - builder.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer()); - builder.registerTypeAdapter(UserAccount.class, new UserAccount.UserAccountSimpleDeserializer()); - builder.registerTypeAdapter(DynamicGlobalProperties.class, new DynamicGlobalProperties.DynamicGlobalPropertiesDeserializer()); - this.gson = builder.create(); - } - - /** - * Constructor used to create a subscription message hub that will call the set_subscribe_callback - * API with the clear_filter parameter set to false, meaning that it will only receive updates - * from objects we register. - * - * @param user: User name, in case the node to which we're going to connect to requires authentication - * @param password: Password, same as above - * @param errorListener: Callback that will be fired in case there is an error. - */ - public SubscriptionMessagesHub(String user, String password, WitnessResponseListener errorListener){ - this(user, password, false, errorListener); - } - /** * Constructor used to create a subscription message hub that will call the set_subscribe_callback * API with the clear_filter parameter set to false, meaning that it will only receive automatic updates