module DiscourseApi::API::Users
Public Instance Methods
activate(id)
click to toggle source
# File lib/discourse_api/api/users.rb, line 5 def activate(id) put("/admin/users/#{id}/activate") end
anonymize(user_id)
click to toggle source
# File lib/discourse_api/api/users.rb, line 113 def anonymize(user_id) put("/admin/users/#{user_id}/anonymize") end
by_external_id(external_id)
click to toggle source
# File lib/discourse_api/api/users.rb, line 100 def by_external_id(external_id) response = get("/users/by-external/#{external_id}") response[:body]["user"] end
check_username(username)
click to toggle source
# File lib/discourse_api/api/users.rb, line 121 def check_username(username) response = get("/users/check_username.json?username=#{CGI.escape(username)}") response[:body] end
create_user(args)
click to toggle source
# File lib/discourse_api/api/users.rb, line 62 def create_user(args) args = API .params(args) .required(:name, :email, :password, :username) .optional(:active, :approved, :staged, :user_fields) .to_h post("/users", args) end
deactivate(user_id)
click to toggle source
# File lib/discourse_api/api/users.rb, line 126 def deactivate(user_id) put("/admin/users/#{user_id}/deactivate") end
delete_user(user_id, delete_posts = false)
click to toggle source
# File lib/discourse_api/api/users.rb, line 117 def delete_user(user_id, delete_posts = false) delete("/admin/users/#{user_id}.json?delete_posts=#{delete_posts}") end
grant_admin(user_id)
click to toggle source
# File lib/discourse_api/api/users.rb, line 81 def grant_admin(user_id) response = put("admin/users/#{user_id}/grant_admin") response[:body] end
grant_moderation(user_id)
click to toggle source
# File lib/discourse_api/api/users.rb, line 91 def grant_moderation(user_id) response = put("admin/users/#{user_id}/grant_moderation") response[:body] end
list_users(type, params = {})
click to toggle source
# File lib/discourse_api/api/users.rb, line 76 def list_users(type, params = {}) response = get("admin/users/list/#{type}.json", params) response[:body] end
log_out(id)
click to toggle source
# File lib/discourse_api/api/users.rb, line 72 def log_out(id) post("/admin/users/#{id}/log_out") end
revoke_admin(user_id)
click to toggle source
# File lib/discourse_api/api/users.rb, line 86 def revoke_admin(user_id) response = put("admin/users/#{user_id}/revoke_admin") response[:body] end
revoke_moderation(user_id)
click to toggle source
# File lib/discourse_api/api/users.rb, line 96 def revoke_moderation(user_id) put("admin/users/#{user_id}/revoke_moderation") end
suspend(user_id, suspend_until, reason)
click to toggle source
# File lib/discourse_api/api/users.rb, line 105 def suspend(user_id, suspend_until, reason) put("/admin/users/#{user_id}/suspend", suspend_until: suspend_until, reason: reason) end
unsuspend(user_id)
click to toggle source
# File lib/discourse_api/api/users.rb, line 109 def unsuspend(user_id) put("/admin/users/#{user_id}/unsuspend") end
update_avatar(username, args)
click to toggle source
# File lib/discourse_api/api/users.rb, line 19 def update_avatar(username, args) args = API.params(args).optional(:file, :url).default(type: "avatar", synchronous: true).to_h upload_response = post("/uploads", args) put("/u/#{username}/preferences/avatar/pick", upload_id: upload_response["id"]) end
update_email(username, email)
click to toggle source
# File lib/discourse_api/api/users.rb, line 26 def update_email(username, email) put("/u/#{username}/preferences/email", email: email) end
update_trust_level(user_id, args)
click to toggle source
# File lib/discourse_api/api/users.rb, line 56 def update_trust_level(user_id, args) args = API.params(args).required(:level).to_h response = put("/admin/users/#{user_id}/trust_level", args) response[:body] end
update_user(username, args)
click to toggle source
# File lib/discourse_api/api/users.rb, line 30 def update_user(username, args) args = API .params(args) .optional( :name, :title, :bio_raw, :location, :website, :profile_background, :card_background, :email_messages_level, :mailing_list_mode, :homepage_id, :theme_ids, :user_fields, ) .to_h put("/u/#{username}", args) end
update_username(username, new_username)
click to toggle source
# File lib/discourse_api/api/users.rb, line 52 def update_username(username, new_username) put("/u/#{username}/preferences/username", new_username: new_username) end
user(username, params = {})
click to toggle source
# File lib/discourse_api/api/users.rb, line 9 def user(username, params = {}) response = get("/users/#{username}.json", params) response[:body]["user"] end
user_sso(user_id)
click to toggle source
# File lib/discourse_api/api/users.rb, line 14 def user_sso(user_id) response = get("/admin/users/#{user_id}.json") response[:body]["single_sign_on_record"] end