connection.rb 1016 B

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