Created
December 12, 2011 14:44
-
-
Save tily/1467564 to your computer and use it in GitHub Desktop.
テキストエリアに書いている途中の内容もそのまま Twitter にポストしてしまうやつ (あんまりおもしろくなかった、このままだとセキュリティに難あり)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
require 'rubygems' | |
require 'haml' | |
require 'sinatra' | |
require 'sinatra-twitter-oauth' | |
require 'json' | |
# TODO: セッションをクッキーに保存する sinatra のデフォルトの挙動をやめる | |
configure do | |
TITLE = '動く指は、書き込み、および、令状した、上に移動' | |
KEY = 'yFObKRMZUyt1cbTwNN5w' | |
SECRET = 'YJpBqzE8WZymkJcN9blBXsL44D6m7cSNWIln4BlSeE' | |
CALLBACK = 'http://localhost:9393/auth' | |
end | |
set :session, false | |
set :twitter_oauth_config, | |
:key => KEY, :secret => SECRET, :callback => CALLBACK | |
get '/' do | |
login_required | |
haml :app | |
end | |
post '/post.json' do | |
login_required | |
content_type 'application/json' | |
setup_client.update(params[:text]) | |
session[:count] = (session[:count] || 0) + 1 | |
{'count' => session[:count]}.to_json | |
end | |
__END__ | |
@@ app | |
%html | |
%head | |
%title= TITLE | |
%link{:rel=>'stylesheet',:href=>'http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css'} | |
%script{:type=>'text/javascript',:src=>'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'} | |
:javascript | |
var prev = '' | |
$(function() { | |
$('textarea').keyup(function() { | |
var text = $(this).val() | |
if(text == prev || text == '') return | |
var li = $('<li>').text('posting...').prependTo('ul#history') | |
$.post('/post.json', {text:text}, function(res) { | |
if(res.count > parseInt($('#count').html())) { | |
$('#count').html(res.count) | |
} | |
li.text(text) | |
}) | |
prev = text | |
}) | |
}) | |
%body | |
.topbar | |
.topbar-inner | |
.container | |
%a{:href=>"/",:class=>'brand'}= TITLE | |
%ul{:class=>'nav'} | |
%li | |
%a== Welcome, #{@user.info['screen_name']}! | |
%li | |
%a{:href=>'logout'}Logout | |
.container | |
%h1 Quickanddeadder | |
%p | |
%span{:id=>'count'} 0 | |
%textarea{:class=>'xxlarge'} | |
%ul#history{:hoge=>'naha'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment