Class: TrackerApi::Endpoints::Webhook

Inherits:
Object
  • Object
show all
Defined in:
lib/tracker_api/endpoints/webhook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Webhook

Returns a new instance of Webhook.



6
7
8
# File 'lib/tracker_api/endpoints/webhook.rb', line 6

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/tracker_api/endpoints/webhook.rb', line 4

def client
  @client
end

Instance Method Details

#create(project_id, params = {}) ⇒ Object



16
17
18
19
20
# File 'lib/tracker_api/endpoints/webhook.rb', line 16

def create(project_id, params={})
  data = client.post("/projects/#{project_id}/webhooks", params: params).body

  Resources::Webhook.new({ client: client }.merge(data))
end

#delete(webhook) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
36
37
# File 'lib/tracker_api/endpoints/webhook.rb', line 32

def delete(webhook)
  raise ArgumentError, 'Valid webhook required to update.' unless webhook.instance_of?(Resources::Webhook)

  data = client.delete("/projects/#{webhook.project_id}/webhooks/#{webhook.id}")
  data.status == 204
end

#delete_from_project(project_id, webhook_id) ⇒ Object



39
40
41
42
# File 'lib/tracker_api/endpoints/webhook.rb', line 39

def delete_from_project(project_id, webhook_id)
  data = client.delete("/projects/#{project_id}/webhooks/#{webhook_id}")
  data.status == 204
end

#get(project_id, id, params = {}) ⇒ Object



10
11
12
13
14
# File 'lib/tracker_api/endpoints/webhook.rb', line 10

def get(project_id, id, params={})
  data = client.get("/projects/#{project_id}/webhooks/#{id}", params: params).body

  Resources::Webhook.new({ client: client, project_id: project_id }.merge(data))
end

#update(webhook, params = {}) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
30
# File 'lib/tracker_api/endpoints/webhook.rb', line 22

def update(webhook, params={})
  raise ArgumentError, 'Valid webhook required to update.' unless webhook.instance_of?(Resources::Webhook)

  data = client.put("/projects/#{webhook.project_id}/webhooks/#{webhook.id}", params: params).body

  webhook.attributes = data
  webhook.clean!
  webhook
end