-
Notifications
You must be signed in to change notification settings - Fork 393
FOLIO: Post to a webhook after submitting a request #5262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maccabeelevine
wants to merge
17
commits into
vufind-org:dev
Choose a base branch
from
maccabeelevine:hold-webhook
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c7f6906
FOLIO: Call webhook after sending a request
maccabeelevine c5395c6
Add missing config
maccabeelevine d9064a3
Fix tests
maccabeelevine d741a05
Allow configuring the webhook timeout
maccabeelevine 29065ea
Use guzzle
maccabeelevine 719f247
Update date
maccabeelevine ac640f3
Defer GuzzleService changes to a a separate PR
maccabeelevine 08fa363
Allow null $webhookConnection
maccabeelevine 5ed0837
Fix style
maccabeelevine 1c841a0
Protect against unset $webhookConnection
maccabeelevine ce25722
Revert whitespace-only change to reduce diffs.
demiankatz d477528
Mark webhooks optional
maccabeelevine 6b04a07
Test the new config
maccabeelevine d463187
More specific assertions.
demiankatz b1d8ec3
Add test.
demiankatz 260f459
Test unsuccessful webhook call
maccabeelevine 79b1ec2
Expand tests.
demiankatz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,75 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Webhook connection class. | ||
| * | ||
| * PHP version 8 | ||
| * | ||
| * Copyright (C) Villanova University 2023. | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 2, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, see | ||
| * <https://www.gnu.org/licenses/>. | ||
| * | ||
| * @category VuFind | ||
| * @package Connection | ||
| * @author Maccabee Levine <msl321@lehigh.edu> | ||
| * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
| * @link https://vufind.org | ||
| */ | ||
|
|
||
| namespace VuFind\Connection; | ||
|
|
||
| use Psr\Log\LoggerAwareInterface; | ||
|
|
||
| /** | ||
| * Webhook connection class. | ||
| * | ||
| * @category VuFind | ||
| * @package Connection | ||
| * @author Maccabee Levine <msl321@lehigh.edu> | ||
| * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
| * @link https://vufind.org | ||
| */ | ||
| class Webhook implements | ||
| \VuFindHttp\HttpServiceAwareInterface, | ||
| LoggerAwareInterface | ||
| { | ||
| use \VuFindHttp\HttpServiceAwareTrait; | ||
| use \VuFind\Log\LoggerAwareTrait { | ||
| logError as error; | ||
| } | ||
|
|
||
| /** | ||
| * Send a webhook post to the given URL. Log but do not throw any errors. | ||
| * | ||
| * @param string $url Target URL (required for proper proxy setup for non-local addresses) | ||
| * @param ?float $timeout Request timeout in seconds (overrides configuration) | ||
| * | ||
| * @return void | ||
| */ | ||
| public function post(string $url, ?float $timeout = null): void | ||
| { | ||
| $client = $this->httpService->createClient($url, 'POST', $timeout); | ||
|
|
||
| try { | ||
| $response = $client->send(); | ||
| if (!$response->isSuccess()) { | ||
| $this->logError( | ||
| "Failed to post to webhook. Code: {$response->getStatusCode()}, body: {$response->getBody()}" | ||
| ); | ||
| } | ||
| } catch (\Exception $e) { | ||
| $this->logError('Failed to post webhook. Unexpected ' . $e::class . ': ' . (string)$e); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.