Module: Thoth::Plugin::Twitter

### Home Classes Methods

### In Files

- lib/thoth/plugin/thoth_twitter.rb

### Methods

- ::recent_tweets

### Files

- robots.txt

### Class/Module Index

Quicksearch

- Thoth
- Thoth::AdminController
- Thoth::ArchiveController
- Thoth::Comment
- Thoth::CommentApiController
- Thoth::CommentController
- Thoth::Config
- Thoth::Error
- Thoth::Importer
- Thoth::MainController
- Thoth::Media
- Thoth::MediaController
- Thoth::MinifyController
- Thoth::Page
- Thoth::PageApiController
- Thoth::PageController
- Thoth::Pager
- Thoth::Plugin
- Thoth::Plugin::Delicious
- Thoth::Plugin::Flickr
- Thoth::Plugin::Tags
- Thoth::Plugin::Twitter
- Thoth::Post
- Thoth::PostApiController
- Thoth::PostController
- Thoth::SchemaError
- Thoth::SearchController
- Thoth::Tag
- Thoth::TagApiController
- Thoth::TagController
- Thoth::TagsPostsMap
- Ramaze
- Ramaze::Dispatcher
- Ramaze::Dispatcher::File
- Ramaze::Helper
- Ramaze::Helper::Admin
- Ramaze::Helper::Cookie
- Ramaze::Helper::Error
- Ramaze::Helper::Pagination
- Ramaze::Helper::Sanitize
- Ramaze::Helper::Wiki
- Ramaze::Helper::Ysearch
- Ramaze::Helper::Ysearch::SearchError
- AddMediaSize
- CreateSchema
- PantsImporter
- PoseidonImporter

No matching classes.

# Thoth::Plugin::Twitter

Twitter plugin for Thoth.

### Public Class Methods

recent_tweets(user, options = {}) click to toggle source

    # File lib/thoth/plugin/thoth_twitter.rb, line 64
    def recent_tweets(user, options = {})
      if @skip_until
        return [] if @skip_until > Time.now
        @skip_until = nil
      end

      cache   = Ramaze::Cache.value_cache
      options = {:count => 5}.merge(options)

      url = "http://twitter.com/statuses/user_timeline/#{user}.json?count=" <<
          options[:count].to_s

      if value = cache[url]
        return value
      end

      tweets = []

      Timeout.timeout(Config.twitter.request_timeout, StandardError) do
        tweets = JSON.parse(open(url).read)
      end

      # Parse the tweets into an easier-to-use format.
      tweets.map! do |tweet|
        {
          :created_at => Time.parse(tweet['created_at']),
          :html       => parse_tweet(tweet),
          :id         => tweet['id'],
          :source     => tweet['source'],
          :text       => tweet['text'],
          :truncated  => tweet['truncated'],
          :url        => "http://twitter.com/#{user}/statuses/#{tweet['id']}"
        }
      end

      @failures = 0

      return cache.store(url, tweets, :ttl => Config.twitter.cache_ttl)

    rescue => e
      @failures ||= 0
      @failures += 1

      if @failures >= Config.twitter.failure_threshold
        @skip_until = Time.now + Config.twitter.failure_timeout
        Ramaze::Log.error("Twitter failed to respond #{@failures} times. " <<
            "Will retry after #{@skip_until}.")
      end

      return []
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.