module DiscourseApi::API::Topics

Public Instance Methods

bookmark_topic(topic_id) click to toggle source
# File lib/discourse_api/api/topics.rb, line 107
def bookmark_topic(topic_id)
  put("/t/#{topic_id}/bookmark.json")
end
change_owner(topic_id, params = {}) click to toggle source
# File lib/discourse_api/api/topics.rb, line 96
def change_owner(topic_id, params = {})
  params = API.params(params).required(:username, :post_ids)

  post("/t/#{topic_id}/change-owner.json", params)
end
change_topic_status(topic_slug, topic_id, params = {}) click to toggle source

TODO: Deprecated. Remove after 20201231

# File lib/discourse_api/api/topics.rb, line 52
def change_topic_status(topic_slug, topic_id, params = {})
  deprecated(__method__, "update_topic_status")
  update_topic_status(topic_id, params)
end
create_topic(args = {}) click to toggle source

:category OPTIONAL name of category, not ID :skip_validations OPTIONAL boolean :auto_track OPTIONAL boolean :created_at OPTIONAL seconds since epoch.

# File lib/discourse_api/api/topics.rb, line 9
def create_topic(args = {})
  args =
    API
      .params(args)
      .required(:title, :raw)
      .optional(:skip_validations, :category, :auto_track, :created_at, :api_username, :tags)
  post("/posts", args.to_h)
end
create_topic_action(args) click to toggle source
# File lib/discourse_api/api/topics.rb, line 18
def create_topic_action(args)
  args = API.params(args).required(:id, :post_action_type_id)
  post("/post_actions", args.to_h.merge(flag_topic: true))
end
delete_topic(id) click to toggle source
# File lib/discourse_api/api/topics.rb, line 72
def delete_topic(id)
  delete("/t/#{id}.json")
end
edit_topic_timestamp(topic_id, timestamp) click to toggle source

timestamp is seconds past the epoch.

# File lib/discourse_api/api/topics.rb, line 24
def edit_topic_timestamp(topic_id, timestamp)
  put("/t/#{topic_id}/change-timestamp", timestamp: timestamp)
end
latest_topics(params = {}) click to toggle source
# File lib/discourse_api/api/topics.rb, line 28
def latest_topics(params = {})
  response = get("/latest.json", params)
  response[:body]["topic_list"]["topics"]
end
new_topics(params = {}) click to toggle source
# File lib/discourse_api/api/topics.rb, line 38
def new_topics(params = {})
  response = get("/new.json", params)
  response[:body]["topic_list"]["topics"]
end
recategorize_topic(topic_id, category_id) click to toggle source
# File lib/discourse_api/api/topics.rb, line 47
def recategorize_topic(topic_id, category_id)
  put("/t/#{topic_id}.json", topic_id: topic_id, category_id: category_id)
end
remove_topic_bookmark(topic_id) click to toggle source
# File lib/discourse_api/api/topics.rb, line 111
def remove_topic_bookmark(topic_id)
  put("/t/#{topic_id}/remove_bookmarks.json")
end
rename_topic(topic_id, title) click to toggle source
# File lib/discourse_api/api/topics.rb, line 43
def rename_topic(topic_id, title)
  put("/t/#{topic_id}.json", topic_id: topic_id, title: title)
end
top_topics(params = {}) click to toggle source
# File lib/discourse_api/api/topics.rb, line 33
def top_topics(params = {})
  response = get("/top.json", params)
  response[:body]["topic_list"]["topics"]
end
topic(id, params = {}) click to toggle source
# File lib/discourse_api/api/topics.rb, line 62
def topic(id, params = {})
  response = get("/t/#{id}.json", params)
  response[:body]
end
topic_posts(topic_id, post_ids = [], params = {}) click to toggle source
# File lib/discourse_api/api/topics.rb, line 76
def topic_posts(topic_id, post_ids = [], params = {})
  params =
    API.params(params).optional(
      :asc,
      :filter,
      :include_raw,
      :include_suggested,
      :post_number,
      :username_filters,
    )

  url = ["/t/#{topic_id}/posts.json"]
  if post_ids.count > 0
    url.push("?")
    url.push(post_ids.map { |id| "post_ids[]=#{id}" }.join("&"))
  end
  response = get(url.join, params)
  response[:body]
end
topic_set_user_notification_level(topic_id, params) click to toggle source
# File lib/discourse_api/api/topics.rb, line 102
def topic_set_user_notification_level(topic_id, params)
  params = API.params(params).required(:notification_level)
  post("/t/#{topic_id}/notifications", params)
end
topics_by(username, params = {}) click to toggle source
# File lib/discourse_api/api/topics.rb, line 67
def topics_by(username, params = {})
  response = get("/topics/created-by/#{username}.json", params)
  response[:body]["topic_list"]["topics"]
end
update_topic_status(topic_id, params = {}) click to toggle source
# File lib/discourse_api/api/topics.rb, line 57
def update_topic_status(topic_id, params = {})
  params = API.params(params).required(:status, :enabled).optional(:api_username)
  put("/t/#{topic_id}/status", params)
end