Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Add javadocs to Arduino API. #123

Merged
merged 6 commits into from
May 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions src/FirebaseArduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,98 @@
#include "Firebase.h"
#include "FirebaseObject.h"

/**
* Main class for Arduino clients to interact with Firebase.
* This implementation is designed to follow Arduino best practices and favor
* simplicity over all else.
* For more complicated usecases and more control see the Firebase class in
* Firebase.h.
*/
class FirebaseArduino {
public:
/**
* Must be called first. This initialize the client with the given
* firebase host and credentials.
* \param host Your firebase db host, usually X.firebaseio.com.
* \param auth Optional credentials for the db, a secret or token.
*/
void begin(const char* host, const char* auth = "");

/**
* Writes data to a new child location under the parent at path.
* Equivalent to the REST API's POST.
* You should check success() after calling.
* \param path The path inside of your db to the parent object.
* \param value Data that you wish to add under the parent.
* \return The unique child key where the data was written.
*/
String push(const String& path, const JsonVariant& value);

/**
* Writes the data in value to the node located at path equivalent to the
* REST API's PUT.
* You should check success() after calling.
* \param path The path inside of your db to the node you wish to update.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/of your db//

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* \param value Data that you wish to write.
*/
void set(const String& path, const JsonVariant& value);


/**
* Gets the value located at path.
* You should check success() after calling.
* \param path The path to the node you wish to retrieve.
* \return The data located at that path. This may either be a single element
* or it may be a json structure. Will only be populated if success() is true.
*/
FirebaseObject get(const char* path);

/**
* Remove the node, and possibly entire tree, located at path.
* You should check success() after calling.
* \param path The path to the node you wish to remove,
* including all of its children.
*/
void remove(const char* path);

/**
* Starts streaming any changes made to the node located at path, including
* any of its children.
* You should check success() after calling.
* This changes the state of this object. Once this is called you may start
Copy link
Contributor

@proppy proppy May 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the state of this object.

We should a separate http object for that not to be true anymore. Maybe add a note that calling another method will interrupt streaming.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current API it is still true regardless of the http objects. Prior to calling stream() FirebaseArduino is in a state where it is not valid to call available() or readEvent().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can call available(), since all it does it poll the underlying socket.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can call it but it has no meaning to the user unless you are streaming as all other operations are synchronous.

* monitoring available() and calling readEvent() to get new events.
* \param path The path inside of your db to the node you wish to monitor.
*/
void stream(const char* path);

/**
* Checks if there are new events available. This is only meaningful once
* stream() has been called.
* \return If a new event is ready.
*/
bool available();

/**
* Reads the next event in a stream. This is only meaningful once stream() has
* been called.
* \return Object will have ["type"] that describes the event type, ["path"]
* that describes the effected path and ["data"] that was updated.
*/
FirebaseObject readEvent();

/**
* \return Whether the last command was successful.
*/
bool success();

/**
* \return Whether the last command failed.
*/
bool failed();

/**
* \return Error message from last command if failed() is true.
*/
const String& error();
private:
String host_;
Expand Down
35 changes: 35 additions & 0 deletions src/FirebaseObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,49 @@
#define FIREBASE_JSONBUFFER_SIZE 200
#endif // FIREBASE_JSONBUFFER_SIZE

/**
* Represents value stored in firebase, may be a singular value (leaf node) or
* a tree structure.
*/
class FirebaseObject {
public:
/**
* Construct from json.
* \param data Json formatted string.
*/
FirebaseObject(const String& data);

/**
* Interpret result as a bool, only applicable if result is a single element
* and not a tree.
*/
operator bool();

/**
* Interpret result as a int, only applicable if result is a single element
* and not a tree.
*/
operator int();

/**
* Interpret result as a float, only applicable if result is a single element
* and not a tree.
*/
operator float();

/**
* Interpret result as a String, only applicable if result is a single element
* and not a tree.
*/
operator const String&();

/**
* Interpret result as a JsonObject, if the result is a tree use this or the
* operator[] methods below.
*/
operator const JsonObject&();

//TODO(proppy): Add comments to these.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that with 5.2 we might be able to get rid of most of this class.

JsonObjectSubscript<const char*> operator[](const char* key);
JsonObjectSubscript<const String&> operator[](const String& key);
JsonVariant operator[](JsonObjectKey key) const;
Expand Down