Class: Apill::Middleware::ApiRequest
- Inherits:
-
Object
- Object
- Apill::Middleware::ApiRequest
- Defined in:
- lib/apill/middleware/api_request.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ApiRequest
constructor
A new instance of ApiRequest.
Constructor Details
#initialize(app) ⇒ ApiRequest
Returns a new instance of ApiRequest.
10 11 12 |
# File 'lib/apill/middleware/api_request.rb', line 10 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/apill/middleware/api_request.rb', line 14 def call(env) env['HTTP_X_APPLICATION_NAME'] = Apill.configuration.application_name subdomain_matcher = Matchers::SubdomainMatcher.new(request: env) if subdomain_matcher.matches? if !subdomain_matcher.matches_api_subdomain? || Matchers::AcceptHeaderMatcher.new.matches?(env) @app.call(env) else Responses::InvalidApiRequestResponse.call(env) end else Responses::InvalidSubdomainResponse.call(env) end end |