88use GuzzleHttp \Exception \GuzzleException ;
99use ProcessMaker \Exception \HttpResponseException ;
1010use ProcessMaker \Helpers \DataTypeHelper ;
11- use ProcessMaker \WebServices \JsonResponseMapper ;
11+ use ProcessMaker \WebServices \RestResponseMapper ;
1212use ProcessMaker \WebServices \RestRequestBuilder ;
1313use ProcessMaker \WebServices \RestServiceCaller ;
14- use ProcessMaker \WebServices \WebServiceConfigBuilder ;
14+ use ProcessMaker \WebServices \RestConfigBuilder ;
1515
1616trait MakeHttpRequests
1717{
@@ -32,7 +32,7 @@ public function request(array $requestData = [], array $config = [])
3232 {
3333 try {
3434 $ request = $ this ->prepareRequestWithOutboundConfig ($ requestData , $ config );
35- $ response = $ this ->call (... $ request );
35+ $ response = $ this ->call ($ request );
3636 return $ this ->responseWithHeaderData ($ response , $ requestData , $ config );
3737 } catch (ClientException $ exception ) {
3838 throw new HttpResponseException ($ exception ->getResponse ());
@@ -41,7 +41,7 @@ public function request(array $requestData = [], array $config = [])
4141
4242 public function prepareRequestWithOutboundConfig ($ data , $ config )
4343 {
44- $ configBuilder = new WebServiceConfigBuilder ();
44+ $ configBuilder = new RestConfigBuilder ();
4545 $ requestBuilder = new RestRequestBuilder ($ this ->client ?? null );
4646 $ dsConfig = ['endpoints ' => $ this ->endpoints , 'credentials ' => $ this ->credentials , 'authtype ' => $ this ->authtype ];
4747 //TODO mover para que config no necesite una prop. privada
@@ -57,12 +57,12 @@ private function responseWithHeaderData($response, array $data = [], array $conf
5757 if (is_array ($ response )) {
5858 $ status = $ response ['status ' ];
5959 $ bodyContent = $ response ['response ' ];
60- $ responseHeaders = $ response ['headers ' ] ?? [];
60+ $ headers = $ response ['headers ' ] ?? [];
6161 }
6262 else {
6363 $ status = $ response ->getStatusCode ();
6464 $ bodyContent = $ response ->getBody ()->getContents ();
65- $ responseHeaders = $ response ->getHeaders ();
65+ $ headers = $ response ->getHeaders ();
6666 }
6767
6868 if (!DataTypeHelper::isJson ($ bodyContent )) {
@@ -80,19 +80,19 @@ private function responseWithHeaderData($response, array $data = [], array $conf
8080 throw new HttpResponseException ($ response );
8181 }
8282
83- $ mapper = new JsonResponseMapper ();
83+ $ mapper = new RestResponseMapper ();
8484 $ dsConfig = ['endpoints ' => $ this ->endpoints , 'credentials ' => $ this ->credentials ];
85- $ mapped = $ mapper ->map ($ content , $ status , $ responseHeaders , $ config , $ dsConfig , $ data );
85+ $ responseData = compact ('content ' , 'status ' , 'headers ' );
86+ $ config ['dataSourceInfo ' ] = $ dsConfig ;
87+ $ mapped = $ mapper ->map ($ responseData , $ config , $ data );
8688
8789 return $ mapped ;
8890 }
8991
90- //private function call($method, $url, array $headers, $body, $bodyType)
91- private function call (...$ request )
92+ private function call ($ request )
9293 {
9394 $ client = $ this ->client ?? new Client (['verify ' => $ this ->verifySsl ]);
9495 $ caller = new RestServiceCaller ($ client );
95- return $ caller ->call ($ this -> config , ... $ request );
96+ return $ caller ->call ($ request );
9697 }
97-
9898}
0 commit comments