module Pixela::Client::WebhookMethods

Public Instance Methods

create_webhook(graph_id:, type:) click to toggle source

Create a new Webhook.

@param graph_id [String] @param type [String]

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/post-webhook

@example

client.create_webhook(graph_id: "test-graph", type: "increment")
# File lib/pixela/client/webhook_methods.rb, line 15
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
delete_webhook(webhook_hash:) click to toggle source

Delete the registered Webhook.

@param webhook_hash [String]

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/delete-webhook

@example

client.delete_webhook(webhook_hash: "<webhookHash>")
# File lib/pixela/client/webhook_methods.rb, line 72
def delete_webhook(webhook_hash:)
  with_error_handling do
    connection.delete("users/#{username}/webhooks/#{webhook_hash}").body
  end
end
get_webhooks() click to toggle source

Get all predefined webhooks definitions.

@return [Array<Hashie::Mash>]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/get-webhooks

@example

client.get_webhooks
# File lib/pixela/client/webhook_methods.rb, line 36
def get_webhooks
  with_error_handling do
    connection.get("users/#{username}/webhooks").body.webhooks
  end
end
invoke_webhook(webhook_hash:) click to toggle source

Invoke the webhook registered in advance.

@param webhook_hash [String]

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/invoke-webhook

@example

client.invoke_webhook(webhook_hash: "<webhookHash>")
# File lib/pixela/client/webhook_methods.rb, line 54
def invoke_webhook(webhook_hash:)
  with_error_handling do
    connection(request_headers: default_headers).post("users/#{username}/webhooks/#{webhook_hash}").body
  end
end