Sha256: 546ebeb414e6199d4abfd9b0284377f1ecafc657ae638ba31bfcad58cde59d2b

Contents?: true

Size: 720 Bytes

Versions: 1

Compression:

Stored size: 720 Bytes

Contents

require 'nokogiri'
require 'open-uri'

module Fletcher
  # This class is responsible for fetching and parsing data.
  class Data
    # Get read url and get data object
    def self.read(url, options = {})
      # Set User Agent
      options[:user_agent] ||= "Ruby/#{RUBY_VERSION}"

      response = open(url, "User-Agent" => options[:user_agent])
      doc = ::Nokogiri::HTML(response.read)
      
      # Save contents of URL/Remote File for debugging
      # response.rewind
      # last_response_file = File.expand_path(File.join("..", "..", "last_response"), File.dirname(__FILE__))        
      # File.new(last_response_file, "w+").write(response.read)

      return doc
    end 
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fletcher-0.6.4 lib/fletcher/data.rb