Skip to content

Commit

Permalink
Merge pull request #19 from apidae-tourisme/edit_autorisation
Browse files Browse the repository at this point in the history
+ v002/autorisation/objet-touristique/modification/
  • Loading branch information
PierreGranger authored May 31, 2021
2 parents 742b371 + 21147f2 commit b9bbedc
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
33 changes: 33 additions & 0 deletions examples/demo-edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

require __DIR__ . "/requires.inc.php";

$client = new \Sitra\ApiClient\Client($config);

/**
* Fill with some offers ID
* Key is the offer ID
* Value is the expected result
* The exemples below should be edited depending on your project owner (default expected results are meant for member 1157 / Apidae Tourisme)
*/
$offers = [
5163353 => 'Offer owned by project manager : Should be allowed',
5023027 => 'Offer masqued, but owned by project manager : Should be allowed',
1 => 'Offer does not exist : 404 / Exception',
];

echo '<pre>';

foreach ($offers as $offer => $expected) {
echo $offer . ' expected : ' . $expected . "\n";
try {
$response = $client->getEditAutorisation(['id' => $offer]);
echo $response['response']->getContents();
} catch (Exception $e) {
echo $e;
}
echo "\n" . '<hr />' . "\n";
}
7 changes: 6 additions & 1 deletion src/Sitra/ApiClient/ApidaeSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function prepareRequest(CommandInterface $command, RequestInterface $r

// If this operation require an OAuth scope
$scope = $operation->getData('scope');
if ($scope && ($scope == ClientApi::META_SCOPE)) {
if ($scope && ($scope == ClientApi::META_SCOPE || $scope == ClientApi::EDIT_SCOPE)) {
$request = $request->withHeader(
'Authorization',
sprintf('Bearer %s', $this->getOAuthToken($scope))
Expand Down Expand Up @@ -225,6 +225,11 @@ protected function getOAuthToken($scope): string
$this->clientApi->config('OAuthClientId'),
$this->clientApi->config('OAuthSecret'),
];
} elseif ($scope === ClientApi::EDIT_SCOPE) {
$auth = [
$this->clientApi->config('editClientId'),
$this->clientApi->config('editSecret'),
];
}

if (is_array($auth)) {
Expand Down
7 changes: 6 additions & 1 deletion src/Sitra/ApiClient/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Sitra\ApiClient\Description\TouristicObjects;
use Sitra\ApiClient\Description\User;
use Sitra\ApiClient\Description\Member;
use Sitra\ApiClient\Description\Edit;
use Sitra\ApiClient\Exception\InvalidExportDirectoryException;
use Sitra\ApiClient\Exception\InvalidMetadataFormatException;
use Sitra\ApiClient\Exception\SitraException;
Expand Down Expand Up @@ -67,6 +68,8 @@
* @method array getUserByMember() getUserByMember(array $params)
* @method array getAllUsers() getAllUsers(array $params)
*
* @method array getEditAutorisation() getEditAutorisation(array $params)
*
*/
class Client extends GuzzleClient
{
Expand All @@ -75,6 +78,7 @@ class Client extends GuzzleClient

const META_SCOPE = 'api_metadonnees';
const SSO_SCOPE = 'sso';
const EDIT_SCOPE = 'api_ecriture';

protected $config = [
'baseUri' => 'https://api.apidae-tourisme.com/',
Expand Down Expand Up @@ -127,7 +131,8 @@ public function __construct(array $config = [], Description $description = null)
Reference::$operations,
Sso::$operations,
User::$operations,
Member::$operations
Member::$operations,
Edit::$operations
);

$descriptionData = [
Expand Down
32 changes: 32 additions & 0 deletions src/Sitra/ApiClient/Description/Edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Sitra\ApiClient\Description;

use Sitra\ApiClient\Client as ClientApi;

class Edit
{
public static $operations = array(
// @see https://dev.apidae-tourisme.com/fr/documentation-technique/v2/api-decriture/v002autorisationobjet-touristiquemodification
'getEditAutorisation' => [
'httpMethod' => 'GET',
'uri' => '/api/v002/autorisation/objet-touristique/modification/{id}',
'responseModel' => 'getResponseBody',
'parameters' => [
'id' => [
'type' => 'integer',
'location' => 'uri',
'required' => true,
],
'tokenSSO' => [
'type' => 'string',
'location' => 'query',
'required' => false,
]
],
'data' => [
'scope' => ClientApi::EDIT_SCOPE,
],
],
);
}

0 comments on commit b9bbedc

Please sign in to comment.