Class: OpenStax::Api::Constraints

Inherits:
Object
  • Object
show all
Defined in:
lib/openstax/api/constraints.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Constraints



6
7
8
9
# File 'lib/openstax/api/constraints.rb', line 6

def initialize(options)
  @version = options[:version]
  @default = options[:default]
end

Instance Method Details

#api_accept_headerObject



11
12
13
14
# File 'lib/openstax/api/constraints.rb', line 11

def api_accept_header
  self.main_app_name ||= OpenStax::Api::Engine::MAIN_APP_NAME.underscore
  "application/vnd.#{self.main_app_name}.openstax.#{@version.to_s}"
end

#matches?(req) ⇒ Boolean



16
17
18
# File 'lib/openstax/api/constraints.rb', line 16

def matches?(req)
  @default || req.headers['Accept'].try(:include?, api_accept_header)
end