Class: DigitalOcean::AuthenticationMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/digital_ocean/authentication_middleware.rb

Instance Method Summary (collapse)

Constructor Details

- (AuthenticationMiddleware) initialize(app, client_id, api_key)

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

- (Object) call(env)



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

- (Object) query_params(url)



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