Am I on the right track here? If so, where do I place the method so it has access to the post method? Any examples I could reference on how this works, as I’m somewhat new to RoR.
Over time this project intends to have a full Discourse API. At the moment there are only a few endpoints available
Reopening the module where you are placing your code and adding your method there might work. Have a look at the second example here: modules_and_classes - Documentation for Ruby 2.3.0. Another option would be to make a pull request to have your code added to the gem.
Since I posted about reopening the module, I figured I should try it out with your method to make sure it’s possible. Adding this code to a file and running it from the command line is working for me.
require 'discourse_api'
module DiscourseApi
module API
module Notifications
def set_group_user_notification_level group, user_id, notification_level
post("/groups/#{group}/notifications?user_id=#{user_id}¬ification_level=#{notification_level}")
end
end
end
end
client = DiscourseApi::Client.new("http://localhost:3000")
client.api_key = "<your-api-key>"
client.api_username = "system"
response = client.set_group_user_notification_level 'running', 1, 3
puts "Response: #{response}"
Thanks for that guidance on reopening modules, which worked for me too. But in the end I submitted a pull request to add the endpoint & an example script to update users Group Notifications to the Group Default.