Beispiel #1
0
 private function getSchema() : Schema
 {
     if (null === $this->jsonSchema) {
         $response = $this->execute($this->api->getImageSchema());
         $this->jsonSchema = new Schema(Utils::jsonDecode($response, false));
     }
     return $this->jsonSchema;
 }
Beispiel #2
0
 /**
  * {@inheritDoc}
  */
 public function populateFromResponse(ResponseInterface $response) : self
 {
     $entries = Utils::jsonDecode($response)['access']['serviceCatalog'];
     foreach ($entries as $entry) {
         $this->entries[] = $this->model(Entry::class, $entry);
     }
     return $this;
 }
 /**
  * Populates the current resource from a response object.
  *
  * @param ResponseInterface $response
  *
  * @return AbstractResource
  */
 public function populateFromResponse(ResponseInterface $response) : self
 {
     if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) {
         $json = Utils::jsonDecode($response);
         if (!empty($json)) {
             $this->populateFromArray(Utils::flattenJson($json, $this->resourceKey));
         }
     }
     return $this;
 }
Beispiel #4
0
 private function fetchResources()
 {
     if ($this->shouldNotSendAnotherRequest()) {
         return false;
     }
     $response = call_user_func($this->requestFn, $this->currentMarker);
     $json = Utils::flattenJson(Utils::jsonDecode($response), $this->resourcesKey);
     if ($response->getStatusCode() === 204 || empty($json)) {
         return false;
     }
     return $json;
 }
Beispiel #5
0
 public function parseMetadata(ResponseInterface $response) : array
 {
     $json = Utils::jsonDecode($response);
     return isset($json['metadata']) ? $json['metadata'] : [];
 }
 public function extractMultipleInstances(ResponseInterface $response, string $key = null) : array
 {
     $key = $key ?: $this->getResourcesKey();
     $resourcesData = Utils::jsonDecode($response)[$key];
     $resources = [];
     foreach ($resourcesData as $resourceData) {
         $resources[] = $this->newInstance()->populateFromArray($resourceData);
     }
     return $resources;
 }
Beispiel #7
0
 public function parseMetadata(ResponseInterface $response) : array
 {
     return Utils::jsonDecode($response)['metadata'];
 }
Beispiel #8
0
 /**
  * {@inheritDoc}
  */
 public function populateFromResponse(ResponseInterface $response) : self
 {
     $this->populateFromArray(Utils::jsonDecode($response)['access']['token']);
     return $this;
 }
Beispiel #9
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function test_decoding_malformed_json_throws_error()
 {
     $response = new Response(200, [], \GuzzleHttp\Psr7\stream_for('{'));
     Utils::jsonDecode($response);
 }