Module: Spotlight::Resources::Web

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/spotlight/resources/web.rb

Overview

Generic web resource harvester base module

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fetch(url) ⇒ Object



30
31
32
33
34
35
# File 'app/models/concerns/spotlight/resources/web.rb', line 30

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

Instance Method Details

#bodyObject



24
25
26
27
28
# File 'app/models/concerns/spotlight/resources/web.rb', line 24

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

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

#harvest!Object



18
19
20
21
22
# File 'app/models/concerns/spotlight/resources/web.rb', line 18

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