Skip to content

Commit f9a0439

Browse files
faaezshariq
authored andcommitted
Adding documentation for push (#2)
* Update firebase.py Enabling push * Update README.md * Update README.md Adding documentation for push
1 parent fccd94b commit f9a0439

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ https://www.firebase.com/signup/
1212

1313

1414

15-
##get and put
15+
##get, put and push
1616

17-
`get` gets the value of a Firebase at some URL, and `put` sets the value of a Firebase at URL to some data.
17+
`get` gets the value of a Firebase at some URL, `put` writes or replaces data at the path defined by URL and `push` appends data to a list at the path defined by URL. A new ID is also generated every time you `push` to a Firebase URL.
1818

1919
```python
2020
>>> import firebase
@@ -36,6 +36,15 @@ tell me everything
3636

3737
>>> print firebase.get(URL + '/color')
3838
red
39+
40+
>>> #Whereas using put replaces existing data, push simply appends to a list
41+
>>> firebase.push(URL+'/listexample',{'color':'red'})
42+
>>> firebase.get(URL+'/listexample')
43+
{'u'-JyAXHX9ZNBh7tPPja4w':{'color':'red'}}
44+
45+
>>> firebase.push(URL+'/listexample',{'color':'green'})
46+
>>> firebase.get(URL+'/listexample')
47+
{'u'-JyAXHX9ZNBh7tPPja4w':{'color':'red'},'-JyAXHX9ZNBh7tPPjasd':{'color':'green'}}
3948
```
4049

4150

firebase.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ def get(URL):
125125
raise FirebaseException(response.text)
126126
return json.loads(response.text)
127127

128-
129-
# Yuck, I don't want to write documentation for this :p
130-
#def push(URL, msg):
131-
# to_post = json.dumps(msg)
132-
# response = requests.post(firebaseURL(URL), data=to_post)
133-
# if response.status_code != 200:
134-
# raise Exception(response.text)
128+
def push(URL, msg):
129+
to_post = json.dumps(msg)
130+
response = requests.post(firebaseURL(URL), data=to_post)
131+
if response.status_code != 200:
132+
raise Exception(response.text)

0 commit comments

Comments
 (0)