use of com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest in project aws-sdk-android by aws-amplify.
the class DeviceOperations method _listDevices.
private ReturningRunnable<ListDevicesResult> _listDevices(final Integer limit, final String paginationToken) {
return new ReturningRunnable<ListDevicesResult>() {
@Override
public ListDevicesResult run() throws Exception {
final ListDevicesRequest listDevicesRequest = new ListDevicesRequest();
listDevicesRequest.setAccessToken(mobileClient.getTokens().getAccessToken().getTokenString());
listDevicesRequest.setLimit(limit);
listDevicesRequest.setPaginationToken(paginationToken);
final com.amazonaws.services.cognitoidentityprovider.model.ListDevicesResult listDevicesResult = userpoolLL.listDevices(listDevicesRequest);
final ArrayList<Device> devices = new ArrayList<Device>(limit);
for (DeviceType deviceType : listDevicesResult.getDevices()) {
devices.add(marshallDeviceTypeToDevice(deviceType));
}
return new ListDevicesResult(devices, listDevicesResult.getPaginationToken());
}
};
}
use of com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest in project aws-sdk-android by aws-amplify.
the class CognitoUser method listDevicesInternal.
/**
* Internal method to fetch all devices trusted by this user.
*
* @param session REQUIRED: A valid {@link CognitoUserSession}.
* @param limit REQUIRED: Maximum number of devices to fetch.
* @param paginationToken REQUIRED: Token to continue with the previous
* srearch.
* @return {@link ListDevicesResult}, service response.
*/
private ListDevicesResult listDevicesInternal(CognitoUserSession session, int limit, String paginationToken) {
if (session != null && session.isValid()) {
final ListDevicesRequest listDevicesRequest = new ListDevicesRequest();
if (limit < 1) {
listDevicesRequest.setLimit(CognitoDeviceHelper.DEFAULT_DEVICE_PAGINATION_LIMIT);
} else {
listDevicesRequest.setLimit(limit);
}
listDevicesRequest.setPaginationToken(paginationToken);
listDevicesRequest.setAccessToken(session.getAccessToken().getJWTToken());
return cognitoIdentityProviderClient.listDevices(listDevicesRequest);
} else {
throw new CognitoNotAuthorizedException("User is not authorized");
}
}
use of com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderDevicesTest method listDevicesInCurrentThread.
@Test
public void listDevicesInCurrentThread() {
// Set mock result for the change password request API call
doReturn(TEST_VALID_LIST_DEVICES_RESPONSE).when(mockCSIClient).listDevices(any(ListDevicesRequest.class));
// Store tokens in shared preferences
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + ".idToken", getValidJWT(3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
testUser.listDevices(10, "ptoken", new DevicesHandler() {
@Override
public void onSuccess(List<CognitoDevice> devices) {
assertNotNull(devices);
ArgumentCaptor<ListDevicesRequest> argumentCaptor = ArgumentCaptor.forClass(ListDevicesRequest.class);
verify(mockCSIClient).listDevices(argumentCaptor.capture());
ListDevicesRequest requestSent = argumentCaptor.getValue();
assertEquals("ptoken", requestSent.getPaginationToken());
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
}
});
}
use of com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderDevicesTest method listDevicesInBackgroundThread.
@Test
public void listDevicesInBackgroundThread() {
// Set mock result for the change password request API call
doReturn(TEST_VALID_LIST_DEVICES_RESPONSE).when(mockCSIClient).listDevices(any(ListDevicesRequest.class));
// Store tokens in shared preferences
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
testUser.listDevicesInBackground(10, "ptoken", new DevicesHandler() {
@Override
public void onSuccess(List<CognitoDevice> devices) {
assertNotNull(devices);
ArgumentCaptor<ListDevicesRequest> argumentCaptor = ArgumentCaptor.forClass(ListDevicesRequest.class);
verify(mockCSIClient).listDevices(argumentCaptor.capture());
ListDevicesRequest requestSent = argumentCaptor.getValue();
assertEquals("ptoken", requestSent.getPaginationToken());
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
}
});
}
Aggregations