Skip to content

Instantly share code, notes, and snippets.

@mediocretes
Last active August 29, 2015 14:23
Show Gist options
  • Save mediocretes/ef8bfdee4e58fe1eb8b8 to your computer and use it in GitHub Desktop.
Save mediocretes/ef8bfdee4e58fe1eb8b8 to your computer and use it in GitHub Desktop.
Delegating webhook events to other methods
EVENTS_ABOUT_WHICH_WE_CARE = ["payment_success", "billing_date_change"]
def handle_event
event = params["event"]
payload = params["payload"]
return head(:unprocessable_entity) unless if event.blank? || payload.blank?
return head(:ok) unless EVENTS_ABOUT_WHICH_WE_CARE.include?(event)
self.send(event, payload)
end
private
def payment_success(payload)
# do things
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment