Adding docs and some tests for a few API handler classes (GetRequiredFees, ListAssets, LookupAccounts, LookupAssetSymbols and SubscriptionMessagesHub

master
Vinícius 2017-07-20 16:37:16 -03:00
parent ad2e414548
commit e364fe678f
5 changed files with 77 additions and 48 deletions

View File

@ -29,7 +29,7 @@ import java.util.Map;
*
* @see <a href="https://goo.gl/MB4TXq">get_required_fees API doc</a>
*/
public class GetRequiredFees extends WebSocketAdapter {
public class GetRequiredFees extends BaseGrapheneHandler {
private WitnessResponseListener mListener;
private List<BaseOperation> operations;
@ -49,6 +49,7 @@ public class GetRequiredFees extends WebSocketAdapter {
* of the transaction broadcast operation.
*/
public GetRequiredFees(List<BaseOperation> operations, Asset asset, boolean oneTime, WitnessResponseListener listener){
super(listener);
this.operations = operations;
this.asset = asset;
this.mOneTime = oneTime;

View File

@ -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.

View File

@ -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 <a href="https://goo.gl/zhPjuW">lookup_accounts API doc</a>
*/
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);
}

View File

@ -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 <a href="https://goo.gl/WvREGV">lookup_asset_symbols API doc</a>
*/
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<Asset> 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<Asset> assets, WitnessResponseListener listener){
this(assets, true, listener);
}
@ -58,6 +82,9 @@ public class LookupAssetSymbols extends BaseGrapheneHandler {
gsonBuilder.registerTypeAdapter(Asset.class, new Asset.AssetDeserializer());
WitnessResponse<List<Asset>> witnessResponse = gsonBuilder.create().fromJson(response, LookupAssetSymbolsResponse);
mListener.onSuccess(witnessResponse);
if(mOneTime){
websocket.disconnect();
}
}
@Override

View File

@ -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