Sha256: 028b10e6494dba332927e66084fdc8b3e480930d5ccc30fd48f6c9546b492d4d

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

module Ubi
  module Consultor
    # Base for araneas (spiders)
    class Base
      HEADERS = { 'User-Agent' => "Ubi v#{Ubi::VERSION}" }

      def initialize(thema)
        @thema = thema
      end

      def query_url
        self.class.url + query.to_query
      end

      def links
        '//a'
      end

      def parser(chunk)
        Nokogiri::HTML(chunk)
      end

      def datum
        @datum ||= Ubi::Datum.new(parser(request), words, links)
      end

      #
      # Make an HTTP(S) request to a geocoding API and
      # return the response object.
      #
      def request(opts = {})
        timeout(10) do
          uri = URI.parse(query_url)
          puts "#{self} working on `#{@thema}` (#{query_url}) #{opts}"
          uri.open(HEADERS).read
        end
      end

      class << self
        def inherited(base)
          Ubi.araneas << base
          # puts "Using aranea #{base}"
        end

        #
        # Human-readable name of the aranea
        #
        def name
          fail "Not implemented by #{self}"
        end

        #
        # Url to query
        #
        def url
          fail "Not implemented by #{self}"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ubi-0.0.8 lib/ubi/consultor.rb
ubi-0.0.7 lib/ubi/consultor.rb
ubi-0.0.5 lib/ubi/consultor.rb