Sha256: d503e0d31f0873de48c2bd64851c5d9c2374c39ec14634862e49518fc8dfa968

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

module DiscourseApi
  module API
    module Categories
      # :color and :text_color are RGB hexadecimal strings
      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

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

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

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

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
discourse_api-0.4.4 lib/discourse_api/api/categories.rb
discourse_api-0.4.3 lib/discourse_api/api/categories.rb
discourse_api-0.4.2 lib/discourse_api/api/categories.rb
discourse_api-0.4.1 lib/discourse_api/api/categories.rb