You are here

protected function FacebookAlbum::response_to_array in Facebook Album 8

Convert the API response into an array based on the content type Currently only, json and plain-text responses are supported

Parameters

$content_type: The type of content returned in the response. I.e. (json, plain-text, html)

$response: The actual response to convert

Return value

mixed A response converted to an array

1 call to FacebookAlbum::response_to_array()
FacebookAlbum::get in src/FacebookAlbum.php
Make a request to the specified url and return a converted response

File

src/FacebookAlbum.php, line 148
Contains \Drupal\facebook_album\FacebookAlbum.

Class

FacebookAlbum
Facebook Album.

Namespace

Drupal\facebook_album

Code

protected function response_to_array($content_type, $response) {
  if (strpos($content_type[0], "text/plain") !== FALSE) {
    $array = [];
    $a = explode(',', $response);
    foreach ($a as $response) {
      $b = explode('=', $response);
      $array[$b[0]] = $b[1];
    }
    $response = $array;
  }
  else {
    if (!($response = Json::decode($response))) {
      $response = [];
      $response['error']['message'] = t("Unrecognized response type. Unable to parse data.");
      $response['error']['code'] = 10000;
    }
  }
  if (!isset($response['data'])) {
    $response['data'] = [];
  }
  return $response;
}