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



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

def activate(id)
  put "/admin/users/#{id}/activate", api_key: api_key, api_username: api_username
end

#create_user(*args) ⇒ Object

Create a user



34
35
36
37
38
39
40
41
42
# File 'lib/discourse_api/api/users.rb', line 34

def create_user(*args)
  # First retrieve the honeypot values
  response = get("/users/hp.json")
  args.first[:password_confirmation] = response[:body]['value']
  args.first[:challenge] = response[:body]['challenge'].reverse

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

#toggle_avatar(username, use_uploaded_avatar) ⇒ Object



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

def toggle_avatar(username, use_uploaded_avatar)
  put("/users/#{username}/preferences/avatar/toggle", { use_uploaded_avatar: use_uploaded_avatar })
end

#update_avatar(username, file) ⇒ Object



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

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

#update_email(username, email) ⇒ Object



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

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

#update_user(username, *args) ⇒ Object



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

def update_user(username, *args)
  put("/users/#{username}", args)
end

#update_username(username, new_username) ⇒ Object



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

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

#user(username, *args) ⇒ Object



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

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