Mapping data from github

@todo replace Buzz with Guzzle

@param Reponse $response

@return array contains normalized user data
13781
public function normalizeGithub($return, $token)
    {
        $data = [
            'id'                => $return['id'],
            'username'          => $return['login'],
            'name'              => $return['name'],
            'email'             => $return['email'],
            'gravatar'          => $return['gravatar_id'],
            'avatar'            => $return['avatar_url'],
            'gitHubProfileLink' => $return['html_url'],
            'firstName'         => false,
            'lastName'          => false,
            'gender'            => false,
            'verified'          => true,
            'locale'            => false,
            'timezone'          => false,
            'isSilhouette'      => true,
            'emailVerified'     => false
        ];

        /**
         * Setup http://developer.github.com/v3/media/
         *
         * @todo application/vnd.github.v3
         */
        $data['email'] = $return['id'].'@github';

        $headers = ['Authorization: bearer '.$token];
        $response = $this->httpRequest('https://api.github.com', '/user/emails', null, $headers);


        if ($response->isOk()) {
            $emails = json_decode($response->getContent(), true);
            $lastEmail = end($emails);
            $data['email'] = $lastEmail['email'];
        }

        return $data;
    }
353404
public static function parseResponse(Response $response)
    {
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
        if ($jsonData && 0 == $jsonData['retcode']) {
            $profileData = $jsonData['result'];
            //注意获取好友详情接口并不返回account和lnick
            return EntityFactory::createEntity(Profile::class, [
                'account' => isset($profileData['account']) ? $profileData['account'] : null,
                'lnick' => isset($profileData['lnick']) ? $profileData['lnick'] : null,
                'face' => $profileData['face'],
                'birthday' => Birthday::createFromArray($profileData['birthday']),
                'occupation' => $profileData['occupation'],
                'phone' => $profileData['phone'],
                'allow' => $profileData['allow'],
                'college' => $profileData['college'],
                'uin' => $profileData['uin'],
                'constel' => $profileData['constel'],
                'blood' => $profileData['blood'],
                'homepage' => $profileData['homepage'],
                'stat' => isset($profileData['stat']) ? $profileData['stat'] : null,
                'vipInfo' => $profileData['vip_info'],
                'country' => $profileData['country'],
                'city' => $profileData['city'],
                'personal' => $profileData['personal'],
                'nick' => $profileData['nick'],
                'shengXiao' => $profileData['shengxiao'],
                'email' => $profileData['email'],
                'province' => $profileData['province'],
                'gender' => $profileData['gender'],
                'mobile' => $profileData['mobile'],
            ]);
        }
        throw new ResponseException($jsonData['retcode'], $response);
    }
483684
private function captchaResponse($response)
    {
        $errors = ['g-recaptcha-response' => ['Oops, something went wrong']];
        foreach ($response->getErrorCodes() as $k => $code) {
            if ($code == 'missing-input-response') {
                $code = 'Please confirm you are not a robot.';
            }
            $errors['g-recaptcha-response'][$k] = $code;
        }

        return new JsonResponse($errors, 422);
    }
206322
public function index(Response $response)
    {
        $payload = [
            'resources' => route('v1.books.index'),
            'authors' => route('v1.authors.index'),
        ];

        return $response->setMeta([
            'message' => "Hello, I'm a appkr/api example",
            'version' => 1,
            'documentation' => route('v1.doc'),
        ])->respond([
            'link' => $payload,
        ]);
    }
945900
public function getTags($repository)
    {
        /* @var $response Response */
        $response = $this->client->get('repos/'.$repository.'/tags')->send();

        return json_decode($response->getBody(true), true);
    }
764081
private function getResult($response)
    {
        $status = $response->getStatusCode();
        if ($status == 200) {
            return json_decode($response->getBody(), JSON_PRETTY_PRINT);
        } else {
            return [$status => $response->getReasonPhrase()];
        }
    }
1361039
public function getResults($response)
    {
        $results = array('rows' => array());

        for ($report_index = 0; $report_index < count($response); $report_index++) {

            $report = $response[$report_index];
            $header = $report->getColumnHeader();

            $dimension_headers = $header->getDimensions();
            $metric_headers = $header->getMetricHeader()->getMetricHeaderEntries();
            $rows = $report->getData()->getRows();

            for ($row_index = 0; $row_index < count($rows); $row_index++) {

                $row = $rows[$row_index];
                $dimensions = $row->getDimensions();
                $metrics = $row->getMetrics();

                for ($i = 0; $i < count($dimension_headers) && $i < count($dimensions); $i++) {
                    $results['rows'][$row_index][$dimension_headers[$i]] = $dimensions[$i];
                }

                for ($j = 0; $j < count($metrics); $j++) {
                    $values = $metrics[$j]->getValues();
                    for ($k = 0; $k < count($values); $k++) {
                        $entry = $metric_headers[$k];
                        $results['rows'][$row_index][$entry->getName()] = $values[$k];
                    }
                }
            }
        }

        return $results;
    }
255125
protected function mapResponse($success, array $response)
    {
        return (new Response())->setRaw($response)->map([
            'success' => $success,
            'message' => $success ? 'Message sent' : $response['message'],
        ]);
    }
1006395
protected function getResponseData(Response $response)
    {
        if ($response instanceof JsonResponse) {
            /** @var $response JsonResponse */
            return $response->getData(true) ?: [];
        }

        $content = $response->getContent();

        return json_decode($content, true) ?: false;
    }
543883
public function mapResponse($success, $response)
    {
        $rawResponse = $response;

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

        if ($object !== 'error' && array_key_exists('type', $response) && isset($response['data']['object'])) {
            $response = $response['data']['object'];
        }

        $type = $this->getType($rawResponse);
        list($reference, $authorization) = $success ? $this->getReferences($response, $type) : [null, null];

        $message = '';

        if ($success) {
            $message = 'Transaction approved';
        } elseif ($object === 'error') {
            foreach (Arr::get($response, 'details') as $detail) {
                $message .= ' '.Arr::get($detail, 'message', '');
            }
            $message = ltrim($message);
        } else {
            $message = Arr::get($response, 'message_to_purchaser') ?: Arr::get($response, 'message', '');
        }

        $isTest = $object === 'error' && isset($response['data'])
            ? !(Arr::get($response['data'], 'livemode', true))
            : !(Arr::get($response, 'livemode', true));

        if ($type === 'refund') {
            $rawResponse['amount_refunded'] = $this->getRefundAmount($rawResponse);
        }

        return (new Response())->setRaw($rawResponse)->map([
            'isRedirect'    => false,
            'success'       => $success,
            'reference'     => $reference,
            'message'       => $message,
            'test'          => $isTest,
            'authorization' => $authorization,
            'status'        => $success ? $this->getStatus(Arr::get($response, 'payment_status', 'paid')) : new Status('failed'),
            'errorCode'     => $success ? null : $this->getErrorCode($response),
            'type'          => $type,
        ]);
    }
554984
private function parseResponse(string $response)
    {
        if (0 === preg_match_all('~--uuid:[a-zA-Z0-9-]+~', $response, $matches, PREG_OFFSET_CAPTURE)) {
            return [[
                'headers' => [
                    'Content-Type'              => 'application/json;charset=UTF-8',
                    'Content-Transfer-Encoding' => 'binary',
                    'Content-ID'                => '<jsonInfos>',
                ],
                'body'    => $response,
            ]];
        }

        $uuids = $matches[0];

        $parts = [];

        for ($i = 0; $i < count($uuids) - 1; $i++) {
            $start = $uuids[$i][1] + strlen($uuids[$i][0]) + 2;
            $parts[] = substr($response, $start, $uuids[$i + 1][1] - $start);
        }

        $responses = [];

        foreach ($parts as $part) {
            list($header, $body) = explode("\r\n\r\n", $part);

            $headers = [];
            foreach (explode("\r\n", $header) as $line) {
                list($key, $value) = explode(':', $line);
                $headers[trim($key)] = trim($value);
            }

            $responses[] = [
                'headers' => $headers,
                'body'    => $body,
            ];
        }

        return $responses;
    }
1115719
private function parseResponse(ResponseInterface $response = null): array
    {
        $body = $response
            ? (string) $response->getBody()
            : null;

        return $body
            ? guzzle_json_decode($body, true)
            : [];
    }
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);
    }
1158597
public function mapResponse($success, $response)
    {
        return (new Response())->setRaw($response)->map([
            'isRedirect'    => false,
            'success'       => $success,
            'reference'     => $success ? $response['id'] : null,
            'message'       => $success ? 'Transaction approved' : Arr::get($response, 'message'),
            'test'          => $this->getTest($response),
            'authorization' => $success ? $this->getAuthorization($response) : false,
            'status'        => $success ? $this->getStatus($response) : new Status('failed'),
            'errorCode'     => $success ? null : $this->getErrorCode(Arr::get($response, 'code')),
            'type'          => array_key_exists('type', $response) ? Arr::get($response, 'type') : Arr::get($response, 'object'),
        ]);
    }
865313
public function mapResponse($success, $response)
    {
        $rawResponse = $response;

        unset($rawResponse['isRedirect']);

        if (array_key_exists('INVALID', $response) || array_key_exists('VERIFIED', $response)) {
            $success = array_key_exists('VERIFIED', $response);

            return (new Response())->setRaw($rawResponse)->map([
                'isRedirect'      => false,
                'success'         => $success ? true : false,
                'reference'       => $success ? Arr::get($response, 'invoice') : false,
                'message'         => $success ? 'VERIFIED' : 'INVALID',
                'test'            => $this->config['test'],
                'authorization'   => $success ? Arr::get($response, 'txn_id') : '',
                'status'          => $success ? $this->getPaymentStatus($response) : new Status('failed'),
                'errorCode'       => null,
                'type'            => $success ? Arr::get($response, 'txn_type') : null,
            ]);
        }

        return (new Response())->setRaw($rawResponse)->map([
            'isRedirect'      => $response['isRedirect'],
            'success'         => $response['isRedirect'] ? false : $success,
            'reference'       => $success ? $this->getReference($response, $response['isRedirect']) : false,
            'message'         => $success ? Arr::get($response, 'ACK', 'Transaction approved') : $response['L_LONGMESSAGE0'],
            'test'            => $this->config['test'],
            'authorization'   => $this->getAuthorization($response, $success, $response['isRedirect']),
            'status'          => $success ? $this->getStatus($response, $response['isRedirect']) : new Status('failed'),
            'errorCode'       => $success ? null : $this->getErrorCode($response['L_ERRORCODE0']),
            'type'            => null,
        ]);
    }
1251447
public static function parseResponse(Response $response)
    {
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
        if ($jsonData && 0 == $jsonData['retcode']) {
            $onlineStatuses = [];
            foreach ($jsonData['result'] as $status) {
                $onlineStatuses[] = EntityFactory::createEntity(OnlineStatus::class, [
                    'clientType' => $status['client_type'],
                    'uin' => $status['uin'],
                    'status' => $status['status'],
                ]);
            }

            return new EntityCollection($onlineStatuses);
        }
        throw new ResponseException($jsonData['retcode'], $response);
    }
283856
public function map(array $response, ResultObjectInterface $result)
    {
        foreach ($response as $field => $value) {
            $method = $this->getSetterName($field);

            if (!method_exists($result, $method)) {
                continue;
            }

            if ($field == 'payment_instrument') {
                $value = $this->transformPaymentInstrumentValue($value, $response['payment_method']);
            } elseif ($field == 'authorization_information') {
                $value = $this->transformAuthorizationInformationValue($value);
            }

            $result->$method($value);
        }

        return $result;
    }