public function NetlifyManager::retrieveLatestBuildsFromNetlifyForEnvironment in Build Hooks 8.2
Same name and namespace in other branches
- 3.x modules/build_hooks_netlify/src/NetlifyManager.php \Drupal\build_hooks_netlify\NetlifyManager::retrieveLatestBuildsFromNetlifyForEnvironment()
 
Get the latest builds from netlify for and environment.
Parameters
array $settings: The plugin settings array.
int $limit: Number of desired builds to retrieve.
Return value
array An array with info about the builds.
Throws
\GuzzleHttp\Exception\GuzzleException
Overrides NetlifyManagerInterface::retrieveLatestBuildsFromNetlifyForEnvironment
File
- modules/
build_hooks_netlify/ src/ NetlifyManager.php, line 60  
Class
- NetlifyManager
 - Class NetlifyManager.
 
Namespace
Drupal\build_hooks_netlifyCode
public function retrieveLatestBuildsFromNetlifyForEnvironment(array $settings, $limit = 1) {
  $url = $this
    ->buildNetlifyApiRetrieveBuildsUrl($settings);
  $options = [
    'headers' => [
      'Accept' => 'application/json',
    ],
  ];
  $response = $this->httpClient
    ->request('GET', $url, $options);
  $payload = json_decode($response
    ->getBody()
    ->getContents(), TRUE);
  // Since there is no way in the api to filter by branch,
  // we do it by filtering the results:
  $results = array_filter($payload, $this
    ->filterByBranch($settings['branch']));
  return array_slice($results, 0, $limit);
}