@@ -90,6 +90,12 @@ def __init__(self, collection_path, api_key, credentials, project_id, requests):
90
90
self ._project_id = project_id
91
91
self ._requests = requests
92
92
93
+ self ._base_path = f"projects/{ self ._project_id } /databases/(default)/documents"
94
+ self ._base_url = f"https://firestore.googleapis.com/v1/{ self ._base_path } "
95
+
96
+ if self ._credentials :
97
+ self .__datastore = Client (credentials = self ._credentials , project = self ._project_id )
98
+
93
99
def document (self , document_id ):
94
100
""" A reference to a document in a collection.
95
101
@@ -105,6 +111,52 @@ def document(self, document_id):
105
111
self ._path .append (document_id )
106
112
return Document (self ._path , api_key = self ._api_key , credentials = self ._credentials , project_id = self ._project_id , requests = self ._requests )
107
113
114
+ def get (self , token = None ):
115
+ """ Returns a list of dict's containing document ID and the
116
+ data stored within them.
117
+
118
+
119
+ :type token: str
120
+ :param token: (Optional) Firebase Auth User ID Token, defaults
121
+ to :data:`None`.
122
+
123
+
124
+ :return: A list of document ID's with the data they possess.
125
+ :rtype: list
126
+ """
127
+
128
+ path = self ._path .copy ()
129
+ self ._path .clear ()
130
+
131
+ docs = []
132
+
133
+ if self ._credentials :
134
+ db_ref = _build_db (self .__datastore , path )
135
+
136
+ results = db_ref .get ()
137
+
138
+ for result in results :
139
+ docs .append ({result .id : result .to_dict ()})
140
+
141
+ else :
142
+
143
+ req_ref = f"{ self ._base_url } /{ '/' .join (path )} ?key={ self ._api_key } "
144
+
145
+ if token :
146
+ headers = {"Authorization" : "Firebase " + token }
147
+ response = self ._requests .get (req_ref , headers = headers )
148
+
149
+ else :
150
+ response = self ._requests .get (req_ref )
151
+
152
+ raise_detailed_error (response )
153
+
154
+ for doc in response .json ()['documents' ]:
155
+ doc_id = doc ['name' ].split ('/' )
156
+ docs .append ({doc_id .pop (): _from_datastore ({'fields' : doc ['fields' ]})})
157
+
158
+ return docs
159
+
108
160
109
161
class Document :
110
162
""" A reference to a document in a Firestore database.
0 commit comments