Sha256: 20ff7df1559e03aa24076ed1687c54ccf4ba56e62b99d710672ae5bccbf2c3f3

Contents?: true

Size: 1.56 KB

Versions: 8

Compression:

Stored size: 1.56 KB

Contents

module RDStation
  class Webhooks
    include HTTParty
    include ::RDStation::RetryableRequest

    def initialize(authorization:)
      @authorization = authorization
    end

    def all
      retryable_request(@authorization) do |authorization|
        response = self.class.get(base_url, headers: authorization.headers)
        ApiResponse.build(response)
      end
    end

    def by_uuid(uuid)
      retryable_request(@authorization) do |authorization|
        response = self.class.get(base_url(uuid), headers: authorization.headers)
        ApiResponse.build(response)
      end
    end

    def create(payload)
      retryable_request(@authorization) do |authorization|
        response = self.class.post(base_url, headers: authorization.headers, body: payload.to_json)
        ApiResponse.build(response)
      end
    end

    def update(uuid, payload)
      retryable_request(@authorization) do |authorization|
        response = self.class.put(base_url(uuid), headers: authorization.headers, body: payload.to_json)
        ApiResponse.build(response)
      end
    end

    def delete(uuid)
      retryable_request(@authorization) do |authorization|
        response = self.class.delete(base_url(uuid), headers: authorization.headers)
        return webhook_deleted_message unless response.body

        RDStation::ErrorHandler.new(response).raise_error
      end
    end

    private

    def webhook_deleted_message
      { message: 'Webhook deleted successfuly!' }
    end

    def base_url(path = '')
      "#{RDStation.host}/integrations/webhooks/#{path}"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rdstation-ruby-client-2.9.0 lib/rdstation/webhooks.rb
rdstation-ruby-client-2.8.2 lib/rdstation/webhooks.rb
rdstation-ruby-client-2.8.1 lib/rdstation/webhooks.rb
rdstation-ruby-client-2.8.0 lib/rdstation/webhooks.rb
rdstation-ruby-client-2.7.0 lib/rdstation/webhooks.rb
rdstation-ruby-client-2.6.0 lib/rdstation/webhooks.rb
rdstation-ruby-client-2.5.3 lib/rdstation/webhooks.rb
rdstation-ruby-client-2.5.2 lib/rdstation/webhooks.rb