0

I am relatively new to writing code against REST APIs. It is possible I am analyzing the wrong problem here, so feel free to give big picture advice. The other twist is that the API I want to use is not yet configured, so I can't test.

I need to write some Rails code to create webhooks on the Jive API. Jive's docs show how to register the webservice via a curl request. I want to build the code as an admin function of my app in case we need to recreate the webhook for any reason.

Here are the Jive Docs.

Based on this guide, I'm thinking I need something like (I expect this example to sent a POST request to "sample.jiveon.com/api/core/v3/webhooks"):

@host = "sample.jiveon.com/api/core/v3"
@port = "443"

@post_ws = "/webhooks"

@payload ={
    "events" => "document",
    "callback" => "my_app/jive_listener",
    "object" => "my/jive/space"
  }.to_json

def post 
    req = Net::HTTP::Post.new(@post_ws, initheader = {'Content-Type' =>'application/json'})
      req['Authorization'] = "Bearer my_key"
      req.body = @payload
      response = Net::HTTP.new(@host, @port).start {|http| http.request(req) }
    end
end

Thanks.

Joe Essey
  • 3,457
  • 8
  • 40
  • 69

1 Answers1

0

It would be better to use gem like 'rest-client(https://github.com/rest-client/rest-client)'

Above gem does the many stuff, which you might be doing manually using bare ruby library. It depends on need of yours.

Sanjiv
  • 813
  • 6
  • 13