bugthesystem / FireSharp

An asynchronous cross-platform .Net library for Firebase
The Unlicense
693 stars 147 forks source link

set upload without returning whole dataset #118

Closed shibuya246 closed 6 years ago

shibuya246 commented 6 years ago

We are uploading new data to a node on firebase on a regular basis. We do not want to get the uploaded data, sent back in the response stream, as it consumes our firebase download quota.

If we use push, it does not contain the uploaded data in the response stream, but we cannot specify the key.

why is all of the data returned on both set and update? is there someway to set a flag to not return data? can there be a feature such as,

** RETURNING DATA FirebaseResponse response =await _client.UpdateAsync("todos/set", todo); Todo todo = response.ResultAs(); //The response will contain the data written

** NOT RETURNING DATA FirebaseResponse response =await _client.UpdateAsync("todos/set", todo, false); //The response will NOT contain the data written

Posisble Solution from the google firebase docs:

curl -X PUT -d '{ "first": "Jack", "last": "Sparrow" }' \ 'https://[PROJECT_ID].firebaseio.com/users/jack/name.json?print=silent'

silent | GET, PUT, POST, PATCH | Used to suppress the output from the server when writing data. The resulting response will be empty and indicated by a 204 No ContentHTTP status code.

shibuya246 commented 6 years ago

looks like if we can edit the PrepareUri function to accept the extra params, then it could work, either adding the params to queryBuilder when it gets passed it, or setting a new param passing it to the PrepareUri function direct

private Uri PrepareUri(string path, QueryBuilder queryBuilder)
{
            var authToken = !string.IsNullOrWhiteSpace(_config.AuthSecret)
                ? $"{path}.json?auth={_config.AuthSecret}"  
                : $"{path}.json?";

            var queryStr = string.Empty;
            if (queryBuilder != null)
            {
                queryStr = $"&{queryBuilder.ToQueryString()}";
            }

            var url = $"{_config.BasePath}{authToken}{queryStr}";

            return new Uri(url);
}
shibuya246 commented 6 years ago

In QueryBuilder.cs https://github.com/ziyasal/FireSharp/blob/master/FireSharp.Core/QueryBuilder.cs

there is already options for "shallow" although that only works on GET requests

line 74

public QueryBuilder Shallow(bool value)
{
    return AddToQueryDictionary(shallowParam, value ? "true" : string.Empty, skipEncoding: true);
}

a similar choice for "silent" would fit in consistently with code here

shibuya246 commented 6 years ago

I have added code to make this work now with Tests as well, and want to publish a branch so i can open a pull request. I don't seem to have permission to access this repository for that.