Private Packagist API Client
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json

README.md

Private Packagist API Client

Requirements

Install

Via Composer:

$ composer require private-packagist/api-client php-http/guzzle6-adapter

Why do you need to require php-http/guzzle6-adapter? We are decoupled from any HTTP messaging client with help by HTTPlug, so you can pick an HTTP client of your choice, guzzle is merely a recommendation.

Basic usage of private-packagist/api-client client

<?php

// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';

$client = new \PrivatePackagist\ApiClient\Client();
$client->authenticate('api-token', 'api-secret');
$packages = $client->packages()->all();

From $client object, you can access the full Private Packagist API.

Documentation

Full documentation can be found in the Private Packagist documentation.

Organization

Trigger a full synchronization
$jobs = $client->organization()->sync();

Returns an array of created jobs. One for every synchronization.

Team

List an organization's teams
$teams = $client->teams()->all();

Returns an array of teams.

Customer

List an organization's customers
$customers = $client->customers()->all();

Returns an array of customers.

Show a customer
$customerId = 42;
$customer = $client->customers()->show($customerId);

Returns a single customer.

Create a customer
$customer = $client->customers()->create('New customer name');

Returns the customer.

Update a customer
$customerId = 42;
$customerData = [
    'name' => $name,
    'urlName' => 'customer',
    'accessToVersionControlSource' => false,
];
$customer = $client->customers()->update($customerId, $customerData);

Returns the customer.

Delete a customer
$customerId = 42;
$client->customers()->remove($customerId);
List a customer's packages
$customerId = 42;
$packages = $client->customers()->listPackages($customerId);

Returns an array of customer packages.

Grant a customer access to a package or update the limitations
$customerId = 42;
$packages = [
    [
        'name' => 'acme-website/package',
        'versionConstraint' => '^1.0 | ^2.0', // optional version constraint to limit updates the customer receives
        'expirationDate' => (new \DateTime())->add(new \DateInterval('P1Y'))->format('c'), // optional expiration date to limit updates the customer receives
    ],
];
$packages = $client->customers()->addOrUpdatePackages($customerId, $packages);

Returns an array of all added or updated customer packages.

Revoke access to a package from a customer
$customerId = 42;
$packageName = 'acme-website/package';
$client->customers()->removePackage($customerId, $packageName);

Regenerate a customer's Composer repository token

$customerId = 42;
$confirmation = [
    'IConfirmOldTokenWillStopWorkingImmediately' => true,
];
$composerRepository = $client->customers()->regenerateToken($customerId, $confirmation);

Returns the updated Composer repository.

Project

List an organization's projects
$projects = $client->projects()->all();

Returns an array of projects.

Show a project
$projectName = 'project';
$project = $client->projects()->show($projectName);

Returns a single project.

Create a project
$project = $client->projects()->create('New project name');

Returns the project.

Delete a project
$projectName = 'project';
$client->projects()->remove($projectName);
List a projects's teams
$projectName = 'project';
$teams = $client->projects()->listTeams($projectName);

Returns an array of projects teams.

Add a team to a project or update the permission
$projectName = 'project';
$teams = [
    [
        'id' => 12,
        'permission' => 'owner',
    ],
];
$teams = $client->customers()->addOrUpdateTeams($projectName, $teams);

Returns an array of added project teams.

Remove a team from a customer
$projectName = 'project';
$teamId = 12;
$client->customers()->removeTeam($projectName, $teamId);
List a projects's packages
$projectName = 'project';
$packages = $client->projects()->listPackages($projectName);

Returns an array of projects packages.

List a projects's authentication tokens
$projectName = 'project';
$tokens = $client->projects()->listTokens($projectName);

Returns an array of authentication tokens.

Create a project authentication token
$projectName = 'project';
$data = [
  'description' => 'Project Token',
  'access' => 'read',
];
$token = $client->projects()->createToken($projectName, $data);

Returns the authentication token.

Delete a project authentication token
$projectName = 'project';
$tokenId = 33;
$client->projects()->removeToken($projectName, $tokenId);
Regenerate a project authentication token
$projectName = 'project';
$tokenId = 33;
$confirmation = [
    'IConfirmOldTokenWillStopWorkingImmediately' => true,
];
$token = $client->projects()->regenerateToken($projectName, $confirmation);

Returns the authentication token.

Package

List an organization's packages
$filters = [
    'origin' => \PrivatePackagist\ApiClient\Api\Packages::ORIGIN_PRIVATE, // optional filter to only receive packages that can be added to customers 
];
$packages = $client->packages()->all($filters);

Returns an array of packages.

Show a package
$package = $client->packages()->show('acme-website/package');

Returns the package.

Create a vcs package
$job = $client->packages()->createVcsPackage('https://github.com/acme-website/package');

Returns a new job.

Create a vcs package with credentials
$credentialId = 42;
$job = $client->packages()->createVcsPackage('https://github.com/acme-website/package', $credentialId);

Returns a new job.

Create a custom package
$packageDefinition = '{...}'
$job = $client->packages()->createCustomPackage($packageDefinition);

Returns a new job.

Create a custom package with credentials
$packageDefinition = '{...}'
$credentialId = 42;
$job = $client->packages()->createCustomPackage($packageDefinition, $credentialId);

Returns a new job.

Update a vcs package
$job = $client->packages()->updateVcsPackage('acme-website/package', 'https://github.com/acme-website/package');

Returns a new job.

Update a custom package
$packageDefinition = '{...}'
$job = $client->packages()->updateCustomPackage('acme-website/package', $packageDefinition);

Returns a new job.

Delete a package
$client->packages()->remove('acme-website/package');
List all customers with access to a package
$client->packages()->listCustomers('acme-website/package');

Returns a list of customers with access to the package.

Credential

List an organization's credentials
$packages = $client->credentials()->all();

Returns an array of credentials.

Show a credential
$credentialId = 42;
$credential = $client->credentials()->show($credentialId);

Returns the credential.

Create a credential
$type = \PrivatePackagist\ApiClient\Api\Credentials::TYPE_HTTP_BASIC;
$credential = $client->credentials()->create('ACME http auth', $type, 'acme-website.com', 'username', 'password');

Returns the new credential.

Update a credential
$credentialId = 42;
$type = \PrivatePackagist\ApiClient\Api\Credentials::TYPE_HTTP_BASIC;
$credential = $client->credentials()->update($credentialId, $type, 'username', 'password');

Returns the updated credential.

Delete a credential
$credentialId = 42;
$client->credentials()->remove($credentialId);

Job

Show a job
$job = $client->jobs()->show($jobId);

Returns the job.

License

private-packagist/api-client is licensed under the MIT License