use of com.zype.fire.api.Model.DevicePinResponse in project zype-firebuilder by zype.
the class ZypeLoginActivity method getAccessTokenWithPin.
public void getAccessTokenWithPin() {
if (NetworkUtils.isConnectedToNetwork(this)) {
(new AsyncTask<Void, Void, Map>() {
@Override
protected Map<String, Object> doInBackground(Void... params) {
String deviceId = AdMacrosHelper.getAdvertisingId(ZypeLoginActivity.this);
// Check if the device is linked
DevicePinResponse responseDevicePin = ZypeApi.getInstance().getDevicePin(deviceId);
if (responseDevicePin != null) {
if (responseDevicePin.data.linked) {
// If linked get access token with device pin
return ZypeAuthentication.getAccessTokenWithPin(deviceId, pin);
} else {
return null;
}
} else {
return null;
}
}
@Override
protected void onPostExecute(Map response) {
super.onPostExecute(response);
if (response != null) {
// Successful login.
ZypeAuthentication.saveAccessToken(response);
setResult(RESULT_OK);
buttonLogin.setEnabled(true);
finish();
} else {
buttonLogin.setEnabled(true);
// There was an error authenticating the user entered token.
setResultAndReturn(null, AuthenticationConstants.AUTHENTICATION_ERROR_CATEGORY);
}
}
}).execute();
} else {
setResultAndReturn(null, AuthenticationConstants.NETWORK_ERROR_CATEGORY);
}
}
use of com.zype.fire.api.Model.DevicePinResponse in project zype-firebuilder by zype.
the class ZypeApi method createDevicePin.
public DevicePinResponse createDevicePin(String deviceId) {
try {
HashMap<String, String> params = new HashMap<>();
params.put(APP_KEY, ZypeSettings.APP_KEY);
params.put(LINKED_DEVICE_ID, deviceId);
Response response = apiImpl.createDevicePin(params).execute();
if (response.isSuccessful()) {
return (DevicePinResponse) response.body();
} else {
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
use of com.zype.fire.api.Model.DevicePinResponse in project zype-firebuilder by zype.
the class ZypeApi method getDevicePin.
public DevicePinResponse getDevicePin(String deviceId) {
try {
HashMap<String, String> params = new HashMap<>();
params.put(APP_KEY, ZypeSettings.APP_KEY);
params.put(LINKED_DEVICE_ID, deviceId);
Response response = apiImpl.getDevicePin(params).execute();
if (response.isSuccessful()) {
return (DevicePinResponse) response.body();
} else {
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
Aggregations