Module: Parliament::Utils::Helpers::RequestHelper

Defined in:
lib/parliament/utils/helpers/request_helper.rb

Constant Summary collapse

NAMESPACE_URI =

The base namespace used for filtering parliamentary data within sparql queries

'https://id.parliament.uk'.freeze

Class Method Summary collapse

Class Method Details

.filter_response_data(request, *filters) ⇒ Parliament::Response

Takes a Parliament::Request and a optional amount of filters and calls the #get method on on the request. Then calls Parliament::Response#filter with the filters as the parameters on the resulting response.

Parameters:

  • request (Parliament::Request)

    a built Parliament::Request object that can just be called with #get

Returns:

  • (Parliament::Response)


26
27
28
# File 'lib/parliament/utils/helpers/request_helper.rb', line 26

def self.filter_response_data(request, *filters)
  request.get.filter(*filters)
end

.namespace_uriString

Returns the base namespace used for filtering parliamentary data within sparql queries

Returns:

  • (String)


33
34
35
# File 'lib/parliament/utils/helpers/request_helper.rb', line 33

def self.namespace_uri
  NAMESPACE_URI
end

.namespace_uri_path(path) ⇒ String

Returns uri with specific path added for filtering parliamentary data within sparql queries

Parameters:

  • Path (String)

    string to append to the base uri

Returns:

  • (String)

    uri with specific path added for filtering parliamentary data within sparql queries



42
43
44
# File 'lib/parliament/utils/helpers/request_helper.rb', line 42

def self.namespace_uri_path(path)
  namespace_uri + path
end

.namespace_uri_schema_path(type) ⇒ String

Returns uri with schema path and specific type added for filtering parliamentary data within sparql queries

Parameters:

  • Type (String)

    string to append to the schema uri

Returns:

  • (String)

    uri with schema path and specific type added for filtering parliamentary data within sparql queries



51
52
53
# File 'lib/parliament/utils/helpers/request_helper.rb', line 51

def self.namespace_uri_schema_path(type)
  namespace_uri_path("/schema/#{type}")
end

.process_available_letters(request) ⇒ Array<String>

Takes a Parliament::Request and calls the #get method. Then maps the #value method on the resulting response.

Parameters:

  • request (Parliament::Request)

    a built Parliament::Request object that can just be called with #get

Returns:

  • (Array<String>)


15
16
17
18
# File 'lib/parliament/utils/helpers/request_helper.rb', line 15

def self.process_available_letters(request)
  response = request.get
  response.map(&:value)
end