module Particle::Client::Webhooks

Client methods for the Particle webhook API

@see docs.particle.io/core/webhooks/

Public Instance Methods

create_webhook(options) click to toggle source

Creates a new Particle webhook

@param options [Hash] Options to configure the webhook @return [Webhook] The webhook object @see docs.particle.io/core/webhooks/#Webhook-options

# File lib/particle/client/webhooks.rb, line 48
def create_webhook(options)
  result = post(Webhook.create_path, options)
  webhook(result)
end
remove_webhook(target) click to toggle source

Remove a Particle webhook

@param target [String, Webhook] A webhook id or {Webhook} object @return [boolean] true for success

# File lib/particle/client/webhooks.rb, line 57
def remove_webhook(target)
  result = delete(webhook(target).path)
  return true if last_response.status == 204
  result[:ok]
end
webhook(target) click to toggle source

Create a domain model for a Particle webhook

@param target [String, Hash, Webhook] A webhook id, hash of attributes or {Device} object @return [Webhook] A webhook object to interact with

# File lib/particle/client/webhooks.rb, line 15
def webhook(target)
  if target.is_a? Webhook
    target
  else
    Webhook.new(self, target)
  end
end
webhook_attributes(target) click to toggle source

Get information about a Particle webhook

The Particle cloud will send a test message to the webhook URL when this is called

@param target [String, Webhook] A webhook id or {Webhook} object @return [Hash] The webhook attributes and test message response

# File lib/particle/client/webhooks.rb, line 39
def webhook_attributes(target)
  get(webhook(target).path)
end
webhooks() click to toggle source

List all Particle webhooks on the account

@return [Array<Webhook>] List of Particle webhooks to interact with

# File lib/particle/client/webhooks.rb, line 26
def webhooks
  get(Webhook.list_path).map do |attributes|
    webhook(attributes)
  end
end