# HG changeset patch # User edogawaconan # Date 1409917045 -32400 # Node ID 207917e419643b22c9cd6b870d26650491e08fa3 # Parent aad3b253ffd583a6bb5ee472efda9ca1d602dfad Add tweets~ Feature is now on par with the thing it's replacing. diff -r aad3b253ffd5 -r 207917e41964 app/controllers/tweets_controller.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/controllers/tweets_controller.rb Fri Sep 05 20:37:25 2014 +0900 @@ -0,0 +1,6 @@ +class TweetsController < ApplicationController + def show + @tweets = Tweet.new(params[:id]).timeline + @user = @tweets.first.user + end +end diff -r aad3b253ffd5 -r 207917e41964 app/helpers/application_helper.rb --- a/app/helpers/application_helper.rb Fri Sep 05 19:03:15 2014 +0900 +++ b/app/helpers/application_helper.rb Fri Sep 05 20:37:25 2014 +0900 @@ -1,2 +1,3 @@ module ApplicationHelper + include Twitter::Autolink end diff -r aad3b253ffd5 -r 207917e41964 app/models/tweet.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/models/tweet.rb Fri Sep 05 20:37:25 2014 +0900 @@ -0,0 +1,21 @@ +class Tweet + CONFIG = { + :consumer_key => ENV["RT_CONSUMER_KEY"], + :consumer_secret => ENV["RT_CONSUMER_SECRET"], + :access_token => ENV["RT_OAUTH_TOKEN"], + :access_token_secret => ENV["RT_OAUTH_TOKEN_SECRET"] + } + + def timeline + @timeline ||= @client.user_timeline(@twitter_id) + end + + def initialize(twitter_id) + @client = Twitter::REST::Client.new do |config| + CONFIG.each do |cfg_key, cfg_value| + config.public_send("#{cfg_key}=", cfg_value) + end + end + @twitter_id = twitter_id + end +end diff -r aad3b253ffd5 -r 207917e41964 app/views/tweets/show.atom.builder --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/tweets/show.atom.builder Fri Sep 05 20:37:25 2014 +0900 @@ -0,0 +1,14 @@ +atom_feed do |feed| + feed.title "#{@user.name} (@#{@user.screen_name})" + feed.updated @tweets.first.created_at + + @tweets.each do |tweet| + feed.entry tweet, :url => tweet.uri, :updated => tweet.created_at do |entry| + entry.title tweet.created_at.rfc2822 + entry.content auto_link(tweet.text), :type => "html" + entry.author do |author| + author.name tweet.user.screen_name + end + end + end +end diff -r aad3b253ffd5 -r 207917e41964 config/routes.rb --- a/config/routes.rb Fri Sep 05 19:03:15 2014 +0900 +++ b/config/routes.rb Fri Sep 05 20:37:25 2014 +0900 @@ -5,6 +5,8 @@ # You can have the root of your site routed with "root" root 'static#index' + get "*id" => "tweets#show", :defaults => { :format => :atom } + # Example of regular route: # get 'products/:id' => 'catalog#view' diff -r aad3b253ffd5 -r 207917e41964 test/controllers/tweets_controller_test.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/controllers/tweets_controller_test.rb Fri Sep 05 20:37:25 2014 +0900 @@ -0,0 +1,8 @@ +require 'test_helper' + +class TweetsControllerTest < ActionController::TestCase + test "should get show" do + get :show, :id => "edogawa_test", :format => :atom + assert_response :success + end +end diff -r aad3b253ffd5 -r 207917e41964 test/models/tweet_test.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/models/tweet_test.rb Fri Sep 05 20:37:25 2014 +0900 @@ -0,0 +1,7 @@ +require 'test_helper' + +class TweetTest < ActiveSupport::TestCase + test "loads a tweet" do + assert_not_nil Tweet.new("edogawa_test") + end +end