Search in sources :

Example 21 with ApiCategory

use of com.amplifyframework.api.ApiCategory in project amplify-android by aws-amplify.

the class TestApiCategory method fromConfiguration.

/**
 * Creates an instance of {@link ApiCategory}, using the provided configuration
 * file, referred to by its android resource ID.
 * @return A configured and initialized ApiCategory instance
 */
@NonNull
static ApiCategory fromConfiguration(@RawRes int resourceId) throws AmplifyException {
    CognitoUserPoolsAuthProvider cognitoUserPoolsAuthProvider = new DefaultCognitoUserPoolsAuthProvider(AWSMobileClient.getInstance());
    ApiAuthProviders providers = ApiAuthProviders.builder().awsCredentialsProvider(AWSMobileClient.getInstance()).cognitoUserPoolsAuthProvider(cognitoUserPoolsAuthProvider).build();
    AWSApiPlugin plugin = AWSApiPlugin.builder().apiAuthProviders(providers).build();
    ApiCategory apiCategory = new ApiCategory();
    apiCategory.addPlugin(plugin);
    CategoryConfiguration apiConfiguration = AmplifyConfiguration.fromConfigFile(getApplicationContext(), resourceId).forCategoryType(CategoryType.API);
    apiCategory.configure(apiConfiguration, getApplicationContext());
    // apiCategory.initialize(...); Doesn't currently contain any logic, so, skip it.
    return apiCategory;
}
Also used : DefaultCognitoUserPoolsAuthProvider(com.amplifyframework.api.aws.sigv4.DefaultCognitoUserPoolsAuthProvider) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration) ApiCategory(com.amplifyframework.api.ApiCategory) DefaultCognitoUserPoolsAuthProvider(com.amplifyframework.api.aws.sigv4.DefaultCognitoUserPoolsAuthProvider) CognitoUserPoolsAuthProvider(com.amplifyframework.api.aws.sigv4.CognitoUserPoolsAuthProvider) NonNull(androidx.annotation.NonNull)

Aggregations

ApiCategory (com.amplifyframework.api.ApiCategory)21 JSONObject (org.json.JSONObject)9 Test (org.junit.Test)9 SynchronousDataStore (com.amplifyframework.testutils.sync.SynchronousDataStore)8 Context (android.content.Context)7 ApplicationProvider.getApplicationContext (androidx.test.core.app.ApplicationProvider.getApplicationContext)6 Person (com.amplifyframework.testmodels.personcar.Person)6 Before (org.junit.Before)6 RawRes (androidx.annotation.RawRes)5 AWSApiPlugin (com.amplifyframework.api.aws.AWSApiPlugin)5 GraphQLResponse (com.amplifyframework.api.graphql.GraphQLResponse)5 CategoryConfiguration (com.amplifyframework.core.category.CategoryConfiguration)5 ModelWithMetadata (com.amplifyframework.datastore.appsync.ModelWithMetadata)5 HubAccumulator (com.amplifyframework.testutils.HubAccumulator)5 ApiCategoryConfiguration (com.amplifyframework.api.ApiCategoryConfiguration)4 GraphQLRequest (com.amplifyframework.api.graphql.GraphQLRequest)4 Consumer (com.amplifyframework.core.Consumer)4 AndroidLoggingPlugin (com.amplifyframework.logging.AndroidLoggingPlugin)4 ApiEndpointStatusChangeEvent (com.amplifyframework.api.events.ApiEndpointStatusChangeEvent)3 PaginatedResult (com.amplifyframework.api.graphql.PaginatedResult)3