Skip to content

Instantly share code, notes, and snippets.

@ardeay
Created April 13, 2016 16:30
Show Gist options
  • Save ardeay/7fca0db056c2837933331c75def5c3be to your computer and use it in GitHub Desktop.
Save ardeay/7fca0db056c2837933331c75def5c3be to your computer and use it in GitHub Desktop.
Example of using the EchoMTGAPI Wrapper Singleton with a call back in an activity or fragment class
// auth example, would be inside an activity or fragment class method
SharedPreferences sharedPref;
sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
String email = "your@email.com";
String pass = "asdfsbfsbsadfsa";
EchoMTGJavaAPIWrapper.getInstance(getActivity().getApplicationContext()).authRequest(new EchoMTGJavaAPIWrapper.EchoCallback(){
@Override
public void onSuccess(String result){
JSONObject jsonObject= null;
String token = null;
try {
jsonObject = new JSONObject(result);
token = jsonObject.getString("token");
} catch (JSONException e) {
e.printStackTrace();
}
Toast.makeText(getActivity().getApplicationContext(), "Successful Login", Toast.LENGTH_SHORT).show();
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString(getString(R.string.token_reference), token);
editor.commit();
}
},email,pass);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment