Sha256: 65e82998bac78674433975e1880543eedcdd1c0948b884cac612aae9f70ea101

Contents?: true

Size: 1.54 KB

Versions: 10

Compression:

Stored size: 1.54 KB

Contents

module DiscourseApi
  module API
    module Categories
      # :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
      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

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

      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

      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

10 entries across 10 versions & 1 rubygems

Version Path
discourse_api-0.10.0 lib/discourse_api/api/categories.rb
discourse_api-0.9.1 lib/discourse_api/api/categories.rb
discourse_api-0.9.0 lib/discourse_api/api/categories.rb
discourse_api-0.8.1 lib/discourse_api/api/categories.rb
discourse_api-0.8.0 lib/discourse_api/api/categories.rb
discourse_api-0.7.0 lib/discourse_api/api/categories.rb
discourse_api-0.6.2 lib/discourse_api/api/categories.rb
discourse_api-0.6.1 lib/discourse_api/api/categories.rb
discourse_api-0.6.0 lib/discourse_api/api/categories.rb
discourse_api-0.5.1 lib/discourse_api/api/categories.rb