Sha256: 5c86b6d3f7ccb0a5e832ed14678a9fde74c4b8001eea66ef291a8506f52b3177

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

module DiscourseApi
  module API
    module Topics
      # :category OPTIONAL name of category, not ID
      # :skip_validations OPTIONAL boolean
      # :auto_track OPTIONAL boolean
      def create_topic(args)
        args = API.params(args)
                  .required(:title, :raw)
                  .optional(:skip_validations, :category, :auto_track)
        post("/posts", args.to_h)
      end

      def latest_topics(params={})
        response = get('/latest.json', params)
        response[:body]['topic_list']['topics']
      end

      def new_topics(params={})
        response = get("/new.json", params)
        response[:body]['topic_list']['topics']
      end

      def rename_topic(topic_id, title)
        put("/t/#{topic_id}.json", { topic_id: topic_id, title: title })
      end

      def recategorize_topic(topic_id, category_id)
        put("/t/#{topic_id}.json", { topic_id: topic_id, category_id: category_id })
      end

      def topic(id, params={})
        response = get("/t/#{id}.json", params)
        response[:body]
      end

      def topics_by(username, params={})
        response = get("/topics/created-by/#{username}.json", params)
        response[:body]['topic_list']['topics']
      end

      def delete_topic(id)
        delete("/t/#{id}.json")
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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