Sha256: d85d3ad6595a8403a6bdd8a66ba54fd719d392600d1f855f0188faf47e03f5d0

Contents?: true

Size: 832 Bytes

Versions: 2

Compression:

Stored size: 832 Bytes

Contents

module SpiffyStoresAPI
  class Connection < ActiveResource::Connection
    attr_reader :response

    module ResponseCapture
      def handle_response(response)
        @response = super
      end
    end

    include ResponseCapture

    module RequestNotification
      def request(method, path, *arguments)
        super.tap do |response|
          notify_about_request(response, arguments)
        end
      rescue => e
        notify_about_request(e.response, arguments) if e.respond_to?(:response)
        raise
      end

      def notify_about_request(response, arguments)
        ActiveSupport::Notifications.instrument("request.active_resource_detailed") do |payload|
          payload[:response] = response
          payload[:data]     = arguments
        end
      end
    end

    include RequestNotification
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spiffy_stores_api-4.11.1 lib/spiffy_stores_api/connection.rb
spiffy_stores_api-4.11.0 lib/spiffy_stores_api/connection.rb