-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1659 from psu-libraries/1656-delete-work-webhook
1656 delete work webhook
- Loading branch information
Showing
11 changed files
with
180 additions
and
44 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
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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class WorkRemovedWebhookJob < ApplicationJob | ||
queue_as :webhooks | ||
|
||
def perform(work_uuid) | ||
WorkRemovedWebhook.new(work_uuid).notify | ||
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
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 |
---|---|---|
|
@@ -26,7 +26,7 @@ def endpoint | |
end | ||
|
||
def rmd_host | ||
'https://metadata.libraries.psu.edu' | ||
ENV['RMD_HOST'] | ||
end | ||
|
||
def api_key | ||
|
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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
class WorkRemovedWebhook | ||
def initialize(work_uuid) | ||
@work_uuid = work_uuid | ||
end | ||
|
||
def notify | ||
conn = Faraday.new( | ||
url: ENV['RMD_HOST'], | ||
headers: { 'X-API-KEY' => ENV['RMD_WEBHOOK_SECRET'] } | ||
) | ||
|
||
conn.post('/webhooks/scholarsphere_events', publication_url: "https://scholarsphere.psu.edu/resources/#{work_uuid}") | ||
end | ||
|
||
private | ||
|
||
attr_reader :work_uuid | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe WorkRemovedWebhookJob do | ||
let(:webhook) { instance_double WorkRemovedWebhook, notify: nil } | ||
|
||
before do | ||
allow(WorkRemovedWebhook).to receive(:new).with('abc123').and_return(webhook) | ||
end | ||
|
||
describe '#perform' do | ||
it 'triggers a work removed webhook' do | ||
described_class.perform_now('abc123') | ||
|
||
expect(webhook).to have_received(:notify) | ||
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
Oops, something went wrong.