Class: BlacklightApiIds
- Inherits:
-
Object
- Object
- BlacklightApiIds
- Includes:
- HTTParty
- Defined in:
- app/models/blacklight_api_ids.rb
Overview
BlacklightApi
Instance Method Summary collapse
- #facets ⇒ Object
- #fetch ⇒ Object
-
#initialize(request, args = {}) ⇒ BlacklightApiIds
constructor
A new instance of BlacklightApiIds.
- #links ⇒ Object
- #load_all ⇒ Object
- #meta ⇒ Object
- #pluck(field) ⇒ Object
- #results ⇒ Object
- #sorts ⇒ Object
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
#facets ⇒ Object
35 36 37 |
# File 'app/models/blacklight_api_ids.rb', line 35 def facets fetch["included"]&.select { |s| s["type"] == "facet" } end |
#fetch ⇒ Object
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 |
#links ⇒ Object
47 48 49 |
# File 'app/models/blacklight_api_ids.rb', line 47 def links fetch["links"] end |
#load_all ⇒ Object
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 |
#meta ⇒ Object
43 44 45 |
# File 'app/models/blacklight_api_ids.rb', line 43 def 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 |
#results ⇒ Object
31 32 33 |
# File 'app/models/blacklight_api_ids.rb', line 31 def results fetch["data"] end |
#sorts ⇒ Object
39 40 41 |
# File 'app/models/blacklight_api_ids.rb', line 39 def sorts fetch["included"].select { |s| s["type"] == "sort" } end |