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



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

def initialize(request:, params:)
  @request = request
  @params = params
  @request_id = request.request_id
  log_request
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



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

def request
  @request
end

#request_idObject (readonly)

Returns the value of attribute request_id.



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

def request_id
  @request_id
end

Instance Method Details

#content_type_for_formatObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/services/qa/linked_data/request_header_service.rb', line 57

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).



43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/services/qa/linked_data/request_header_service.rb', line 43

def fetch_header
  header = {}
  header[:request] = request
  header[:request_id] = request_id
  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).



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/qa/linked_data/request_header_service.rb', line 27

def search_header
  header = {}
  header[:request] = request
  header[:request_id] = request_id
  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