Class: BlacklightApi
- Inherits:
-
Object
- Object
- BlacklightApi
- Includes:
- HTTParty
- Defined in:
- app/models/blacklight_api.rb
Overview
BlacklightApi
Instance Method Summary collapse
- #facets ⇒ Object
- #fetch ⇒ Object
-
#initialize(request, args) ⇒ BlacklightApi
constructor
A new instance of BlacklightApi.
- #links ⇒ Object
- #load_all ⇒ Object
- #meta ⇒ Object
- #pluck(field) ⇒ Object
- #results ⇒ Object
- #sorts ⇒ Object
Constructor Details
#initialize(request, args) ⇒ BlacklightApi
Returns a new instance of BlacklightApi.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/blacklight_api.rb', line 10 def initialize(request, args) defaults = { q: "*", page: 1, sort: "score+desc%2C+dc_title_sort+asc", rows: 20 } @request = request @options = defaults.merge(args) append_facets(@options[:f], @options) append_daterange(@options[:f], @options) @options.compact! end |
Instance Method Details
#facets ⇒ Object
32 33 34 |
# File 'app/models/blacklight_api.rb', line 32 def facets fetch["included"]&.select { |s| s["type"] == "facet" } end |
#fetch ⇒ Object
24 25 26 |
# File 'app/models/blacklight_api.rb', line 24 def fetch @fetch ||= self.class.get("#{@request}#{BLACKLIGHT_JSON_API}", query: @options) end |
#links ⇒ Object
44 45 46 |
# File 'app/models/blacklight_api.rb', line 44 def links fetch["links"] end |
#load_all ⇒ Object
48 49 50 |
# File 'app/models/blacklight_api.rb', line 48 def load_all results.map { |result| Document.find_by(friendlier_id: result["id"]) } end |
#meta ⇒ Object
40 41 42 |
# File 'app/models/blacklight_api.rb', line 40 def fetch["meta"] end |
#pluck(field) ⇒ Object
52 53 54 |
# File 'app/models/blacklight_api.rb', line 52 def pluck(field) load_all.pluck(field.to_sym) end |
#results ⇒ Object
28 29 30 |
# File 'app/models/blacklight_api.rb', line 28 def results fetch["data"] end |
#sorts ⇒ Object
36 37 38 |
# File 'app/models/blacklight_api.rb', line 36 def sorts fetch["included"].select { |s| s["type"] == "sort" } end |