Class: Praxicraft::Resources::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/praxicraft/resources/webhooks.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Webhooks

Returns a new instance of Webhooks.



6
7
8
# File 'lib/praxicraft/resources/webhooks.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#create(args = nil, **kwargs) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/praxicraft/resources/webhooks.rb', line 14

def create(args = nil, **kwargs)
  body = normalize(args || kwargs) || {}
  url = body["url"]
  events = body["events"]
  if url.nil? || url.to_s.strip.empty?
    raise APIError.new("url is required", "INVALID_ARGUMENT")
  end
  if !events.is_a?(Array) || events.empty?
    raise APIError.new("events must be a non-empty list", "INVALID_ARGUMENT")
  end

  @client.post("/webhooks/create/", body)
end

#delete(webhook_id) ⇒ Object



43
44
45
46
# File 'lib/praxicraft/resources/webhooks.rb', line 43

def delete(webhook_id)
  key = Client.path_segment(webhook_id, "webhook_id")
  @client.delete("/webhooks/#{key}/")
end

#deliveries(webhook_id) ⇒ Object



48
49
50
51
# File 'lib/praxicraft/resources/webhooks.rb', line 48

def deliveries(webhook_id)
  key = Client.path_segment(webhook_id, "webhook_id")
  @client.get("/webhooks/#{key}/deliveries/")
end

#list(params = nil) ⇒ Object



10
11
12
# File 'lib/praxicraft/resources/webhooks.rb', line 10

def list(params = nil)
  @client.get("/webhooks/", normalize(params))
end

#retrieve(webhook_id) ⇒ Object



28
29
30
31
# File 'lib/praxicraft/resources/webhooks.rb', line 28

def retrieve(webhook_id)
  key = Client.path_segment(webhook_id, "webhook_id")
  @client.get("/webhooks/#{key}/")
end

#test(webhook_id) ⇒ Object



53
54
55
56
# File 'lib/praxicraft/resources/webhooks.rb', line 53

def test(webhook_id)
  key = Client.path_segment(webhook_id, "webhook_id")
  @client.post("/webhooks/#{key}/test/")
end

#update(webhook_id, fields = nil, **kwargs) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/praxicraft/resources/webhooks.rb', line 33

def update(webhook_id, fields = nil, **kwargs)
  body = normalize(fields || kwargs)
  if body.nil? || body.empty?
    raise APIError.new("update() requires at least one field to change", "INVALID_ARGUMENT")
  end

  key = Client.path_segment(webhook_id, "webhook_id")
  @client.patch("/webhooks/#{key}/", body)
end