Class: Nanoc3::DataSources::Twitter
- Nanoc3::Plugin
- Nanoc3::DataSource
- Nanoc3::DataSources::Twitter
Nanoc3::DataSources::Twitter provides tweets from a single user as items (Nanoc3::Item instances).
The configuration must have a "username" attribute containing the username of the account from which to fetch the tweets.
The items returned by this data source will be mounted at root/{id}, where id is the unique identifier of the tweet.
The items returned by this data source will have the following attributes:
| :created_at: | The timestamp when this tweet was posted (a string). |
| source: | The client used to tweet this message (HTML-encoded). |
Constants Inherited from Nanoc3::Plugin
Constructor Summary
This class inherits a constructor from Nanoc3::DataSource.
Public Visibility
Public Class Methods Inherited from Nanoc3::DataSource
Public Class Methods Inherited from Nanoc3::Plugin
Public Instance Method Summary
| #items |
|---|
Public Instance Methods Inherited from Nanoc3::DataSource
code_snippets, create_item, create_layout, down, layouts, loading, setup, unuse, up, update, use
Public Instance Methods Included from Nanoc3::DataSource
code_snippets, create_item, create_layout, down, layouts, loading, setup, unuse, up, update, use
Public Instance Method Details
items
public
items
[View source]
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/nanoc3/data_sources/twitter.rb', line 21 def items @item ||= begin require 'json' require 'time' # Get data @http_client ||= Nanoc3::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'] # TODO add more } identifier = "/#{raw_item['id']}/" mtime = Time.parse(raw_item['created_at']) # Build item Nanoc3::Item.new(content, attributes, identifier, mtime) end end end |