Class: Nanoc::DataSources::Delicious Deprecated

Inherits:
Nanoc::DataSource show all
Defined in:
lib/nanoc/data_sources/deprecated/delicious.rb

Overview

Deprecated.

Fetch data from online data sources manually instead

Instance Attribute Summary

Attributes inherited from Nanoc::DataSource

#config, #items_root, #layouts_root

Instance Method Summary (collapse)

Methods inherited from Nanoc::DataSource

#create_item, #create_layout, #down, #initialize, #layouts, #loading, #setup, #sync, #unuse, #up, #update, #use

Methods included from PluginRegistry::PluginMethods

#all, #identifier, #identifiers, #named, #register

Constructor Details

This class inherits a constructor from Nanoc::DataSource

Instance Method Details

- (Object) items



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nanoc/data_sources/deprecated/delicious.rb', line 8

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

    # Get data
    @http_client ||= Nanoc::Extra::CHiCk::Client.new
    _status, _headers, data = *@http_client.get("http://feeds.delicious.com/v2/json/#{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
      Nanoc::Item.new(content, attributes, identifier, mtime)
    end
  end
end