# REST API vs. the Ruby API

**URL:** <https://meta.discourse.org/t/rest-api-vs-the-ruby-api/108654>\
**Category:** Development\
**Created:** [February 8, 2019, 2:34am UTC](https://meta.discourse.org/t/rest-api-vs-the-ruby-api/108654 "2019-02-08T02:34:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimardenmiller](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kimardenmiller/32/119631_2.png) [@kimardenmiller](https://meta.discourse.org/u/kimardenmiller)\
**Post date:** [February 8, 2019, 2:34am UTC](https://meta.discourse.org/t/rest-api-vs-the-ruby-api/108654/1 "2019-02-08T02:34:52Z")

</div>

Is it safe to assume there is not a 1 to 1 mapping, i.e. the Ruby API does not do everything the REST API can do?

I did not see a way to update a user’s group notification level, so tried to write the method:

 ![image](https://global.discourse-cdn.com/meta/original/3X/b/d/bd7a6d2d1c4f58d3421dee1ea9e7ec308ab1bcfe.png)

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.

---

<div class="post-metadata">

**Author:** ![kimardenmiller](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kimardenmiller/32/119631_2.png) [@kimardenmiller](https://meta.discourse.org/u/kimardenmiller)\
**Post date:** [February 8, 2019, 5:49am UTC](https://meta.discourse.org/t/rest-api-vs-the-ruby-api/108654/2 "2019-02-08T05:49:05Z")

</div>

Ok, looks as if placing my method in the api code and calling thought the client works:

```
response = client.set_group_user_note_lev(@group_name, user['id'], 2)
puts response

```

Though the response did not seem to print as it does in Postman, e.g.:

```
{
  "success": "OK"
}

```

It seems messy adding my code to the published Ruby API’s code. Best practices?

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [February 8, 2019, 6:08am UTC](https://meta.discourse.org/t/rest-api-vs-the-ruby-api/108654/3 "2019-02-08T06:08:29Z")

</div>

> [@kimardenmiller](#):
>
> Is it safe to assume there is not a 1 to 1 mapping, i.e. the Ruby API does not do everything the REST API can do?

From the [discourse\_api README](https://github.com/discourse/discourse_api):

> Over time this project intends to have a full Discourse API. At the moment there are only a few endpoints available

> [@kimardenmiller](#):
>
> It seems messy adding my code to the published Ruby API’s code. Best practices?

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](https://docs.ruby-lang.org/en/2.3.0/syntax/modules_and_classes_rdoc.html#label-Module+Definition). Another option would be to make a pull request to have your code added to the gem.

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [February 9, 2019, 4:28am UTC](https://meta.discourse.org/t/rest-api-vs-the-ruby-api/108654/4 "2019-02-09T04:28:55Z")

</div>

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.

```plaintext
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}&notification_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}"

```

---

<div class="post-metadata">

**Author:** ![kimardenmiller](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kimardenmiller/32/119631_2.png) [@kimardenmiller](https://meta.discourse.org/u/kimardenmiller)\
**Post date:** [February 9, 2019, 11:47pm UTC](https://meta.discourse.org/t/rest-api-vs-the-ruby-api/108654/5 "2019-02-09T23:47:38Z")

</div>

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.

[https://github.com/discourse/discourse\_api/pull/167](https://github.com/discourse/discourse_api/pull/167)
