class RelatonBsi::HitCollection

Page of hit collection.

Constants

DOMAIN

Public Class Methods

new(ref, year = nil) click to toggle source

@param ref [String] @param year [String]

Calls superclass method
# File lib/relaton_bsi/hit_collection.rb, line 16
def initialize(ref, year = nil)
  super ref, year
  # @agent = Mechanize.new
  # resp = agent.get "#{DOMAIN}/SearchResults/?q=#{ref}"
  config = Algolia::Search::Config.new(application_id: "575YE157G9", api_key: "a057b4e74099445df2eddb7940828a10")
  client = Algolia::Search::Client.new config, logger: ::Logger.new($stderr)
  index = client.init_index "shopify_products"
  resp = index.search text, facetFilters: "product_type:standard"
  @array = hits resp[:hits]
end

Private Instance Methods

hits(hits) click to toggle source

@param hits [Array<Hash>] @return [Array<RelatonBsi::Hit>]

# File lib/relaton_bsi/hit_collection.rb, line 31
def hits(hits) # rubocop:disable Metrics/MethodLength
  hits.map do |h|
    Hit.new(
      {
        code: h[:meta][:global][:primaryDesignator],
        title: h[:title],
        url: h[:handle],
        date: h[:meta][:global][:publishedDate],
        publisher: h[:meta][:global][:publisher],
        status: h[:meta][:global][:status],
        ics: h[:meta][:global][:icsCodesAlgoliaStringArray],
        doctype: h[:product_type],
      }, self
    )
  end
end