Sha256: 38c3d821fa822e44ada67f668923c1bdd65f1bf1867d42ae26cae9f9d71b0195

Contents?: true

Size: 882 Bytes

Versions: 3

Compression:

Stored size: 882 Bytes

Contents

require 'cpaas-sdk/util'

module Cpaas
  # @private

  class NotificationChannel
    def self.create_channel(params)
      options = {
        body: {
          notificationChannel: {
            channelData: {
              'x-webhookURL': params[:webhook_url]
            },
            channelType: 'webhooks',
            clientCorrelator: Cpaas.api.client_correlator
          }
        }
      }

      response = Cpaas.api.send_request("#{base_url}/channels", options, :post)

      process_response(response) do |res|
        channel = res.dig(:notification_channel)

        {
          channel_id: channel[:callback_url],
          webhook_url: channel[:channel_data][:x_webhook_url],
          channel_type: channel[:channel_type]
        }
      end
    end

    private

    def self.base_url
      "/cpaas/notificationchannel/v1/#{Cpaas.api.user_id}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cpaas-sdk-1.2.0 lib/cpaas-sdk/resources/notification_channel.rb
cpaas-sdk-1.1.0 lib/cpaas-sdk/resources/notification_channel.rb
cpaas-sdk-1.0.0 lib/cpaas-sdk/resources/notification_channel.rb