public function callApi($path, $data, $type = self::POST, $json = true) { if (!$this->checkToken()) { throw CouldNotSendNotification::invalidFacebookToken(); } try { if ($json) { $response = $this->client->request($type, $this->api_url . $path, ['query' => ['access_token' => $this->token], 'json' => $data]); } else { $data['access_token'] = $this->token; $response = $this->client->request($type, $this->api_url . $path, ['query' => $data]); } if ($response->getStatusCode() == 200) { return json_decode($response->getBody()); } else { throw CouldNotSendNotification::invalidStatusCode($response->getStatusCode()); } } catch (ClientException $ex) { throw CouldNotSendNotification::facebookResponseError($ex); } catch (\Exception $ex) { throw CouldNotSendNotification::couldNotCommunicateWithFacebook($ex); } }