Class: DigitalOcean::AuthenticationMiddleware
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- DigitalOcean::AuthenticationMiddleware
- Extended by:
- Forwardable
- Defined in:
- lib/digital_ocean/authentication_middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, client_id, api_key) ⇒ AuthenticationMiddleware
constructor
A new instance of AuthenticationMiddleware.
- #query_params(url) ⇒ Object
Constructor Details
#initialize(app, client_id, api_key) ⇒ AuthenticationMiddleware
Returns a new instance of AuthenticationMiddleware.
6 7 8 9 10 11 |
# File 'lib/digital_ocean/authentication_middleware.rb', line 6 def initialize(app, client_id, api_key) @client_id = client_id @api_key = api_key super(app) end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/digital_ocean/authentication_middleware.rb', line 13 def call(env) params = { 'client_id' => @client_id, 'api_key' => @api_key }.update query_params(env[:url]) env[:url].query = build_query params @app.call(env) end |
#query_params(url) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/digital_ocean/authentication_middleware.rb', line 21 def query_params(url) if url.query.nil? or url.query.empty? {} else parse_query url.query end end |