-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
55 lines (44 loc) · 1.27 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
50
51
52
53
54
55
require 'rubygems'
require 'sinatra'
require 'tumblr_client'
require 'omniauth'
require 'omniauth-tumblr'
class SinatraApp < Sinatra::Base
configure do
set :sessions, true
set :inline_templates, true
end
use OmniAuth::Builder do
provider :tumblr, ENV['TUMBLR_CONSUMER_KEY'], ENV['TUMBLR_CONSUMER_SECRET']
end
get '/' do
if session[:authenticated]
erb :index
else
erb :signin
end
end
get '/auth/:provider/callback' do
session[:authenticated] = true
auth = request.env["omniauth.auth"]
session[:user_id] = auth["uid"]
session[:access_token] = auth['credentials']['token']
session[:access_token_secret] = auth['credentials']['secret']
Tumblr.configure do |config|
config.consumer_key = ENV['TUMBLR_CONSUMER_KEY']
config.consumer_secret = ENV['TUMBLR_CONSUMER_SECRET']
config.oauth_token = session[:access_token]
config.oauth_token_secret = session[:access_token_secret]
end
@@client = Tumblr::Client.new
redirect '/'
end
post '/' do
title = params[:title]
body = params[:body]
name = @@client.info['user']['name']
@@client.text("#{name}.tumblr.com",{:title => title, :body => body})
redirect '/'
end
end
SinatraApp.run! if __FILE__ == $0