Module: DiscourseApi::API::Categories
- Included in:
- Client
- Defined in:
- lib/discourse_api/api/categories.rb
Instance Method Summary collapse
- #categories(params = {}) ⇒ Object
- #category(id) ⇒ Object
- #category_latest_topics(args = {}) ⇒ Object
- #category_new_topics(category_slug) ⇒ Object
- #category_top_topics(category_slug) ⇒ Object
-
#create_category(args = {}) ⇒ Object
: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.
Instance Method Details
#categories(params = {}) ⇒ Object
16 17 18 19 |
# File 'lib/discourse_api/api/categories.rb', line 16 def categories(params={}) response = get('/categories.json', params) response[:body]['category_list']['categories'] end |
#category(id) ⇒ Object
43 44 45 46 |
# File 'lib/discourse_api/api/categories.rb', line 43 def category(id) response = get("/c/#{id}/show") response.body['category'] end |
#category_latest_topics(args = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/discourse_api/api/categories.rb', line 21 def category_latest_topics(args={}) params = API.params(args) .required(:category_slug) .optional(:page).to_h url = "/c/#{params[:category_slug]}/l/latest.json" if params.include?(:page) url = "#{url}?page=#{params[:page]}" end response = get(url) response[:body]['topic_list']['topics'] end |
#category_new_topics(category_slug) ⇒ Object
38 39 40 41 |
# File 'lib/discourse_api/api/categories.rb', line 38 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
33 34 35 36 |
# File 'lib/discourse_api/api/categories.rb', line 33 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 :permissions is a hash with the group name and permission_type which is an integer 1 = Full 2 = Create Post 3 = Read Only
7 8 9 10 11 12 13 14 |
# File 'lib/discourse_api/api/categories.rb', line 7 def create_category(args={}) args = API.params(args) .required(:name, :color, :text_color) .optional(:description, :permissions) .default(parent_category_id: nil) response = post("/categories", args) response['category'] end |