Skip to content

Commit 19cc18d

Browse files
authored
Merge pull request #29 from SlicingDice/feature/new-api-formats
Change client to match new api formats
2 parents 26686b4 + b417b82 commit 19cc18d

File tree

16 files changed

+49488
-53792
lines changed

16 files changed

+49488
-53792
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
### Updated
55
- Make client compatible with python 3
66
- Correct data extraction validator to accept columns: all
7+
- Add support for SQL queries on client
8+
- Adapt test queries to the changes on SlicingDice API
79

810
## [2.0.0]
911
### Updated

README.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ If this is the first register ever entered into the system,
3636
from pyslicer import SlicingDice
3737

3838
# Configure the client
39-
client = SlicingDice(master_key='API_KEY', uses_test_endpoint=False)
39+
client = SlicingDice(master_key='API_KEY')
4040

4141
# Inserting data
4242
insert_data = {
@@ -90,7 +90,7 @@ Get information about current database(related to api keys informed on construct
9090

9191
```python
9292
from pyslicer import SlicingDice
93-
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
93+
client = SlicingDice('MASTER_API_KEY')
9494
print(client.get_database())
9595
```
9696

@@ -116,7 +116,7 @@ Get all created columns, both active and inactive ones. This method corresponds
116116

117117
```python
118118
from pyslicer import SlicingDice
119-
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
119+
client = SlicingDice('MASTER_API_KEY')
120120
print(client.get_columns())
121121
```
122122

@@ -155,7 +155,7 @@ Create a new column. This method corresponds to a [POST request at /column](http
155155

156156
```python
157157
from pyslicer import SlicingDice
158-
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
158+
client = SlicingDice('MASTER_API_KEY')
159159
column = {
160160
"name": "Year",
161161
"api-name": "year",
@@ -182,7 +182,7 @@ Insert data to existing entities or create new entities, if necessary. This meth
182182

183183
```python
184184
from pyslicer import SlicingDice
185-
client = SlicingDice('MASTER_OR_WRITE_API_KEY', uses_test_endpoint=False)
185+
client = SlicingDice('MASTER_OR_WRITE_API_KEY')
186186
insert_data = {
187187
"user1@slicingdice.com": {
188188
"car-model": "Ford Ka",
@@ -239,7 +239,7 @@ Verify which entities exist in a table (uses `default` table if not provided) gi
239239

240240
```python
241241
from pyslicer import SlicingDice
242-
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
242+
client = SlicingDice('MASTER_OR_READ_API_KEY')
243243
ids = [
244244
"user1@slicingdice.com",
245245
"user2@slicingdice.com",
@@ -271,7 +271,7 @@ Count the number of inserted entities in the whole database. This method corresp
271271

272272
```python
273273
from pyslicer import SlicingDice
274-
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
274+
client = SlicingDice('MASTER_OR_READ_API_KEY')
275275

276276
print(client.count_entity_total())
277277
```
@@ -295,7 +295,7 @@ Count the total number of inserted entities in the given tables. This method cor
295295

296296
```python
297297
from pyslicer import SlicingDice
298-
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
298+
client = SlicingDice('MASTER_OR_READ_API_KEY')
299299

300300
tables = ['default']
301301

@@ -321,7 +321,7 @@ Count the number of entities matching the given query. This method corresponds t
321321

322322
```python
323323
from pyslicer import SlicingDice
324-
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
324+
client = SlicingDice('MASTER_OR_READ_API_KEY')
325325
query = [
326326
{
327327
"query-name": "corolla-or-fit",
@@ -375,7 +375,7 @@ Count the number of occurrences for time-series events matching the given query.
375375

376376
```python
377377
from pyslicer import SlicingDice
378-
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
378+
client = SlicingDice('MASTER_OR_READ_API_KEY')
379379
query = [
380380
{
381381
"query-name": "test-drives-in-ny",
@@ -431,7 +431,7 @@ Return the top values for entities matching the given query. This method corresp
431431

432432
```python
433433
from pyslicer import SlicingDice
434-
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
434+
client = SlicingDice('MASTER_OR_READ_API_KEY')
435435
query = {
436436
"car-year": {
437437
"year": 2
@@ -489,7 +489,7 @@ Return the aggregation of all columns in the given query. This method correspond
489489

490490
```python
491491
from pyslicer import SlicingDice
492-
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
492+
client = SlicingDice('MASTER_OR_READ_API_KEY')
493493
query = {
494494
"query": [
495495
{
@@ -538,7 +538,7 @@ Get all saved queries. This method corresponds to a [GET request at /query/saved
538538

539539
```python
540540
from pyslicer import SlicingDice
541-
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
541+
client = SlicingDice('MASTER_API_KEY')
542542
print(client.get_saved_queries())
543543
```
544544

@@ -589,7 +589,7 @@ Create a saved query at SlicingDice. This method corresponds to a [POST request
589589

590590
```python
591591
from pyslicer import SlicingDice
592-
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
592+
client = SlicingDice('MASTER_API_KEY')
593593
query = {
594594
"name": "my-saved-query",
595595
"type": "count/entity",
@@ -643,7 +643,7 @@ Update an existing saved query at SlicingDice. This method corresponds to a [PUT
643643

644644
```python
645645
from pyslicer import SlicingDice
646-
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
646+
client = SlicingDice('MASTER_API_KEY')
647647
new_query = {
648648
"type": "count/entity",
649649
"query": [
@@ -696,7 +696,7 @@ Executed a saved query at SlicingDice. This method corresponds to a [GET request
696696

697697
```python
698698
from pyslicer import SlicingDice
699-
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
699+
client = SlicingDice('MASTER_OR_READ_API_KEY')
700700
print(client.get_saved_query('my-saved-query'))
701701
```
702702

@@ -733,7 +733,7 @@ Delete a saved query at SlicingDice. This method corresponds to a [DELETE reques
733733

734734
```python
735735
from pyslicer import SlicingDice
736-
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
736+
client = SlicingDice('MASTER_API_KEY')
737737
print(client.delete_saved_query('my-saved-query'))
738738
```
739739

@@ -768,7 +768,7 @@ Retrieve inserted values for entities matching the given query. This method corr
768768

769769
```python
770770
from pyslicer import SlicingDice
771-
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
771+
client = SlicingDice('MASTER_OR_READ_API_KEY')
772772
query = {
773773
"query": [
774774
{
@@ -855,7 +855,6 @@ print(client.score(query))
855855
}
856856
},
857857
"page": 1,
858-
"page": 1,
859858
"next-page": null,
860859
"took": 0.063
861860
}

pyslicer/api.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(
2727
use_ssl(bool) -- Define if the request uses verification SSL for
2828
HTTPS requests. Defaults False.(Optional)
2929
timeout(int) -- Define timeout to request,
30-
defaults 30 secs(Optional).
30+
defaults 60 secs(Optional).
3131
"""
3232
self.keys = self._organize_keys(
3333
master_key, custom_key, read_key, write_key)
@@ -78,25 +78,31 @@ def _check_key(self, key_level):
7878
"This key is not allowed to perform this operation.")
7979
return current_key_level[0]
8080

81-
def _make_request(self, url, req_type, key_level, json_data=None):
81+
def _make_request(self, url, req_type, key_level, json_data=None,
82+
string_data=None, content_type='application/json'):
8283
"""Returns a object request result
8384
8485
Keyword arguments:
8586
url(string) -- the url to make a request
8687
req_type(string) -- the request type (POST, PUT, DELETE or GET)
8788
key_level(int) -- Define the key level needed
8889
json_data(json) -- The json to use on request (default None)
90+
content_type(string) -- The content_type to use in the request (default
91+
'application/json')
8992
"""
9093
self._check_key(key_level)
91-
headers = {'Content-Type': 'application/json',
94+
headers = {'Content-Type': content_type,
9295
'Authorization': self._api_key}
9396

97+
data = json_data
98+
if string_data is not None and json_data is None:
99+
data = string_data
94100
req = None
95101

96102
if req_type == "post":
97103
req = self._requester.post(
98104
url,
99-
data=json_data,
105+
data=data,
100106
headers=headers)
101107
elif req_type == "get":
102108
req = self._requester.get(
@@ -111,7 +117,7 @@ def _make_request(self, url, req_type, key_level, json_data=None):
111117
elif req_type == "put":
112118
req = self._requester.put(
113119
url,
114-
data=json_data,
120+
data=data,
115121
headers=headers)
116122

117123
return self._handler_request(req)
@@ -128,7 +134,8 @@ def _handler_request(self, req):
128134
try:
129135
result = ujson.loads(req.text)
130136
except ValueError as e:
131-
raise exceptions.InternalException("Error while trying to load Json: %s" % e.message)
137+
raise exceptions.InternalException("Error while trying to load"
138+
" Json: %s" % e.message)
132139

133140
sd_response = SDHandlerResponse(
134141
result=result,

0 commit comments

Comments
 (0)