Parse tags and create download links.

@param \stdClass|array $response Response from API call.
@param string          $repo_type

@return array
15510
protected function parse_tags( $response, $repo_type ) {
		$tags     = [];
		$rollback = [];

		foreach ( (array) $response as $tag ) {
			// $download_base    = implode(
			// '/',
			// [
			// $repo_type['base_download'],
			// $this->type->owner,
			// $this->type->owner,
			// 'get/',
			// ]
			// );
			$download_base    = "{$repo_type['base_download']}/{$this->type->owner}/{$this->type->owner}/get/";
			$tags[]           = $tag;
			$rollback[ $tag ] = $download_base . $tag . '.zip';
		}

		return [ $tags, $rollback ];
	}
336168
public function repository(string $user, string $repo): ?array
    {
        $api = $this->client->api('repo');
        $params = [$user, $repo];

        $repo = $this->callGitHub([$api, 'show'], $params);

        return is_array($repo) ? $repo : null;
    }
18138
function parseGitHubTrendingRepos(err, body) {
    if (err) { return tubesio.finish(err); }

    // Load the raw HTML into a cheerio object so we can traverse
    // the data using CSS selectors ala jQuery.
    var $ = cheerio.load(body),
        result = {
            title: $('title').text(),
            trending: []
        };

    // Iterate over the trending repositories extracting the names
    // and hyperlinks.
    $('#trending-repositories > ol > li').each(function (i, e) {
        result.trending.push({
            name: us.trim($(e).find('h3').text()),
            href: 'https://github.com' + $(e).find('a').last().attr('href')
        });
    });

    // Return our results object
    tubesio.finish(result); 
}
177678
protected function parseResponse(Response $response)
    {
        $contentType = explode(';', $response->getHeader('content-type'))[0];

        switch ($contentType) {
            case 'application/json':
            case 'application/vnd.api+json':
                return $response->json();

            case 'application/xml':
                return $response->xml();
        }

        throw new RuntimeException("Unsupported returned content-type [$contentType]");
    }
1272690
public function getUrl(Repo $repo)
    {
        return $this->helper->getUrl(
            $repo->getSlug(),
            $repo->getType()
        );
    }
75109
private function getClass($repo)
    {
        $class = S::create(
            str_replace(['.'], ['-'], basename($repo, '.git'))
        )->camelize();

        return ucfirst(trim($class));
    }
1127599
protected function processTogglResponse($response)
    {
        // We only need to do something if results are paginated
        if ($response->total_count <= 50) {
            return $response->data;
        }

        $reqdata = [];
        $reqdata = json_encode($reqdata);
        $pages = ceil($response->total_count / 50);
        $curr_page = 1;
        $data = $response->data;

        $orig_uri = $this->uri;

        while ($curr_page < $pages) {
            $curr_page++;
            $this->uri .= '&page=' . $curr_page;
            $response = $this->processRequest($reqdata, self::GET);
            $this->_handleError($reqdata, $response);
            foreach ($response->data as $entry) {
                $data[] = $entry;
            }
            $this->uri = $orig_uri;
        }

        return $data;
    }
1244360
public function parse_tag_response( $response ) {
		if ( $this->validate_response( $response ) ) {
			return $response;
		}

		$arr = [];
		array_map(
			function ( $e ) use ( &$arr ) {
				$arr[] = $e->tag_name;

				return $arr;
			},
			(array) $response
		);

		return $arr;
	}
155577
public function load(Repo $repo)
    {
        // Travis own its ID
        $id = $repo->getId();
        $this->client->fetchRepository($repo);
        $repo->setId($id);

        return $repo;
    }
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);
    }
232494
private function parse_release_asset( $git, $request, $response ) {
		switch ( $git ) {
			case 'github':
				$download_link = isset( $response->assets[0] ) && ! is_wp_error( $response ) ? $response->assets[0]->browser_download_url : null;

				// Private repo.
				$response = ( null !== $download_link && ( property_exists( $this->type, 'is_private' ) && $this->type->is_private ) ) ? $response->assets[0]->url : $download_link;
				break;
			case 'bitbucket':
				$download_base = $this->get_api_url( $request, true );
				$response      = isset( $response->values[0] ) && ! is_wp_error( $response ) ? $download_base . '/' . $response->values[0]->name : null;
				break;
			case 'bbserver':
				// TODO: make work.
				break;
			case 'gitlab':
				$response = $this->get_api_url( $request );
				break;
			case 'gitea':
				break;
		}

		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);
    }
158974
public function get_remote_repo_meta( $repo ) {
		$file = 'style.css';
		if ( false !== stripos( $repo->type, 'plugin' ) ) {
			$file = basename( $repo->file );
		}

		$repo_api = Singleton::get_instance( 'API', $this )->get_repo_api( $repo->git, $repo );
		if ( null === $repo_api ) {
			return false;
		}

		$this->{$repo->type} = $repo;
		$this->set_defaults( $repo->type );

		if ( $repo_api->get_remote_info( $file ) ) {
			if ( ! self::is_wp_cli() ) {
				if ( ! apply_filters( 'github_updater_run_at_scale', false ) ) {
					$repo_api->get_repo_meta();
					$changelog = $this->get_changelog_filename( $repo );
					if ( $changelog ) {
						$repo_api->get_remote_changes( $changelog );
					}
					$repo_api->get_remote_readme();
				}
				if ( ! empty( self::$options['branch_switch'] ) ) {
					$repo_api->get_remote_branches();
				}
			}
			$repo_api->get_remote_tag();
			$repo->download_link = $repo_api->construct_download_link();
			$language_pack       = new Language_Pack( $repo, new Language_Pack_API( $repo ) );
			$language_pack->run();
		}

		$this->remove_hooks( $repo_api );

		return true;
	}
533319
private function get_language_pack_json( $git, $headers, $response ) {
		switch ( $git ) {
			case 'github':
				$response = $this->api( '/repos/' . $headers['owner'] . '/' . $headers['repo'] . '/contents/language-pack.json' );
				$response = isset( $response->content )
					? json_decode( base64_decode( $response->content ) )
					: null;
				break;
			case 'bitbucket':
				$response = $this->api( '/2.0/repositories/' . $headers['owner'] . '/' . $headers['repo'] . '/src/master/language-pack.json' );
				break;
			case 'gitlab':
				$id       = rawurlencode( $headers['owner'] . '/' . $headers['repo'] );
				$response = $this->api( '/projects/' . $id . '/repository/files/language-pack.json' );
				$response = isset( $response->content )
					? json_decode( base64_decode( $response->content ) )
					: null;
				break;
			case 'gitea':
				$response = $this->api( '/repos/' . $headers['owner'] . '/' . $headers['repo'] . '/raw/master/language-pack.json' );
				$response = isset( $response->content )
					? json_decode( base64_decode( $response->content ) )
					: null;
				break;
		}

		if ( $this->validate_response( $response ) ) {
			return false;
		}

		return $response;
	}
250455
public static function parseLinkHeader(Response $response)
    {
        $linkHeader = $response->getHeader('Link');

        if (!strpos($linkHeader, 'rel')) {
            return null;
        }

        $out = [
            "next" => null,
            "last" => null,
            "prev" => null,
            "first" => null,
        ];

        $links = explode(',', $linkHeader);
        foreach ($links as $link) {
            $parts = explode(';', $link);
            if (count($parts) < 2) {
                continue;
            }

            // Get the URL
            $url = trim(array_shift($parts), '<> ');
            $relParts = explode('=', trim(array_shift($parts)));

            if (count($relParts) !== 2 || $relParts[0] != 'rel') {
                continue;
            }

            // Get the rel="" value (next, prev, first, last)
            $rel = trim($relParts[1], ' "\'');
            $out[$rel] = $url;
        }

        return $out;
    }
715178
public function parse_meta_response( $response ) {
		if ( $this->validate_response( $response ) ) {
			return $response;
		}
		$arr      = [];
		$response = [ $response ];

		array_filter(
			$response,
			function ( $e ) use ( &$arr ) {
				$arr['private']      = $e->private;
				$arr['last_updated'] = $e->pushed_at;
				$arr['watchers']     = $e->watchers;
				$arr['forks']        = $e->forks;
				$arr['open_issues']  = $e->open_issues;
			}
		);

		return $arr;
	}
765277
public function download($type, $id, GeneratorListener $listener)
    {
        $model = Report::where('id', $id)->first();
        if (is_null($model)) {
            return $listener->downloadFailed();
        }
        $filename = snake_case(str_replace(['-', ':', ' '], '_', $model->name));
        switch ($type) {
            case 'pdf':
                $snappy = app('snappy.pdf.wrapper');
                $appKey = config('app.key');
                $ch     = curl_init();
                curl_setopt($ch, CURLOPT_URL, handles('antares::logger/view/' . $id . '/html'));
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_HTTPHEADER, ["generator:  {$appKey}"]);
                $html   = curl_exec($ch);
                curl_close($ch);
                $snappy->loadHTML($html);
                $return = $snappy->download($filename . '.pdf');
                break;
            default:
                $return = Response::make($model->html, '200', array(
                            'Content-Type'        => 'application/octet-stream',
                            'Content-Disposition' => 'attachment; filename="' . $filename . '.html'
                ));
                break;
        }
        return $return;
    }