-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cv2 3435 alegre with presto for audio (#1647)
* CV2-3435 add alegre webhook * update fixtures to match actual alegre resposne * remove unnecessary copypasting * fix test call * small fix * try different setup * readd request * downgrade to type checking for the moment * replace test with known direct relationship count changing test * update stub * finally fix test * add newline per codeclimate * CV2-3435 updates to alegre to work locally * update test * remove token passing * resolve error in returned value of request_api * add prefix, add blank safety check * CV2-3435 update tests as per @caiosba commentary * Clean-up and test simplification --------- Co-authored-by: Caio <[email protected]>
- Loading branch information
Showing
7 changed files
with
67 additions
and
4 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
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,26 @@ | ||
class AlegreCallbackError < StandardError | ||
end | ||
|
||
module AlegreWebhooks | ||
extend ActiveSupport::Concern | ||
|
||
module ClassMethods | ||
def valid_request?(request) | ||
token = request.params['token'] || request.query_parameters['token'] | ||
!token.blank? && token == CheckConfig.get('alegre_token') | ||
end | ||
|
||
def webhook(request) | ||
begin | ||
doc_id = request.params.dig('data', 'requested', 'body', 'id') | ||
raise 'Unexpected params format' if doc_id.blank? | ||
redis = Redis.new(REDIS_CONFIG) | ||
key = "alegre:webhook:#{doc_id}" | ||
redis.lpush(key, request.params.to_json) | ||
redis.expire(key, 1.day.to_i) | ||
rescue StandardError => e | ||
CheckSentry.notify(AlegreCallbackError.new(e.message), { alegre_response: request.params }) | ||
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
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