aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-12-03 07:20:43 -0800
committerAustin Hellyer <[email protected]>2016-12-03 07:38:11 -0800
commitdae723e612d62c1b9150f3f522ecf1fede2764ff (patch)
treea7c085256b1bca64f8bfd872743b440b44a519d4 /src
parentAdd rose water colour (diff)
downloadserenity-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')
-rw-r--r--src/client/context.rs4
-rw-r--r--src/client/rest/mod.rs22
2 files changed, 22 insertions, 4 deletions
diff --git a/src/client/context.rs b/src/client/context.rs
index bc983bf..6968233 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -828,7 +828,7 @@ impl Context {
rest::edit_nickname(guild_id.into().0, new_nickname)
}
- /// Edits the current user's settings.
+ /// Edits the current user's profile settings.
///
/// Refer to `EditProfile`'s documentation for its methods.
///
@@ -840,7 +840,7 @@ impl Context {
/// context.edit_member(|p|
/// p.username("meew zero"));
/// ```
- pub fn edit_profile<F: FnOnce(EditProfile) -> EditProfile>(&mut self, f: F)
+ pub fn edit_profile<F: FnOnce(EditProfile) -> EditProfile>(&self, f: F)
-> Result<CurrentUser> {
let user = try!(rest::get_current_user());
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.