Making other API classes extend the BaseGrapheneHandler

This commit is contained in:
Nelson R. Perez 2017-04-10 16:27:56 -05:00
parent eceb096607
commit a23d059d16
7 changed files with 71 additions and 176 deletions

View file

@ -1,19 +1,8 @@
package de.bitsharesmunich.graphenej.api; package de.bitsharesmunich.graphenej.api;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import de.bitsharesmunich.graphenej.AccountOptions;
import de.bitsharesmunich.graphenej.Authority;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.AccountProperties;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.BaseResponse;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import com.neovisionaries.ws.client.WebSocketException;
import com.neovisionaries.ws.client.WebSocketFrame; import com.neovisionaries.ws.client.WebSocketFrame;
import java.io.Serializable; import java.io.Serializable;
@ -22,15 +11,24 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import de.bitsharesmunich.graphenej.AccountOptions;
import de.bitsharesmunich.graphenej.Authority;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.AccountProperties;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
/** /**
* Created by nelson on 11/15/16. * Created by nelson on 11/15/16.
*/ */
public class GetAccountByName extends WebSocketAdapter { public class GetAccountByName extends BaseGrapheneHandler {
private String accountName; private String accountName;
private WitnessResponseListener mListener; private WitnessResponseListener mListener;
public GetAccountByName(String accountName, WitnessResponseListener listener){ public GetAccountByName(String accountName, WitnessResponseListener listener){
super(listener);
this.accountName = accountName; this.accountName = accountName;
this.mListener = listener; this.mListener = listener;
} }
@ -70,17 +68,4 @@ public class GetAccountByName extends WebSocketAdapter {
System.out.println(">>> "+frame.getPayloadText()); System.out.println(">>> "+frame.getPayloadText());
} }
} }
@Override
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
@Override
public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception {
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
} }

View file

@ -1,23 +1,9 @@
package de.bitsharesmunich.graphenej.api; package de.bitsharesmunich.graphenej.api;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import de.bitsharesmunich.graphenej.AccountOptions;
import de.bitsharesmunich.graphenej.Authority;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.UserAccount;
import de.bitsharesmunich.graphenej.interfaces.JsonSerializable;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.AccountProperties;
import de.bitsharesmunich.graphenej.models.BaseResponse;
import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import com.neovisionaries.ws.client.WebSocketException;
import com.neovisionaries.ws.client.WebSocketFrame; import com.neovisionaries.ws.client.WebSocketFrame;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -25,22 +11,33 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import de.bitsharesmunich.graphenej.AccountOptions;
import de.bitsharesmunich.graphenej.Authority;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.UserAccount;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.AccountProperties;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
/** /**
* *
* @author henry * @author henry
*/ */
public class GetAccounts extends WebSocketAdapter { public class GetAccounts extends BaseGrapheneHandler {
private String accountId; private String accountId;
private List<UserAccount> userAccounts; private List<UserAccount> userAccounts;
private WitnessResponseListener mListener; private WitnessResponseListener mListener;
public GetAccounts(String accountId, WitnessResponseListener listener){ public GetAccounts(String accountId, WitnessResponseListener listener){
super(listener);
this.accountId = accountId; this.accountId = accountId;
this.mListener = listener; this.mListener = listener;
} }
public GetAccounts(List<UserAccount> accounts, WitnessResponseListener listener){ public GetAccounts(List<UserAccount> accounts, WitnessResponseListener listener){
super(listener);
this.userAccounts = accounts; this.userAccounts = accounts;
this.mListener = listener; this.mListener = listener;
} }
@ -85,22 +82,4 @@ public class GetAccounts extends WebSocketAdapter {
if(frame.isTextFrame()) if(frame.isTextFrame())
System.out.println(">>> "+frame.getPayloadText()); System.out.println(">>> "+frame.getPayloadText());
} }
@Override
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
System.out.println("onError");
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
@Override
public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception {
System.out.println("handleCallbackError. Msg: "+cause.getMessage());
StackTraceElement[] stack = cause.getStackTrace();
for(StackTraceElement element : stack) {
System.out.println("> "+element.getClassName()+"."+element.getMethodName()+" : "+element.getLineNumber());
}
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
} }

View file

@ -4,13 +4,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import com.neovisionaries.ws.client.WebSocketException;
import com.neovisionaries.ws.client.WebSocketFrame; import com.neovisionaries.ws.client.WebSocketFrame;
import de.bitsharesmunich.graphenej.Asset;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.*;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -20,10 +14,19 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import de.bitsharesmunich.graphenej.Asset;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.BaseResponse;
import de.bitsharesmunich.graphenej.models.BucketObject;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
/** /**
* Created by nelson on 12/22/16. * Created by nelson on 12/22/16.
*/ */
public class GetMarketHistory extends WebSocketAdapter { public class GetMarketHistory extends BaseGrapheneHandler {
// Sequence of message ids // Sequence of message ids
private final static int LOGIN_ID = 1; private final static int LOGIN_ID = 1;
private final static int GET_HISTORY_ID = 2; private final static int GET_HISTORY_ID = 2;
@ -41,6 +44,7 @@ public class GetMarketHistory extends WebSocketAdapter {
private int apiId = -1; private int apiId = -1;
public GetMarketHistory(Asset base, Asset quote, long bucket, Date start, Date end, WitnessResponseListener listener){ public GetMarketHistory(Asset base, Asset quote, long bucket, Date start, Date end, WitnessResponseListener listener){
super(listener);
this.base = base; this.base = base;
this.quote = quote; this.quote = quote;
this.bucket = bucket; this.bucket = bucket;
@ -105,21 +109,4 @@ public class GetMarketHistory extends WebSocketAdapter {
if(frame.isTextFrame()) if(frame.isTextFrame())
System.out.println(">>> "+frame.getPayloadText()); System.out.println(">>> "+frame.getPayloadText());
} }
@Override
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
System.out.println("onError. Msg: "+cause.getMessage());
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
@Override
public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception {
System.out.println("handleCallbackError. cause: "+cause.getMessage()+", error: "+cause.getClass());
for (StackTraceElement element : cause.getStackTrace()){
System.out.println(element.getFileName()+"#"+element.getClassName()+":"+element.getLineNumber());
}
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
} }

View file

@ -3,18 +3,7 @@ package de.bitsharesmunich.graphenej.api;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import de.bitsharesmunich.graphenej.AssetAmount;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.operations.TransferOperation;
import de.bitsharesmunich.graphenej.UserAccount;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.BaseResponse;
import de.bitsharesmunich.graphenej.models.HistoricalTransfer;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import com.neovisionaries.ws.client.WebSocketException;
import com.neovisionaries.ws.client.WebSocketFrame; import com.neovisionaries.ws.client.WebSocketFrame;
import java.io.Serializable; import java.io.Serializable;
@ -23,11 +12,21 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import de.bitsharesmunich.graphenej.AssetAmount;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.UserAccount;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.BaseResponse;
import de.bitsharesmunich.graphenej.models.HistoricalTransfer;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
import de.bitsharesmunich.graphenej.operations.TransferOperation;
/** /**
* Class used to encapsulate the communication sequence used to retrieve the transaction history of * Class used to encapsulate the communication sequence used to retrieve the transaction history of
* a given user. * a given user.
*/ */
public class GetRelativeAccountHistory extends WebSocketAdapter { public class GetRelativeAccountHistory extends BaseGrapheneHandler {
// Sequence of message ids // Sequence of message ids
private final static int LOGIN_ID = 1; private final static int LOGIN_ID = 1;
private final static int GET_HISTORY_ID = 2; private final static int GET_HISTORY_ID = 2;
@ -57,6 +56,7 @@ public class GetRelativeAccountHistory extends WebSocketAdapter {
* @param listener Listener to be notified with the result of this query * @param listener Listener to be notified with the result of this query
*/ */
public GetRelativeAccountHistory(UserAccount userAccount, int stop, int limit, int start, WitnessResponseListener listener){ public GetRelativeAccountHistory(UserAccount userAccount, int stop, int limit, int start, WitnessResponseListener listener){
super(listener);
if(limit > MAX_LIMIT) limit = MAX_LIMIT; if(limit > MAX_LIMIT) limit = MAX_LIMIT;
this.mUserAccount = userAccount; this.mUserAccount = userAccount;
this.stop = stop; this.stop = stop;
@ -71,6 +71,7 @@ public class GetRelativeAccountHistory extends WebSocketAdapter {
* @param listener Listener to be notified with the result of this query * @param listener Listener to be notified with the result of this query
*/ */
public GetRelativeAccountHistory(UserAccount userAccount, WitnessResponseListener listener){ public GetRelativeAccountHistory(UserAccount userAccount, WitnessResponseListener listener){
super(listener);
this.mUserAccount = userAccount; this.mUserAccount = userAccount;
this.stop = DEFAULT_STOP; this.stop = DEFAULT_STOP;
this.limit = MAX_LIMIT; this.limit = MAX_LIMIT;
@ -132,18 +133,4 @@ public class GetRelativeAccountHistory extends WebSocketAdapter {
if(frame.isTextFrame()) if(frame.isTextFrame())
System.out.println(">>> "+frame.getPayloadText()); System.out.println(">>> "+frame.getPayloadText());
} }
@Override
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
System.out.println("onError. Msg: "+cause.getMessage());
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
@Override
public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception {
System.out.println("handleCallbackError. Msg: "+cause.getMessage());
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
} }

View file

@ -3,15 +3,7 @@ package de.bitsharesmunich.graphenej.api;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import com.neovisionaries.ws.client.WebSocketException;
import com.neovisionaries.ws.client.WebSocketFrame; import com.neovisionaries.ws.client.WebSocketFrame;
import de.bitsharesmunich.graphenej.MarketTrade;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.BaseResponse;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -19,10 +11,16 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import de.bitsharesmunich.graphenej.MarketTrade;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
/** /**
* @author henry * @author henry
*/ */
public class GetTradeHistory extends WebSocketAdapter { public class GetTradeHistory extends BaseGrapheneHandler {
private String a; private String a;
private String b; private String b;
@ -32,6 +30,7 @@ public class GetTradeHistory extends WebSocketAdapter {
private WitnessResponseListener mListener; private WitnessResponseListener mListener;
public GetTradeHistory(String a, String b, String toTime, String fromTime,int limit, WitnessResponseListener mListener) { public GetTradeHistory(String a, String b, String toTime, String fromTime,int limit, WitnessResponseListener mListener) {
super(mListener);
this.a = a; this.a = a;
this.b = b; this.b = b;
this.toTime = toTime; this.toTime = toTime;
@ -82,16 +81,4 @@ public class GetTradeHistory extends WebSocketAdapter {
System.out.println(">>> " + frame.getPayloadText()); System.out.println(">>> " + frame.getPayloadText());
} }
} }
@Override
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
@Override
public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception {
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
} }

View file

@ -2,15 +2,7 @@ package de.bitsharesmunich.graphenej.api;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.UserAccount;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.BaseResponse;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import com.neovisionaries.ws.client.WebSocketException;
import com.neovisionaries.ws.client.WebSocketFrame; import com.neovisionaries.ws.client.WebSocketFrame;
import java.io.Serializable; import java.io.Serializable;
@ -19,10 +11,16 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.UserAccount;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
/** /**
* Created by henry on 07/12/16. * Created by henry on 07/12/16.
*/ */
public class LookupAccounts extends WebSocketAdapter { public class LookupAccounts extends BaseGrapheneHandler {
public static final int DEFAULT_MAX = 1000; public static final int DEFAULT_MAX = 1000;
private final String accountName; private final String accountName;
@ -30,12 +28,14 @@ public class LookupAccounts extends WebSocketAdapter {
private final WitnessResponseListener mListener; private final WitnessResponseListener mListener;
public LookupAccounts(String accountName, WitnessResponseListener listener){ public LookupAccounts(String accountName, WitnessResponseListener listener){
super(listener);
this.accountName = accountName; this.accountName = accountName;
this.maxAccounts = DEFAULT_MAX; this.maxAccounts = DEFAULT_MAX;
this.mListener = listener; this.mListener = listener;
} }
public LookupAccounts(String accountName, int maxAccounts, WitnessResponseListener listener){ public LookupAccounts(String accountName, int maxAccounts, WitnessResponseListener listener){
super(listener);
this.accountName = accountName; this.accountName = accountName;
this.maxAccounts = maxAccounts; this.maxAccounts = maxAccounts;
this.mListener = listener; this.mListener = listener;
@ -73,16 +73,4 @@ public class LookupAccounts extends WebSocketAdapter {
if(frame.isTextFrame()) if(frame.isTextFrame())
System.out.println(">>> "+frame.getPayloadText()); System.out.println(">>> "+frame.getPayloadText());
} }
@Override
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
@Override
public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception {
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
} }

View file

@ -3,15 +3,7 @@ package de.bitsharesmunich.graphenej.api;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import com.neovisionaries.ws.client.WebSocketException;
import com.neovisionaries.ws.client.WebSocketFrame; import com.neovisionaries.ws.client.WebSocketFrame;
import de.bitsharesmunich.graphenej.Asset;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.BaseResponse;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -19,14 +11,21 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import de.bitsharesmunich.graphenej.Asset;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
/** /**
* Created by nelson on 12/12/16. * Created by nelson on 12/12/16.
*/ */
public class LookupAssetSymbols extends WebSocketAdapter { public class LookupAssetSymbols extends BaseGrapheneHandler {
private WitnessResponseListener mListener; private WitnessResponseListener mListener;
private List<Asset> assets; private List<Asset> assets;
public LookupAssetSymbols(List<Asset> assets, WitnessResponseListener listener){ public LookupAssetSymbols(List<Asset> assets, WitnessResponseListener listener){
super(listener);
this.assets = assets; this.assets = assets;
this.mListener = listener; this.mListener = listener;
} }
@ -59,21 +58,4 @@ public class LookupAssetSymbols extends WebSocketAdapter {
if(frame.isTextFrame()) if(frame.isTextFrame())
System.out.println(">>> "+frame.getPayloadText()); System.out.println(">>> "+frame.getPayloadText());
} }
@Override
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
System.out.println("onError. cause: "+cause.getMessage());
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
@Override
public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception {
System.out.println("handleCallbackError. cause: "+cause.getMessage()+", error: "+cause.getClass());
for (StackTraceElement element : cause.getStackTrace()){
System.out.println(element.getFileName()+"#"+element.getClassName()+":"+element.getLineNumber());
}
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
} }