2020-07-02 05:07:27 +00:00
|
|
|
import { AdapterTypes, ModelRegistry } from './framework/model-registry';
|
|
|
|
import { APIAdapter } from './framework/api/api-adapter';
|
|
|
|
import { AxiosAPIService } from './framework/api/axios/axios-api-service';
|
2020-07-01 20:58:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes all of the APIAdapters with a client to communicate with the API.
|
|
|
|
*
|
|
|
|
* @param {ModelRegistry} registry The model registry that we want to initialize.
|
|
|
|
* @param {string} apiURL The base URL for the API.
|
|
|
|
* @param {string} consumerKey The OAuth consumer key for the API service.
|
|
|
|
* @param {string} consumerSecret The OAuth consumer secret for the API service.
|
|
|
|
*/
|
|
|
|
export function initializeAPIAdapters(
|
|
|
|
registry: ModelRegistry,
|
|
|
|
apiURL: string,
|
|
|
|
consumerKey: string,
|
|
|
|
consumerSecret: string,
|
|
|
|
): void {
|
|
|
|
const adapters = registry.getAdapters( AdapterTypes.API ) as APIAdapter<any>[];
|
|
|
|
if ( ! adapters.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const apiService = new AxiosAPIService( apiURL, consumerKey, consumerSecret );
|
|
|
|
for ( const adapter of adapters ) {
|
|
|
|
adapter.setAPIService( apiService );
|
|
|
|
}
|
|
|
|
}
|