35
35
_RESERVED_FILTERS = ('$key' , '$value' , '$priority' )
36
36
37
37
38
- def get_reference (path = '/' , app = None ):
38
+ def reference (path = '/' , app = None ):
39
39
"""Returns a database Reference representing the node at the specified path.
40
40
41
41
If no path is specified, this function returns a Reference that represents the database root.
@@ -69,7 +69,7 @@ class Reference(object):
69
69
def __init__ (self , ** kwargs ):
70
70
"""Creates a new Reference using the provided parameters.
71
71
72
- This method is for internal use only. Use db.get_reference () to obtain an instance of
72
+ This method is for internal use only. Use db.reference () to obtain an instance of
73
73
Reference.
74
74
"""
75
75
self ._client = kwargs .get ('client' )
@@ -119,7 +119,7 @@ def child(self, path):
119
119
full_path = self ._pathurl + '/' + path
120
120
return Reference (client = self ._client , path = full_path )
121
121
122
- def get_value (self ):
122
+ def get (self ):
123
123
"""Returns the value at the current location of the database.
124
124
125
125
Returns:
@@ -130,41 +130,21 @@ def get_value(self):
130
130
"""
131
131
return self ._client .request ('get' , self ._add_suffix ())
132
132
133
- def get_priority (self ):
134
- """Returns the priority of this node, if specified.
135
-
136
- Returns:
137
- object: A priority value or None.
138
-
139
- Raises:
140
- ApiCallError: If an error occurs while communicating with the remote database server.
141
- """
142
- return self .
EDBE
_client .request ('get' , self ._add_suffix ('/.priority.json' ))
143
-
144
- def set_value (self , value , priority = None ):
133
+ def set (self , value ):
145
134
"""Sets the data at this location to the given value.
146
135
147
- The value must be JSON-serializable and not None. If a priority is specified, the node will
148
- be assigned that priority along with the value.
136
+ The value must be JSON-serializable and not None.
149
137
150
138
Args:
151
139
value: JSON-serialable value to be set at this location.
152
- priority: A numeric or alphanumeric priority value (optional).
153
140
154
141
Raises:
155
- ValueError: If the value is None or priority is invalid .
142
+ ValueError: If the value is None.
156
143
TypeError: If the value is not JSON-serializable.
157
144
ApiCallError: If an error occurs while communicating with the remote database server.
158
145
"""
159
146
if value is None :
160
147
raise ValueError ('Value must not be None.' )
161
- if priority is not None :
162
- Reference ._check_priority (priority )
163
- if isinstance (value , dict ):
164
- value = dict (value )
165
- value ['.priority' ] = priority
166
- else :
167
- value = {'.value' : value , '.priority' : priority }
168
148
params = {'print' : 'silent' }
169
149
self ._client .request_oneway ('put' , self ._add_suffix (), json = value , params = params )
170
150
@@ -191,7 +171,7 @@ def push(self, value=''):
191
171
push_id = output .get ('name' )
192
172
return self .child (push_id )
193
173
194
- def update_children (self , value ):
174
+ def update (self , value ):
195
175
"""Updates the specified child keys of this Reference to the provided values.
196
176
197
177
Args:
@@ -257,20 +237,6 @@ def order_by_value(self):
257
237
"""
258
238
return Query (order_by = '$value' , client = self ._client , pathurl = self ._add_suffix ())
259
239
260
- def order_by_priority (self ):
261
- """Creates a Query that orderes data by priority.
262
-
263
- Returned Query can be used to set additional parameters, and execute complex database
264
- queries (e.g. limit queries, range queries). Due to a limitation of the
265
- underlying REST API, the order-by-priority constraint can only be enforced during
266
- the execution time of the Query. When the Query returns results, the actual results
267
- will be returned as an unordered collection.
268
-
269
- Returns:
270
- Query: A database Query instance.
271
- """
272
- return Query (order_by = '$priority' , client = self ._client , pathurl = self ._add_suffix ())
273
-
274
240
def _add_suffix (self , suffix = '.json' ):
275
241
return self ._pathurl + suffix
276
242
@@ -294,8 +260,7 @@ class Query(object):
294
260
the final result is returned by the server as an unordered collection. Therefore the Query
295
261
interface performs another round of sorting at the client-side before returning the results
296
262
to the caller. This client-side sorted results are returned to the user as a Python
297
- OrderedDict. However, client-side sorting is not feasible for order-by-priority queries.
298
- Therefore for such queries results are returned as a regular unordered dict.
263
+ OrderedDict.
299
264
"""
300
265
301
266
def __init__ (self , ** kwargs ):
@@ -315,7 +280,7 @@ def __init__(self, **kwargs):
315
280
if kwargs :
316
281
raise ValueError ('Unexpected keyword arguments: {0}' .format (kwargs ))
317
282
318
- def set_limit_first (self , limit ):
283
+ def limit_to_first (self , limit ):
319
284
"""Creates a query with limit, and anchors it to the start of the window.
320
285
321
286
Args:
@@ -334,7 +299,7 @@ def set_limit_first(self, limit):
334
299
self ._params ['limitToFirst' ] = limit
335
300
return self
336
301
337
- def set_limit_last (self , limit ):
302
+ def limit_to_last (self , limit ):
338
303
"""Creates a query with limit, and anchors it to the end of the window.
339
304
340
305
Args:
@@ -353,7 +318,7 @@ def set_limit_last(self, limit):
353
318
self ._params ['limitToLast' ] = limit
354
319
return self
355
320
356
- def set_start_at (self , start ):
321
+ def start_at (self , start ):
357
322
"""Sets the lower bound for a range query.
358
323
359
324
The Query will only return child nodes with a value greater than or equal to the specified
@@ -373,7 +338,7 @@ def set_start_at(self, start):
373
338
self ._params ['startAt' ] = json .dumps (start )
374
339
return self
375
340
376
- def set_end_at (self , end ):
341
+ def end_at (self , end ):
377
342
"""Sets the upper bound for a range query.
378
343
379
344
The Query will only return child nodes with a value less than or equal to the specified
@@ -393,7 +358,7 @@ def set_end_at(self, end):
393
358
self ._params ['endAt' ] = json .dumps (end )
394
359
return self
395
360
396
- def set_equal_to (self , value ):
361
+ def equal_to (self , value ):
397
362
"""Sets an equals constraint on the Query.
398
363
399
364
The Query will only return child nodes whose value is equal to the specified value.
@@ -419,7 +384,7 @@ def querystr(self):
419
384
params .append ('{0}={1}' .format (key , self ._params [key ]))
420
385
return '&' .join (params )
421
386
422
- def run (self ):
387
+ def get (self ):
423
388
"""Executes this Query and returns the results.
424
389
425
390
The results will be returned as a sorted list or an OrderedDict, except in the case of
@@ -587,18 +552,19 @@ def __init__(self, url=None, auth=None, session=None):
587
552
@classmethod
588
553
def from_app (cls , app ):
589
554
"""Created a new _Client for a given App"""
590
- url = app .options .get ('dbURL ' )
555
+ url = app .options .get ('databaseURL ' )
591
556
if not url or not isinstance (url , six .string_types ):
592
557
raise ValueError (
593
- 'Invalid dbURL option: "{0}". dbURL must be a non-empty URL string.' .format (url ))
558
+ 'Invalid databaseURL option: "{0}". databaseURL must be a non-empty URL '
559
+ 'string.' .format (url))
594
560
parsed = urllib .parse .urlparse (url )
595
561
if parsed .scheme != 'https' :
596
562
raise ValueError (
597
- 'Invalid dbURL option: "{0}". dbURL must be an HTTPS URL.' .format (url ))
563
+ 'Invalid databaseURL option: "{0}". databaseURL must be an HTTPS URL.' .format (url ))
598
564
elif not parsed .netloc .endswith ('.firebaseio.com' ):
599
565
raise ValueError (
600
- 'Invalid dbURL option: "{0}". dbURL must be a valid URL to a Firebase Realtime '
601
- 'Database instance.' .format (url ))
566
+ 'Invalid databaseURL option: "{0}". databaseURL must be a valid URL to a '
567
+ 'Firebase Realtime Database instance.' .format (url ))
602
568
return _Client ('https://{0}' .format (parsed .netloc ), _OAuth (app ), requests .Session ())
603
569
604
570
def request (self , method , urlpath , ** kwargs ):
@@ -668,5 +634,6 @@ def __init__(self, app):
668
634
self ._app = app
669
635
670
636
def __call__ (self , req ):
671
- req .headers ['Authorization' ] = 'Bearer {0}' .format (self ._app .get_token ())
637
+ # pylint: disable=protected-access
638
+ req .headers ['Authorization' ] = 'Bearer {0}' .format (self ._app ._get_token ())
672
639
return req
0 commit comments