Sha256: a710a034df1b648f105cc1ecc0d4f982a8a56fe9e2db34bd4fd77b34983cfd2d

Contents?: true

Size: 572 Bytes

Versions: 2

Compression:

Stored size: 572 Bytes

Contents

require 'nokogiri'
require 'httparty'

module RapGenius
  module Scraper
    BASE_URL = "http://rapgenius.com/".freeze

    attr_reader :url


    def url=(url)
      if !(url =~ /^https?:\/\//)
        @url = "#{BASE_URL}#{url}" 
      else
        @url = url
      end
    end

    def document
      @document ||= Nokogiri::HTML(fetch(@url))
    end

    private
    def fetch(url)
      response = HTTParty.get(url)

      if response.code != 200
        raise ScraperError, "Received a #{response.code} HTTP response"
      end

      response.body
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rapgenius-0.0.2 lib/rapgenius/scraper.rb
rapgenius-0.0.1 lib/rapgenius/scraper.rb