Prases a response and returns a collection or item

@param Response $response
@return Collection
190232
protected function parseResponse(Response $response)
    {
        if ($response->getStatusCode() > 199 && $response->getStatusCode() < 299) {
            if ($body = json_decode($response->getBody()->getContents(), 1)) {
                return new Collection($body);
            }
        }

        return new Collection;
    }
1248642
public function getUserFromTokenResponse($response)
    {
        $user = $this->mapUserToObject($this->getUserByToken(
            $token = $this->parseAccessToken($response)
        ));

        $this->credentialsResponseBody = $response;

        if ($user instanceof User) {
            $user->setAccessTokenResponseBody($this->credentialsResponseBody);
        }

        return $user->setToken($token)
            ->setRefreshToken($this->parseRefreshToken($response))
            ->setExpiresIn($this->parseExpiresIn($response));
    }
211000
protected function handleResponse(Response $response)
    {
        $statusCode = $response->getStatusCode();

        switch ($statusCode) {
            case 401:
                $response = $this->processNotAuthorized();
                break;
        }

        return $response;
    }
781450
public function fromResponse($response)
    {
        $this->page        = $response->list_info->page;
        $this->num_pages   = $response->list_info->num_pages;
        $this->num_results = $response->list_info->num_results;
        $this->page_size   = $response->list_info->page_size;

        property_exists($response, $this->list_type) && $this->setCollection($response->{$this->list_type});

        return $this;
    }
844196
protected function fetchCorreiosServices(Response $response)
    {
        $xml = simplexml_load_string($response->getBody()->getContents());
        $results = json_decode(json_encode($xml->Servicos))->cServico;

        if (! is_array($results)) {
            return [get_object_vars($results)];
        }

        return array_map('get_object_vars', $results);
    }
93467
protected function needToUpdateResponse(Response $response)
    {
        $isJsonResponse = $response instanceof JsonResponse || $response->headers->contains('content-type',
                'application/json');

        return $isJsonResponse && !$this->storage->isEmpty();
    }
381943
protected function parseGetLanguagesResponse(Response $response)
    {
        $responseBody = $response->getBody();
        $responseData = json_decode($responseBody);
        $languages = [];
        foreach ($responseData as $language) {
            $translation = explode('-', $language);
            $from = $translation[0];
            $to = $translation[1];
            $languages[] = [$from,$to];
        }
        return $languages;
    }
1358918
private function _parseResponse(Response $response)
    {
        switch ($this->_format) {
            case self::FORMAT_JSON:
                return json_decode($response, $this->_isJsonDecodeAssoc);
                break;
            default:
                return $response;
        }
    }
1217779
private function _createItem(array $response)
    {
        $model = new Item();
        $model->setName($response[Item::FIELD_NAME])
            ->setDescription($response[Item::FIELD_DESCRIPTION])
            ->setItemNumber($response[Item::FIELD_ITEM_NUMBER])
            ->setUrl($response[Item::FIELD_URL])
            ->setAmount($response[Item::FIELD_AMOUNT])
            ->setQuantity($response[Item::FIELD_QUANTITY]);
        
        return $model;
    }
50690
public function handleResponse($response)
    {
        // recursion for batch
        if (is_array($response)) {
            $response_arr = array();
            foreach ($response as $res) {
                $response_arr[$res->id] = $this->handleResponse($res);
            }
            return $response_arr;
        }

        // return error response
        if (property_exists($response, 'error')) {
            return new Response(null, $response->id, $response->error->code, $response->error->message);
        }

        // return successful response
        return new Response($response->result, $response->id);
    }
1007273
public static function respond(Response $response)
    {
        $next = function () use ($response) {
            return $response;
        };

        (new static())->handle(Request::capture(), $next)->send();

        exit;
    }
840911
public function paginate(Response $response, $limit = null)
    {
        return $this->container->get(AdapterInterface::class)
            ->paginate($response, $limit);
    }
779336
protected function respond($response)
    {
        if (Arr::get($response, 'object') === 'list') {
            if (!empty($response['data'])) {
                foreach ($response['data'] as $responseItem) {
                    $success = Arr::get($responseItem, 'object', 'error') !== 'error';

                    $responses[] = $this->mapResponse($success, $responseItem);
                }

                return $responses;
            } else {
                $response = $response['data'];
            }
        }

        $success = Arr::get($response, 'object', 'error') !== 'error';

        return $this->mapResponse($success, $response);
    }
350603
public function filter($response)
    {
        $filter = $this->_request->getParam(static::FILTER_PARAMETER);
        if (!is_string($filter)) {
            return $response;
        }
        $filterArray = $this->parse($filter);
        if ($filterArray === null) {
            return $response;
        }
        $partialResponse = $this->applyFilter($response, $filterArray);
        return $partialResponse;
    }
1131970
public static function parseResponse(Response $response)
    {
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
        if ($jsonData && 0 == $jsonData['retcode']) {
            $recentList = [];
            foreach ($jsonData['result'] as $recent) {
                $recentList[] = EntityFactory::createEntity(Recent::class, [
                    'type' => $recent['type'],
                    'uin' => $recent['uin'],
                ]);
            }

            return new EntityCollection($recentList);
        }
        throw new ResponseException($jsonData['retcode'], $response);
    }
595415
protected function getResponse( $response ) {
		if ( is_string( $response ) ) {
			return Response::output( $response );
		}

		if ( is_array( $response ) ) {
			return Response::json( $response );
		}

		if ( $response instanceof ResponsableInterface ) {
			return $response->toResponse();
		}

		return $response;
	}
20045
private function createBucketProps(GetResponse $response)
    {
        $values = [];

        foreach ($response as $key => $value) {
            $values[$key] = $value;
        }

        if ($response->linkwalkFunction) {
            $values['linkwalkFunction'] = ErlangFunction::createFromArray($response->linkwalkFunction);
        }

        if ($response->chashKeyFunction) {
            $values['chashKeyFunction'] = ErlangFunction::createFromArray($response->chashKeyFunction);
        }

        if ($response->precommitHooks) {
            $values['precommitHooks'] = $this->parseHooks($response->precommitHooks);
        }

        if ($response->postcommitHooks) {
            $values['postcommitHooks'] = $this->parseHooks($response->postcommitHooks);
        }

        return new BucketProperties($values);
    }