Skip to content

Commit d12ebbf

Browse files
authored
Merge pull request #14 from packagist/t/customer-url-name-paramter
Customers: allow urlName to be passed instead of id for all calls
2 parents f71316d + 0bf6786 commit d12ebbf

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Returns an array of customers.
6262
```php
6363
$customerId = 42;
6464
$customer = $client->customers()->show($customerId);
65+
// or
66+
$customerUrlName = 'customer-url-name';
67+
$customer = $client->customers()->show($customerUrlName);
6568
```
6669
Returns a single customer.
6770

Diff for: src/Api/Customers.php

+20-20
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public function all()
1111
return $this->get('/customers/');
1212
}
1313

14-
public function show($customerId)
14+
public function show($customerIdOrUrlName)
1515
{
16-
return $this->get(sprintf('/customers/%s/', $customerId));
16+
return $this->get(sprintf('/customers/%s/', $customerIdOrUrlName));
1717
}
1818

1919
public function create($name, $accessToVersionControlSource = false)
@@ -24,64 +24,64 @@ public function create($name, $accessToVersionControlSource = false)
2424
/**
2525
* @deprecated Use edit instead
2626
*/
27-
public function update($customerId, array $customer)
27+
public function update($customerIdOrUrlName, array $customer)
2828
{
29-
return $this->edit($customerId, $customer);
29+
return $this->edit($customerIdOrUrlName, $customer);
3030
}
3131

32-
public function edit($customerId, array $customer)
32+
public function edit($customerIdOrUrlName, array $customer)
3333
{
34-
return $this->put(sprintf('/customers/%s/', $customerId), $customer);
34+
return $this->put(sprintf('/customers/%s/', $customerIdOrUrlName), $customer);
3535
}
3636

37-
public function remove($customerId)
37+
public function remove($customerIdOrUrlName)
3838
{
39-
return $this->delete(sprintf('/customers/%s/', $customerId));
39+
return $this->delete(sprintf('/customers/%s/', $customerIdOrUrlName));
4040
}
4141

42-
public function listPackages($customerId)
42+
public function listPackages($customerIdOrUrlName)
4343
{
44-
return $this->get(sprintf('/customers/%s/packages/', $customerId));
44+
return $this->get(sprintf('/customers/%s/packages/', $customerIdOrUrlName));
4545
}
4646

4747
/**
4848
* @deprecated Use addOrEditPackages instead
4949
*/
50-
public function addOrUpdatePackages($customerId, array $packages)
50+
public function addOrUpdatePackages($customerIdOrUrlName, array $packages)
5151
{
52-
return $this->addOrEditPackages($customerId, $packages);
52+
return $this->addOrEditPackages($customerIdOrUrlName, $packages);
5353
}
5454

55-
public function addOrEditPackages($customerId, array $packages)
55+
public function addOrEditPackages($customerIdOrUrlName, array $packages)
5656
{
5757
foreach ($packages as $package) {
5858
if (!isset($package['name'])) {
5959
throw new InvalidArgumentException('Parameter "name" is required.');
6060
}
6161
}
6262

63-
return $this->post(sprintf('/customers/%s/packages/', $customerId), $packages);
63+
return $this->post(sprintf('/customers/%s/packages/', $customerIdOrUrlName), $packages);
6464
}
6565

6666
/**
6767
* @deprecated Use addOrEditPackages instead
6868
*/
69-
public function addPackages($customerId, array $packages)
69+
public function addPackages($customerIdOrUrlName, array $packages)
7070
{
71-
return $this->addOrEditPackages($customerId, $packages);
71+
return $this->addOrEditPackages($customerIdOrUrlName, $packages);
7272
}
7373

74-
public function removePackage($customerId, $packageName)
74+
public function removePackage($customerIdOrUrlName, $packageName)
7575
{
76-
return $this->delete(sprintf('/customers/%s/packages/%s/', $customerId, $packageName));
76+
return $this->delete(sprintf('/customers/%s/packages/%s/', $customerIdOrUrlName, $packageName));
7777
}
7878

79-
public function regenerateToken($customerId, array $confirmation)
79+
public function regenerateToken($customerIdOrUrlName, array $confirmation)
8080
{
8181
if (!isset($confirmation['IConfirmOldTokenWillStopWorkingImmediately'])) {
8282
throw new InvalidArgumentException('Confirmation is required to regenerate the Composer repository token.');
8383
}
8484

85-
return $this->post(sprintf('/customers/%s/token/regenerate', $customerId), $confirmation);
85+
return $this->post(sprintf('/customers/%s/token/regenerate', $customerIdOrUrlName), $confirmation);
8686
}
8787
}

0 commit comments

Comments
 (0)