FirebaseParam.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. using UnityEngine;
  2. namespace SimpleFirebaseUnity
  3. {
  4. public struct FirebaseParam
  5. {
  6. string param;
  7. /// <summary>
  8. /// Created parameter for REST API call
  9. /// </summary>
  10. public string Parameter
  11. {
  12. get
  13. {
  14. return param;
  15. }
  16. }
  17. /// <summary>
  18. /// Created parameter for REST API call with the symbols encoded to url-safe escape characters.
  19. /// </summary>
  20. public string SafeParameter
  21. {
  22. get
  23. {
  24. return WWW.EscapeURL(param);
  25. }
  26. }
  27. /// <summary>
  28. /// Create new FirebaseQuery
  29. /// </summary>
  30. /// <param name="param">REST call parameters on a string. Example: &quot;orderBy=&#92;"$key&#92;"&quot;print=pretty&quot;auth=secret123"></param>
  31. public FirebaseParam(string _param = "")
  32. {
  33. param = _param;
  34. }
  35. /// <summary>
  36. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  37. /// </summary>
  38. public FirebaseParam Add(string parameter)
  39. {
  40. if (param != null && param.Length > 0)
  41. param += "&";
  42. param += parameter;
  43. return this;
  44. }
  45. /// <summary>
  46. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data . Set quoted parameter if necessary
  47. /// </summary>
  48. public FirebaseParam Add(string header, string value, bool quoted = true)
  49. {
  50. return (quoted) ? Add(header + "=\"" + value + "\"") : Add(header + "=" + value);
  51. }
  52. /// <summary>
  53. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  54. /// </summary>
  55. public FirebaseParam Add(string header, int value)
  56. {
  57. return Add(header + "=" + value);
  58. }
  59. /// <summary>
  60. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  61. /// </summary>
  62. public FirebaseParam Add(string header, float value)
  63. {
  64. return Add(header + "=" + value);
  65. }
  66. /// <summary>
  67. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  68. /// </summary>
  69. public FirebaseParam Add(string header, bool value)
  70. {
  71. return Add(header + "=" + value);
  72. }
  73. /// <summary>
  74. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  75. /// </summary>
  76. public FirebaseParam OrderByChild(string key)
  77. {
  78. return Add("orderBy", key);
  79. }
  80. /// <summary>
  81. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  82. /// </summary>
  83. public FirebaseParam OrderByKey()
  84. {
  85. return Add("orderBy", "$key");
  86. }
  87. /// <summary>
  88. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  89. /// </summary>
  90. public FirebaseParam OrderByValue()
  91. {
  92. return Add("orderBy", "$value");
  93. }
  94. /// <summary>
  95. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  96. /// </summary>
  97. public FirebaseParam OrderByPriority()
  98. {
  99. return Add("orderBy", "$priority");
  100. }
  101. /// <summary>
  102. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  103. /// </summary>
  104. public FirebaseParam LimitToFirst(int lim)
  105. {
  106. return Add("limitToFirst", lim);
  107. }
  108. /// <summary>
  109. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  110. /// </summary>
  111. public FirebaseParam LimitToLast(int lim)
  112. {
  113. return Add("limitToLast", lim);
  114. }
  115. /// <summary>
  116. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  117. /// </summary>
  118. public FirebaseParam StartAt(string start)
  119. {
  120. return Add("startAt", start);
  121. }
  122. /// <summary>
  123. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  124. /// </summary>
  125. public FirebaseParam StartAt(int start)
  126. {
  127. return Add("startAt", start);
  128. }
  129. /// <summary>
  130. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  131. /// </summary>
  132. public FirebaseParam StartAt(bool start)
  133. {
  134. return Add("startAt", start);
  135. }
  136. /// <summary>
  137. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  138. /// </summary>
  139. public FirebaseParam StartAt(float start)
  140. {
  141. return Add("startAt", start);
  142. }
  143. /// <summary>
  144. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  145. /// </summary>
  146. public FirebaseParam EndAt(string end)
  147. {
  148. return Add("endAt", end);
  149. }
  150. /// <summary>
  151. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  152. /// </summary>
  153. public FirebaseParam EndAt(int end)
  154. {
  155. return Add("endAt", end);
  156. }
  157. /// <summary>
  158. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  159. /// </summary>
  160. public FirebaseParam EndAt(bool end)
  161. {
  162. return Add("endAt", end);
  163. }
  164. /// <summary>
  165. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  166. /// </summary>
  167. public FirebaseParam EndAt(float end)
  168. {
  169. return Add("endAt", end);
  170. }
  171. /// <summary>
  172. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  173. /// </summary>
  174. public FirebaseParam EqualTo(string at)
  175. {
  176. return Add("equalTo", at);
  177. }
  178. /// <summary>
  179. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  180. /// </summary>
  181. public FirebaseParam EqualTo(int at)
  182. {
  183. return Add("equalTo", at);
  184. }
  185. /// <summary>
  186. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  187. /// </summary>
  188. public FirebaseParam EqualTo(bool at)
  189. {
  190. return Add("equalTo", at);
  191. }
  192. /// <summary>
  193. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  194. /// </summary>
  195. public FirebaseParam EqualTo(float at)
  196. {
  197. return Add("equalTo", at);
  198. }
  199. /// <summary>
  200. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  201. /// </summary>
  202. public FirebaseParam PrintPretty()
  203. {
  204. return Add("print=pretty");
  205. }
  206. /// <summary>
  207. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  208. /// </summary>
  209. public FirebaseParam PrintSilent()
  210. {
  211. return Add("print=silent");
  212. }
  213. /// <summary>
  214. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  215. /// </summary>
  216. public FirebaseParam Shallow()
  217. {
  218. return Add("shallow=true");
  219. }
  220. /// <summary>
  221. /// For details see https://firebase.google.com/docs/database/rest/retrieve-data
  222. /// </summary>
  223. public FirebaseParam Auth(string cred)
  224. {
  225. return Add("auth=" + cred);
  226. }
  227. public override string ToString()
  228. {
  229. return param;
  230. }
  231. /// <summary>
  232. /// Empty paramete or \"\"
  233. /// </summary>
  234. public static FirebaseParam Empty
  235. {
  236. get
  237. {
  238. return new FirebaseParam();
  239. }
  240. }
  241. }
  242. }