Sha256: 2a5d30062b7315f2f3d87dacf13ee1fda6fa7155ad3461633e41e631a7d9780e

Contents?: true

Size: 1.28 KB

Versions: 52

Compression:

Stored size: 1.28 KB

Contents

module Picky

  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
        warn_gem_missing 'www-delicious', 'the delicious source'
        exit 1
      end

      def to_s
        "#{self.class.name}(#{@username})"
      end

      # Harvests the data to index.
      #
      def harvest category
        get_data do |indexed_id, data|
          text = data[category.from]
          next unless text
          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

end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
picky-3.5.1 lib/picky/sources/delicious.rb
picky-3.5.0 lib/picky/sources/delicious.rb
picky-3.4.3 lib/picky/sources/delicious.rb
picky-3.4.2 lib/picky/sources/delicious.rb
picky-3.4.1 lib/picky/sources/delicious.rb
picky-3.4.0 lib/picky/sources/delicious.rb
picky-3.3.3 lib/picky/sources/delicious.rb
picky-3.3.2 lib/picky/sources/delicious.rb
picky-3.3.1 lib/picky/sources/delicious.rb
picky-3.3.0 lib/picky/sources/delicious.rb
picky-3.2.0 lib/picky/sources/delicious.rb
picky-3.1.13 lib/picky/sources/delicious.rb
picky-3.1.12 lib/picky/sources/delicious.rb
picky-3.1.11 lib/picky/sources/delicious.rb
picky-3.1.10 lib/picky/sources/delicious.rb
picky-3.1.9 lib/picky/sources/delicious.rb
picky-3.1.8 lib/picky/sources/delicious.rb
picky-3.1.7 lib/picky/sources/delicious.rb
picky-3.1.6 lib/picky/sources/delicious.rb
picky-3.1.5 lib/picky/sources/delicious.rb