Skip to content

Commit

Permalink
Merge pull request #20 from SlicingDice/feature/change-table-to-dimen…
Browse files Browse the repository at this point in the history
…sion

Change table to dimension on code
  • Loading branch information
joaosimbiose authored Feb 26, 2018
2 parents 7ac3e5f + e97cf6e commit c635194
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 66 deletions.
123 changes: 75 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ If this is the first register ever entered into the system,
use Slicer\SlicingDice;

// Configure the client
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

// Inserting data
$insertData = array(
"[email protected]" => array(
"age" => 22
),
"auto-create" => array("table", "column")
"auto-create" => array("dimension", "column")
);
$client->insert($insertData);

Expand Down Expand Up @@ -95,9 +95,8 @@ print_r($client->countEntity($queryData));

### Constructor

`_construct($key, $usesTestEndpoint=false, $timeout=60)`
`_construct($key, $timeout=60)`
* `$key (array)` - [API key](https://docs.slicingdice.com/docs/api-keys) to authenticate requests with the SlicingDice API.
* `$usesTestEndpoint=false (boolean)` - If false the client will send requests to production end-point, otherwise to tests end-point.
* `$timeout (int)` - Amount of time, in seconds, to wait for results for each request.

### `getDatabase()`
Expand All @@ -108,8 +107,8 @@ Get information about current database. This method corresponds to a `GET` reque
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
print_r($client->getDatabase());
?>
```
Expand Down Expand Up @@ -137,8 +136,8 @@ Get all created columns, both active and inactive ones. This method corresponds
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
print_r($client->getColumns());
?>
```
Expand Down Expand Up @@ -179,8 +178,8 @@ Create a new column. This method corresponds to a [POST request at /column](http
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$column = array(
"name" => "Year",
"api-name" => "year",
Expand Down Expand Up @@ -209,8 +208,8 @@ Insert data to existing entities or create new entities, if necessary. This meth
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$insertData = array(
"[email protected]" => array(
"car-model" => "Ford Ka",
Expand Down Expand Up @@ -244,7 +243,7 @@ $insertData = array(
"date" => "2016-08-17T13:23:47+00:00"
)
),
"auto-create" => array("table", "column")
"auto-create" => array("dimension", "column")
);
print_r($client->insert($insertData));
?>
Expand All @@ -261,16 +260,16 @@ print_r($client->insert($insertData));
}
```

### `existsEntity($ids, $table)`
Verify which entities exist in a table (uses `default` table if not provided) given a list of entity IDs. This method corresponds to a [POST request at /query/exists/entity](https://docs.slicingdice.com/docs/exists).
### `existsEntity($ids, $dimension)`
Verify which entities exist in a dimension (uses `default` dimension if not provided) given a list of entity IDs. This method corresponds to a [POST request at /query/exists/entity](https://docs.slicingdice.com/docs/exists).

#### Request example

```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$ids = array(
"[email protected]",
"[email protected]",
Expand Down Expand Up @@ -304,8 +303,8 @@ Count the number of inserted entities in the whole database. This method corresp
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

print_r($client->countEntityTotal());
?>
Expand All @@ -323,20 +322,20 @@ print_r($client->countEntityTotal());
}
```

### `countEntityTotal($tables)`
Count the total number of inserted entities in the given tables. This method corresponds to a [POST request at /query/count/entity/total](https://docs.slicingdice.com/docs/total#section-counting-specific-tables).
### `countEntityTotal($dimensions)`
Count the total number of inserted entities in the given dimensions. This method corresponds to a [POST request at /query/count/entity/total](https://docs.slicingdice.com/docs/total#section-counting-specific-tables).

#### Request example

```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$tables = array("default");
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$dimensions = array("default");

print_r($client->countEntityTotal($tables));
print_r($client->countEntityTotal($dimensions));
?>
```

Expand All @@ -360,8 +359,8 @@ Count the number of entities matching the given query. This method corresponds t
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$query = array(
array(
"query-name" => "corolla-or-fit",
Expand Down Expand Up @@ -417,8 +416,8 @@ Count the number of occurrences for time-series events matching the given query.
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$query = array(
array(
"query-name" => "test-drives-in-ny",
Expand Down Expand Up @@ -476,8 +475,8 @@ Return the top values for entities matching the given query. This method corresp
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$query = array(
"car-year" => array(
"year" => 2
Expand Down Expand Up @@ -537,8 +536,8 @@ Return the aggregation of all columns in the given query. This method correspond
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$query = array(
"query" => array(
array(
Expand Down Expand Up @@ -592,8 +591,8 @@ Get all saved queries. This method corresponds to a [GET request at /query/saved
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
print_r($client->getSavedQueries());
?>
```
Expand Down Expand Up @@ -646,8 +645,8 @@ Create a saved query at SlicingDice. This method corresponds to a [POST request
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$query = array(
"name" => "my-saved-query",
"type" => "count/entity",
Expand Down Expand Up @@ -703,8 +702,8 @@ Update an existing saved query at SlicingDice. This method corresponds to a [PUT
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$newQuery = array(
"type" => "count/entity",
"query" => array(
Expand Down Expand Up @@ -758,8 +757,8 @@ Executed a saved query at SlicingDice. This method corresponds to a [GET request
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
print_r($client->getSavedQuery("my-saved-query"));
?>
```
Expand Down Expand Up @@ -798,8 +797,8 @@ Delete a saved query at SlicingDice. This method corresponds to a [DELETE reques
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
print_r($client->deleteSavedQuery("my-saved-query"));
?>
```
Expand Down Expand Up @@ -837,8 +836,8 @@ Retrieve inserted values for entities matching the given query. This method corr
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$query = array(
"query" => array(
array(
Expand Down Expand Up @@ -889,8 +888,8 @@ Retrieve inserted values as well as their relevance for entities matching the gi
```php
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$query = array(
"query" => array(
array(
Expand Down Expand Up @@ -935,6 +934,34 @@ print_r($client->score($query));
}
```

### `sql($query)`
Retrieve inserted values using a SQL syntax. This method corresponds to a POST request at /query/sql.

#### Request example

```php
<?php
use Slicer\SlicingDice;

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$query = "SELECT COUNT(*) FROM default WHERE age BETWEEN 0 AND 49";
print_r($client->sql($query));
?>
```

#### Output example

```json
{
"took":0.063,
"result":[
{"COUNT": 3}
],
"count":1,
"status":"success"
}
```

## License

[MIT](https://opensource.org/licenses/MIT)
14 changes: 7 additions & 7 deletions src/SlicingDice.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ public function insert($data){

/**
* Get count entity total queries
* @param array $tables An array containing the tables in which
* @param array $dimensions An array containing the dimensions in which
* the total query will be performed
*/
public function countEntityTotal($tables=array()) {
$query = array("tables" => $tables);
public function countEntityTotal($dimensions=array()) {
$query = array("dimensions" => $dimensions);
$url = $this->urlWrapper() . URLResources::QUERY_COUNT_ENTITY_TOTAL;
return $this->makeRequest($url, "POST", 0, $query);
}
Expand Down Expand Up @@ -260,13 +260,13 @@ public function countEvent($query) {
* Get if exists entities SlicingDice
*
* @param array $ids A list of ids
* @param string $table In which table entities check be checked
* @param string $dimension In which dimension entities check be checked
*/
public function existsEntity($ids, $table=NULL) {
public function existsEntity($ids, $dimension=NULL) {
$url = $this->urlWrapper() . URLResources::QUERY_EXISTS_ENTITY;
$query = array('ids' => $ids, );
if ($table) {
$query['table'] = $table;
if ($dimension) {
$query['dimension'] = $dimension;
}
return $this->makeRequest($url, "POST", 0, $query);
}
Expand Down
6 changes: 3 additions & 3 deletions tests_and_examples/examples/count_entity.json
Original file line number Diff line number Diff line change
Expand Up @@ -23283,7 +23283,7 @@
"name": "Test for a \"COUNT ENTITY\" query using automatically created columns, operator \"AND\" and parameter \"EQUALS\".",
"columns": [],
"insert": {
"auto-create": ["table", "column"],
"auto-create": ["dimension", "column"],
"24": {
"string-test-column": "value:matched_value",
"numeric-test-column": 1000001
Expand Down Expand Up @@ -23713,7 +23713,7 @@
"name": "Test for a \"COUNT ENTITY\" query using automatically created columns, operators \"AND\" and \"OR\" and parameter \"EQUALS\".",
"columns": [],
"insert": {
"auto-create": ["table", "column"],
"auto-create": ["dimension", "column"],
"24": {
"string-test-column": "value:matched_value",
"boolean-test-column": "true",
Expand Down Expand Up @@ -24251,7 +24251,7 @@
"name": "Test for a \"COUNT ENTITY\" query using automatically created columns, operators \"AND\" and \"OR\" and parameters \"EQUALS\", \"BETWEEN\" and \"MINFREQ\".",
"columns": [],
"insert": {
"auto-create": ["table", "column"],
"auto-create": ["dimension", "column"],
"24": {
"string-test-column": "value:matched_value",
"boolean-test-column": "true",
Expand Down
Loading

0 comments on commit c635194

Please sign in to comment.