Class: Particle::Webhook

Inherits:
Model
  • Object
show all
Defined in:
lib/particle/webhook.rb

Overview

Domain model for one Particle device

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

attribute_reader, #attributes, #id, #inspect

Constructor Details

#initialize(client, attributes) ⇒ Webhook

Returns a new instance of Webhook.



7
8
9
# File 'lib/particle/webhook.rb', line 7

def initialize(client, attributes)
  super(client, attributes)
end

Class Method Details

.create_pathObject



53
54
55
# File 'lib/particle/webhook.rb', line 53

def self.create_path
  "v1/webhooks"
end

.list_pathObject



49
50
51
# File 'lib/particle/webhook.rb', line 49

def self.list_path
  "v1/webhooks"
end

Instance Method Details

#createObject

Add a Particle webhook



38
39
40
41
42
# File 'lib/particle/webhook.rb', line 38

def create
  new_webhook = @client.create_webhook(@attributes)
  @attributes = new_webhook.attributes
  self
end

#errorObject

The error from the web server to a test message If nil, check response



23
24
25
26
# File 'lib/particle/webhook.rb', line 23

def error
  get_attributes unless @loaded
  @error
end

#get_attributesObject

Force reloading the attributes for the webhook



29
30
31
32
33
34
35
# File 'lib/particle/webhook.rb', line 29

def get_attributes
  @loaded = true
  result = @client.webhook_attributes(self)
  @response = result[:response]
  @error = result[:error]
  @attributes = result[:webhook]
end

#pathObject



57
58
59
# File 'lib/particle/webhook.rb', line 57

def path
  "/v1/webhooks/#{id}"
end

#removeObject

Remove a Particle webhook



45
46
47
# File 'lib/particle/webhook.rb', line 45

def remove
  @client.remove_webhook(self)
end

#responseObject

The response of the web server to a test message If nil, check error



16
17
18
19
# File 'lib/particle/webhook.rb', line 16

def response
  get_attributes unless @loaded
  @response
end