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

  • format (Hash)

    a customizable set of options



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

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



47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/services/qa/linked_data/request_header_service.rb', line 47

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



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

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

#search_headerObject

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



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

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