module DiscourseApi::API::Categories

Public Instance Methods

categories(params = {}) click to toggle source
# File lib/discourse_api/api/categories.rb, line 76
def categories(params = {})
  categories_full(params)["category_list"]["categories"]
end
categories_full(params = {}) click to toggle source
# File lib/discourse_api/api/categories.rb, line 80
def categories_full(params = {})
  response = get("/categories.json", params)
  response[:body]
end
category(id) click to toggle source
# File lib/discourse_api/api/categories.rb, line 126
def category(id)
  response = get("/c/#{id}/show")
  response[:body]["category"]
end
category_latest_topics(args = {}) click to toggle source
# File lib/discourse_api/api/categories.rb, line 85
def category_latest_topics(args = {})
  response = category_latest_topics_full(args)
  if response["errors"]
    response["errors"]
  else
    response["topic_list"]["topics"]
  end
end
category_latest_topics_full(args = {}) click to toggle source
# File lib/discourse_api/api/categories.rb, line 94
def category_latest_topics_full(args = {})
  params = API.params(args).required(:category_slug).optional(:page).to_h
  url = "/c/#{params[:category_slug]}/l/latest.json"
  url = "#{url}?page=#{params[:page]}" if params.include?(:page)
  response = get(url)
  response[:body]
end
category_new_topics(category_slug) click to toggle source
# File lib/discourse_api/api/categories.rb, line 116
def category_new_topics(category_slug)
  response = category_new_topics_full(category_slug)
  response["topic_list"]["topics"]
end
category_new_topics_full(category_slug) click to toggle source
# File lib/discourse_api/api/categories.rb, line 121
def category_new_topics_full(category_slug)
  response = get("/c/#{category_slug}/l/new.json")
  response[:body]
end
category_set_user_notification(args = {}) click to toggle source

TODO: Deprecated. Remove after 20210727

# File lib/discourse_api/api/categories.rb, line 132
def category_set_user_notification(args = {})
  category_id = args[:id]
  args = API.params(args).required(:notification_level)
  post("/category/#{category_id}/notifications", args)
end
category_set_user_notification_level(category_id, params) click to toggle source
# File lib/discourse_api/api/categories.rb, line 138
def category_set_user_notification_level(category_id, params)
  params = API.params(params).required(:notification_level)
  post("/category/#{category_id}/notifications", params)
end
category_top_topics(category_slug) click to toggle source
# File lib/discourse_api/api/categories.rb, line 102
def category_top_topics(category_slug)
  response = category_top_topics_full(category_slug)
  if response["errors"]
    response["errors"]
  else
    response["topic_list"]["topics"]
  end
end
category_top_topics_full(category_slug) click to toggle source
# File lib/discourse_api/api/categories.rb, line 111
def category_top_topics_full(category_slug)
  response = get("/c/#{category_slug}/l/top.json")
  response[:body]
end
create_category(args = {}) click to toggle source

:color and :text_color are RGB hexadecimal strings :permissions is a hash with the group name and permission_type which is an integer 1 = Full 2 = Create Post 3 = Read Only

# File lib/discourse_api/api/categories.rb, line 8
def create_category(args = {})
  args =
    API
      .params(args)
      .required(:name, :color, :text_color)
      .optional(
        :slug,
        :permissions,
        :auto_close_hours,
        :auto_close_based_on_last_post,
        :position,
        :email_in,
        :email_in_allow_strangers,
        :logo_url,
        :background_url,
        :allow_badges,
        :topic_template,
        :custom_fields,
        :description,
        :reviewable_by_group_name,
        :show_subcategory_list,
        :subcategory_list_style,
        :allowed_tags,
        :allowed_tag_groups,
        :required_tag_group_name,
      )
      .default(parent_category_id: nil)
  response = post("/categories", args)
  response["category"]
end
delete_category(id) click to toggle source
# File lib/discourse_api/api/categories.rb, line 71
def delete_category(id)
  response = delete("/categories/#{id}")
  response[:body]["success"]
end
update_category(args = {}) click to toggle source
# File lib/discourse_api/api/categories.rb, line 39
def update_category(args = {})
  category_id = args[:id]
  args =
    API
      .params(args)
      .required(:id, :name, :color, :text_color)
      .optional(
        :slug,
        :permissions,
        :auto_close_hours,
        :auto_close_based_on_last_post,
        :position,
        :email_in,
        :email_in_allow_strangers,
        :logo_url,
        :background_url,
        :allow_badges,
        :topic_template,
        :custom_fields,
        :description,
        :reviewable_by_group_name,
        :show_subcategory_list,
        :subcategory_list_style,
        :allowed_tags,
        :allowed_tag_groups,
        :required_tag_group_name,
      )
      .default(parent_category_id: nil)
  response = put("/categories/#{category_id}", args)
  response["body"]["category"] if response["body"]
end