Author: Nate Good (me@nategood.com)
コード例 #1
0
 protected static function process_response(Response $response)
 {
     if ($response->hasBody()) {
         return $response->body;
     } else {
         throw 'Invalid Response';
     }
 }
コード例 #2
0
 /**
  * Handle the response returned by the server
  *
  * Child classes could override this method to do something with the response.
  * By default this class throws an exception when the response has han error
  *
  * @param \Httpful\Response $response
  * @Param CRM_Civirules_TriggerData_TriggerData $triggerData
  * @param \Httpful\Request $request
  * @throws \Exception
  */
 protected function handleResponse(\Httpful\Response $response, \Httpful\Request $request, CRM_Civirules_TriggerData_TriggerData $triggerData)
 {
     //by default throw an error if response is not a 200 response
     if ($response->hasErrors()) {
         throw new Exception('Invalid response. Got a HTTP ' . $response->code . "\r\n\r\n" . $response->raw_headers . "\r\n\r\n" . $response->raw_body . "\r\n\r\nRequest was: " . $request->method . ': ' . $request->uri . "\r\n" . $request->raw_headers . "\r\n\r\n" . $request->payload);
     }
     //do something with the response. You could override this method in a child class to do something with the response.
 }
コード例 #3
0
 /**
  * Build a single response to return to the user
  * @param array $event the event that the response is related to
  * @param \Httpful\Response $response The response from the API
  * @return Response
  */
 private function buildResponse($event, $response)
 {
     $success = !$response->hasErrors();
     $duplicate = $response->code == 409;
     $statusCode = $response->code;
     $errorMessage = null;
     if ($response->code == 401) {
         $errorMessage = 'Unauthorised. Please check your Project Id and API Key';
     }
     if ($response->body != null && $response->body->errorMessage != null) {
         $errorMessage = $response->body->errorMessage;
     }
     return new Response($success, $duplicate, $statusCode, $errorMessage, $event);
 }
コード例 #4
0
ファイル: HttpfulTest.php プロジェクト: noahkim/kowop
 function testMultiHeaders()
 {
     $req = Request::init();
     $response = new Response(self::SAMPLE_JSON_RESPONSE, self::SAMPLE_MULTI_HEADER, $req);
     $parse_headers = $response->_parseHeaders(self::SAMPLE_MULTI_HEADER);
     $this->assertEquals('Value1,Value2', $parse_headers['X-My-Header']);
 }