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-4.3.6 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.3.5 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.3.4 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.3.3 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.3.2 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.3.1 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.3.0 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.2.0 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.1.2 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.1.1 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.1.0 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.0.3 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.0.2 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.0.1 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-4.0.0 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-3.6.0.beta10 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-3.6.0.beta9 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-3.6.0.beta8 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-3.6.0.beta7 app/models/concerns/spotlight/resources/web.rb
blacklight-spotlight-3.6.0.beta6 app/models/concerns/spotlight/resources/web.rb