Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added twitter list

  • Loading branch information...
commit bbb0a76e174af3c891bcc7b7662695769079c6a1 1 parent d485ef4
@mattetti authored
View
3  app/assets/javascripts/tweets.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
69 app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,69 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+a {
+ color: #000;
+ &:visited {
+ color: #666;
+ }
+ &:hover {
+ color: #fff;
+ background-color: #000;
+ }
+}
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px;
+ }
+}
+
+#notice {
+ color: green;
+}
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff;
+ }
+ ul li {
+ font-size: 12px;
+ list-style: square;
+ }
+}
View
3  app/assets/stylesheets/tweets.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the tweets controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
19 app/controllers/application_controller.rb
@@ -1,3 +1,22 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+
+ private
+
+ def auth_required
+ session[:current_user]
+ end
+
+ def twitter_client
+ if @twitter_client
+ @twitter_client
+ else
+ @twitter_client = Twitter::Client.new(
+ :oauth_token => auth_required['credentials']['token'],
+ :oauth_token_secret => auth_required['credentials']['secret']
+ )
+ Rails.logger.info @twitter_client.inspect
+ @twitter_client
+ end
+ end
end
View
3  app/controllers/sessions_controller.rb
@@ -1,7 +1,6 @@
class SessionsController < ApplicationController
def create
- @user = auth_hash #User.find_or_create_from_auth_hash(auth_hash)
- self.current_user = @user
+ session[:current_user] = auth_hash
redirect_to '/'
end
View
86 app/controllers/tweets_controller.rb
@@ -0,0 +1,86 @@
+class TweetsController < ApplicationController
+
+ before_filter :auth_required
+
+ # GET /tweets
+ # GET /tweets.json
+ def index
+ @tweets = twitter_client.home_timeline
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @tweets }
+ end
+ end
+
+ # GET /tweets/1
+ # GET /tweets/1.json
+ def show
+ @tweet = Tweet.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @tweet }
+ end
+ end
+
+ # GET /tweets/new
+ # GET /tweets/new.json
+ def new
+ @tweet = Tweet.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @tweet }
+ end
+ end
+
+ # GET /tweets/1/edit
+ def edit
+ @tweet = Tweet.find(params[:id])
+ end
+
+ # POST /tweets
+ # POST /tweets.json
+ def create
+ @tweet = Tweet.new(params[:tweet])
+
+ respond_to do |format|
+ if @tweet.save
+ format.html { redirect_to @tweet, notice: 'Tweet was successfully created.' }
+ format.json { render json: @tweet, status: :created, location: @tweet }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @tweet.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /tweets/1
+ # PUT /tweets/1.json
+ def update
+ @tweet = Tweet.find(params[:id])
+
+ respond_to do |format|
+ if @tweet.update_attributes(params[:tweet])
+ format.html { redirect_to @tweet, notice: 'Tweet was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @tweet.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /tweets/1
+ # DELETE /tweets/1.json
+ def destroy
+ @tweet = Tweet.find(params[:id])
+ @tweet.destroy
+
+ respond_to do |format|
+ format.html { redirect_to tweets_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
2  app/helpers/tweets_helper.rb
@@ -0,0 +1,2 @@
+module TweetsHelper
+end
View
3  app/models/tweet.rb
@@ -0,0 +1,3 @@
+class Tweet < ActiveRecord::Base
+ # attr_accessible :title, :body
+end
View
17 app/views/tweets/_form.html.erb
@@ -0,0 +1,17 @@
+<%= form_for(@tweet) do |f| %>
+ <% if @tweet.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@tweet.errors.count, "error") %> prohibited this tweet from being saved:</h2>
+
+ <ul>
+ <% @tweet.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/tweets/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing tweet</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @tweet %> |
+<%= link_to 'Back', tweets_path %>
View
21 app/views/tweets/index.html.erb
@@ -0,0 +1,21 @@
+<h1>Listing tweets</h1>
+
+<table>
+ <tr>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @tweets.each do |tweet| %>
+ <tr>
+ <td><%= link_to 'Show', tweet.text %></td>
+ <td><%#= link_to 'Edit', edit_tweet_path(tweet) %></td>
+ <td><%#= link_to 'Destroy', tweet, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%#= link_to 'New Tweet', new_tweet_path %>
View
5 app/views/tweets/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New tweet</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', tweets_path %>
View
5 app/views/tweets/show.html.erb
@@ -0,0 +1,5 @@
+<p id="notice"><%= notice %></p>
+
+
+<%= link_to 'Edit', edit_tweet_path(@tweet) %> |
+<%= link_to 'Back', tweets_path %>
View
30 config/database.yml
@@ -1,25 +1,27 @@
-# SQLite version 3.x
-# gem install sqlite3
-#
-# Ensure the SQLite 3 gem is defined in your Gemfile
-# gem 'sqlite3'
development:
- adapter: sqlite3
- database: db/development.sqlite3
+ adapter: postgresql
+ encoding: unicode
+ database: twhike_development
pool: 5
- timeout: 5000
+ username: root
+ password:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
- adapter: sqlite3
- database: db/test.sqlite3
+ adapter: postgresql
+ encoding: unicode
+ database: twhike_test
pool: 5
- timeout: 5000
+ username: root
+ password:
production:
- adapter: sqlite3
- database: db/production.sqlite3
+ adapter: postgresql
+ encoding: unicode
+ database: twhike
pool: 5
- timeout: 5000
+ username: root
+ password:
+
View
4 config/initializers/twitter.rb
@@ -0,0 +1,4 @@
+Twitter.configure do |config|
+ config.consumer_key = ENV['TWITTER_KEY']
+ config.consumer_secret = ENV['TWITTER_SECRET']
+end
View
2  config/routes.rb
@@ -1,4 +1,6 @@
Twhike::Application.routes.draw do
+ resources :tweets
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
8 db/migrate/20120901200035_create_tweets.rb
@@ -0,0 +1,8 @@
+class CreateTweets < ActiveRecord::Migration
+ def change
+ create_table :tweets do |t|
+
+ t.timestamps
+ end
+ end
+end
View
11 test/fixtures/tweets.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
View
49 test/functional/tweets_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class TweetsControllerTest < ActionController::TestCase
+ setup do
+ @tweet = tweets(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:tweets)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create tweet" do
+ assert_difference('Tweet.count') do
+ post :create, tweet: { }
+ end
+
+ assert_redirected_to tweet_path(assigns(:tweet))
+ end
+
+ test "should show tweet" do
+ get :show, id: @tweet
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @tweet
+ assert_response :success
+ end
+
+ test "should update tweet" do
+ put :update, id: @tweet, tweet: { }
+ assert_redirected_to tweet_path(assigns(:tweet))
+ end
+
+ test "should destroy tweet" do
+ assert_difference('Tweet.count', -1) do
+ delete :destroy, id: @tweet
+ end
+
+ assert_redirected_to tweets_path
+ end
+end
View
4 test/unit/helpers/tweets_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class TweetsHelperTest < ActionView::TestCase
+end
View
7 test/unit/tweet_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class TweetTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.