Sha256: 8077356d0f70d4220c6a26d9f512c6b561762bb1a65c8f35c301e21bd4f325f8

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

module Sources
  
  # Describes a Delicious (http://deli.cio.us) source.
  #
  # This source has a fixed set of categories:
  # * title
  # * tags
  # * url
  #
  # Examples:
  #  Sources::CSV.new('usrnam', 'paswrd')
  #
  class Delicious < Base
    
    def initialize username, password
      check_gem
      @username = username
      @password = password
    end
    def check_gem # :nodoc:
      require 'www/delicious'
    rescue LoadError
      puts_gem_missing 'www-delicious', 'the delicious source'
      exit 1
    end
    
    # Harvests the data to index.
    #
    def harvest _, category
      get_data do |uid, data|
        indexed_id = uid
        text = data[category.from]
        next unless text
        text.force_encoding 'utf-8' # TODO Still needed?
        yield indexed_id, text
      end
    end
    
    #
    #
    def get_data # :nodoc:
      @generated_id ||= 0
      @posts ||= WWW::Delicious.new(@username, @password).posts_recent(count: 100)
      @posts.each do |post|
        data = {
          title: post.title,
          tags:  post.tags.join(' '),
          url:   post.url.to_s
        }
        @generated_id += 1
        yield @generated_id, data
      end
    end
    
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
picky-1.3.0 lib/picky/sources/delicious.rb
picky-1.2.4 lib/picky/sources/delicious.rb
picky-1.2.3 lib/picky/sources/delicious.rb
picky-1.2.2 lib/picky/sources/delicious.rb
picky-1.2.1 lib/picky/sources/delicious.rb