Sha256: b52573950c967d7655b993c5d9b4b287a94b0dcd42b08f4b22618f05f707808d

Contents?: true

Size: 1.79 KB

Versions: 7

Compression:

Stored size: 1.79 KB

Contents

module Pixela::Client::WebhookMethods
  # Create a new Webhook.
  #
  # @param graph_id [String]
  # @param type     [String]
  #
  # @return [Pixela::Response]
  #
  # @raise [Pixela::PixelaError] API is failed
  #
  # @see https://docs.pixe.la/entry/post-webhook
  #
  # @example
  #   client.create_webhook(graph_id: "test-graph", type: "increment")
  def create_webhook(graph_id:, type:)
    params = {
      graphID: graph_id,
      type:    type,
    }

    with_error_handling do
      connection.post("users/#{username}/webhooks", params).body
    end
  end

  # Get all predefined webhooks definitions.
  #
  # @return [Array<Hashie::Mash>]
  #
  # @raise [Pixela::PixelaError] API is failed
  #
  # @see https://docs.pixe.la/entry/get-webhooks
  #
  # @example
  #   client.get_webhooks
  def get_webhooks
    with_error_handling do
      connection.get("users/#{username}/webhooks").body.webhooks
    end
  end

  # Invoke the webhook registered in advance.
  #
  # @param webhook_hash [String]
  #
  # @return [Pixela::Response]
  #
  # @raise [Pixela::PixelaError] API is failed
  #
  # @see https://docs.pixe.la/entry/invoke-webhook
  #
  # @example
  #   client.invoke_webhook(webhook_hash: "<webhookHash>")
  def invoke_webhook(webhook_hash:)
    with_error_handling do
      connection(default_headers).post("users/#{username}/webhooks/#{webhook_hash}").body
    end
  end

  # Delete the registered Webhook.
  #
  # @param webhook_hash [String]
  #
  # @return [Pixela::Response]
  #
  # @raise [Pixela::PixelaError] API is failed
  #
  # @see https://docs.pixe.la/entry/delete-webhook
  #
  # @example
  #   client.delete_webhook(webhook_hash: "<webhookHash>")
  def delete_webhook(webhook_hash:)
    with_error_handling do
      connection.delete("users/#{username}/webhooks/#{webhook_hash}").body
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pixela-2.0.0 lib/pixela/client/webhook_methods.rb
pixela-1.5.0 lib/pixela/client/webhook_methods.rb
pixela-1.4.2 lib/pixela/client/webhook_methods.rb
pixela-1.4.1 lib/pixela/client/webhook_methods.rb
pixela-1.4.0 lib/pixela/client/webhook_methods.rb
pixela-1.3.1 lib/pixela/client/webhook_methods.rb
pixela-1.3.0 lib/pixela/client/webhook_methods.rb