lib/ey-hmac/faraday.rb in ey-hmac-1.0.0 vs lib/ey-hmac/faraday.rb in ey-hmac-2.0.0
- old
+ new
@@ -1,20 +1,11 @@
require 'ey-hmac'
require 'faraday'
-if Faraday.respond_to? :register_middleware
- Faraday.register_middleware(:request, {:hmac => lambda { Ey::Hmac::Faraday }})
-end
+class Ey::Hmac::Faraday < Faraday::Response::Middleware
+ dependency("ey-hmac")
-# Request middleware that performs HMAC request signing
-require 'faraday_middleware/response_middleware'
-
-class Ey::Hmac::Faraday < FaradayMiddleware::ResponseMiddleware
- dependency do
- require 'ey-hmac' unless defined?(Ey::Hmac)
- end
-
attr_reader :key_id, :key_secret, :options
def initialize(app, key_id, key_secret, options = {})
super(app)
@key_id, @key_secret = key_id, key_secret
@@ -25,6 +16,6 @@
Ey::Hmac.sign!(env, key_id, key_secret, {adapter: Ey::Hmac::Adapter::Faraday}.merge(options))
@app.call(env)
end
end
-Faraday::Request.register_middleware(:hmac => lambda { Ey::Hmac::Faraday })
+Faraday::Middleware.register_middleware :hmac => Ey::Hmac::Faraday