use of com.zype.fire.api.Model.ConsumerResponse in project zype-firebuilder by zype.
the class ZypeApi method getConsumer.
public ConsumerResponse getConsumer(String consumerId, String accessToken) {
try {
HashMap<String, String> params = new HashMap<>();
params.put(ACCESS_TOKEN, accessToken);
Response response = apiImpl.getConsumer(consumerId, params).execute();
if (response.isSuccessful()) {
return (ConsumerResponse) response.body();
} else {
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
use of com.zype.fire.api.Model.ConsumerResponse in project zype-firebuilder by zype.
the class ZypeAuthentication method getAccessTokenWithPin.
public static Map<String, Object> getAccessTokenWithPin(String deviceId, String pin) {
AccessTokenResponse responseAccessToken = ZypeApi.getInstance().retrieveAccessTokenWithPin(deviceId, pin);
AccessTokenInfoResponse responseAccessTokenInfo = null;
ConsumerResponse responseConsumer = null;
if (responseAccessToken != null) {
responseAccessTokenInfo = ZypeApi.getInstance().getAccessTokenInfo(responseAccessToken.getAccessToken());
if (responseAccessTokenInfo != null) {
responseConsumer = ZypeApi.getInstance().getConsumer(responseAccessTokenInfo.resourceOwnerId, responseAccessToken.getAccessToken());
}
} else {
return null;
}
Map<String, Object> result = new HashMap<>();
result.put(RESPONSE_ACCESS_TOKEN, responseAccessToken);
result.put(RESPONSE_ACCESS_TOKEN_INFO, responseAccessTokenInfo);
result.put(RESPONSE_CONSUMER, responseConsumer);
result.put(RESPONSE_IS_DEVICE_LINKED, true);
return result;
}
use of com.zype.fire.api.Model.ConsumerResponse in project zype-firebuilder by zype.
the class ZypeApi method unlinkDevicePin.
public ConsumerResponse unlinkDevicePin(String consumerId, String pin) {
try {
HashMap<String, String> params = new HashMap<>();
params.put(APP_KEY, ZypeSettings.APP_KEY);
params.put(CONSUMER_ID, consumerId);
params.put(PIN, pin);
Response response = apiImpl.unlinkDevicePin(params).execute();
if (response.isSuccessful()) {
return (ConsumerResponse) response.body();
} else {
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
use of com.zype.fire.api.Model.ConsumerResponse in project zype-firebuilder by zype.
the class ZypeAuthentication method refreshToken.
private Map<String, Object> refreshToken(ResponseHandler responseHandler) {
AccessTokenResponse responseAccessToken = ZypeApi.getInstance().refreshAccessToken(Preferences.getString(PREFERENCE_REFRESH_TOKEN));
AccessTokenInfoResponse responseAccessTokenInfo = null;
ConsumerResponse responseConsumer = null;
if (responseAccessToken != null) {
responseAccessTokenInfo = ZypeApi.getInstance().getAccessTokenInfo(responseAccessToken.getAccessToken());
if (responseAccessTokenInfo != null) {
responseConsumer = ZypeApi.getInstance().getConsumer(responseAccessTokenInfo.resourceOwnerId, responseAccessToken.getAccessToken());
}
} else {
return null;
}
Map<String, Object> result = new HashMap<>();
result.put(RESPONSE_ACCESS_TOKEN, responseAccessToken);
result.put(RESPONSE_ACCESS_TOKEN_INFO, responseAccessTokenInfo);
result.put(RESPONSE_CONSUMER, responseConsumer);
result.put(RESPONSE_IS_DEVICE_LINKED, Preferences.getBoolean(PREFERENCE_IS_DEVICE_LINKED));
return result;
}
use of com.zype.fire.api.Model.ConsumerResponse in project zype-firebuilder by zype.
the class ZypeAuthentication method getAccessToken.
public static Map<String, Object> getAccessToken(String username, String password) {
// Save user name and password for re-login
// TODO: Save encoded password
Preferences.setString(ZypeAuthentication.PREFERENCE_CONSUMER_EMAIL, username);
Preferences.setString(ZypeAuthentication.PREFERENCE_CONSUMER_PASSWORD, password);
AccessTokenResponse responseAccessToken = ZypeApi.getInstance().retrieveAccessToken(username, password);
AccessTokenInfoResponse responseAccessTokenInfo = null;
ConsumerResponse responseConsumer = null;
if (responseAccessToken != null) {
responseAccessTokenInfo = ZypeApi.getInstance().getAccessTokenInfo(responseAccessToken.getAccessToken());
if (responseAccessTokenInfo != null) {
responseConsumer = ZypeApi.getInstance().getConsumer(responseAccessTokenInfo.resourceOwnerId, responseAccessToken.getAccessToken());
}
} else {
return null;
}
Map<String, Object> result = new HashMap<>();
result.put(RESPONSE_ACCESS_TOKEN, responseAccessToken);
result.put(RESPONSE_ACCESS_TOKEN_INFO, responseAccessTokenInfo);
result.put(RESPONSE_CONSUMER, responseConsumer);
result.put(RESPONSE_IS_DEVICE_LINKED, false);
return result;
}
Aggregations