public function testDate() { $data = "{\"faultCause\":\"AccessDenied\",\"blame\":\"CLIENT\",\"message\":\"No such account: >>>foo<<<!\",\"applicationErrorCode\":\"1201\",\"retrySameLocation\":{\"retryType\":\"NO\"},\"retryOtherLocations\":{\"retryType\":\"NO\"},\"httpStatusCode\":401,\"httpStatusMeaning\":\"Unauthorized\"}"; $faultInfo = FaultInfoUnmarshaller::unmarshallJsonString($data); $this->assertEquals("AccessDenied", $faultInfo->getFaultCause()); $this->assertTrue($faultInfo->getBlame()->isClient()); $this->assertEquals("No such account: >>>foo<<<!", $faultInfo->getMessage()); $this->assertEquals("1201", $faultInfo->getApplicationErrorCode()); $this->assertEquals(null, $faultInfo->getIncidentId()); }
/** * @param $data The json object you got from json_decode("json string") * @return FaultInfo * @throws \Exception */ public static function unmarshallJsonObject($data) { try { $retrySame = null; if (isset($data->retrySameLocation)) { $retrySame = FaultInfoUnmarshaller::unmarshallRetry($data->retrySameLocation); } $retryOther = null; if (isset($data->retryOtherLocations)) { $retryOther = FaultInfoUnmarshaller::unmarshallRetry($data->retryOtherLocations); } return new FaultInfo($data->faultCause, new Blame($data->blame), $data->message, isset($data->applicationErrorCode) ? $data->applicationErrorCode : null, isset($data->incidentId) ? $data->incidentId : null, $retrySame, $retryOther); //httpStatusCode\":401,\"httpStatusMeaning\":\"Unauthorized\"}" } catch (\Exception $e) { throw new \Exception("Failed unmarshalling json object into FaultInfo!", 0, $e); } }