diff options
| author | Austin Hellyer <[email protected]> | 2016-12-03 07:20:43 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-12-03 07:38:11 -0800 |
| commit | dae723e612d62c1b9150f3f522ecf1fede2764ff (patch) | |
| tree | a7c085256b1bca64f8bfd872743b440b44a519d4 /src/client/rest | |
| parent | Add rose water colour (diff) | |
| download | serenity-dae723e612d62c1b9150f3f522ecf1fede2764ff.tar.xz serenity-dae723e612d62c1b9150f3f522ecf1fede2764ff.zip | |
Make rest::edit_profile set new token
If a user account changes their profile settings, they'll receive a new
token; update the locally stored token for REST requests with this
token.
Additionally, the `Context::edit_profile` does not need mutability over
self.
Fixes #25.
Diffstat (limited to 'src/client/rest')
| -rw-r--r-- | src/client/rest/mod.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/client/rest/mod.rs b/src/client/rest/mod.rs index a325f15..d5e5761 100644 --- a/src/client/rest/mod.rs +++ b/src/client/rest/mod.rs @@ -690,12 +690,30 @@ pub fn edit_note(user_id: u64, map: Value) -> Result<()> { user_id)) } -/// Edits profile we're connected to. +/// Edits the current user's profile settings. +/// +/// For bot users, the password is optional. +/// +/// # User Accounts +/// +/// If a new token is received due to a password change, then the stored token +/// internally will be updated. +/// +/// **Note**: this token change may cause requests made between the actual token +/// change and when the token is internally changed to be invalid requests, as +/// the token may be outdated. +/// pub fn edit_profile(map: Value) -> Result<CurrentUser> { let body = try!(serde_json::to_string(&map)); let response = request!(Route::UsersMe, patch(body), "/users/@me"); - CurrentUser::decode(try!(serde_json::from_reader(response))) + let mut map: BTreeMap<String, Value> = try!(serde_json::from_reader(response)); + + if let Some(Value::String(token)) = map.remove("token") { + set_token(&token) + } + + CurrentUser::decode(Value::Object(map)) } /// Changes a role in a guild. |