Skip to content
This repository has been archived by the owner on Feb 22, 2019. It is now read-only.

Add documentation for specification routes in SDK #297

Merged
merged 6 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ title: deleteSpecifications

# deleteSpecifications


<blockquote class="js">
<p>
**URL:** `http://kuzzle:7512/<index>/<collection>/_specifications`
Expand Down Expand Up @@ -42,11 +41,11 @@ title: deleteSpecifications
"collection": "<collection>",
"action": "deleteSpecifications",
"controller": "collection",
"result": {}
"result": true
}
```

Deletes the validation specification set for the <index>/<collection>.
It responds 200 even there where no validation specification manually set before.

***Note:*** by default, an empty specification is implicitally applied to all collections which. In a way, "no specification set" means "all documents are valid". This is why, using this route when no specifications have been set before, does not produce an error.
***Note:*** by default, an empty specification is implicitly applied to all collections which. In a way, "no specification set" means "all documents are valid". This is why, using this route when no specifications have been set before, does not produce an error.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-which

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed

100 changes: 100 additions & 0 deletions src/sdk-reference/collection/delete-specifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
layout: side-code.html
language-tab:
js: Javascript
java: Android
php: PHP
algolia: true
title: deleteSpecifications
---

# deleteSpecifications

```js
// Deleting specifications using callbacks (NodeJS or Web Browser)
kuzzle
.collection('collection', 'index')
.deleteSpecifications(function (err, deleted) {
// callback called once the delete action has been completed
});

// Deleting specifications using promises (NodeJS)
kuzzle
.collection('collection', 'index')
.deleteSpecificationsPromise()
.then(deleted => {
// promises resolved once the delete action has been completed
});
```

```java
// Deleting one document
kuzzle
.collection("collection", "index")
.deleteSpecifications(new ResponseListener<Boolean>() {
@Override
public void onSuccess(Boolean deleted) {

}

@Override
public void onError(JSONObject error) {
// Handle error
}
});
```

```php
<?php

use \Kuzzle\Kuzzle;

$kuzzle = new Kuzzle('localhost');
$dataCollection = $kuzzle->collection('collection', 'index');

// Deleting one document
try {
$deleted = $dataCollection->deleteSpecifications();
}
catch (ErrorException $e) {

}
```

> Callback response:

```json
true
```

Delete specifications linked to the collection object.

---

## deleteSpecifications([options], [callback])

| Arguments | Type | Description |
|---------------|---------|----------------------------------------|
| ``options`` | JSON object | Optional parameters |
| ``callback`` | function | Optional callback |

---

## Options

| Option | Type | Description | Default |
|---------------|---------|----------------------------------------|---------|
| ``queuable`` | boolean | Mark this request as (not) queuable | ``true`` |
| ``refresh`` | string | If set to ``wait_for``, Kuzzle will wait the persistence layer indexation to return (available with Elasticsearch 5.x and above) | ``undefined`` |

---

## Return value

Returns the `Collection` object to allow chaining.

---

## Callback response

Resolves to a boolean confirming the success of the delete action.
98 changes: 98 additions & 0 deletions src/sdk-reference/collection/get-specifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
layout: side-code.html
language-tab:
js: Javascript
java: Android
php: PHP
algolia: true
title: getSpecifications
---

# getSpecifications

```js
// Using callbacks (NodeJS or Web Browser)
kuzzle
.collection('collection', 'index')
.getSpecifications(function (error, specifications) {
// specifications is a JSON object
});

// Using promises (NodeJS)
kuzzle
.collection('collection', 'index')
.getSpecificationsPromise()
.then(specifications => {
// specifications is a JSON object
});
```

```java
kuzzle
.collection("collection", "index")
.getSpecifications(new ResponseListener<JSONObject>() {
@Override
public void onSuccess(JSONObject specifications) {
// specifications is a JSONObject
}

@Override
public void onError(JSONObject error) {
// Handle error
}
});
```

```php
<?php

use \Kuzzle\Kuzzle;

$kuzzle = new Kuzzle('localhost');
$dataCollection = $kuzzle->collection('collection', 'index');

try {
$specifications = $dataCollection->getSpecifications();
}
catch (ErrorException $e) {

}
```

> Callback response

```json
{
"validation": {
"strict": "true",
"fields": {
"foo": {
"mandatory": "true",
"type": "string",
"defaultValue": "bar"
}
}
},
"index": "index",
"collection": "collection"
}
```

Retrieves the specifications linked to the collection object.

---

## getSpecifications([options], callback)

| Arguments | Type | Description |
|---------------|---------|----------------------------------------|
| ``options`` | JSON Object | Optional parameters |
| ``callback`` | function | Callback handling the response |

---

## Options

| Option | Type | Description | Default |
|---------------|---------|----------------------------------------|---------|
| ``queuable`` | boolean | Mark this request as (not) queuable | ``true`` |
116 changes: 116 additions & 0 deletions src/sdk-reference/collection/scroll-specifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
layout: side-code.html
language-tab:
js: Javascript
java: Android
php: PHP
algolia: true
title: scrollSpecifications
---

# scrollSpecifications

```js
// Using callbacks (NodeJS or Web Browser)
kuzzle
.collection('collection', 'index')
.scrollSpecifications(scrollId, {scroll: '1m'}, function (err, res) {
res.hits.forEach(function (specification) {
console.log(specification);
});

res.total // Total specifications count
});

// Using promises (NodeJS only)
kuzzle
.collection('collection', 'index')
.scrollSpecificationsPromise(scrollId, {scroll: '1m'})
.then(res => {
res.hits.forEach(specification => {
console.log(specification);
});

res.total // Total specifications count
});
```

```java
Options opts = new Options();
opts.setScroll("1m");

kuzzle
.collection("collection", "index")
.scrollSpecifications(scrollId, opts, new ResponseListener<JSONObject>() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As seen in the corresponding SDK PRs, this method now resolves to a SearchResult/KuzzleSearchResult object

@Override
public void onSuccess(JSONObject res) {
for (int i = 0; i < res.getJSONArray("hits").length(); i++) {
res.getJSONArray("hits").getJSONObject(i) // Specification
}

res.getString("total"); // Total specifications count
}

@Override
public void onError(JSONObject error) {
// Handle error
}
});
```

```php
<?php

use \Kuzzle\Kuzzle;

$kuzzle = new Kuzzle('localhost');
$dataCollection = $kuzzle->collection('collection', 'index');

try {
$res = $dataCollection->scrollSpecifications($scrollId, ['scroll' => '1m']);

foreach ($res['hits'] as $specification) {
// Specification
}

// Total specifications count
$res['total'];
}
catch (ErrorException $e) {

}
```

> Callback response

```json
{
"hits": [
{"first": "specification"},
{"second": "specification"}
],
"total": 2
}
```

Returns a JSON object containing the next page of the scroll session, and the `scrollId` to be used by the next `scroll` action.
A scroll session is always initiated by a `searchSpecification` action by using the `scroll` argument.

---

## scrollSpecifications(scrollId, [options], callback)

| Arguments | Type | Description |
|---------------|---------|----------------------------------------|
| ``scrollId`` | string | The "scrollId" provided with the last scrollSpecifications response or from the initial searchSpecifications request |
| ``options`` | JSON object | Optional parameters |
| ``callback`` | function | Callback handling the response |

---

## Options

| Option | Type | Description | Default |
|---------------|---------|----------------------------------------|---------|
| ``queuable`` | boolean | Mark this request as (not) queuable | ``true`` |
| ``scroll`` | string | Re-initializes the scroll session timeout to its value. If not defined, the scroll timeout is defaulted to a Kuzzle configuration | ``undefined`` |
Loading