Skip to content

Commit 22ab480

Browse files
Improved basic documentation
1 parent 08e117d commit 22ab480

File tree

2 files changed

+76
-11
lines changed

2 files changed

+76
-11
lines changed

README.md

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,89 @@ 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) 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/3.0/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 three 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+
$c = new Bitbucket\Client();
57+
58+
$c->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+
$c = new Bitbucket\Client();
70+
71+
$c->authenticate(
72+
Bitbucket\Client::AUTH_HTTP_PASSWORD,
73+
'your-username-here',
74+
'your-password-here'
75+
);
76+
```
77+
78+
#### JSON Web Token
5179

52-
use Bitbucket\Client;
80+
Finally, we support logging in using JSON web tokens (JWTs). This method is exclusively required by some of Bitbucket's API endpoints, such as the addons API. Generate your JWT, perahps using [lcobucci/jwt](https://github.com/lcobucci/jwt/tree/3.3.2), then provide it as below:
5381

54-
$c = new Client();
5582

56-
$c->authenticate(Client::AUTH_OAUTH_TOKEN, 'your-token-here');
57-
// $c->authenticate(Client::AUTH_HTTP_PASSWORD, 'your-username', 'your-password');
83+
```php
84+
$c = new Bitbucket\Client();
5885

59-
var_dump($c->currentUser()->show());
86+
$c->authenticate(
87+
Bitbucket\Client::AUTH_jwt,
88+
'your-jwt-here'
89+
);
6090
```
6191

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 [source code](https://github.com/BitbucketAPI/Client/tree/3.0/src) to get a full picture of what is available to use.
92+
### Examples
93+
94+
In the following examples, `$client` will be an authenticated client, as above.
95+
96+
#### Example 1
97+
98+
It is possible to show basic information about the currently logged in user:
99+
100+
```php
101+
$currentUser = $client->currentUser()->show();
102+
```
103+
104+
#### Example 2
105+
106+
It is possible to grab a repository as follows:
107+
108+
```php
109+
$repository = $client->repositories()
110+
->workspaces('atlassian')
111+
->show('stash-example-plugin');
112+
```
113+
114+
#### Example 3
115+
116+
We support automatic pagination without you having to lift a finger. The following example gets all branches of a repository:
117+
118+
```php
119+
$paginator = new Bitbucket\ResultPager($client);
120+
121+
$branchesClient = $client->repositories()
122+
->workspaces('atlassianlabs')
123+
->refs('stash-log-parser'])
124+
->branches();
125+
126+
$branches = $paginator->fetchAll($branchesClient, 'list');
127+
```
63128

64129

65130
## Security

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
class Client
4141
{
4242
/**
43-
* The OAuth token authentication method.
43+
* The OAuth 2 token authentication method.
4444
*
4545
* @var string
4646
*/
@@ -54,7 +54,7 @@ class Client
5454
public const AUTH_HTTP_PASSWORD = 'http_password';
5555

5656
/**
57-
* The JSON Web Token authentication method.
57+
* The JSON web token authentication method.
5858
*
5959
* @var string
6060
*/

0 commit comments

Comments
 (0)