forked from bugthesystem/FireSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e11ede7
commit d6a802c
Showing
6 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ namespace FireSharp | |
public class FirebaseClient : IFirebaseClient, IDisposable | ||
{ | ||
private readonly IRequestManager _requestManager; | ||
private readonly IFirebaseConfig _config; | ||
|
||
private readonly Action<HttpStatusCode, string> _defaultErrorHandler = (statusCode, body) => | ||
{ | ||
|
@@ -26,6 +27,7 @@ public class FirebaseClient : IFirebaseClient, IDisposable | |
public FirebaseClient(IFirebaseConfig config) | ||
: this(new RequestManager(config)) | ||
{ | ||
_config = config; | ||
} | ||
|
||
internal FirebaseClient(IRequestManager requestManager) | ||
|
@@ -188,6 +190,110 @@ public async Task<PushResponse> PushAsync<T>(string path, T data) | |
} | ||
} | ||
|
||
public FirebaseResponse ResetPassword(string email, string password) | ||
{ | ||
/* | ||
/v2/luminous-heat-7934/users/[email protected]/password?&email=tedwards%40hachisoft.com&_method=POST&v=node-2.3.2&transport=json&suppress_status_codes=true | ||
* */ | ||
try | ||
{ | ||
string query = string.Format(@"&email={0}&_method=POST&transport=json&suppress_status_codes=true", Uri.EscapeDataString(email)); | ||
string path = string.Format("users/{0}/password", email); | ||
|
||
HttpResponseMessage response = _requestManager.RequestApiAsync(HttpMethod.Post, path, query, null).Result; | ||
string content = response.Content.ReadAsStringAsync().Result; | ||
HandleIfErrorResponse(response.StatusCode, content); | ||
return new FirebaseResponse(content, response.StatusCode); | ||
} | ||
catch (HttpRequestException ex) | ||
{ | ||
throw new FirebaseException(ex); | ||
} | ||
} | ||
|
||
public FirebaseResponse ChangePassword(string email, string oldPassword, string newPassword) | ||
{ | ||
/* | ||
/v2/luminous-heat-7934/users/[email protected]/password?&email=tedwards%40hachisoft.com&oldPassword=oldPassword&newPassword=newPassword&_method=PUT&password=newPassword&v=node-2.3.2&transport=json&suppress_status_codes=true | ||
* */ | ||
try | ||
{ | ||
string query = string.Format(@"&email={0}&oldPassword={1}&newPassword={2}&_method=PUT&password={2}&v=node-2.3.2&transport=json&suppress_status_codes=true", Uri.EscapeDataString(email), Uri.EscapeDataString(oldPassword), Uri.EscapeDataString(newPassword)); | ||
string path = string.Format("users/{0}/password",email); | ||
|
||
HttpResponseMessage response = _requestManager.RequestApiAsync(HttpMethod.Put, path, query, null).Result; | ||
string content = response.Content.ReadAsStringAsync().Result; | ||
HandleIfErrorResponse(response.StatusCode, content); | ||
return new FirebaseResponse(content, response.StatusCode); | ||
} | ||
catch (HttpRequestException ex) | ||
{ | ||
throw new FirebaseException(ex); | ||
} | ||
} | ||
|
||
public FirebaseResponse CreateUser(string email, string password) | ||
{ | ||
try | ||
{ | ||
string query = string.Format(@"&email={0}&password={1}&_method=POST&v=node-2.3.2&transport=json&suppress_status_codes=true", Uri.EscapeDataString(email),Uri.EscapeDataString(password)); | ||
string path = "users"; | ||
|
||
HttpResponseMessage response = _requestManager.RequestApiAsync(HttpMethod.Post, path,query, null).Result; | ||
string content = response.Content.ReadAsStringAsync().Result; | ||
HandleIfErrorResponse(response.StatusCode, content); | ||
return new FirebaseResponse(content, response.StatusCode); | ||
} | ||
catch (HttpRequestException ex) | ||
{ | ||
throw new FirebaseException(ex); | ||
} | ||
} | ||
|
||
public FirebaseResponse RemoveUser(string email, string password) | ||
{ | ||
/* | ||
/v2/luminous-heat-7934/users/[email protected]?&email=tedwards%40hachisoft.com&password=password&_method=DELETE&v=node-2.3.2&transport=json&suppress_status_codes=true | ||
* */ | ||
try | ||
{ | ||
string query = string.Format(@"&email={0}&password={1}&_method=DELETE&transport=json&suppress_status_codes=true", Uri.EscapeDataString(email), Uri.EscapeDataString(password)); | ||
string path = string.Format("users/{0}", email); | ||
|
||
HttpResponseMessage response = _requestManager.RequestApiAsync(HttpMethod.Delete, path, query, null).Result; | ||
string content = response.Content.ReadAsStringAsync().Result; | ||
HandleIfErrorResponse(response.StatusCode, content); | ||
return new FirebaseResponse(content, response.StatusCode); | ||
} | ||
catch (HttpRequestException ex) | ||
{ | ||
throw new FirebaseException(ex); | ||
} | ||
} | ||
|
||
public FirebaseResponse ChangeEmail(string oldEmail, string password, string newEmail) | ||
{ | ||
/* | ||
/v2/luminous-heat-7934/users/[email protected]/email?&oldEmail=tedwards%40hachisoft.com&password=password&newEmail=tedwards%40hachisoft.com&_method=PUT&email=tedwards%40hachisoft.com&v=node-2.3.2&transport=json&suppress_status_codes=true | ||
* */ | ||
try | ||
{ | ||
string query = string.Format(@"&oldEmail={0}&password={1}&newEmail={2}&_method=PUT&email={2}&v=node-2.3.2&transport=json&suppress_status_codes=true", Uri.EscapeDataString(oldEmail), Uri.EscapeDataString(password), Uri.EscapeDataString(newEmail)); | ||
string path = string.Format("users/{0}/email", oldEmail); | ||
|
||
HttpResponseMessage response = _requestManager.RequestApiAsync(HttpMethod.Put, path, query, null).Result; | ||
string content = response.Content.ReadAsStringAsync().Result; | ||
HandleIfErrorResponse(response.StatusCode, content); | ||
return new FirebaseResponse(content, response.StatusCode); | ||
} | ||
catch (HttpRequestException ex) | ||
{ | ||
throw new FirebaseException(ex); | ||
} | ||
} | ||
|
||
|
||
|
||
public async Task<FirebaseResponse> DeleteAsync(string path) | ||
{ | ||
try | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters