use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class WebGetExchangeRatesRequestHandler method handle.
@Override
public ApiResponse handle(ApiRequest apiRequest) {
JSONObject result = JSONUrlReader.readJsonObjectFromUrl(context, Constants.WWW_RUN_IOTA + "/xchange.jsp");
if (result != null) {
Store.updateTickers(context, result);
JSONArray msgs = result.optJSONArray("sysmsg");
if (msgs != null && msgs.length() > 0) {
for (int i = 0; i < msgs.length(); i++) {
Store.addSystemMessage(context, msgs.optJSONObject(i));
}
}
return new WebGetExchangeRatesResponse(result);
}
return new WebGetExchangeRatesResponse(new JSONObject());
// NetworkError error = new NetworkError();
// error.setErrorType(NetworkErrorType.NETWORK_ERROR);
// return error;
}
use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class WebGetExchangeRatesHistoryRequestHandler method handle.
@Override
public ApiResponse handle(ApiRequest apiRequest) {
WebGetExchangeRatesHistoryRequest req = (WebGetExchangeRatesHistoryRequest) apiRequest;
// Currency curr=Store.getDefaultCurrency(context);
// Log.e("XCHANGE",Constants.WWW_RUN_IOTA+"/xchangehist.jsp?step="+req.step+"&cp="+req.cp);
JSONObject result = JSONUrlReader.readJsonObjectFromUrl(context, Constants.WWW_RUN_IOTA + "/xchangehist.jsp?step=" + req.step + "&cp=" + req.cp);
if (result != null) {
// Log.e("GOT-HIST",result.toString());
Store.updateTickerHist(context, result);
return new WebGetExchangeRatesHistoryResponse(result);
}
NetworkError error = new NetworkError();
error.setErrorType(NetworkErrorType.NETWORK_ERROR);
return error;
}
use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class JSONUrlReader method readJsonFromUrlPlainText.
public static JSONObject readJsonFromUrlPlainText(Context context, String url) {
URL serverUrl = null;
try {
serverUrl = new URL(url);
} catch (Exception e) {
// Log.e("JSONpt1", "" + e.getMessage());
}
JSONObject json = null;
InputStream is = null;
try {
is = serverUrl.openStream();
} catch (IOException e) {
// Log.e("JSONpt2",""+e.getMessage());
}
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = readAll(rd);
json = new JSONObject(jsonText);
} catch (Exception e) {
// Log.e("JSONpt3",""+e.getMessage());
}
try {
is.close();
} catch (Exception e) {
// Log.e("JSONpt4",""+e.getMessage());
}
return json;
}
use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class JSONUrlReader method readJsonObjectFromUrl.
public static JSONObject readJsonObjectFromUrl(Context context, String url) {
URL serverUrl = null;
HttpURLConnection urlConnection = null;
try {
serverUrl = new URL(url);
urlConnection = (HttpURLConnection) serverUrl.openConnection();
} catch (Exception e) {
// Log.e("JSON1", "" + e.getMessage());
}
JSONObject json = null;
String useCookie = cookieStore.get(url);
InputStream is = null;
if (useCookie != null) {
urlConnection.setRequestProperty("Cookie", useCookie);
}
try {
urlConnection.setRequestProperty("User-Agent", getUserAgent(context));
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setConnectTimeout(URL_TIMEOUT_MILLIS);
urlConnection.setReadTimeout(URL_TIMEOUT_MILLIS);
urlConnection.setInstanceFollowRedirects(true);
} catch (Exception e) {
// Log.e("readJsonObjectFromUrl().error.msg","2:"+e.getMessage());
}
try {
urlConnection.connect();
} catch (Exception e) {
cookieStore.remove(url);
// Log.e("readJsonObjectFromUrl().error.msg","3 - connect(): "+e.getMessage());
}
try {
is = urlConnection.getInputStream();
} catch (IOException e) {
// Log.e("JSON4",""+e.getMessage());
}
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
// BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String jsonText = readAll(rd);
// Log.e("GOTJSON",jsonText+"");
json = new JSONObject(jsonText);
} catch (Exception e) {
// Log.e("JSON5",""+e.getMessage());
}
try {
is.close();
} catch (Exception e) {
// Log.e("JSON6",""+e.getMessage());
}
return json;
}
use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class Address method toJson.
public JSONObject toJson() {
JSONObject job = new JSONObject();
job.put("add", address);
job.put("used", used);
job.put("att", attached);
job.put("val", value);
job.put("pval", pendingValue);
job.put("ind", index);
job.put("inn", indexName);
job.put("mil", lastMilestone);
job.put("sec", security);
job.put("pig", pig);
return job;
}
Aggregations