Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
also send webhook deletes when deleting from the dashboard
closes #90
- Loading branch information
Showing
4 changed files
with
76 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
class WebHooks | ||
|
||
def self.notify(site, link, source, target, _private) | ||
# If a callback URL is defined for this site, send to the callback now | ||
if !site.callback_url.blank? | ||
begin | ||
puts "Sending to callback URL: #{site.callback_url}" | ||
|
||
jf2 = Formats.build_jf2_from_link(link) | ||
|
||
data = { | ||
secret: site.callback_secret, | ||
source: source, | ||
target: target, | ||
private: _private, | ||
post: jf2 | ||
} | ||
|
||
RestClient::Request.execute(:method => :post, | ||
:url => site.callback_url, | ||
:payload => data.to_json, | ||
:headers => {:content_type => 'application/json'}, | ||
:ssl_ca_file => './helpers/ca-bundle.crt') | ||
puts "... success!" | ||
rescue => e | ||
puts "Failed to send to callback URL #{site.callback_url} #{e.inspect}" | ||
end | ||
end | ||
end | ||
|
||
def self.deleted(site, source, target, _private) | ||
# If a callback URL is defined for this site, send the delete notification to the callback now | ||
if !site.callback_url.blank? | ||
begin | ||
puts "Sending DELETE to callback URL: #{site.callback_url}" | ||
|
||
data = { | ||
secret: site.callback_secret, | ||
source: source, | ||
target: target, | ||
private: _private, | ||
deleted: true | ||
} | ||
|
||
RestClient::Request.execute(:method => :post, | ||
:url => site.callback_url, | ||
:payload => data.to_json, | ||
:headers => {:content_type => 'application/json'}, | ||
:ssl_ca_file => './helpers/ca-bundle.crt') | ||
puts "... success!" | ||
rescue => e | ||
puts "Failed to send to callback URL #{site.callback_url} #{e.inspect}" | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters