/** * Factory method to create an instance of this class from a FedEx response * object. * * @param ResponseInterface $response The response object to get errors from * * @return ResponseErrorException */ public static function createFromResponse(ResponseInterface $response) { $messages = array(); foreach ($response->getNotifications()->getBySeverity(array('FAILURE', 'ERROR')) as $n) { $messages[] = sprintf('%s: (%s) %s', $n->severity, $n->code, $n->message); } $exception = new self(sprintf('FedEx API Request Failure: %s', implode(', ', $messages))); $exception->setResponse($response); return $exception; }
/** * Factory method to create a collection of notification from a FedEx API * response. * * @param ResponseInterface $response The response to get notifications from * * @return Collection */ public static function loadFromResponse(ResponseInterface $response) { $collection = new self(); if (!isset($response->getData()->Notifications)) { return $collection; } $notifications = $response->getData()->Notifications; // If there's only one notification, it's never in an array :-( if (is_object($notifications)) { $notifications = array($notifications); } foreach ($notifications as $notificationData) { $notification = new Notification(); $notification->severity = $notificationData->Severity; $notification->source = $notificationData->Source; $notification->code = $notificationData->Code; $notification->message = $notificationData->Message; $collection->add($notification); } return $collection; }