use of com.android.volley.toolbox.JsonObjectRequest in project yellowmessenger-sdk by yellowmessenger.
the class XMPPService method createUser.
private void createUser(final String username) {
if (creatingUser) {
return;
}
try {
creatingUser = true;
String salt = "a04aa6a74e76bf8f57b0e2e715138171";
MessageDigest md = MessageDigest.getInstance("MD5");
md.update((username + salt).getBytes());
byte[] byteData = md.digest();
// convert the byte to hex format method 1
StringBuffer sb = new StringBuffer();
for (int i = 0; i < byteData.length; i++) {
sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
}
String hash = sb.toString();
String url = "https://sso.botplatform.io/createUser";
JSONObject jsonObject = new JSONObject();
jsonObject.put("username", username);
jsonObject.put("hash", hash);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
if (response.getBoolean("success") && PreferencesManager.getInstance(getBaseContext()).getXMPPUser() == null) {
JSONObject data = response.getJSONObject("data");
PreferencesManager.getInstance(getBaseContext()).setXMPPUser(new XMPPUser(data.getString("username"), data.getString("password")));
creatingUser = false;
XMPPService.this.login();
}
} catch (Exception e) {
e.printStackTrace();
creatingUser = false;
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
creatingUser = false;
}
});
jsonObjectRequest.setRetryPolicy(retryPolicy);
if (PreferencesManager.getInstance(getBaseContext()).getXMPPUser() == null) {
queue.add(jsonObjectRequest);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.android.volley.toolbox.JsonObjectRequest in project MPW by shineangelic.
the class KratosInstrumentedTest method testJsonWalletRequest.
@Test
public void testJsonWalletRequest() throws Exception {
final GsonBuilder builder = new GsonBuilder();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getWalletStatsUrl(sharedPreferences) + minerAddr, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(final JSONObject response) {
Log.i(Constants.TAG, response.toString());
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
Wallet retrieved = gson.fromJson(response.toString(), Wallet.class);
assertNotNull(retrieved);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(Constants.TAG, "Error: " + error.getMessage());
fail(error.getMessage());
}
});
// Adding request to request queue
JSONClientSingleton.getInstance(appContext).addToRequestQueue(jsonObjReq);
}
use of com.android.volley.toolbox.JsonObjectRequest in project MPW by shineangelic.
the class KratosInstrumentedTest method testJsonBlockRequest.
@Test
public void testJsonBlockRequest() throws Exception {
final GsonBuilder builder = new GsonBuilder();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getBlocksURL(sharedPreferences), null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(final JSONObject response) {
Log.i(Constants.TAG, response.toString());
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
Block retrieved = gson.fromJson(response.toString(), Block.class);
assertNotNull(retrieved);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(Constants.TAG, "Error: " + error.getMessage());
fail(error.getMessage());
}
});
// Adding request to request queue
JSONClientSingleton.getInstance(appContext).addToRequestQueue(jsonObjReq);
}
use of com.android.volley.toolbox.JsonObjectRequest in project MPW by shineangelic.
the class MainActivity method issueRefresh.
private void issueRefresh(final PoolDbHelper mDbHelper, final GsonBuilder builder) {
Log.i(Constants.TAG, "JsonObjectRequest for: " + Utils.getHomeStatsURL(PreferenceManager.getDefaultSharedPreferences(MainActivity.this)));
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getHomeStatsURL(PreferenceManager.getDefaultSharedPreferences(MainActivity.this)), null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(final JSONObject response) {
Log.d(Constants.TAG, response.toString());
hashText.post(new Runnable() {
@Override
public void run() {
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
HomeStats retrieved = gson.fromJson(response.toString(), HomeStats.class);
mDbHelper.logHomeStats(retrieved);
// dati semi grezzi
int radioButtonID = radioGroupBackTo.getCheckedRadioButtonId();
View radioButton = findViewById(radioButtonID);
storia = mDbHelper.getHistoryData(BackToEnum.valueOf((String) radioButton.getTag()));
updateCurrentStats();
final RadioButton radioDay = findViewById(R.id.radioButtonDay);
final RadioButton radioMin = findViewById(R.id.radioButtonMinutes);
GranularityEnum granoEnum = GranularityEnum.HOUR;
if (radioDay.isChecked())
granoEnum = GranularityEnum.DAY;
else if (radioMin.isChecked())
granoEnum = GranularityEnum.MINUTE;
ChartUtils.drawDifficultyHistory(textViewNetDiffTitle, PoolQueryGrouper.groupAvgQueryResult(storia, granoEnum), (LineView) findViewById(R.id.line_view_difficulty), granoEnum);
ChartUtils.drawHashrateHistory(hashText, PoolQueryGrouper.groupAvgQueryResult(storia, granoEnum), (LineView) findViewById(R.id.line_view_hashrate), granoEnum);
}
});
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(Constants.TAG, "Error: " + error.getMessage());
Snackbar.make(findViewById(android.R.id.content), "Network Error", Snackbar.LENGTH_SHORT).show();
// prevent stale data appear
updateCurrentStats();
}
});
/*
JsonArrayRequest jsonArrayCurrenciesReq = new JsonArrayRequest(Request.Method.GET,
Constants.ETHER_STATS_URL, null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(final JSONArray response) {
Log.d(Constants.TAG, response.toString());
hashText.post(new Runnable() {
@Override
public void run() {
Gson gson = builder.create();
Log.d(Constants.TAG, response.toString());
Type listType = new TypeToken<List<Ticker>>() {}.getType();
List<Ticker> posts = gson.fromJson(response.toString(), listType);
Ticker fnd = null;
for (Ticker currency : posts) {
if (mCur.name().equalsIgnoreCase(currency.getSymbol()) || mCur.toString().equalsIgnoreCase(currency.getName())) {
fnd = currency;
}
//always save ETH
if (CurrencyEnum.ETH.name().equalsIgnoreCase(currency.getSymbol())) {
CryptoSharedPreferencesUtils.saveEthereumValues(currency, MainActivity.this);
}
//always save BTC
if (CurrencyEnum.BTC.name().equalsIgnoreCase(currency.getSymbol())) {
CryptoSharedPreferencesUtils.saveBtcValues(currency, MainActivity.this);
}
}
//eventually resets when fnd = null
CryptoSharedPreferencesUtils.saveEtherValues(fnd, MainActivity.this);
}
});
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(Constants.TAG, "Error: " + error.getMessage());
Crashlytics.logException(error);
}
});*/
// Adding request to request queue
JSONClientSingleton.getInstance(this).addToRequestQueue(jsonObjReq);
// JSONClientSingleton.getInstance(this).addToRequestQueue(jsonArrayCurrenciesReq);
}
use of com.android.volley.toolbox.JsonObjectRequest in project MPW by shineangelic.
the class MinersActivity method fetchMinerStats.
private void fetchMinerStats(final MinerDBRecord rec) {
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Utils.getWalletStatsUrl(PreferenceManager.getDefaultSharedPreferences(this)) + rec.getAddress(), null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// update known miners TABLE
Log.d(Constants.TAG, response.toString());
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
final Wallet retrieved = gson.fromJson(response.toString(), Wallet.class);
if (retrieved.getWorkersTotal() > (rec.getTopMiners() == null ? -1 : rec.getTopMiners()))
rec.setTopMiners(retrieved.getWorkersTotal());
if (retrieved.getCurrentHashrate() > (rec.getTopHr() == null ? -1 : rec.getTopHr()))
rec.setTopHr(retrieved.getCurrentHashrate());
rec.setPaid(retrieved.getStats().getPaid());
try {
// compute first paymt
Payment pp = retrieved.getPayments().get(retrieved.getPayments().size() - 1);
rec.setFirstSeen(pp.getTimestamp());
} catch (Exception io) {
// dont look back in anger
}
rec.setAvgHr(rec.getAvgHr() == null ? retrieved.getHashrate() : ((rec.getAvgHr() + retrieved.getHashrate()) / 2));
// aggiorna UI
rec.setLastSeen(retrieved.getStats().getLastShare());
rec.setBlocksFound(retrieved.getStats().getBlocksFound());
mDbHelper.updateMiner(rec);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e(Constants.TAG, "Error: " + error.getMessage());
}
});
// Adding request to request queue
JSONClientSingleton.getInstance(this).addToRequestQueue(jsonObjReq);
}
Aggregations