PcoCollection<T extends PcoResource>.fromApiResponse constructor

PcoCollection<T extends PcoResource>.fromApiResponse(
  1. PlanningCenterApiResponse<PlanningCenterApiData> response,
  2. dynamic endpoint,
  3. dynamic apiVersion
)

we also require the original endpoint and the apiversion so that subsequent requests like getMore and nextPage can be built easily off of this one.

Implementation

factory PcoCollection.fromApiResponse(
    PlanningCenterApiResponse response, endpoint, apiVersion) {
  List<T> items = [];

  // handle the main data
  for (var item in response.data) {
    var res = buildResource<T>(response.application, item.asMap,
        withIncluded: response.included);
    if (res != null) items.add(res as T);
  }

  return PcoCollection<T>(
      items, response.meta, response, response.query, endpoint, apiVersion);
}