Skip to content

Blobs API parses JSON file contents #357

@morozov

Description

@morozov

Currently it's impossible to get raw file contents of a JSON-encoded file (tested with v1.5.1):

$client = new Github\Client();
$api = $client->api('git_data')->blobs();
$api->configure('raw');

// fetching README.md
$contents = $api->show('KnpLabs', 'php-github-api', 'cc56952432293f57c29517b7cd556433ea5f1971');
echo gettype($contents), PHP_EOL;
// outputs "string"

// fetching composer.json
$contents = $api->show('KnpLabs', 'php-github-api', 'dc16d3e77fd4e40638cb722927ffe15fa85b1434');
echo gettype($contents), PHP_EOL;
// outputs "array"

A potential solution is to make ResponseMediator content type aware and only do json_decode in cases of application/json. Another approach is to not even try to json_decode() in case of Blob API because the return value is expected to be returned as is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions