Class: BlacklightApiIds

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
app/models/blacklight_api_ids.rb

Overview

BlacklightApi

Instance Method Summary collapse

Constructor Details

#initialize(request, args = {}) ⇒ BlacklightApiIds

Returns a new instance of BlacklightApiIds.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/blacklight_api_ids.rb', line 10

def initialize(request, args = {})
  defaults = {
    q: "*",
    page: 1,
    sort: "score+desc%2C+dc_title_sort+asc",
    rows: 1000
  }

  @request = request
  @options = defaults.merge(**args)
  append_facets(@options[:f], @options)
  append_daterange(@options[:f], @options)
  @options.compact!
end

Instance Method Details

#facetsObject



35
36
37
# File 'app/models/blacklight_api_ids.rb', line 35

def facets
  fetch["included"]&.select { |s| s["type"] == "facet" }
end

#fetchObject



25
26
27
28
29
# File 'app/models/blacklight_api_ids.rb', line 25

def fetch
  Rails.logger.debug { "BlacklightApiIds > fetch > query: #{@options.inspect}" }

  @fetch ||= self.class.get("#{@request}#{BLACKLIGHT_JSON_API_IDS}", query: @options)
end


47
48
49
# File 'app/models/blacklight_api_ids.rb', line 47

def links
  fetch["links"]
end

#load_allObject



51
52
53
# File 'app/models/blacklight_api_ids.rb', line 51

def load_all
  results.map { |result| Document.find_by(friendlier_id: result["id"]) }
end

#metaObject



43
44
45
# File 'app/models/blacklight_api_ids.rb', line 43

def meta
  fetch["meta"]
end

#pluck(field) ⇒ Object



55
56
57
# File 'app/models/blacklight_api_ids.rb', line 55

def pluck(field)
  load_all.pluck(field.to_sym)
end

#resultsObject



31
32
33
# File 'app/models/blacklight_api_ids.rb', line 31

def results
  fetch["data"]
end

#sortsObject



39
40
41
# File 'app/models/blacklight_api_ids.rb', line 39

def sorts
  fetch["included"].select { |s| s["type"] == "sort" }
end