class Apiphobic::Requests::AcceptHeader
Constants
- ACCEPT_PARAM_PATTERN
Attributes
request[RW]
Public Class Methods
new(request)
click to toggle source
# File lib/apiphobic/requests/accept_header.rb, line 12 def initialize(request) self.request = request end
resolve(request)
click to toggle source
# File lib/apiphobic/requests/accept_header.rb, line 16 def self.resolve(request) return request if request.class == self new(request) end
Public Instance Methods
accept_header()
click to toggle source
# File lib/apiphobic/requests/accept_header.rb, line 22 def accept_header if accept_header_from_header.valid? || accept_header_from_params.invalid? raw_accept_header_from_header else raw_accept_header_from_params end end
Private Instance Methods
accept_header_from_header()
click to toggle source
# File lib/apiphobic/requests/accept_header.rb, line 32 def accept_header_from_header @accept_header_from_header ||= \ ::Apiphobic::AcceptHeader.new(raw_accept_header_from_header, application_name: /.*?/) end
accept_header_from_params()
click to toggle source
# File lib/apiphobic/requests/accept_header.rb, line 38 def accept_header_from_params @accept_header_from_params ||= \ ::Apiphobic::AcceptHeader.new(raw_accept_header_from_params, application_name: /.*?/) end
raw_accept_header_from_header()
click to toggle source
# File lib/apiphobic/requests/accept_header.rb, line 44 def raw_accept_header_from_header if request.respond_to?(:headers) request.headers['Accept'] else request['HTTP_ACCEPT'] end end
raw_accept_header_from_params()
click to toggle source
# File lib/apiphobic/requests/accept_header.rb, line 52 def raw_accept_header_from_params if request.respond_to?(:params) request.params['_accept'] else URI.unescape(request['QUERY_STRING'][ACCEPT_PARAM_PATTERN, 1] || '') # rubocop:disable Lint/UriEscapeUnescape end end