public function __construct(ResponseObjectBuilder $builder) { $this->setResponseCode($builder->getResponseCode()); $this->setMessage($builder->getMessage()); $this->setErrorCode($builder->getErrorCode()); if ($builder->getBody() != NULL) { $this->setBody($builder->getBody()); } }
public static function buildFromJSON($json) { // TODO parse and verify json $jsonObject = json_decode($json); $builder = new ResponseObjectBuilder(); $builder->responseCode($jsonObject->responseCode); if (property_exists($jsonObject, 'message')) { $builder->message($jsonObject->message); } if (property_exists($jsonObject, 'errorCode')) { $builder->errorCode($jsonObject->errorCode); } if (property_exists($jsonObject, 'body')) { $builder->body(json_encode($jsonObject->body)); } return $builder->build(); }
/** * retrieves the request body as a ResponseObject * * returns ResponseObject */ public function getDecodedBody() { return ResponseObjectBuilder::buildFromJSON($this->body); }
public function testResponse() { $response = (new ResponseObjectBuilder())->responseCode(12345)->errorCode('12345')->message('my message')->body('{"message":"text"}')->build(); $this->assertEquals($response, ResponseObjectBuilder::buildFromJSON($response->getJSONString())); }