Sha256: f7b9e44cdcf46bb1f26e29747a08aabb6fefa4fae9b88053e408886dbbb0999c

Contents?: true

Size: 668 Bytes

Versions: 8

Compression:

Stored size: 668 Bytes

Contents

require 'json'
require 'net/http'

class PushmiPullyu::AIP::SolrFetcher

  class SolrFetchError < StandardError; end

  def initialize(noid)
    @noid = noid
  end

  def fetch_permission_object_ids
    hash = JSON.parse(run_query_json)

    return [] if hash['response']['docs'].empty?

    hash['response']['docs'].map { |hit| hit['id'] }
  end

  private

  # Return fetched results, else raise an error
  def run_query_json
    response = Net::HTTP.get_response(
      URI("#{PushmiPullyu.options[:solr][:url]}/select?q=accessTo_ssim:#{@noid}&fl=id&wt=json")
    )

    return response.body if response.is_a?(Net::HTTPSuccess)

    raise SolrFetchError
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pushmi_pullyu-0.2.7 lib/pushmi_pullyu/aip/solr_fetcher.rb
pushmi_pullyu-0.2.6 lib/pushmi_pullyu/aip/solr_fetcher.rb
pushmi_pullyu-0.2.5 lib/pushmi_pullyu/aip/solr_fetcher.rb
pushmi_pullyu-0.2.4 lib/pushmi_pullyu/aip/solr_fetcher.rb
pushmi_pullyu-0.2.3 lib/pushmi_pullyu/aip/solr_fetcher.rb
pushmi_pullyu-0.2.2 lib/pushmi_pullyu/aip/solr_fetcher.rb
pushmi_pullyu-0.2.1 lib/pushmi_pullyu/aip/solr_fetcher.rb
pushmi_pullyu-0.2.0 lib/pushmi_pullyu/aip/solr_fetcher.rb