This repository was archived by the owner on Mar 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 493
add typed push and set. #80
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,14 @@ String makeFirebaseURL(const String& path, const String& auth) { | |
return url; | ||
} | ||
|
||
template <typename T> | ||
String jsonEncode(const T& value) { | ||
JsonVariant json(value); | ||
String buf; | ||
json.printTo(buf); | ||
return buf; | ||
} | ||
|
||
} // namespace | ||
|
||
Firebase::Firebase(const String& host) : host_(host) { | ||
|
@@ -53,11 +61,45 @@ FirebaseGet Firebase::get(const String& path) { | |
return FirebaseGet(host_, auth_, path, &http_); | ||
} | ||
|
||
FirebaseSet Firebase::set(const String& path, int value) { | ||
return FirebaseSet(host_, auth_, path, jsonEncode(value), &http_); | ||
} | ||
FirebaseSet Firebase::set(const String& path, float value) { | ||
return FirebaseSet(host_, auth_, path, jsonEncode(value), &http_); | ||
} | ||
FirebaseSet Firebase::set(const String& path, double value) { | ||
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. bool is missing |
||
return FirebaseSet(host_, auth_, path, jsonEncode(value), &http_); | ||
} | ||
FirebaseSet Firebase::set(const String& path, const String& value) { | ||
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. Note: that this will break client that were pushing json encoded string. If needed, we could error out if the 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. Ya I like that idea. |
||
return FirebaseSet(host_, auth_, path, jsonEncode(value), &http_); | ||
} | ||
FirebaseSet Firebase::set(const String& path, const JsonObject& value) { | ||
String buf; | ||
value.printTo(buf); | ||
return FirebaseSet(host_, auth_, path, buf, &http_); | ||
} | ||
FirebaseSet Firebase::setRaw(const String& path, const String& value) { | ||
return FirebaseSet(host_, auth_, path, value, &http_); | ||
} | ||
|
||
FirebasePush Firebase::push(const String& path, int value) { | ||
return FirebasePush(host_, auth_, path, jsonEncode(value), &http_); | ||
} | ||
FirebasePush Firebase::push(const String& path, float value) { | ||
return FirebasePush(host_, auth_, path, jsonEncode(value), &http_); | ||
} | ||
FirebasePush Firebase::push(const String& path, double value) { | ||
return FirebasePush(host_, auth_, path, jsonEncode(value), &http_); | ||
} | ||
FirebasePush Firebase::push(const String& path, const String& value) { | ||
return FirebasePush(host_, auth_, path, jsonEncode(value), &http_); | ||
} | ||
FirebasePush Firebase::push(const String& path, const JsonObject& value) { | ||
String buf; | ||
value.printTo(buf); | ||
return FirebasePush(host_, auth_, path, buf, &http_); | ||
} | ||
FirebasePush Firebase::pushRaw(const String& path, const String& value) { | ||
return FirebasePush(host_, auth_, path, value, &http_); | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
seems these would be easy to template.
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.
Yes, but then we won't be able to really generate typed documentation for them, I prefered templating the internal helper:
jsonEncode
.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.
makes sense.