Sha256: 48604dfc44d8a60ebdbc1b225d2c3d28753531423a96019ee22868825e693c6d

Contents?: true

Size: 745 Bytes

Versions: 24

Compression:

Stored size: 745 Bytes

Contents

# frozen_string_literal: true

require 'nokogiri'

module Spotlight
  module Resources
    ##
    # Generic web resource harvester base module
    module Web
      extend ActiveSupport::Concern

      included do
        before_create do
          harvest!
        end
      end

      def harvest!
        response = Spotlight::Resources::Web.fetch url
        data[:headers] = response.headers
        data[:body] = response.body
      end

      def body
        harvest! if data[:body].blank?

        @body ||= Nokogiri::HTML.parse data[:body]
      end

      def self.fetch(url)
        Faraday.new(url) do |b|
          b.response :follow_redirects
          b.adapter Faraday.default_adapter
        end.get
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
blacklight-spotlight-3.6.0.beta5 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-3.6.0.beta4 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-3.6.0.beta3 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-3.6.0.beta1 app/models/concerns/spotlight/resources/web.rb