Skip to content

Commit 7ee983b

Browse files
Merge pull request #23 from SlicingDice/feature/updateAPIVocabulary
Feature/update api vocabulary
2 parents a1de8a6 + b8bc00f commit 7ee983b

16 files changed

+30062
-30916
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Updated
44
- Update API errors code
5+
- Remove auto_create_columns parameter from insert method
56

67
## [1.0.0]
78
### Added

README.md

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Official Python client for [SlicingDice](http://www.slicingdice.com/), Data Ware
99

1010
If you are new to SlicingDice, check our [quickstart guide](http://panel.slicingdice.com/docs/#quickstart-guide) and learn to use it in 15 minutes.
1111

12-
Please refer to the [SlicingDice official documentation](http://panel.slicingdice.com/docs/) for more information on [analytics databases](http://panel.slicingdice.com/docs/#analytics-concepts), [data modeling](http://panel.slicingdice.com/docs/#data-modeling), [indexing](http://panel.slicingdice.com/docs/#data-indexing), [querying](http://panel.slicingdice.com/docs/#data-querying), [limitations](http://panel.slicingdice.com/docs/#current-slicingdice-limitations) and [API details](http://panel.slicingdice.com/docs/#api-details).
12+
Please refer to the [SlicingDice official documentation](http://panel.slicingdice.com/docs/) for more information on [analytics databases](http://panel.slicingdice.com/docs/#analytics-concepts), [data modeling](http://panel.slicingdice.com/docs/#data-modeling), [insertion](http://panel.slicingdice.com/docs/#data-insertion), [querying](http://panel.slicingdice.com/docs/#data-querying), [limitations](http://panel.slicingdice.com/docs/#current-slicingdice-limitations) and [API details](http://panel.slicingdice.com/docs/#api-details).
1313

1414
## Tests and Examples
1515

@@ -40,14 +40,14 @@ from pyslicer import SlicingDice
4040
# Configure the client
4141
client = SlicingDice(master_key='API_KEY', uses_test_endpoint=False)
4242

43-
# Indexing data
44-
index_data = {
43+
# Inserting data
44+
insert_data = {
4545
"user1@slicingdice.com": {
4646
"age": 22
4747
},
48-
"auto-create-fields": True
48+
"auto-create": ["table", "column"]
4949
}
50-
client.index(index_data)
50+
client.insert(insert_data)
5151

5252
# Querying data
5353
query_data = {
@@ -85,49 +85,37 @@ print client.count_entity(query_data)
8585
* `timeout (int)` - Amount of time, in seconds, to wait for results for each request.
8686
* `uses_test_endpoint (bool)` - If false the client will send requests to production end-point, otherwise to tests end-point.
8787

88-
### `get_projects()`
89-
Get all created projects, both active and inactive ones. This method corresponds to a [GET request at /project](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-project).
88+
### `get_database()`
89+
Get information about current database(related to api keys informed on construction). This method corresponds to a [GET request at /database](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-database).
9090

9191
#### Request example
9292

9393
```python
9494
from pyslicer import SlicingDice
9595
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
96-
print client.get_projects()
96+
print client.get_database()
9797
```
9898

9999
#### Output example
100100

101101
```json
102102
{
103-
"active": [
104-
{
105-
"name": "Project 1",
106-
"description": "My first project",
107-
"data-expiration": 30,
108-
"created-at": "2016-04-05T10:20:30Z"
109-
}
110-
],
111-
"inactive": [
112-
{
113-
"name": "Project 2",
114-
"description": "My second project",
115-
"data-expiration": 90,
116-
"created-at": "2016-04-05T10:20:30Z"
117-
}
118-
]
103+
"name": "Database 1",
104+
"description": "My first database",
105+
"data-expiration": 30,
106+
"created-at": "2016-04-05T10:20:30Z"
119107
}
120108
```
121109

122-
### `get_fields(test=False)`
123-
Get all created fields, both active and inactive ones. This method corresponds to a [GET request at /field](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-field).
110+
### `get_columns(test=False)`
111+
Get all created columns, both active and inactive ones. This method corresponds to a [GET request at /column](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-column).
124112

125113
#### Request example
126114

127115
```python
128116
from pyslicer import SlicingDice
129117
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
130-
print client.get_fields()
118+
print client.get_columns()
131119
```
132120

133121
#### Output example
@@ -158,22 +146,22 @@ print client.get_fields()
158146
}
159147
```
160148

161-
### `create_field(json_data, test=False)`
162-
Create a new field. This method corresponds to a [POST request at /field](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-field).
149+
### `create_column(json_data, test=False)`
150+
Create a new column. This method corresponds to a [POST request at /column](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-column).
163151

164152
#### Request example
165153

166154
```python
167155
from pyslicer import SlicingDice
168156
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
169-
field = {
157+
column = {
170158
"name": "Year",
171159
"api-name": "year",
172160
"type": "integer",
173161
"description": "Year of manufacturing",
174162
"storage": "latest-value"
175163
}
176-
print client.create_field(field)
164+
print client.create_column(column)
177165
```
178166

179167
#### Output example
@@ -185,15 +173,15 @@ print client.create_field(field)
185173
}
186174
```
187175

188-
### `index(json_data, auto_create_fields=False)`
189-
Index data to existing entities or create new entities, if necessary. This method corresponds to a [POST request at /index](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-index).
176+
### `insert(json_data)`
177+
Insert data to existing entities or create new entities, if necessary. This method corresponds to a [POST request at /insert](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-insert).
190178

191179
#### Request example
192180

193181
```python
194182
from pyslicer import SlicingDice
195183
client = SlicingDice('MASTER_OR_WRITE_API_KEY', uses_test_endpoint=False)
196-
index_data = {
184+
insert_data = {
197185
"user1@slicingdice.com": {
198186
"car-model": "Ford Ka",
199187
"year": 2016
@@ -226,24 +214,24 @@ index_data = {
226214
"date": "2016-08-17T13:23:47+00:00"
227215
}
228216
},
229-
"auto-create-fields": True
217+
"auto-create": ["table", "column"]
230218
}
231-
print client.index(index_data)
219+
print client.insert(insert_data)
232220
```
233221

234222
#### Output example
235223

236224
```json
237225
{
238226
"status": "success",
239-
"indexed-entities": 4,
240-
"indexed-fields": 12,
227+
"inserted-entities": 4,
228+
"inserted-columns": 12,
241229
"took": 0.023
242230
}
243231
```
244232

245233
### `exists_entity(ids)`
246-
Verify which entities exist in a project given a list of entity IDs. This method corresponds to a [POST request at /query/exists/entity](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-query-exists-entity).
234+
Verify which entities exist in a database given a list of entity IDs. This method corresponds to a [POST request at /query/exists/entity](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-query-exists-entity).
247235

248236
#### Request example
249237

@@ -275,7 +263,7 @@ print client.exists_entity(ids)
275263
```
276264

277265
### `count_entity_total()`
278-
Count the number of indexed entities. This method corresponds to a [GET request at /query/count/entity/total](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-query-count-entity-total).
266+
Count the number of inserted entities. This method corresponds to a [GET request at /query/count/entity/total](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-query-count-entity-total).
279267

280268
#### Request example
281269

@@ -466,7 +454,7 @@ print client.top_values(query)
466454
```
467455

468456
### `aggregation(json_data)`
469-
Return the aggregation of all fields in the given query. This method corresponds to a [POST request at /query/aggregation](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-query-aggregation).
457+
Return the aggregation of all columns in the given query. This method corresponds to a [POST request at /query/aggregation](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-query-aggregation).
470458

471459
#### Request example
472460

@@ -745,7 +733,7 @@ print client.delete_saved_query('my-saved-query')
745733
```
746734

747735
### `result(json_data)`
748-
Retrieve indexed values for entities matching the given query. This method corresponds to a [POST request at /data_extraction/result](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-data-extraction-result).
736+
Retrieve inserted values for entities matching the given query. This method corresponds to a [POST request at /data_extraction/result](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-data-extraction-result).
749737

750738
#### Request example
751739

@@ -766,7 +754,7 @@ query = {
766754
}
767755
}
768756
],
769-
"fields": ["car-model", "year"],
757+
"columns": ["car-model", "year"],
770758
"limit": 2
771759
}
772760
print client.result(query)
@@ -793,7 +781,7 @@ print client.result(query)
793781
```
794782

795783
### `score(json_data)`
796-
Retrieve indexed values as well as their relevance for entities matching the given query. This method corresponds to a [POST request at /data_extraction/score](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-data-extraction-score).
784+
Retrieve inserted values as well as their relevance for entities matching the given query. This method corresponds to a [POST request at /data_extraction/score](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-data-extraction-score).
797785

798786
#### Request example
799787

@@ -814,7 +802,7 @@ query = {
814802
}
815803
}
816804
],
817-
"fields": ["car-model", "year"],
805+
"columns": ["car-model", "year"],
818806
"limit": 2
819807
}
820808
print client.score(query)

pyslicer/client.py

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,29 @@ class SlicingDice(SlicingDiceAPI):
3535
from pyslicer.api import SlicingDice
3636
sd = SlicingDice('my-token')
3737
38-
To create a field:
38+
To create a column:
3939
40-
field_json = {
41-
'name': 'Pyslicer String Field',
40+
column_json = {
41+
'name': 'Pyslicer String Column',
4242
'description': 'Pyslicer example description',
4343
'type': 'string',
4444
'cardinality': 'low'}
45-
print sd.create_field(field_json)
45+
print sd.create_column(column_json)
4646
4747
To make a query:
4848
4949
query_json = {
5050
'type': 'count',
5151
'select': [
5252
{
53-
"pyslicer-string-field":
53+
"pyslicer-string-column":
5454
{
5555
"equal": "test_value_1"
5656
}
5757
},
5858
"or",
5959
{
60-
"pyslicer-string-field":
60+
"pyslicer-string-column":
6161
{
6262
"equal": "test_value_2"
6363
}
@@ -66,19 +66,19 @@ class SlicingDice(SlicingDiceAPI):
6666
}
6767
print sd.query(query_json)
6868
69-
To make a index:
69+
To insert data:
7070
71-
indexing_json = {
71+
inserting_json = {
7272
'foo@bar.com': {
73-
'pyslicer-string-field': 'test_value_1',
74-
'pyslicer-integer-field': 42,
73+
'pyslicer-string-column': 'test_value_1',
74+
'pyslicer-integer-column': 42,
7575
},
7676
'baz@bar.com': {
77-
'pyslicer-string-field': 'test_value_2',
78-
'pyslicer-integer-field': 42,
77+
'pyslicer-string-column': 'test_value_2',
78+
'pyslicer-integer-column': 42,
7979
},
8080
}
81-
print sd.index(indexing_json)
81+
print sd.insert(inserting_json)
8282
"""
8383
def __init__(
8484
self, write_key=None, read_key=None, master_key=None,
@@ -151,56 +151,52 @@ def _saved_query_wrapper(self, url, query, update=False):
151151
req_type=req_type,
152152
key_level=2)
153153

154-
def get_projects(self):
155-
"""Get a list of projects (all)"""
156-
url = SlicingDice.BASE_URL + URLResources.PROJECT
154+
def get_database(self):
155+
"""Get a database associated with this client (related to keys passed on construction)"""
156+
url = SlicingDice.BASE_URL + URLResources.DATABASE
157157
return self._make_request(
158158
url=url,
159159
req_type="get",
160160
key_level=2
161161
)
162162

163-
def create_field(self, data):
164-
"""Create field in Slicing Dice
163+
def create_column(self, data):
164+
"""Create column in Slicing Dice
165165
166166
Keyword arguments:
167-
data -- A dictionary or list on the Slicing Dice field
167+
data -- A dictionary or list on the Slicing Dice column
168168
format.
169169
"""
170170
base_url = self._wrapper_test()
171-
sd_data = validators.FieldValidator(data)
171+
sd_data = validators.ColumnValidator(data)
172172
if sd_data.validator():
173-
url = base_url + URLResources.FIELD
173+
url = base_url + URLResources.COLUMN
174174
return self._make_request(
175175
url=url,
176176
req_type="post",
177177
json_data=ujson.dumps(data),
178178
key_level=1)
179179

180-
def get_fields(self):
181-
"""Get a list of fields"""
180+
def get_columns(self):
181+
"""Get a list of columns"""
182182
base_url = self._wrapper_test()
183-
url = base_url + URLResources.FIELD
183+
url = base_url + URLResources.COLUMN
184184
return self._make_request(
185185
url=url,
186186
req_type="get",
187187
key_level=2)
188188

189-
def index(self, data, auto_create_fields=False):
190-
"""Make a index in Slicing Dice API
189+
def insert(self, data):
190+
"""Insert data into Slicing Dice API
191191
192192
Keyword arguments:
193-
data -- A dictionary in the Slicing Dice index
193+
data -- A dictionary in the Slicing Dice data format
194194
format.
195-
auto_create_fields(bool) -- if true SlicingDice API will automatically
196-
create nonexistent fields (default False)
197195
"""
198-
if auto_create_fields:
199-
data["auto-create-fields"] = True
200196
base_url = self._wrapper_test()
201-
sd_data = validators.IndexValidator(data)
197+
sd_data = validators.InsertValidator(data)
202198
if sd_data.validator():
203-
url = base_url + URLResources.INDEX
199+
url = base_url + URLResources.INSERT
204200
return self._make_request(
205201
url=url,
206202
json_data=ujson.dumps(data),
@@ -247,10 +243,10 @@ def aggregation(self, query):
247243
if "query" not in query:
248244
raise exceptions.InvalidQueryException(
249245
"The aggregation query must have up the key 'query'.")
250-
fields = query["query"]
251-
if len(fields) > 5:
246+
columns = query["query"]
247+
if len(columns) > 5:
252248
raise exceptions.MaxLimitException(
253-
"The aggregation query must have up to 5 fields per request.")
249+
"The aggregation query must have up to 5 columns per request.")
254250
return self._make_request(
255251
url=url,
256252
json_data=ujson.dumps(query),

pyslicer/core/handler_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def _raise_error(self):
1414
"""Find API error."""
1515
code_error = int(self.result['errors'][0]['code'])
1616
exception = slicer_exceptions[code_error]
17-
raise exception(self.result['errors'][0]['message'])
17+
raise exception(**self.result['errors'][0])
1818

1919
def request_successful(self):
2020
"""Returns true if request was successful

0 commit comments

Comments
 (0)