-
Notifications
You must be signed in to change notification settings - Fork 493
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
Refactored Firebase library #42
Conversation
…eturn type to include status, changed style to match Google Style guide.
Also should note this is based on the other pull request so ignore that one here and only accept this one when that one is in. |
If we make As I commented on #41: I'm not sure we should make it easy for the user to do multiple thing at a time with the same client. If they want to do streaming and post update they could create multiple instance of the The idea was that Ideally I like to converge in a direction where there the only difference between |
// handle error. | ||
if (fbase.error()) { | ||
// add a new entry. | ||
FirebaseResultWithMessage push = fbase.push("/logs", "{\".sv\": \"timestamp\"}"); |
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.
Is that a different type: FirebaseResultWithMessage
? I don't see it declared in Firebase.h
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.
Yup, I had it then decided it wasn't worth the complexity to maintain two types. I liked that it was explicit in what returned a body and what didn't.
I will fix it.
I did a major change over to a different paradigm. Let me know what you think of this one. This pushes more of the logic into the returned object a FirebaseCall. This allows the optional rawResponse() call or the library to not read the response if the user is not interested in it. It reuses the http object for all calls except the streaming one. I still kept the streaming impl pretty separate but accessable through the main Firebase interface. It just feels really disjoint to me. It holds the http object for a while, the others are all immediate. It allows multiple reads, it has events. I am off until next week so we can discuss more then, just wanted to post this up. I am not sure the streaming example works for me either. |
void loop() { | ||
if (fbase.error()) { | ||
void loop() { | ||
static FirebaseEventStream stream = fbase.stream("/bitcoin"); |
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.
I didn't realize this would force the user to store a static
, I think we should find a way that keep the state in the Firebase object so that the user don't have to worry about the lifetime of the result object.
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.
Ya I am still playing with that but it would have to be either a static like this and use return value optimization to allow this to be constructed or to switch over to returning a unique_ptr which is a little ugly but would work like we want.
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.
maybe we could move this as a global?
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.
Give it a shot, I thought something was preventing that from working. I think it was you can't construct the event stream until setup() is called which won't happen if you directly initialize the global.
It isn't really a copyable object with the HTTP connection so you can't create a global then copy this value in.
I think we either need to make it a movable object which is probably the cleanest for the client, or return a unique_ptr<> to the object on the heap. This way is the most standard for c++ but maybe not arduino and looks ungly.
Made a few more comments, I like the separation of the logic but I'd like to find a way not to push the
I feel like the streaming impl is a call that can yield multiple result, all the other methods also hold the http object in a way since they don't re-inialize the connection between each call. |
I feel we should hold on the refactoring until we merge #43: json will likely warrant returning @ed7coyne @aliafshar does that sound OK with you? |
This reverts commit 077e060.
Updated to reflect changes decided in #41 |
|
||
class FirebaseGetResult : public FirebaseResult { | ||
public: | ||
static FirebaseGetResult FromError(const String& error_message) { |
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.
does this need to be public? it seems it is only being used by the client impl.
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.
We could make them private and make them friend classes. This way allows clients to create tests easily though. I don't feel strongly either way.
// True if no error. | ||
operator bool() const; | ||
|
||
bool isError() const; |
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.
I wonder if we should keep the separate FirebaseError
type, with a message()
method, etc, and have API method specifics result types compose the generic error and the method specific result.
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.
Sounds good.
Just some nits, I'd be happy to send a PR addressing them. |
return url; | ||
} | ||
|
||
class FirebaseCall { |
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.
Maybe we should rename that into HTTPRequest
since there is not much specific to firebase in this helper (basically just the port and the fingerprint).
firebase: refactor the refactoring
Let's merge this once we fix the streaming sample. |
FirebaseCall::FirebaseCall(const String& host, const String& auth, | ||
const char* method, const String& path, | ||
const String& data, HTTPClient* http) { | ||
if (!http) { |
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.
We should probably reuse the client for now (even for stream) and do that in a separate PR (that might be the cause of the crash we see with the stream sample)
firebase: fix stream example
Refactor merge
As discussed in issue #41
Refactored to provide result and not depend on class state for error reporting, conform to Google C++ style.
Also broke FirebaseEventStream out from Firebase. When this is connected I believe any other calls (push,fetch,etc..) to the class would break it. For that reason it really seems like this should be its own focused class. Or you need large comments explaining this gotcha.