Class: Europeana::Blacklight::Repository

Inherits:
Blacklight::AbstractRepository
  • Object
show all
Defined in:
lib/europeana/blacklight/repository.rb

Overview

Repository hooked up to Europeana REST API via europeana-api gem

See Also:

  • API

Instance Method Summary collapse

Instance Method Details

#build_connectionObject



43
44
45
46
47
# File 'lib/europeana/blacklight/repository.rb', line 43

def build_connection
  Europeana::API.tap do |api|
    api.key = blacklight_config.connection_config[:europeana_api_key]
  end
end

#find(id, params = {}) ⇒ Object

Finds a single Europeana record via the API

Parameters:

  • id (String)

    record ID



14
15
16
17
18
19
20
21
22
# File 'lib/europeana/blacklight/repository.rb', line 14

def find(id, params = {})
  id = "/#{id}" unless id[0] == '/'
  res = connection.record.fetch(params.merge(id: id))

  blacklight_config.response_model.new(
    res, params, document_model: blacklight_config.document_model,
                 blacklight_config: blacklight_config
  )
end

#more_like_this(doc, field = nil, params = {}) ⇒ Object

Queries the API for items similar to a given document



35
36
37
38
39
40
41
# File 'lib/europeana/blacklight/repository.rb', line 35

def more_like_this(doc, field = nil, params = {})
  query = doc.more_like_this_query(field)
  return [nil, []] if query.nil?
  mlt_params = { query: query, rows: 4, profile: 'rich' }.merge(params)
  mlt_response = search(mlt_params)
  [mlt_response, mlt_response.documents]
end

#search(params = {}) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/europeana/blacklight/repository.rb', line 24

def search(params = {})
  res = connection.record.search(params.to_h)

  blacklight_config.response_model.new(
    res, params, document_model: blacklight_config.document_model,
                 blacklight_config: blacklight_config
  )
end