/ESP8266/libraries/firebase-arduino-master/src/FirebaseArduino.h

https://bitbucket.org/amwip/home-automation-frontend · C Header · 234 lines · 38 code · 29 blank · 167 comment · 0 complexity · 12ff7d821e55feb179960ebff343980d MD5 · raw file

  1. //
  2. // Copyright 2016 Google Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #ifndef FIREBASE_ARDUINO_H
  17. #define FIREBASE_ARDUINO_H
  18. #include <string>
  19. #include "Firebase.h"
  20. #include "FirebaseObject.h"
  21. /**
  22. * Main class for Arduino clients to interact with Firebase.
  23. * This implementation is designed to follow Arduino best practices and favor
  24. * simplicity over all else.
  25. * For more complicated usecases and more control see the Firebase class in
  26. * Firebase.h.
  27. */
  28. class FirebaseArduino {
  29. public:
  30. /**
  31. * Must be called first. This initialize the client with the given
  32. * firebase host and credentials.
  33. * \param host Your firebase db host, usually X.firebaseio.com.
  34. * \param auth Optional credentials for the db, a secret or token.
  35. */
  36. void begin(const String& host, const String& auth = "");
  37. /**
  38. * Appends the integer value to the node at path.
  39. * Equivalent to the REST API's POST.
  40. * You should check success() after calling.
  41. * \param path The path of the parent node.
  42. * \param value Integer value that you wish to append to the node.
  43. * \return The unique key of the new child node.
  44. */
  45. String pushInt(const String& path, int value);
  46. /**
  47. * Appends the float value to the node at path.
  48. * Equivalent to the REST API's POST.
  49. * You should check success() after calling.
  50. * \param path The path of the parent node.
  51. * \param value Float value that you wish to append to the node.
  52. * \return The unique key of the new child node.
  53. */
  54. String pushFloat(const String& path, float value);
  55. /**
  56. * Appends the bool value to the node at path.
  57. * Equivalent to the REST API's POST.
  58. * You should check success() after calling.
  59. * \param path The path of the parent node.
  60. * \param value Bool value that you wish to append to the node.
  61. * \return The unique key of the new child node.
  62. */
  63. String pushBool(const String& path, bool value);
  64. /**
  65. * Appends the String value to the node at path.
  66. * Equivalent to the REST API's POST.
  67. * You should check success() after calling.
  68. * \param path The path of the parent node.
  69. * \param value String value that you wish to append to the node.
  70. * \return The unique key of the new child node.
  71. */
  72. String pushString(const String& path, const String& value);
  73. /**
  74. * Appends the JSON data to the node at path.
  75. * Equivalent to the REST API's POST.
  76. * You should check success() after calling.
  77. * \param path The path of the parent node.
  78. * \param value JSON data that you wish to append to the node.
  79. * \return The unique key of the new child node.
  80. */
  81. String push(const String& path, const JsonVariant& value);
  82. /**
  83. * Writes the integer value to the node located at path equivalent to the
  84. * REST API's PUT.
  85. * You should check success() after calling.
  86. * \param path The path inside of your db to the node you wish to update.
  87. * \param value Integer value that you wish to write.
  88. */
  89. void setInt(const String& path, int value);
  90. /**
  91. * Writes the float value to the node located at path equivalent to the
  92. * REST API's PUT.
  93. * You should check success() after calling.
  94. * \param path The path inside of your db to the node you wish to update.
  95. * \param value Float value that you wish to write.
  96. */
  97. void setFloat(const String& path, float value);
  98. /**
  99. * Writes the bool value to the node located at path equivalent to the
  100. * REST API's PUT.
  101. * You should check success() after calling.
  102. * \param path The path inside of your db to the node you wish to update.
  103. * \param value Bool value that you wish to write.
  104. */
  105. void setBool(const String& path, bool value);
  106. /**
  107. * Writes the String value to the node located at path equivalent to the
  108. * REST API's PUT.
  109. * You should check success() after calling.
  110. * \param path The path inside of your db to the node you wish to update.
  111. * \param value String value that you wish to write.
  112. */
  113. void setString(const String& path, const String& value);
  114. /**
  115. * Writes the JSON data to the node located at path.
  116. * Equivalent to the REST API's PUT.
  117. * You should check success() after calling.
  118. * \param path The path inside of your db to the node you wish to update.
  119. * \param value JSON data that you wish to write.
  120. */
  121. void set(const String& path, const JsonVariant& value);
  122. /**
  123. * Gets the integer value located at path.
  124. * You should check success() after calling.
  125. * \param path The path to the node you wish to retrieve.
  126. * \return The integer value located at that path. Will only be populated if success() is true.
  127. */
  128. int getInt(const String& path);
  129. /**
  130. * Gets the float value located at path.
  131. * You should check success() after calling.
  132. * \param path The path to the node you wish to retrieve.
  133. * \return The float value located at that path. Will only be populated if success() is true.
  134. */
  135. float getFloat(const String& path);
  136. /**
  137. * Gets the string value located at path.
  138. * You should check success() after calling.
  139. * \param path The path to the node you wish to retrieve.
  140. * \return The string value located at that path. Will only be populated if success() is true.
  141. */
  142. String getString(const String& path);
  143. /**
  144. * Gets the boolean value located at path.
  145. * You should check success() after calling.
  146. * \param path The path to the node you wish to retrieve.
  147. * \return The boolean value located at that path. Will only be populated if success() is true.
  148. */
  149. bool getBool(const String& path);
  150. /**
  151. * Gets the json object value located at path.
  152. * You should check success() after calling.
  153. * \param path The path to the node you wish to retrieve.
  154. * \return a FirebaseObject value located at that path. Will only be populated if success() is true.
  155. */
  156. FirebaseObject get(const String& path);
  157. /**
  158. * Remove the node, and possibly entire tree, located at path.
  159. * You should check success() after calling.
  160. * \param path The path to the node you wish to remove,
  161. * including all of its children.
  162. */
  163. void remove(const String& path);
  164. /**
  165. * Starts streaming any changes made to the node located at path, including
  166. * any of its children.
  167. * You should check success() after calling.
  168. * This changes the state of this object. Once this is called you may start
  169. * monitoring available() and calling readEvent() to get new events.
  170. * \param path The path inside of your db to the node you wish to monitor.
  171. */
  172. void stream(const String& path);
  173. /**
  174. * Checks if there are new events available. This is only meaningful once
  175. * stream() has been called.
  176. * \return If a new event is ready.
  177. */
  178. bool available();
  179. /**
  180. * Reads the next event in a stream. This is only meaningful once stream() has
  181. * been called.
  182. * \return FirebaseObject will have ["type"] that describes the event type, ["path"]
  183. * that describes the effected path and ["data"] that was updated.
  184. */
  185. FirebaseObject readEvent();
  186. /**
  187. * \return Whether the last command was successful.
  188. */
  189. bool success();
  190. /**
  191. * \return Whether the last command failed.
  192. */
  193. bool failed();
  194. /**
  195. * \return Error message from last command if failed() is true.
  196. */
  197. const String& error();
  198. private:
  199. std::string host_;
  200. std::string auth_;
  201. FirebaseError error_;
  202. std::shared_ptr<FirebaseHttpClient> http_;
  203. };
  204. extern FirebaseArduino Firebase;
  205. #endif // FIREBASE_ARDUINO_H