Skip to content

Commit 6575cc1

Browse files
Backported documentation improvements
1 parent b21ea45 commit 6575cc1

File tree

1 file changed

+61
-10
lines changed

1 file changed

+61
-10
lines changed

README.md

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This version requires [PHP](https://php.net) 7.1-7.4.
2828
To get the latest version, simply require the project using [Composer](https://getcomposer.org). You will need to install any package that "provides" `php-http/client-implementation`. Pure PHP users will want something like:
2929

3030
```bash
31-
$ composer require bitbucket/client:2.1 php-http/guzzle6-adapter:^2.0.1
31+
$ composer require bitbucket/client:^2.1 php-http/guzzle6-adapter:^2.0.1
3232
```
3333

3434
Laravel users will want something like:
@@ -42,24 +42,75 @@ We are decoupled from any HTTP messaging client with help by [HTTPlug](http://ht
4242

4343
## Usage
4444

45-
The main point of entry is the `Bitbucket\Client` class. Simply create a new instance of that, and you're good to go!
45+
The main point of entry is the `Bitbucket\Client` class. Simply create a new instance of that, authenticate, and you're good to go! As of time of writing (Saturday 29th June 2019), every endpoint (excluding issue export and import, and various deprecated endpoints) available on the Bitbucket API 2.0 is also available through this PHP client. We'd recommend looking through the [Bitbucket documentation](https://developer.atlassian.com/bitbucket/api/2/reference/), and also the [source code](https://github.com/BitbucketAPI/Client/tree/2.1/src) to get a full picture of what is available to use.
4646

47-
Practically, you will also want to set authentication details before calling any of the endpoint, however, this is not required to call endpoints for which authentication is not needed. We support logging in with an OAuth2 token, or with a username and password.
47+
### Authentication
48+
49+
There are two ways to authenticate our client:
50+
51+
#### OAuth 2 Token
52+
53+
The most common way to authenticate is using an OAuth 2 token. You will need to generate this by some means outside of the library, and then provide it as below:
54+
55+
```php
56+
$client = new Bitbucket\Client();
57+
58+
$client->authenticate(
59+
Bitbucket\Client::AUTH_OAUTH_TOKEN,
60+
'your-token-here'
61+
);
62+
```
63+
64+
#### HTTP Password
65+
66+
It is possible to login using a username and password combination. This method is not recommended for production use, however you find it useful never the less:
4867

4968
```php
50-
<?php
69+
$client = new Bitbucket\Client();
70+
71+
$client->authenticate(
72+
Bitbucket\Client::AUTH_HTTP_PASSWORD,
73+
'your-username-here',
74+
'your-password-here'
75+
);
76+
```
77+
78+
### Examples
5179

52-
use Bitbucket\Client;
80+
In the following examples, `$client` will be an authenticated client, as above.
5381

54-
$c = new Client();
82+
#### Example 1
5583

56-
$c->authenticate(Client::AUTH_OAUTH_TOKEN, 'your-token-here');
57-
// $c->authenticate(Client::AUTH_HTTP_PASSWORD, 'your-username', 'your-password');
84+
It is possible to show basic information about the currently logged in user:
5885

59-
var_dump($c->currentUser()->show());
86+
```php
87+
$currentUser = $client->currentUser()->show();
88+
```
89+
90+
#### Example 2
91+
92+
It is possible to grab a repository as follows:
93+
94+
```php
95+
$repository = $client->repositories()
96+
->users('atlassian')
97+
->show('stash-example-plugin');
6098
```
6199

62-
As of time of writing (Saturday 29th June 2019), every endpoint (excluding issue export and import) available on the Bitbucket API 2.0 is also available through this PHP client. I'd recommend looking through the [Bitbucket documentation](https://developer.atlassian.com/bitbucket/api/2/reference/), and also the [generated documentation](https://bitbucketapi.github.io/Client/).
100+
#### Example 3
101+
102+
We support automatic pagination without you having to lift a finger. The following example gets all branches of a repository:
103+
104+
```php
105+
$paginator = new Bitbucket\ResultPager($client);
106+
107+
$branchesClient = $client->repositories()
108+
->users('atlassianlabs')
109+
->refs('stash-log-parser'])
110+
->branches();
111+
112+
$branches = $paginator->fetchAll($branchesClient, 'list');
113+
```
63114

64115

65116
## Security

0 commit comments

Comments
 (0)