Larabros\Elogram\Http\Response::createFromJson PHP Method

createFromJson() public static method

Creates a new instance of :php:class:Response from a JSON-decoded response body.
public static createFromJson ( array $response ) : static
$response array
return static
    public static function createFromJson(array $response)
    {
        $meta = array_key_exists('meta', $response) ? $response['meta'] : ['code' => 200];
        $data = array_key_exists('data', $response) ? $response['data'] : $response;
        $pagination = array_key_exists('pagination', $response) ? $response['pagination'] : [];
        return new static($meta, $data, $pagination);
    }

Usage Example

Example #1
0
 /**
  * {@inheritDoc}
  */
 public function request($method, $uri, array $parameters = [])
 {
     try {
         $response = $this->guzzle->request($method, $uri, $parameters);
     } catch (ClientException $e) {
         if (!$e->hasResponse()) {
             throw $e;
         }
         throw $this->resolveExceptionClass($e);
     } catch (Exception $e) {
         throw $e;
     }
     return Response::createFromJson(json_decode($response->getBody()->getContents(), true));
 }
All Usage Examples Of Larabros\Elogram\Http\Response::createFromJson