Sha256: 54dd235fa242b8014efb9e707e2f0500a8677373068c1a817409c2f337f4bdf4

Contents?: true

Size: 983 Bytes

Versions: 23

Compression:

Stored size: 983 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/#{self.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

23 entries across 23 versions & 1 rubygems

Version Path
nanoc-3.6.7 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.6.6 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.6.5 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.6.4 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.6.3 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.6.2 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.6.1 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.6.0 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.5.0 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.5.0b2 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.5.0b1 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.4.3 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.4.2 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.4.1 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.4.0 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.3.7 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.3.6 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.3.5 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.3.4 lib/nanoc/data_sources/deprecated/twitter.rb
nanoc-3.3.3 lib/nanoc/data_sources/deprecated/twitter.rb