Class: Qa::LinkedData::RequestHeaderService

Inherits:
Object
  • Object
show all
Defined in:
app/services/qa/linked_data/request_header_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request:, params:) ⇒ RequestHeaderService

Note:

params may have additional attribute-value pairs that are passed through via replacements (only configured replacements are used)

Returns a new instance of RequestHeaderService.

Parameters:

  • request (HttpRequest)

    request from controller

  • params (Hash)

    attribute-value pairs holding the request parameters

  • subauthority (Hash)

    a customizable set of options

  • lang (Hash)

    a customizable set of options

  • performance_data (Hash)

    a customizable set of options

  • context (Hash)

    a customizable set of options

  • response_header (Hash)

    a customizable set of options

  • format (Hash)

    a customizable set of options



16
17
18
19
# File 'app/services/qa/linked_data/request_header_service.rb', line 16

def initialize(request:, params:)
  @request = request
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'app/services/qa/linked_data/request_header_service.rb', line 5

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



5
6
7
# File 'app/services/qa/linked_data/request_header_service.rb', line 5

def request
  @request
end

Instance Method Details

#content_type_for_formatObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/services/qa/linked_data/request_header_service.rb', line 50

def content_type_for_format
  case format
  when 'jsonld'
    'application/ld+json'
  when 'n3'
    'text/n3'
  when 'ntriples'
    'application/n-triples'
  else
    'application/json'
  end
end

#fetch_headerObject

Construct request parameters to pass to fetching a term (linked data module).



38
39
40
41
42
43
44
45
46
47
# File 'app/services/qa/linked_data/request_header_service.rb', line 38

def fetch_header
  header = {}
  header[:subauthority] = params.fetch(:subauthority, nil)
  header[:user_language] = user_language
  header[:performance_data] = performance_data?
  header[:format] = format
  header[:response_header] = response_header?
  header[:replacements] = replacements
  header
end

#search_headerObject

Construct request parameters to pass to search_query (linked data module).



24
25
26
27
28
29
30
31
32
33
# File 'app/services/qa/linked_data/request_header_service.rb', line 24

def search_header
  header = {}
  header[:subauthority] = params.fetch(:subauthority, nil)
  header[:user_language] = user_language
  header[:performance_data] = performance_data?
  header[:context] = context?
  header[:response_header] = response_header?
  header[:replacements] = replacements
  header
end