connection.rb 943 B

1234567891011121314151617181920212223242526272829303132333435
  1. module ShopifyAPI
  2. class Connection < ActiveResource::Connection
  3. attr_reader :response
  4. module ResponseCapture
  5. def handle_response(response)
  6. @response = super
  7. end
  8. end
  9. include ResponseCapture
  10. module RequestNotification
  11. def request(method, path, *arguments)
  12. super.tap do |response|
  13. notify_about_request(method, path, response, arguments)
  14. end
  15. rescue => e
  16. notify_about_request(method, path, e.response, arguments) if e.respond_to?(:response)
  17. raise
  18. end
  19. def notify_about_request(method, path, response, arguments)
  20. ActiveSupport::Notifications.instrument("request.active_resource_detailed") do |payload|
  21. payload[:method] = method
  22. payload[:path] = path
  23. payload[:response] = response
  24. payload[:data] = arguments
  25. end
  26. end
  27. end
  28. include RequestNotification
  29. end
  30. end