@@ -32,21 +32,21 @@ class SlicingDice(SlicingDiceAPI):
32
32
33
33
To create an object of the SliceDicer:
34
34
35
- >>> from pyslicer.api import SlicingDice
36
- >>> sd = SlicingDice('my-token')
35
+ from pyslicer.api import SlicingDice
36
+ sd = SlicingDice('my-token')
37
37
38
38
To create a field:
39
39
40
- >>> field_json = {
40
+ field_json = {
41
41
'name': 'Pyslicer String Field',
42
42
'description': 'Pyslicer example description',
43
43
'type': 'string',
44
44
'cardinality': 'low'}
45
- >>> print sd.create_field(field_json)
45
+ print sd.create_field(field_json)
46
46
47
47
To make a query:
48
48
49
- >>> query_json = {
49
+ query_json = {
50
50
'type': 'count',
51
51
'select': [
52
52
{
@@ -64,11 +64,11 @@ class SlicingDice(SlicingDiceAPI):
64
64
},
65
65
]
66
66
}
67
- >>> print sd.query(query_json)
67
+ print sd.query(query_json)
68
68
69
69
To make a index:
70
70
71
- >>> indexing_json = {
71
+ indexing_json = {
72
72
'foo@bar.com': {
73
73
'pyslicer-string-field': 'test_value_1',
74
74
'pyslicer-integer-field': 42,
@@ -78,7 +78,7 @@ class SlicingDice(SlicingDiceAPI):
78
78
'pyslicer-integer-field': 42,
79
79
},
80
80
}
81
- >>> print sd.index(indexing_json)
81
+ print sd.index(indexing_json)
82
82
"""
83
83
def __init__ (
84
84
self , write_key = None , read_key = None , master_key = None ,
@@ -87,10 +87,10 @@ def __init__(
87
87
88
88
Keyword arguments:
89
89
key(string or SlicerKey obj) -- Key to access API
90
- timeout(int) -- Define timeout to request,
91
- defaults 30 secs(default 30).
92
90
use_ssl(bool) -- Define if the request uses verification SSL for
93
91
HTTPS requests. Defaults False.(Optional)
92
+ timeout(int) -- Define timeout to request,
93
+ defaults 30 secs(default 30).
94
94
"""
95
95
super (SlicingDice , self ).__init__ (
96
96
write_key , read_key , master_key , custom_key , use_ssl , timeout )
@@ -141,20 +141,17 @@ def _saved_query_wrapper(self, url, query, update=False):
141
141
update(bool) -- Indicates with operation is update a
142
142
saved query or not.(default false)
143
143
"""
144
+ req_type = "post"
144
145
if update :
145
- return self ._make_request (
146
- url = url ,
147
- json_data = ujson .dumps (query ),
148
- req_type = "put" ,
149
- key_level = 2 )
146
+ req_type = "put"
150
147
return self ._make_request (
151
148
url = url ,
152
149
json_data = ujson .dumps (query ),
153
- req_type = "post" ,
150
+ req_type = req_type ,
154
151
key_level = 2 )
155
152
156
153
def get_projects (self ):
157
- """Get a list of projects"""
154
+ """Get a list of projects (all) """
158
155
url = SlicingDice .BASE_URL + URLResources .PROJECT
159
156
return self ._make_request (
160
157
url = url ,
@@ -168,6 +165,7 @@ def create_field(self, data, test=False):
168
165
Keyword arguments:
169
166
data -- A dictionary in the Slicing Dice field
170
167
format.
168
+ test(bool) -- if true will use tests end-point (default False)
171
169
"""
172
170
base_url = self ._wrapper_test (test )
173
171
sd_data = validators .FieldValidator (data )
@@ -180,7 +178,11 @@ def create_field(self, data, test=False):
180
178
key_level = 1 )
181
179
182
180
def get_fields (self , test = False ):
183
- """Get a list of fields"""
181
+ """Get a list of fields
182
+
183
+ Keyword arguments:
184
+ test(bool) -- if true will use tests end-point (default False)
185
+ """
184
186
base_url = self ._wrapper_test (test )
185
187
url = base_url + URLResources .FIELD
186
188
return self ._make_request (
@@ -189,11 +191,14 @@ def get_fields(self, test=False):
189
191
key_level = 2 )
190
192
191
193
def index (self , data , auto_create_fields = False , test = False ):
192
- """Make a index in Slicing Dice
194
+ """Make a index in Slicing Dice API
193
195
194
196
Keyword arguments:
195
197
data -- A dictionary in the Slicing Dice index
196
198
format.
199
+ auto_create_fields(bool) -- if true SlicingDice API will automatically
200
+ create nonexistent fields (default False)
201
+ test(bool) -- if true will use tests end-point (default False)
197
202
"""
198
203
if auto_create_fields :
199
204
data ["auto-create-fields" ] = True
@@ -212,13 +217,17 @@ def count_entity(self, query, test=False):
212
217
213
218
Keyword arguments:
214
219
query -- A dictionary in the Slicing Dice query
220
+ test(bool) -- if true will use tests end-point (default False)
215
221
"""
216
222
base_url = self ._wrapper_test (test )
217
223
url = base_url + URLResources .QUERY_COUNT_ENTITY
218
224
return self ._count_query_wrapper (url , query )
219
225
220
226
def count_entity_total (self , test = False ):
221
- """Make a count entity total query"""
227
+ """Make a count entity total query
228
+
229
+ test(bool) -- if true will use tests end-point (default False)
230
+ """
222
231
base_url = self ._wrapper_test (test )
223
232
url = base_url + URLResources .QUERY_COUNT_ENTITY_TOTAL
224
233
return self ._make_request (
@@ -231,6 +240,7 @@ def count_event(self, query, test=False):
231
240
232
241
Keyword arguments:
233
242
data -- A dictionary query
243
+ test(bool) -- if true will use tests end-point (default False)
234
244
"""
235
245
base_url = self ._wrapper_test (test )
236
246
url = base_url + URLResources .QUERY_COUNT_EVENT
@@ -240,7 +250,8 @@ def aggregation(self, query, test=False):
240
250
"""Make a aggregation query
241
251
242
252
Keyword arguments:
243
- data -- A dictionary query
253
+ query -- An aggregation query
254
+ test(bool) -- if true will use tests end-point (default False)
244
255
"""
245
256
base_url = self ._wrapper_test (test )
246
257
url = base_url + URLResources .QUERY_AGGREGATION
@@ -262,6 +273,7 @@ def top_values(self, query, test=False):
262
273
263
274
Keyword arguments:
264
275
query -- A dictionary query
276
+ test(bool) -- if true will use tests end-point (default False)
265
277
"""
266
278
base_url = self ._wrapper_test (test )
267
279
url = base_url + URLResources .QUERY_TOP_VALUES
@@ -278,6 +290,7 @@ def exists_entity(self, ids, test=False):
278
290
279
291
Keyword arguments:
280
292
ids -- A list with entity to check if exists
293
+ test(bool) -- if true will use tests end-point (default False)
281
294
"""
282
295
base_url = self ._wrapper_test (test )
283
296
url = base_url + URLResources .QUERY_EXISTS_ENTITY
@@ -297,7 +310,8 @@ def get_saved_query(self, query_name, test=False):
297
310
"""Get a saved query
298
311
299
312
Keyword arguments:
300
- query_name(string) -- A string with query name
313
+ query_name(string) -- The name of the saved query
314
+ test(bool) -- if true will use tests end-point (default False)
301
315
"""
302
316
base_url = self ._wrapper_test (test )
303
317
url = base_url + URLResources .QUERY_SAVED + query_name
@@ -310,7 +324,8 @@ def get_saved_queries(self, test=False):
310
324
"""Get all saved queries
311
325
312
326
Keyword arguments:
313
- query_name(string) -- A string with query name
327
+ query_name(string) -- The name of the saved query
328
+ test(bool) -- if true will use tests end-point (default False)
314
329
"""
315
330
base_url = self ._wrapper_test (test )
316
331
url = base_url + URLResources .QUERY_SAVED
@@ -323,7 +338,8 @@ def delete_saved_query(self, query_name, test=False):
323
338
"""Delete a saved query
324
339
325
340
Keyword arguments:
326
- query_name(string) -- A string with query name
341
+ query_name(string) -- The name of the saved query
342
+ test(bool) -- if true will use tests end-point (default False)
327
343
"""
328
344
base_url = self ._wrapper_test (test )
329
345
url = base_url + URLResources .QUERY_SAVED + query_name
@@ -338,6 +354,7 @@ def create_saved_query(self, query, test=False):
338
354
339
355
Keyword arguments:
340
356
query -- A dictionary query
357
+ test(bool) -- if true will use tests end-point (default False)
341
358
"""
342
359
base_url = self ._wrapper_test (test )
343
360
url = base_url + URLResources .QUERY_SAVED
@@ -347,8 +364,9 @@ def update_saved_query(self, name, query, test=False):
347
364
"""Get a list of queries saved
348
365
349
366
Keyword arguments:
350
- name -- A dictionary query
367
+ name -- The name of the saved query to update
351
368
query -- A dictionary query
369
+ test(bool) -- if true will use tests end-point (default False)
352
370
"""
353
371
base_url = self ._wrapper_test (test )
354
372
url = base_url + URLResources .QUERY_SAVED + name
@@ -359,16 +377,18 @@ def result(self, query, test=False):
359
377
360
378
Keyword arguments:
361
379
query -- A dictionary query
380
+ test(bool) -- if true will use tests end-point (default False)
362
381
"""
363
382
base_url = self ._wrapper_test (test )
364
383
url = base_url + URLResources .QUERY_DATA_EXTRACTION_RESULT
365
384
return self ._data_extraction_wrapper (url , query )
366
385
367
386
def score (self , query , test = False ):
368
- """Get a data extraction result
387
+ """Get a data extraction score
369
388
370
389
Keyword arguments:
371
390
query -- A dictionary query
391
+ test(bool) -- if true will use tests end-point (default False)
372
392
"""
373
393
base_url = self ._wrapper_test (test )
374
394
url = base_url + URLResources .QUERY_DATA_EXTRACTION_SCORE
0 commit comments