Exemplo n.º 1
0
 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());
     }
 }
Exemplo n.º 2
0
 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();
 }
Exemplo n.º 3
0
 /**
  * retrieves the request body as a ResponseObject 
  *
  * returns ResponseObject
  */
 public function getDecodedBody()
 {
     return ResponseObjectBuilder::buildFromJSON($this->body);
 }
Exemplo n.º 4
0
 public function testResponse()
 {
     $response = (new ResponseObjectBuilder())->responseCode(12345)->errorCode('12345')->message('my message')->body('{"message":"text"}')->build();
     $this->assertEquals($response, ResponseObjectBuilder::buildFromJSON($response->getJSONString()));
 }