Skip to content

Commit

Permalink
Update to YouTrack PHP SDK stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev committed May 22, 2017
1 parent ff582aa commit 6556c51
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

All notable changes to `laravel-youtrack-sdk` will be documented in this file.

## 1.0.0 - 2017-05-19
## 1.0.0 - 2017-05-22

- Initial release
- Initial release.
42 changes: 36 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Laravel wrapper for the [YouTrack PHP SDK](https://github.com/cybercog/youtrack-
- Using contracts to keep high customization capabilities.
- Multiple authorization strategies: Token, Cookie.
- Following PHP Standard Recommendations:
- [PSR-1 (Basic Coding Standard)](http://www.php-fig.org/psr/psr-1/).
- [PSR-2 (Coding Style Guide)](http://www.php-fig.org/psr/psr-2/).
- [PSR-4 (Autoloading Standard)](http://www.php-fig.org/psr/psr-4/).
- [PSR-7 (HTTP Message Interface)](http://www.php-fig.org/psr/psr-7/).
Expand Down Expand Up @@ -121,6 +122,31 @@ $youtrack = app(\Cog\YouTrack\Rest\YouTrackClient::class);

### API requests

#### HTTP request

```php
$method = 'POST'; // GET, POST, PUT, DELETE, PATCH or any custom ones
$response = $youtrack->request($method, '/issue', [
'project' => 'TEST',
'summary' => 'New test issue',
'description' => 'Test description',
]);
```

You can [customize requests created and transferred by a client using request options](http://docs.guzzlephp.org/en/latest/request-options.html). Request options control various aspects of a request including, headers, query string parameters, timeout settings, the body of a request, and much more.

```php
$options = [
'debug' => true,
'sink' => '/path/to/dump/file',
];
$response = $youtrack->request('POST', '/issue', [
'project' => 'TEST',
'summary' => 'New test issue',
'description' => 'Test description',
], $options);
```

#### HTTP GET request

```php
Expand All @@ -142,7 +168,7 @@ $response = $youtrack->post('/issue', [
```php
$response = $youtrack->put('/issue/TEST-1', [
'summary' => 'Updated summary',
'description' => Updated description,
'description' => 'Updated description',
]);
```

Expand All @@ -158,25 +184,29 @@ Each successful request to the API returns instance of `\Cog\YouTrack\Rest\Respo

#### Get PSR HTTP response

PSR HTTP response could be accessed by calling `getResponse` method on API Response.
PSR HTTP response could be accessed by calling `httpResponse` method on API Response.

```php
$youtrackResponse = $youtrack->get('/issue/TEST-1');
$psrResponse = $youtrackResponse->getResponse();
$psrResponse = $youtrackResponse->httpResponse();
```

#### Get response Cookie

Returns `Set-Cookie` headers as string from the HTTP response.

```php
$apiResponse = $youtrack->get('/issue/TEST-1');
$cookieString = $apiResponse->getCookie();
$cookieString = $apiResponse->cookie();
```

#### Get response Location

Returns `Location` header from the HTTP response.

```php
$apiResponse = $youtrack->get('/issue/TEST-1');
$location = $apiResponse->getLocation();
$location = $apiResponse->location();
```

#### Transform response to array
Expand All @@ -190,7 +220,7 @@ $location = $apiResponse->toArray();

```php
$apiResponse = $youtrack->get('/issue/TEST-1');
$location = $apiResponse->getStatusCode();
$location = $apiResponse->statusCode();
```

## Change log
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"docs": "https://github.com/cybercog/laravel-youtrack-sdk/wiki"
},
"require": {
"cybercog/youtrack-php-sdk": "dev-master",
"cybercog/youtrack-php-sdk": "^1.0",
"illuminate/support": "~5.1.20|~5.2.0|~5.3.0|~5.4.0",
"php": "^7.1"
},
Expand Down
19 changes: 14 additions & 5 deletions src/Providers/YouTrackServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

namespace Cog\Laravel\YouTrack\Providers;

use Cog\YouTrack\Rest\Authenticator\CookieAuthenticator;
use Cog\YouTrack\Rest\Authorizer\Contracts\Authorizer as AuthorizerContract;
use Cog\YouTrack\Rest\Client\Contracts\Client as ClientContract;
use Cog\YouTrack\Rest\Client\YouTrackClient;
use Cog\YouTrack\Rest\HttpClient\GuzzleHttpClient;
use GuzzleHttp\Client as HttpClient;
use Illuminate\Contracts\Config\Repository as ConfigContract;
use Illuminate\Support\ServiceProvider;
Expand Down Expand Up @@ -49,11 +51,11 @@ public function register(): void
$this->app->bind(ClientContract::class, function () {
$config = $this->app->make(ConfigContract::class);

$http = new HttpClient([
$httpClient = new GuzzleHttpClient(new HttpClient([
'base_uri' => $config->get('youtrack.base_uri'),
]);
]));

return new YouTrackClient($http, $this->resolveAuthorizer($config));
return new YouTrackClient($httpClient, $this->resolveAuthorizer($config));
});
}

Expand Down Expand Up @@ -83,8 +85,15 @@ protected function bootConfig(): void
*/
protected function resolveAuthorizer(ConfigContract $config): AuthorizerContract
{
$options = $config->get('youtrack.authorizers.' . $config->get('youtrack.authorizer'));
$authorizer = $config->get('youtrack.authorizer');

return new $options['driver']($options);
$options = $config->get('youtrack.authorizers.' . $authorizer);
if ($authorizer == 'cookie') {
return new $options['driver'](
new CookieAuthenticator($options['username'], $options['password'])
);
}

return new $options['driver']($options['token']);
}
}

0 comments on commit 6556c51

Please sign in to comment.