Sha256: 2c3d2504293059ff1c9ac8668dd9be57a30c6729e342321af272c3280bd5ca99

Contents?: true

Size: 980 Bytes

Versions: 8

Compression:

Stored size: 980 Bytes

Contents

# encoding: utf-8

module Nanoc::DataSources

  # @deprecated Fetch data from online data sources manually instead
  class Twitter < Nanoc::DataSource

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

        # Get data
        @http_client ||= Nanoc::Extra::CHiCk::Client.new
        _status, _headers, data = *@http_client.get("http://twitter.com/statuses/user_timeline/#{config[:username]}.json")

        # 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['text']
          attributes = {
            :created_at  => raw_item['created_at'],
            :source      => raw_item['source']
          }
          identifier = "/#{raw_item['id']}/"
          mtime = Time.parse(raw_item['created_at'])

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

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
nanoc-3.7.3 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.7.2 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.7.1 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.7.0 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.6.11 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.6.10 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.6.9 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.6.8 lib/nanoc/data_sources/deprecated/twitter.rb