From de0f076ef9ff546c9a90513259ad6c42cd2224b3 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Sat, 29 Sep 2018 16:51:26 +0200 Subject: added firebase api --- FireBase/Query/AuthQuery.cs | 33 ++++ FireBase/Query/ChildQuery.cs | 56 ++++++ FireBase/Query/FilterQuery.cs | 81 ++++++++ FireBase/Query/FirebaseQuery.cs | 314 +++++++++++++++++++++++++++++++ FireBase/Query/IFirebaseQuery.cs | 43 +++++ FireBase/Query/OrderQuery.cs | 34 ++++ FireBase/Query/ParameterQuery.cs | 43 +++++ FireBase/Query/QueryExtensions.cs | 207 ++++++++++++++++++++ FireBase/Query/QueryFactoryExtensions.cs | 176 +++++++++++++++++ FireBase/Query/SilentQuery.cs | 18 ++ 10 files changed, 1005 insertions(+) create mode 100644 FireBase/Query/AuthQuery.cs create mode 100644 FireBase/Query/ChildQuery.cs create mode 100644 FireBase/Query/FilterQuery.cs create mode 100644 FireBase/Query/FirebaseQuery.cs create mode 100644 FireBase/Query/IFirebaseQuery.cs create mode 100644 FireBase/Query/OrderQuery.cs create mode 100644 FireBase/Query/ParameterQuery.cs create mode 100644 FireBase/Query/QueryExtensions.cs create mode 100644 FireBase/Query/QueryFactoryExtensions.cs create mode 100644 FireBase/Query/SilentQuery.cs (limited to 'FireBase/Query') diff --git a/FireBase/Query/AuthQuery.cs b/FireBase/Query/AuthQuery.cs new file mode 100644 index 0000000..8a8d3e8 --- /dev/null +++ b/FireBase/Query/AuthQuery.cs @@ -0,0 +1,33 @@ +namespace Firebase.Database.Query +{ + using System; + + /// + /// Represents an auth parameter in firebase query, e.g. "?auth=xyz". + /// + public class AuthQuery : ParameterQuery + { + private readonly Func tokenFactory; + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The authentication token factory. + /// The owner. + public AuthQuery(FirebaseQuery parent, Func tokenFactory, FirebaseClient client) : base(parent, () => client.Options.AsAccessToken ? "access_token" : "auth", client) + { + this.tokenFactory = tokenFactory; + } + + /// + /// Build the url parameter value of this child. + /// + /// The child of this child. + /// The . + protected override string BuildUrlParameter(FirebaseQuery child) + { + return this.tokenFactory(); + } + } +} diff --git a/FireBase/Query/ChildQuery.cs b/FireBase/Query/ChildQuery.cs new file mode 100644 index 0000000..1696ea8 --- /dev/null +++ b/FireBase/Query/ChildQuery.cs @@ -0,0 +1,56 @@ +namespace Firebase.Database.Query +{ + using System; + + /// + /// Firebase query which references the child of current node. + /// + public class ChildQuery : FirebaseQuery + { + private readonly Func pathFactory; + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The path to the child node. + /// The owner. + public ChildQuery(FirebaseQuery parent, Func pathFactory, FirebaseClient client) + : base(parent, client) + { + this.pathFactory = pathFactory; + } + + /// + /// Initializes a new instance of the class. + /// + /// The client. + /// The path to the child node. + public ChildQuery(FirebaseClient client, Func pathFactory) + : this(null, pathFactory, client) + { + } + + /// + /// Build the url segment of this child. + /// + /// The child of this child. + /// The . + protected override string BuildUrlSegment(FirebaseQuery child) + { + var s = this.pathFactory(); + + if (s != string.Empty && !s.EndsWith("/")) + { + s += '/'; + } + + if (!(child is ChildQuery)) + { + return s + ".json"; + } + + return s; + } + } +} diff --git a/FireBase/Query/FilterQuery.cs b/FireBase/Query/FilterQuery.cs new file mode 100644 index 0000000..f9f6271 --- /dev/null +++ b/FireBase/Query/FilterQuery.cs @@ -0,0 +1,81 @@ +namespace Firebase.Database.Query +{ + using System; + using System.Globalization; + + /// + /// Represents a firebase filtering query, e.g. "?LimitToLast=10". + /// + public class FilterQuery : ParameterQuery + { + private readonly Func valueFactory; + private readonly Func doubleValueFactory; + private readonly Func boolValueFactory; + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The filter. + /// The value for filter. + /// The owning client. + public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory, FirebaseClient client) + : base(parent, filterFactory, client) + { + this.valueFactory = valueFactory; + } + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The filter. + /// The value for filter. + /// The owning client. + public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory, FirebaseClient client) + : base(parent, filterFactory, client) + { + this.doubleValueFactory = valueFactory; + } + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The filter. + /// The value for filter. + /// The owning client. + public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory, FirebaseClient client) + : base(parent, filterFactory, client) + { + this.boolValueFactory = valueFactory; + } + + /// + /// The build url parameter. + /// + /// The child. + /// Url parameter part of the resulting path. + protected override string BuildUrlParameter(FirebaseQuery child) + { + if (this.valueFactory != null) + { + if(this.valueFactory() == null) + { + return $"null"; + } + return $"\"{this.valueFactory()}\""; + } + else if (this.doubleValueFactory != null) + { + return this.doubleValueFactory().ToString(CultureInfo.InvariantCulture); + } + else if (this.boolValueFactory != null) + { + return $"{this.boolValueFactory().ToString().ToLower()}"; + } + + return string.Empty; + } + } +} diff --git a/FireBase/Query/FirebaseQuery.cs b/FireBase/Query/FirebaseQuery.cs new file mode 100644 index 0000000..0e1b84a --- /dev/null +++ b/FireBase/Query/FirebaseQuery.cs @@ -0,0 +1,314 @@ +namespace Firebase.Database.Query +{ + using System; + using System.Collections.Generic; + using System.Net.Http; + using System.Reactive.Linq; + using System.Threading.Tasks; + + using Firebase.Database.Http; + using Firebase.Database.Offline; + using Firebase.Database.Streaming; + + using Newtonsoft.Json; + using System.Net; + + /// + /// Represents a firebase query. + /// + public abstract class FirebaseQuery : IFirebaseQuery, IDisposable + { + protected TimeSpan DEFAULT_HTTP_CLIENT_TIMEOUT = new TimeSpan(0, 0, 180); + + protected readonly FirebaseQuery Parent; + + private HttpClient client; + + /// + /// Initializes a new instance of the class. + /// + /// The parent of this query. + /// The owning client. + protected FirebaseQuery(FirebaseQuery parent, FirebaseClient client) + { + this.Client = client; + this.Parent = parent; + } + + /// + /// Gets the client. + /// + public FirebaseClient Client + { + get; + } + + /// + /// Queries the firebase server once returning collection of items. + /// + /// Optional timeout value. + /// Type of elements. + /// Collection of holding the entities returned by server. + public async Task>> OnceAsync(TimeSpan? timeout = null) + { + var url = string.Empty; + + try + { + url = await this.BuildUrlAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + throw new FirebaseException("Couldn't build the url", string.Empty, string.Empty, HttpStatusCode.OK, ex); + } + + return await this.GetClient(timeout).GetObjectCollectionAsync(url, Client.Options.JsonSerializerSettings) + .ConfigureAwait(false); + } + + + /// + /// Assumes given query is pointing to a single object of type and retrieves it. + /// + /// Optional timeout value. + /// Type of elements. + /// Single object of type . + public async Task OnceSingleAsync(TimeSpan? timeout = null) + { + var responseData = string.Empty; + var statusCode = HttpStatusCode.OK; + var url = string.Empty; + + try + { + url = await this.BuildUrlAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + throw new FirebaseException("Couldn't build the url", string.Empty, responseData, statusCode, ex); + } + + try + { + var response = await this.GetClient(timeout).GetAsync(url).ConfigureAwait(false); + statusCode = response.StatusCode; + responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + + response.EnsureSuccessStatusCode(); + response.Dispose(); + + return JsonConvert.DeserializeObject(responseData, Client.Options.JsonSerializerSettings); + } + catch (Exception ex) + { + throw new FirebaseException(url, string.Empty, responseData, statusCode, ex); + } + } + + /// + /// Starts observing this query watching for changes real time sent by the server. + /// + /// Type of elements. + /// Optional custom root element of received json items. + /// Observable stream of . + public IObservable> AsObservable(EventHandler> exceptionHandler = null, string elementRoot = "") + { + return Observable.Create>(observer => + { + var sub = new FirebaseSubscription(observer, this, elementRoot, new FirebaseCache()); + sub.ExceptionThrown += exceptionHandler; + return sub.Run(); + }); + } + + /// + /// Builds the actual URL of this query. + /// + /// The . + public async Task BuildUrlAsync() + { + // if token factory is present on the parent then use it to generate auth token + if (this.Client.Options.AuthTokenAsyncFactory != null) + { + var token = await this.Client.Options.AuthTokenAsyncFactory().ConfigureAwait(false); + return this.WithAuth(token).BuildUrl(null); + } + + return this.BuildUrl(null); + } + + /// + /// Posts given object to repository. + /// + /// The object. + /// Specifies whether the key should be generated offline instead of online. + /// Optional timeout value. + /// Type of + /// Resulting firebase object with populated key. + public async Task> PostAsync(string data, bool generateKeyOffline = true, TimeSpan? timeout = null) + { + // post generates a new key server-side, while put can be used with an already generated local key + if (generateKeyOffline) + { + var key = FirebaseKeyGenerator.Next(); + await new ChildQuery(this, () => key, this.Client).PutAsync(data).ConfigureAwait(false); + + return new FirebaseObject(key, data); + } + else + { + var c = this.GetClient(timeout); + var sendData = await this.SendAsync(c, data, HttpMethod.Post).ConfigureAwait(false); + var result = JsonConvert.DeserializeObject(sendData, Client.Options.JsonSerializerSettings); + + return new FirebaseObject(result.Name, data); + } + } + + /// + /// Patches data at given location instead of overwriting them. + /// + /// The object. + /// Optional timeout value. + /// Type of + /// The . + public async Task PatchAsync(string data, TimeSpan? timeout = null) + { + var c = this.GetClient(timeout); + + await this.Silent().SendAsync(c, data, new HttpMethod("PATCH")).ConfigureAwait(false); + } + + /// + /// Sets or overwrites data at given location. + /// + /// The object. + /// Optional timeout value. + /// Type of + /// The . + public async Task PutAsync(string data, TimeSpan? timeout = null) + { + var c = this.GetClient(timeout); + + await this.Silent().SendAsync(c, data, HttpMethod.Put).ConfigureAwait(false); + } + + /// + /// Deletes data from given location. + /// + /// Optional timeout value. + /// The . + public async Task DeleteAsync(TimeSpan? timeout = null) + { + var c = this.GetClient(timeout); + var url = string.Empty; + var responseData = string.Empty; + var statusCode = HttpStatusCode.OK; + + try + { + url = await this.BuildUrlAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + throw new FirebaseException("Couldn't build the url", string.Empty, responseData, statusCode, ex); + } + + try + { + var result = await c.DeleteAsync(url).ConfigureAwait(false); + statusCode = result.StatusCode; + responseData = await result.Content.ReadAsStringAsync().ConfigureAwait(false); + + result.EnsureSuccessStatusCode(); + } + catch (Exception ex) + { + throw new FirebaseException(url, string.Empty, responseData, statusCode, ex); + } + } + + /// + /// Disposes this instance. + /// + public void Dispose() + { + this.client?.Dispose(); + } + + /// + /// Build the url segment of this child. + /// + /// The child of this query. + /// The . + protected abstract string BuildUrlSegment(FirebaseQuery child); + + private string BuildUrl(FirebaseQuery child) + { + var url = this.BuildUrlSegment(child); + + if (this.Parent != null) + { + url = this.Parent.BuildUrl(this) + url; + } + + return url; + } + + private HttpClient GetClient(TimeSpan? timeout = null) + { + if (this.client == null) + { + this.client = new HttpClient(); + } + + if (!timeout.HasValue) + { + this.client.Timeout = DEFAULT_HTTP_CLIENT_TIMEOUT; + } + else + { + this.client.Timeout = timeout.Value; + } + + return this.client; + } + + private async Task SendAsync(HttpClient client, string data, HttpMethod method) + { + var responseData = string.Empty; + var statusCode = HttpStatusCode.OK; + var requestData = data; + var url = string.Empty; + + try + { + url = await this.BuildUrlAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + throw new FirebaseException("Couldn't build the url", requestData, responseData, statusCode, ex); + } + + var message = new HttpRequestMessage(method, url) + { + Content = new StringContent(requestData) + }; + + try + { + var result = await client.SendAsync(message).ConfigureAwait(false); + statusCode = result.StatusCode; + responseData = await result.Content.ReadAsStringAsync().ConfigureAwait(false); + + result.EnsureSuccessStatusCode(); + + return responseData; + } + catch (Exception ex) + { + throw new FirebaseException(url, requestData, responseData, statusCode, ex); + } + } + } +} diff --git a/FireBase/Query/IFirebaseQuery.cs b/FireBase/Query/IFirebaseQuery.cs new file mode 100644 index 0000000..2e8c671 --- /dev/null +++ b/FireBase/Query/IFirebaseQuery.cs @@ -0,0 +1,43 @@ +namespace Firebase.Database.Query +{ + using System; + using System.Collections.Generic; + using System.Threading.Tasks; + + using Firebase.Database.Streaming; + + /// + /// The FirebaseQuery interface. + /// + public interface IFirebaseQuery + { + /// + /// Gets the owning client of this query. + /// + FirebaseClient Client + { + get; + } + + /// + /// Retrieves items which exist on the location specified by this query instance. + /// + /// Optional timeout value. + /// Type of the items. + /// Collection of . + Task>> OnceAsync(TimeSpan? timeout = null); + + /// + /// Returns current location as an observable which allows to real-time listening to events from the firebase server. + /// + /// Type of the items. + /// Cold observable of . + IObservable> AsObservable(EventHandler> exceptionHandler, string elementRoot = ""); + + /// + /// Builds the actual url of this query. + /// + /// The . + Task BuildUrlAsync(); + } +} diff --git a/FireBase/Query/OrderQuery.cs b/FireBase/Query/OrderQuery.cs new file mode 100644 index 0000000..46ebd2c --- /dev/null +++ b/FireBase/Query/OrderQuery.cs @@ -0,0 +1,34 @@ +namespace Firebase.Database.Query +{ + using System; + + /// + /// Represents a firebase ordering query, e.g. "?OrderBy=Foo". + /// + public class OrderQuery : ParameterQuery + { + private readonly Func propertyNameFactory; + + /// + /// Initializes a new instance of the class. + /// + /// The query parent. + /// The property name. + /// The owning client. + public OrderQuery(ChildQuery parent, Func propertyNameFactory, FirebaseClient client) + : base(parent, () => "orderBy", client) + { + this.propertyNameFactory = propertyNameFactory; + } + + /// + /// The build url parameter. + /// + /// The child. + /// The . + protected override string BuildUrlParameter(FirebaseQuery child) + { + return $"\"{this.propertyNameFactory()}\""; + } + } +} 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; + + /// + /// Represents a parameter in firebase query, e.g. "?data=foo". + /// + public abstract class ParameterQuery : FirebaseQuery + { + private readonly Func parameterFactory; + private readonly string separator; + + /// + /// Initializes a new instance of the class. + /// + /// The parent of this query. + /// The parameter. + /// The owning client. + protected ParameterQuery(FirebaseQuery parent, Func parameterFactory, FirebaseClient client) + : base(parent, client) + { + this.parameterFactory = parameterFactory; + this.separator = (this.Parent is ChildQuery) ? "?" : "&"; + } + + /// + /// Build the url segment represented by this query. + /// + /// The child. + /// The . + protected override string BuildUrlSegment(FirebaseQuery child) + { + return $"{this.separator}{this.parameterFactory()}={this.BuildUrlParameter(child)}"; + } + + /// + /// The build url parameter. + /// + /// The child. + /// The . + protected abstract string BuildUrlParameter(FirebaseQuery child); + } +} diff --git a/FireBase/Query/QueryExtensions.cs b/FireBase/Query/QueryExtensions.cs new file mode 100644 index 0000000..77db644 --- /dev/null +++ b/FireBase/Query/QueryExtensions.cs @@ -0,0 +1,207 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace Firebase.Database.Query +{ + /// + /// Query extensions providing linq like syntax for firebase server methods. + /// + public static class QueryExtensions + { + /// + /// Adds an auth parameter to the query. + /// + /// The child. + /// The auth token. + /// The . + internal static AuthQuery WithAuth(this FirebaseQuery node, string token) + { + return node.WithAuth(() => token); + } + + /// + /// Appends print=silent to save bandwidth. + /// + /// The child. + /// The . + internal static SilentQuery Silent(this FirebaseQuery node) + { + return new SilentQuery(node, node.Client); + } + + /// + /// References a sub child of the existing node. + /// + /// The child. + /// The path of sub child. + /// The . + public static ChildQuery Child(this ChildQuery node, string path) + { + return node.Child(() => path); + } + + /// + /// Order data by given . Note that this is used mainly for following filtering queries and due to firebase implementation + /// the data may actually not be ordered. + /// + /// The child. + /// The property name. + /// The . + public static OrderQuery OrderBy(this ChildQuery child, string propertyName) + { + return child.OrderBy(() => propertyName); + } + + /// + /// Instructs firebase to send data greater or equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery StartAt(this ParameterQuery child, string value) + { + return child.StartAt(() => value); + } + + /// + /// Instructs firebase to send data lower or equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EndAt(this ParameterQuery child, string value) + { + return child.EndAt(() => value); + } + + /// + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child, string value) + { + return child.EqualTo(() => value); + } + + /// + /// Instructs firebase to send data greater or equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery StartAt(this ParameterQuery child, double value) + { + return child.StartAt(() => value); + } + + /// + /// Instructs firebase to send data lower or equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EndAt(this ParameterQuery child, double value) + { + return child.EndAt(() => value); + } + + /// + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child, double value) + { + return child.EqualTo(() => value); + } + + /// + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child, bool value) + { + return child.EqualTo(() => value); + } + + /// + /// Instructs firebase to send data equal to null. This must be preceded by an OrderBy query. + /// + /// Current node. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child) + { + return child.EqualTo(() => null); + } + + /// + /// Limits the result to first items. + /// + /// Current node. + /// Number of elements. + /// The . + public static FilterQuery LimitToFirst(this ParameterQuery child, int count) + { + return child.LimitToFirst(() => count); + } + + /// + /// Limits the result to last items. + /// + /// Current node. + /// Number of elements. + /// The . + public static FilterQuery LimitToLast(this ParameterQuery child, int count) + { + return child.LimitToLast(() => count); + } + + public static Task PutAsync(this FirebaseQuery query, T obj) + { + return query.PutAsync(JsonConvert.SerializeObject(obj, query.Client.Options.JsonSerializerSettings)); + } + + public static Task PatchAsync(this FirebaseQuery query, T obj) + { + return query.PatchAsync(JsonConvert.SerializeObject(obj, query.Client.Options.JsonSerializerSettings)); + } + + public static async Task> PostAsync(this FirebaseQuery query, T obj, bool generateKeyOffline = true) + { + var result = await query.PostAsync(JsonConvert.SerializeObject(obj, query.Client.Options.JsonSerializerSettings), generateKeyOffline); + + return new FirebaseObject(result.Key, obj); + } + + /// + /// Fan out given item to multiple locations at once. See https://firebase.googleblog.com/2015/10/client-side-fan-out-for-data-consistency_73.html for details. + /// + /// Type of object to fan out. + /// Current node. + /// Object to fan out. + /// Locations where to store the item. + public static async Task FanOut(this ChildQuery child, T item, params string[] relativePaths) + { + if (relativePaths == null) + { + throw new ArgumentNullException(nameof(relativePaths)); + } + + var fanoutObject = new Dictionary(relativePaths.Length); + + foreach (var path in relativePaths) + { + fanoutObject.Add(path, item); + } + + await child.PatchAsync(fanoutObject); + } + } +} diff --git a/FireBase/Query/QueryFactoryExtensions.cs b/FireBase/Query/QueryFactoryExtensions.cs new file mode 100644 index 0000000..b36e74a --- /dev/null +++ b/FireBase/Query/QueryFactoryExtensions.cs @@ -0,0 +1,176 @@ +namespace Firebase.Database.Query +{ + using System; + + /// + /// Query extensions providing linq like syntax for firebase server methods. + /// + public static class QueryFactoryExtensions + { + /// + /// Adds an auth parameter to the query. + /// + /// The child. + /// The auth token. + /// The . + internal static AuthQuery WithAuth(this FirebaseQuery node, Func tokenFactory) + { + return new AuthQuery(node, tokenFactory, node.Client); + } + + /// + /// References a sub child of the existing node. + /// + /// The child. + /// The path of sub child. + /// The . + public static ChildQuery Child(this ChildQuery node, Func pathFactory) + { + return new ChildQuery(node, pathFactory, node.Client); + } + + /// + /// Order data by given . Note that this is used mainly for following filtering queries and due to firebase implementation + /// the data may actually not be ordered. + /// + /// The child. + /// The property name. + /// The . + public static OrderQuery OrderBy(this ChildQuery child, Func propertyNameFactory) + { + return new OrderQuery(child, propertyNameFactory, child.Client); + } + + /// + /// Order data by $key. Note that this is used mainly for following filtering queries and due to firebase implementation + /// the data may actually not be ordered. + /// + /// The child. + /// The . + public static OrderQuery OrderByKey(this ChildQuery child) + { + return child.OrderBy("$key"); + } + + /// + /// Order data by $value. Note that this is used mainly for following filtering queries and due to firebase implementation + /// the data may actually not be ordered. + /// + /// The child. + /// The . + public static OrderQuery OrderByValue(this ChildQuery child) + { + return child.OrderBy("$value"); + } + + /// + /// Order data by $priority. Note that this is used mainly for following filtering queries and due to firebase implementation + /// the data may actually not be ordered. + /// + /// The child. + /// The . + public static OrderQuery OrderByPriority(this ChildQuery child) + { + return child.OrderBy("$priority"); + } + + /// + /// Instructs firebase to send data greater or equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery StartAt(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "startAt", valueFactory, child.Client); + } + + /// + /// Instructs firebase to send data lower or equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EndAt(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "endAt", valueFactory, child.Client); + } + + /// + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "equalTo", valueFactory, child.Client); + } + + /// + /// Instructs firebase to send data greater or equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery StartAt(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "startAt", valueFactory, child.Client); + } + + /// + /// Instructs firebase to send data lower or equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EndAt(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "endAt", valueFactory, child.Client); + } + + /// + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "equalTo", valueFactory, child.Client); + } + + /// + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "equalTo", valueFactory, child.Client); + } + + /// + /// Limits the result to first items. + /// + /// Current node. + /// Number of elements. + /// The . + public static FilterQuery LimitToFirst(this ParameterQuery child, Func countFactory) + { + return new FilterQuery(child, () => "limitToFirst", () => countFactory(), child.Client); + } + + /// + /// Limits the result to last items. + /// + /// Current node. + /// Number of elements. + /// The . + public static FilterQuery LimitToLast(this ParameterQuery child, Func countFactory) + { + return new FilterQuery(child, () => "limitToLast", () => countFactory(), child.Client); + } + } +} diff --git a/FireBase/Query/SilentQuery.cs b/FireBase/Query/SilentQuery.cs new file mode 100644 index 0000000..15584f6 --- /dev/null +++ b/FireBase/Query/SilentQuery.cs @@ -0,0 +1,18 @@ +namespace Firebase.Database.Query +{ + /// + /// Appends print=silent to the url. + /// + public class SilentQuery : ParameterQuery + { + public SilentQuery(FirebaseQuery parent, FirebaseClient client) + : base(parent, () => "print", client) + { + } + + protected override string BuildUrlParameter(FirebaseQuery child) + { + return "silent"; + } + } +} -- cgit v1.2.3-70-g09d2