/** * @param string $level * @param ResponseInterface $response * @param array $context */ public function logResponse($level, ResponseInterface $response, array $context = array()) { $msg = "[FacebookAPI] [Response] \n"; $msg .= $response->getStatusCode() . ' '; foreach ($response->getHeaders() as $name => $value) { $msg .= "\r\n{$name}: " . $value; } $message = "{$msg}\r\n\r\n" . $response->getBody(); $this->logger->log($level, $message, $context); }
/** * @param ResponseInterface $response * @return array * @throws \InvalidArgumentException */ protected function assureResponseData(ResponseInterface $response) { $content = $response->getContent(); if (!isset($content['data']) || !is_array($content['data'])) { throw new \InvalidArgumentException("Malformed response data"); } return $content['data']; }
/** * @param ResponseInterface $response */ public function __construct(ResponseInterface $response) { $content = array('error' => array('message' => 'Empty Response')); $response->setBody(json_encode($content)); parent::__construct($response); }
/** * @return int */ public function getHttpStatusCode() { return $this->response->getStatusCode(); }
/** * @param ResponseInterface $response * @return array * @throws \InvalidArgumentException */ protected function assureResponseData(ResponseInterface $response) { $content = $response->getContent(); // First, check if the content contains data if (isset($content['data']) && is_array($content['data'])) { $data = $content['data']; // If data is an object wrap the object into an array if ($this->isJsonObject($data)) { $data = array($data); } return $data; } // Second, check if the content contains special entries if (isset($content['targetingsentencelines'])) { return $content['targetingsentencelines']; } if (isset($content['adaccounts'])) { return $content['adaccounts']; } if (isset($content['users'])) { return $content['users']; } // Third, check if the content is an array of objects indexed by id $is_id_indexed_array = true; $objects = array(); if (is_array($content) && count($content) >= 1) { foreach ($content as $key => $value) { if ($key === '__fb_trace_id__') { continue; } if ($value !== null && $this->isJsonObject($value) && isset($value['id']) && $value['id'] !== null && $value['id'] === $key) { $objects[] = $value; } else { $is_id_indexed_array = false; break; } } } else { $is_id_indexed_array = false; } if ($is_id_indexed_array) { return $objects; } throw new \InvalidArgumentException("Malformed response data"); }