Created
October 25, 2012 15:48
-
-
Save kule/3953544 to your computer and use it in GitHub Desktop.
Example handle_defensio_callback
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
# Public: This will take the request object and update the relevant model | |
def self.handle_defensio_callback(request) | |
query_params = CGI::parse(request.query_string) | |
defender_model = query_params['model'].first.strip | |
if defender_model.empty? | |
raise DefenderError, 'Incorrect url structure; missing callback url param' | |
else | |
begin | |
document = document_from_defensio_callback(request) | |
unless document.nil? | |
record_to_update = defender_model.constantize.find_by_defensio_sig(document['signature']) | |
record_to_update.set_defensio_status(document) | |
record_to_update.save | |
end | |
rescue NameError | |
raise DefenderError, "Could not constantize class #{defender_model}" | |
rescue ActiveRecord::RecordNotFound | |
raise DefenderError, "Could not find #{defender_model.constantize}.id=#{defender_model_id} perhaps it was deleted?" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment