Module: DiscourseApi::API::Users

Included in:
Client
Defined in:
lib/discourse_api/api/users.rb

Instance Method Summary collapse

Instance Method Details

#activate(id) ⇒ Object



4
5
6
# File 'lib/discourse_api/api/users.rb', line 4

def activate(id)
  put("/admin/users/#{id}/activate")
end

#by_external_id(external_id) ⇒ Object



79
80
81
82
# File 'lib/discourse_api/api/users.rb', line 79

def by_external_id(external_id)
  response = get("/users/by-external/#{external_id}")
  response[:body]['user']
end

#create_user(args) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/discourse_api/api/users.rb', line 48

def create_user(args)
  args = API.params(args)
            .required(:name, :email, :password, :username)
            .optional(:active, :staged)
            .to_h
  post("/users", args)
end

#grant_admin(user_id) ⇒ Object



69
70
71
72
# File 'lib/discourse_api/api/users.rb', line 69

def grant_admin(user_id)
  response = put("admin/users/#{user_id}/grant_admin")
  response[:body]
end

#invite_admin(args = {}) ⇒ Object



60
61
62
# File 'lib/discourse_api/api/users.rb', line 60

def invite_admin(args={})
  post("/admin/users/invite_admin", args)
end

#list_users(type) ⇒ Object



64
65
66
67
# File 'lib/discourse_api/api/users.rb', line 64

def list_users(type)
  response = get("admin/users/list/#{type}.json")
  response[:body]
end

#log_out(id) ⇒ Object



56
57
58
# File 'lib/discourse_api/api/users.rb', line 56

def log_out(id)
  post("/admin/users/#{id}/log_out")
end

#revoke_admin(user_id) ⇒ Object



74
75
76
77
# File 'lib/discourse_api/api/users.rb', line 74

def revoke_admin(user_id)
  response = put("admin/users/#{user_id}/revoke_admin")
  response[:body]
end

#suspend(user_id, days, reason) ⇒ Object



84
85
86
# File 'lib/discourse_api/api/users.rb', line 84

def suspend(user_id, days, reason)
  put("/admin/users/#{user_id}/suspend", {duration: days, reason: reason})
end

#unsuspend(user_id) ⇒ Object



88
89
90
# File 'lib/discourse_api/api/users.rb', line 88

def unsuspend(user_id)
  put("/admin/users/#{user_id}/unsuspend")
end

#update_avatar(args) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/discourse_api/api/users.rb', line 18

def update_avatar(args)
  args = API.params(args)
            .required(:username)
            .optional(:file, :url)
            .default(type: 'avatar', synchronous: true)
            .to_h
  upload_response = post("/uploads", args)
  put("/users/#{args[:username]}/preferences/avatar/pick", { upload_id: upload_response['id'] })
end

#update_email(username, email) ⇒ Object



28
29
30
# File 'lib/discourse_api/api/users.rb', line 28

def update_email(username, email)
  put("/users/#{username}/preferences/email", { email: email, api_key: api_key })
end

#update_trust_level(args) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/discourse_api/api/users.rb', line 40

def update_trust_level(args)
  args = API.params(args)
            .required(:user_id, :level)
            .to_h
  response = put("/admin/users/#{args[:user_id]}/trust_level", args)
  response[:body]
end

#update_user(username, params = {}) ⇒ Object



32
33
34
# File 'lib/discourse_api/api/users.rb', line 32

def update_user(username, params={})
  put("/users/#{username}", params)
end

#update_username(username, new_username) ⇒ Object



36
37
38
# File 'lib/discourse_api/api/users.rb', line 36

def update_username(username, new_username)
  put("/users/#{username}/preferences/username", { new_username: new_username, api_key: api_key })
end

#user(username, params = {}) ⇒ Object



8
9
10
11
# File 'lib/discourse_api/api/users.rb', line 8

def user(username, params={})
  response = get("/users/#{username}.json", params)
  response[:body]['user']
end

#user_sso(user_id) ⇒ Object



13
14
15
16
# File 'lib/discourse_api/api/users.rb', line 13

def user_sso(user_id)
  response = get("/admin/users/#{user_id}.json")
  response[:body]['single_sign_on_record']
end