summaryrefslogtreecommitdiff
path: root/FireBase/Query/ParameterQuery.cs
diff options
context:
space:
mode:
authorTrueKuehli <rctcoaster2000@hotmail.de>2018-09-29 17:19:43 +0200
committerTrueKuehli <rctcoaster2000@hotmail.de>2018-09-29 17:19:43 +0200
commitb83fc90abacc73262e0f8404cebadf6d64eb10ae (patch)
treed63b921c9bcdf8d381fc02ecfb0a1dd425ebb561 /FireBase/Query/ParameterQuery.cs
parent586d564f3c4c509c1aae931331e96f0382178f80 (diff)
parent680967aee589e4a8d277044b204de07cbe32f41e (diff)
Merge branch 'WebApi' of https://github.com/TrueDoctor/DiscoBot into WebApi
Merged the stuffs
Diffstat (limited to 'FireBase/Query/ParameterQuery.cs')
-rw-r--r--FireBase/Query/ParameterQuery.cs43
1 files changed, 43 insertions, 0 deletions
diff --git a/FireBase/Query/ParameterQuery.cs b/FireBase/Query/ParameterQuery.cs
new file mode 100644
index 0000000..e3d9717
--- /dev/null
+++ b/FireBase/Query/ParameterQuery.cs
@@ -0,0 +1,43 @@
+namespace Firebase.Database.Query
+{
+ using System;
+
+ /// <summary>
+ /// Represents a parameter in firebase query, e.g. "?data=foo".
+ /// </summary>
+ public abstract class ParameterQuery : FirebaseQuery
+ {
+ private readonly Func<string> parameterFactory;
+ private readonly string separator;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ParameterQuery"/> class.
+ /// </summary>
+ /// <param name="parent"> The parent of this query. </param>
+ /// <param name="parameterFactory"> The parameter. </param>
+ /// <param name="client"> The owning client. </param>
+ protected ParameterQuery(FirebaseQuery parent, Func<string> parameterFactory, FirebaseClient client)
+ : base(parent, client)
+ {
+ this.parameterFactory = parameterFactory;
+ this.separator = (this.Parent is ChildQuery) ? "?" : "&";
+ }
+
+ /// <summary>
+ /// Build the url segment represented by this query.
+ /// </summary>
+ /// <param name="child"> The child. </param>
+ /// <returns> The <see cref="string"/>. </returns>
+ protected override string BuildUrlSegment(FirebaseQuery child)
+ {
+ return $"{this.separator}{this.parameterFactory()}={this.BuildUrlParameter(child)}";
+ }
+
+ /// <summary>
+ /// The build url parameter.
+ /// </summary>
+ /// <param name="child"> The child. </param>
+ /// <returns> The <see cref="string"/>. </returns>
+ protected abstract string BuildUrlParameter(FirebaseQuery child);
+ }
+}