Module: DiscourseApi::API::Categories

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

Instance Method Summary collapse

Instance Method Details

#categories(params = {}) ⇒ Object



14
15
16
17
# File 'lib/discourse_api/api/categories.rb', line 14

def categories(params={})
  response = get('/categories.json', params)
  response[:body]['category_list']['categories']
end

#category(id) ⇒ Object



34
35
36
37
# File 'lib/discourse_api/api/categories.rb', line 34

def category(id)
  response = get("/c/#{id}/show")
  response.body['category']
end

#category_latest_topics(category_slug) ⇒ Object



19
20
21
22
# File 'lib/discourse_api/api/categories.rb', line 19

def category_latest_topics(category_slug)
  response = get("/category/#{category_slug}/l/latest.json")
  response[:body]['topic_list']['topics']
end

#category_new_topics(category_slug) ⇒ Object



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

def category_new_topics(category_slug)
  response = get("/category/#{category_slug}/l/new.json")
  response[:body]['topic_list']['topics']
end

#category_top_topics(category_slug) ⇒ Object



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

def category_top_topics(category_slug)
  response = get("/category/#{category_slug}/l/top.json")
  response[:body]['topic_list']['topics']
end

#create_category(args) ⇒ Object

:color and :text_color are RGB hexadecimal strings



5
6
7
8
9
10
11
12
# File 'lib/discourse_api/api/categories.rb', line 5

def create_category(args)
  args = API.params(args)
            .required(:name, :color, :text_color)
            .optional(:description)
            .default(parent_category_id: nil)
  response = post("/categories", args)
  response['category']
end