Class: Mapboxkit::Client::Connection::AuthorizationMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/mapboxkit/connection.rb

Overview

Authorization middleware for the connection

Instance Method Summary collapse

Constructor Details

#initialize(app, access_token) ⇒ AuthorizationMiddleware

Returns a new instance of AuthorizationMiddleware.



68
69
70
71
72
# File 'lib/mapboxkit/connection.rb', line 68

def initialize(app, access_token)
  @access_token = access_token

  super(app)
end

Instance Method Details

#on_request(env) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/mapboxkit/connection.rb', line 74

def on_request(env)
  return unless @access_token

  env.url.then do |uri|
    uri.query = [uri.query, "access_token=#{@access_token}"].compact.join('&')
  end
end