Skip to content

Commit

Permalink
Update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
eljam committed Jun 15, 2016
1 parent 6124bb8 commit a7a0236
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -14,11 +14,11 @@ php:
matrix:
include:
- php: 5.4
env: COMPOSER_FLAGS="--prefer-lowest"
env: SYMFONY_VERSION='2.3.*'
- php: 5.5
env: COMPOSER_FLAGS="--prefer-lowest"
env: SYMFONY_VERSION='2.3.*'
- php: 5.6
env: COMPOSER_FLAGS="--prefer-lowest"
env: SYMFONY_VERSION='2.3.*'
- php: 5.6
env: SYMFONY_VERSION='2.7.*'
- php: 5.6
Expand Down
6 changes: 3 additions & 3 deletions Controller/ApiController.php
Expand Up @@ -192,9 +192,9 @@ protected function onError(FormInterface $form)
{
$view = View::create()
->setStatusCode(Codes::HTTP_BAD_REQUEST)
->setData(array(
'form' => $form,
))
->setData([
'errors' => $form,
])
;

return $view;
Expand Down
8 changes: 4 additions & 4 deletions Resources/config/routing.yml
@@ -1,19 +1,19 @@
GundanDistributedConfigurationBundle_get:
path: /configuration/{key}
path: /keys/{key}
defaults: { _controller: GundanDistributedConfigurationBundle:Api:get }
methods: [GET]

GundanDistributedConfigurationBundle_create:
path: /configuration
path: /keys
defaults: { _controller: GundanDistributedConfigurationBundle:Api:create }
methods: [POST]

GundanDistributedConfigurationBundle_update:
path: /configuration/{key}
path: /keys/{key}
defaults: { _controller: GundanDistributedConfigurationBundle:Api:update }
methods: [PUT, PATCH]

GundanDistributedConfigurationBundle_delete:
path: /configuration/{key}
path: /keys/{key}
defaults: { _controller: GundanDistributedConfigurationBundle:Api:delete }
methods: [DELETE]
20 changes: 19 additions & 1 deletion Resources/doc/index.md
Expand Up @@ -35,6 +35,24 @@ gundan_distributed_configuration:
path: "%kernel.root_dir%/test.json"
```

Configure your routing file in `app/config/routing.yml`:

``` yaml
# app/config/routing.yml
gundan_distributed_configuration_api:
resource: "@GundanDistributedConfigurationBundle/Resources/config/routing.yml"
prefix: /v1

fos_rest:
format_listener:
rules:
- { path: '^/v1/', priorities: ['json'], fallback_format: json, prefer_extension: false }
```

## Usage

TODO
Use your favorite http client

```php
$response = $client->request('POST','/v1/keys', ['body' => json_encode(['client_uri' => 'http://api.example.org'])]);
```
22 changes: 19 additions & 3 deletions Tests/ApiTest.php
Expand Up @@ -33,7 +33,7 @@ public function testApiCreate()
{
$this->client->request(
'POST',
'/distributed_configuration/configuration',
'/v1/keys',
[],
[],
['HTTP_CONTENT_TYPE' => 'application/json', 'CONTENT_TYPE' => 'application/json'],
Expand All @@ -52,13 +52,29 @@ public function testApiCreate()
$this->assertEquals(201, $this->client->getResponse()->getStatusCode());
}

public function testApiPatch()
{
$this->createKeyValue('key_to_patch');

$this->client->request(
'PATCH',
'/v1/keys/key_to_patch',
[],
[],
['HTTP_CONTENT_TYPE' => 'application/json', 'CONTENT_TYPE' => 'application/json'],
json_encode(['value' => 'value_to_patch'])
);

$this->assertEquals(204, $this->client->getResponse()->getStatusCode());
}

public function testApiUpdate()
{
$this->createKeyValue('key_to_update');

$this->client->request(
'PUT',
'/distributed_configuration/configuration/key_to_update',
'/v1/keys/key_to_update',
[],
[],
['HTTP_CONTENT_TYPE' => 'application/json', 'CONTENT_TYPE' => 'application/json'],
Expand All @@ -74,7 +90,7 @@ public function testApiDelete()

$this->client->request(
'DELETE',
'/distributed_configuration/configuration/key with space',
'/v1/keys/key with space',
[],
[],
['HTTP_CONTENT_TYPE' => 'application/json', 'CONTENT_TYPE' => 'application/json']
Expand Down
2 changes: 1 addition & 1 deletion Tests/App/config/config.yml
Expand Up @@ -17,4 +17,4 @@ gundan_distributed_configuration:
fos_rest:
format_listener:
rules:
- { path: '^/distributed_configuration', priorities: ['json'], fallback_format: json, prefer_extension: false }
- { path: '^/v1/', priorities: ['json'], fallback_format: json, prefer_extension: false }
2 changes: 1 addition & 1 deletion Tests/App/config/routing.yml
@@ -1,3 +1,3 @@
gundan_distributed_configuration_api:
resource: "@GundanDistributedConfigurationBundle/Resources/config/routing.yml"
prefix: /distributed_configuration
prefix: /v1

0 comments on commit a7a0236

Please sign in to comment.