Sha256: 743601fdf4da1defe9af442016b4114d3872fc3ec8a32d3b684212ba6789ed04

Contents?: true

Size: 1.13 KB

Versions: 19

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

module Nanoc3::DataSources

  # @deprecated Fetch data from online data sources manually instead
  class Delicious < Nanoc3::DataSource

    def items
      @items ||= begin
        require 'json'
        require 'time'
        require 'enumerator'

        # Get data
        @http_client ||= Nanoc3::Extra::CHiCk::Client.new
        status, headers, data = *@http_client.get("http://feeds.delicious.com/v2/json/#{self.config[:username]}")

        # Parse as JSON
        raw_items = JSON.parse(data)

        # Convert to items
        raw_items.enum_with_index.map do |raw_item, i|
          # Get data
          content = raw_item['n']
          attributes = {
            :url         => raw_item['u'],
            :description => raw_item['d'],
            :tags        => raw_item['t'],
            :date        => Time.parse(raw_item['dt']),
            :note        => raw_item['n'],
            :author      => raw_item['a']
          }
          identifier = "/#{i}/"
          mtime = nil

          # Build item
          Nanoc3::Item.new(content, attributes, identifier, mtime)
        end
      end
    end

  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
nanoc3-3.1.9 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.8 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.7 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.6 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.2.0a3 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.5 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.4 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.2.0a2 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.3 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.2.0a1 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.2 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.1 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.0 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.0rc1 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.0b2 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.0b1 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.0a3 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.0a2 lib/nanoc3/data_sources/deprecated/delicious.rb
nanoc3-3.1.0a1 lib/nanoc3/data_sources/deprecated/delicious.rb