-
Notifications
You must be signed in to change notification settings - Fork 3
[NJ][Feature][IOS] Solved a get error on the last version of MicroPython #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,3 +127,4 @@ dmypy.json | |
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
| .DS_Store | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| import ujson | ||
| import urequests | ||
| import _thread | ||
|
|
||
| import urequests | ||
|
|
||
| class FirestoreException(Exception): | ||
| def __init__(self, message, code=400): | ||
|
|
@@ -42,38 +41,39 @@ def get_resource_name(url): | |
| return url[url.find("projects"):] | ||
|
|
||
|
|
||
| def send_request(path, method="get", params=dict(), data=None, dump=True): | ||
| def send_request(path, method="GET", params=dict(), data=None, dump=True): | ||
| headers = {} | ||
|
|
||
| if FIREBASE_GLOBAL_VAR.ACCESS_TOKEN: | ||
| headers["Authorization"] = "Bearer " + FIREBASE_GLOBAL_VAR.ACCESS_TOKEN | ||
|
|
||
| response = urequests.request( | ||
| method, path, params=params, headers=headers, json=data) | ||
| if method == "POST": | ||
| response = urequests.request(method, path, data=None, json=data) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should include the headers, no? |
||
| else: | ||
| response = urequests.request(method, path, headers=headers) | ||
|
|
||
| if dump == True: | ||
| if response.status_code < 200 or response.status_code > 299: | ||
| print(response.text) | ||
| raise FirestoreException(response.reason, response.status_code) | ||
|
|
||
| json = response.json() | ||
| if json.get("error"): | ||
| jsonResponse = response.json() | ||
| if jsonResponse.get("error"): | ||
| error = json["error"] | ||
| code = error["code"] | ||
| message = error["message"] | ||
| raise FirestoreException(message, code) | ||
| return json | ||
| return jsonResponse | ||
|
|
||
|
|
||
| class INTERNAL: | ||
|
|
||
| def patch(DOCUMENT_PATH, DOC, cb, update_mask=None): | ||
| PATH = construct_url(DOCUMENT_PATH) | ||
| LOCAL_PARAMS = to_url_params() | ||
| if update_mask: | ||
| for field in update_mask: | ||
| LOCAL_PARAMS += "updateMask.fieldPaths=" + field | ||
| DATA = DOC.process(get_resource_name(PATH)) | ||
| LOCAL_OUTPUT = send_request(PATH+LOCAL_PARAMS, "post", data=DATA) | ||
| LOCAL_PARAMS += "updateMask=" + field | ||
| DATA = DOC.process() | ||
| LOCAL_OUTPUT = send_request(PATH, "POST", data=DATA) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here one would need to use a PATCH method and the updateMask.fieldPaths notation is correct in the original, it just needs proper ampersand joining as the to_url_params function supports |
||
| if cb: | ||
| try: | ||
| return cb(LOCAL_OUTPUT) | ||
|
|
@@ -86,7 +86,7 @@ def create(COLLECTION_PATH, DOC, cb, document_id=None): | |
| PATH = construct_url(COLLECTION_PATH) | ||
| PARAMS = {"documentId": document_id} | ||
| DATA = DOC.process(get_resource_name(PATH)) | ||
| LOCAL_OUTPUT = send_request(PATH, "post", PARAMS, DATA) | ||
| LOCAL_OUTPUT = send_request(PATH, "POST", PARAMS, DATA) | ||
| if cb: | ||
| try: | ||
| return cb(LOCAL_OUTPUT) | ||
|
|
@@ -101,7 +101,7 @@ def get(DOCUMENT_PATH, cb, mask=None): | |
| if mask: | ||
| for field in mask: | ||
| LOCAL_PARAMS += "mask.fieldPaths=" + field | ||
| LOCAL_OUTPUT = send_request(PATH+LOCAL_PARAMS, "get") | ||
| LOCAL_OUTPUT = send_request(PATH+LOCAL_PARAMS, "GET") | ||
| if cb: | ||
| try: | ||
| return cb(LOCAL_OUTPUT) | ||
|
|
@@ -167,7 +167,7 @@ def list_collection_ids(DOCUMENT_PATH, cb, page_size=None, page_token=None): | |
| "pageSize": page_size, | ||
| "pageToken": page_token | ||
| } | ||
| LOCAL_OUTPUT = send_request(PATH, "post", data=DATA) | ||
| LOCAL_OUTPUT = send_request(PATH, "POST", data=DATA) | ||
| if cb: | ||
| try: | ||
| return cb(LOCAL_OUTPUT.get("collectionIds"), | ||
|
|
@@ -183,7 +183,7 @@ def run_query(DOCUMENT_PATH, query, cb): | |
| DATA = { | ||
| "structuredQuery": query.data | ||
| } | ||
| LOCAL_OUTPUT = send_request(PATH, "post", data=DATA) | ||
| LOCAL_OUTPUT = send_request(PATH, "POST", data=DATA) | ||
| if cb: | ||
| try: | ||
| return cb(LOCAL_OUTPUT.get("document")) | ||
|
|
@@ -267,3 +267,4 @@ def run_query(PATH, query, bg=True, cb=None): | |
| INTERNAL.run_query, [PATH, query, cb]) | ||
| else: | ||
| return INTERNAL.run_query(PATH, query, cb) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also worth noting that the patch function should be a "PATCH" method to work properly (this may be a new thing, this is such an old pull request that it may predate it)