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", api_key: api_key, api_username: api_username
end

#create_user(args = {}) ⇒ Object

Create a user



30
31
32
33
34
35
36
37
38
39
# File 'lib/discourse_api/api/users.rb', line 30

def create_user(args={})
  # First retrieve the honeypot values
  # TODO, none of this should be needed via API
  response = get("/users/hp.json")
  args[:password_confirmation] = response[:body]['value']
  args[:challenge] = response[:body]['challenge'].reverse

  # POST the args
  post("/users", args)
end

#invite_admin(args = {}) ⇒ Object



45
46
47
# File 'lib/discourse_api/api/users.rb', line 45

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

#log_out(id) ⇒ Object



41
42
43
# File 'lib/discourse_api/api/users.rb', line 41

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

#update_avatar(username, file) ⇒ Object



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

def update_avatar(username, file)
  put("/users/#{username}/preferences/avatar", { file: file, api_key: api_key })
end

#update_email(username, email) ⇒ Object



17
18
19
# File 'lib/discourse_api/api/users.rb', line 17

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

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



21
22
23
# File 'lib/discourse_api/api/users.rb', line 21

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

#update_username(username, new_username) ⇒ Object



25
26
27
# File 'lib/discourse_api/api/users.rb', line 25

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

#user(username, *args) ⇒ Object



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

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