Class: FastBound::Webhook

Inherits:
Base
  • Object
show all
Includes:
API
Defined in:
lib/fastbound-ruby/webhook.rb

Constant Summary collapse

CREATE_AND_EDIT_ATTRS =
{
  permitted: %i( name url description events ).freeze,
  required:  %i( name url events ).freeze
}
ENDPOINTS =
{
  create: "webhooks".freeze,
  edit:   "webhooks/%s".freeze,
  fetch:  "webhooks/%s".freeze,
  delete: "webhooks/%s".freeze,
  events: "webhooks/events".freeze
}

Constants included from API

API::FILE_UPLOAD_ATTRS, API::ROOT_URL, API::USER_AGENT

Instance Method Summary collapse

Methods included from API

#delete_request, #get_request, #post_file_request, #post_request, #put_request

Constructor Details

#initialize(client) ⇒ Webhook

Returns a new instance of Webhook.



21
22
23
# File 'lib/fastbound-ruby/webhook.rb', line 21

def initialize(client)
  @client = client
end

Instance Method Details

#create(webhook_data) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/fastbound-ruby/webhook.rb', line 25

def create(webhook_data)
  requires!(webhook_data, *CREATE_AND_EDIT_ATTRS[:required])

  endpoint = ENDPOINTS[:create]
  webhook_data = standardize_body_data(webhook_data, CREATE_AND_EDIT_ATTRS[:permitted])

  post_request(@client, endpoint, webhook_data)
end

#delete(webhook_name) ⇒ Object



47
48
49
50
51
# File 'lib/fastbound-ruby/webhook.rb', line 47

def delete(webhook_name)
  endpoint = ENDPOINTS[:delete] % webhook_name

  delete_request(@client, endpoint)
end

#edit(webhook_name, webhook_data) ⇒ Object



34
35
36
37
38
39
# File 'lib/fastbound-ruby/webhook.rb', line 34

def edit(webhook_name, webhook_data)
  endpoint = ENDPOINTS[:edit] % webhook_name
  webhook_data = standardize_body_data(webhook_data, CREATE_AND_EDIT_ATTRS[:permitted])

  put_request(@client, endpoint, webhook_data)
end

#eventsObject



53
54
55
56
57
# File 'lib/fastbound-ruby/webhook.rb', line 53

def events
  endpoint = ENDPOINTS[:events]

  get_request(@client, endpoint)
end

#fetch(webhook_name) ⇒ Object



41
42
43
44
45
# File 'lib/fastbound-ruby/webhook.rb', line 41

def fetch(webhook_name)
  endpoint = ENDPOINTS[:fetch] % webhook_name

  get_request(@client, endpoint)
end