Module: DiscourseApi::API::Topics

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

Instance Method Summary collapse

Instance Method Details

#create_topic(args) ⇒ Object

:category OPTIONAL name of category, not ID :skip_validations OPTIONAL boolean :auto_track OPTIONAL boolean



7
8
9
10
11
12
13
14
15
# File 'lib/discourse_api/api/topics.rb', line 7

def create_topic(args)

  args =
    API.params(args)
      .required(:title, :raw)
      .optional(:skip_validations, :category, :auto_track)

  post("/posts", args.to_h)
end

#delete_topic(id) ⇒ Object



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

def delete_topic(id)
  delete("/t/#{id}.json")
end

#latest_topics(*args) ⇒ Object



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

def latest_topics(*args)
  response = get('/latest.json', args)
  response[:body]['topic_list']['topics']
end

#new_topics(*args) ⇒ Object



22
23
24
25
# File 'lib/discourse_api/api/topics.rb', line 22

def new_topics(*args)
  response = get("/new.json", args)
  response[:body]['topic_list']['topics']
end

#recategorize_topic(topic_id, category_id) ⇒ Object



31
32
33
# File 'lib/discourse_api/api/topics.rb', line 31

def recategorize_topic(topic_id, category_id)
  put("/t/#{topic_id}.json", { topic_id: topic_id, category_id: category_id })
end

#rename_topic(topic_id, title) ⇒ Object



27
28
29
# File 'lib/discourse_api/api/topics.rb', line 27

def rename_topic(topic_id, title)
  put("/t/#{topic_id}.json", { topic_id: topic_id, title: title })
end

#topic(id, *args) ⇒ Object



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

def topic(id, *args)
  response = get("/t/#{id}.json", args)
  response[:body]
end

#topics_by(username, *args) ⇒ Object



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

def topics_by(username, *args)
  response = get("/topics/created-by/#{username}.json", args)
  response[:body]['topic_list']['topics']
end