Module: Particle::Client::Webhooks

Included in:
Particle::Client
Defined in:
lib/particle/client/webhooks.rb

Overview

Client methods for the Particle webhook API

Instance Method Summary collapse

Instance Method Details

#create_webhook(options) ⇒ Webhook

Creates a new Particle webhook

Parameters:

  • options (Hash)

    Options to configure the webhook

Returns:

See Also:



48
49
50
51
# File 'lib/particle/client/webhooks.rb', line 48

def create_webhook(options)
  result = post(Webhook.create_path, options)
  webhook(result)
end

#remove_webhook(target) ⇒ boolean

Remove a Particle webhook

Parameters:

Returns:

  • (boolean)

    true for success



57
58
59
60
# File 'lib/particle/client/webhooks.rb', line 57

def remove_webhook(target)
  result = delete(webhook(target).path)
  result[:ok]
end

#webhook(target) ⇒ Webhook

Create a domain model for a Particle webhook

Parameters:

  • target (String, Hash, Webhook)

    A webhook id, hash of attributes or Device object

Returns:

  • (Webhook)

    A webhook object to interact with



15
16
17
18
19
20
21
# 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) ⇒ Hash

Get information about a Particle webhook

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

Parameters:

Returns:

  • (Hash)

    The webhook attributes and test message response



39
40
41
# File 'lib/particle/client/webhooks.rb', line 39

def webhook_attributes(target)
  get(webhook(target).path)
end

#webhooksArray<Webhook>

List all Particle webhooks on the account

Returns:

  • (Array<Webhook>)

    List of Particle webhooks to interact with



26
27
28
29
30
# File 'lib/particle/client/webhooks.rb', line 26

def webhooks
  get(Webhook.list_path).map do |attributes|
    webhook(attributes)
  end
end