You are here

function _fontsquirrel_api_get_fonts_from_api in @font-your-face 8.3

Retrieves fonts from api and parses them for consumption.

Return value

array List of fonts ready for ingesting as FontInterface objects.

1 call to _fontsquirrel_api_get_fonts_from_api()
fontsquirrel_api_fontyourface_import in modules/fontsquirrel_api/fontsquirrel_api.module
Implements hook_fontyourface_import().

File

modules/fontsquirrel_api/fontsquirrel_api.module, line 217
Font Squirrel API module file.

Code

function _fontsquirrel_api_get_fonts_from_api() {
  try {
    $uri = 'https://www.fontsquirrel.com/api/fontlist/all';
    $response = \Drupal::httpClient()
      ->get($uri, [
      'headers' => [
        'Accept' => 'text/plain',
      ],
    ]);
    $data = json_decode($response
      ->getBody());
  } catch (RequestException $e) {
    Drupal::messenger()
      ->addMessage(t('There was an error downloading font list from Font Squirrel.'), 'error');
    fontyourface_log('Invalid drupal_http_request response: @response', [
      '@response' => $e
        ->getMessage(),
    ]);
    return FALSE;
  }
  return $data;
}