Skip to content

packagist/private-packagist-api-client

Repository files navigation

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
$client->organization()->sync();

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.

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

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 updades the customer receives
        'expirationDate' => (new \DateTime())->add(new \DateInterval('P1Y'))->format('c'), // optional expiration date to limit updades the customer receives
    ],
];
$packages = $client->customers()->addOrUpdatePackages($customerId, $packages);

Returns an array of added 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.

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.

License

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