# frozen_string_literal: true $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require File.expand_path('../../lib/discourse_api', __FILE__) client = DiscourseApi::Client.new("http://localhost:3000") client.api_key = "YOUR_API_KEY" client.api_username = "YOUR_USERNAME" response = client.create_topic( category: "Boing Boing", skip_validations: true, auto_track: false, title: "Concert Master: A new way to choose", raw: "This is the raw markdown for my post" ) # get topic_id and topic_slug from response topic_id = response['topic_id'] topic_slug = response['topic_slug'] ## # available options (guessing from reading discourse source) # status can be: ['autoclose', 'closed', 'archived', 'disabled', 'visible'] # enabled can be: [true, false] ## # lock topic (note: api_username determines user that is performing action) params = { status: 'closed', enabled: true, api_username: "YOUR USERNAME/USERS USERNAME" } client.change_topic_status(topic_slug, topic_id, params) # unlock topic (note: api_username determines user that is performing action) params = { status: 'closed', enabled: false, api_username: "YOUR USERNAME/USERS USERNAME" } client.change_topic_status(topic_slug, topic_id, params)