Class: LD4L::WorksRDF::GetSolrResultsFromSolrQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/ld4l/works_rdf/services/negotiation_services/get_solr_results_from_solr_query.rb

Class Method Summary collapse

Class Method Details

.call(solr_query_url) ⇒ Object

Get solr documents populated from the solr query url via content negotiation.

Parameters:

  • solr_query_url (String)

    for the work(s)

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ld4l/works_rdf/services/negotiation_services/get_solr_results_from_solr_query.rb', line 11

def self.call( solr_query_url )
  raise ArgumentError, 'solr_query_url argument must be a uri string'  unless solr_query_url.kind_of?(String)

  http = Curl.get(solr_query_url) do |curl|
    curl.headers['Accept'] = 'application/xml'
    curl.headers['Api-Version'] = '2.2'
    curl.follow_location = true
    curl.max_redirects = 3
    curl.connect_timeout = 30
    curl.useragent = "curb"
  end
  header = http.header_str

  status = LD4L::WorksRDF::ResponseHeader.get_status(header)
  raise EncodingError, "Status #{status} returned from query"  unless status == '200'

  response_content_type = LD4L::WorksRDF::ResponseHeader.get_content_type(header)
  raise EncodingError, "uri returned results of type '#{response_content_type}' instead of expected 'application/xml'"  unless response_content_type == 'application/xml'

  results = http.body_str
  results
end