Search in sources :

Example 1 with JSONObject

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;
}
Also used : JSONObject(run.wallet.common.json.JSONObject) JSONArray(run.wallet.common.json.JSONArray) WebGetExchangeRatesResponse(run.wallet.iota.api.responses.WebGetExchangeRatesResponse)

Example 2 with JSONObject

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;
}
Also used : WebGetExchangeRatesHistoryRequest(run.wallet.iota.api.requests.WebGetExchangeRatesHistoryRequest) JSONObject(run.wallet.common.json.JSONObject) WebGetExchangeRatesHistoryResponse(run.wallet.iota.api.responses.WebGetExchangeRatesHistoryResponse) NetworkError(run.wallet.iota.api.responses.error.NetworkError)

Example 3 with JSONObject

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;
}
Also used : JSONObject(run.wallet.common.json.JSONObject) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 4 with JSONObject

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;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JSONObject(run.wallet.common.json.JSONObject) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 5 with JSONObject

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;
}
Also used : JSONObject(run.wallet.common.json.JSONObject)

Aggregations

JSONObject (run.wallet.common.json.JSONObject)37 SharedPreferences (android.content.SharedPreferences)24 JSONArray (run.wallet.common.json.JSONArray)21 ArrayList (java.util.ArrayList)6 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Fragment (android.app.Fragment)1 FragmentManager (android.app.FragmentManager)1 FragmentTransaction (android.app.FragmentTransaction)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 File (java.io.File)1 HttpURLConnection (java.net.HttpURLConnection)1 TextFile (run.wallet.common.TextFile)1 JSONException (run.wallet.common.json.JSONException)1 WebGetExchangeRatesHistoryRequest (run.wallet.iota.api.requests.WebGetExchangeRatesHistoryRequest)1