-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathconfig.ru
More file actions
172 lines (101 loc) · 3.77 KB
/
config.ru
File metadata and controls
172 lines (101 loc) · 3.77 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
begin
require ::File.expand_path('.bundle/environment', __FILE__)
rescue LoadError
require 'rubygems'
require 'bundler'
Bundler.setup
end
require 'sinatra'
require 'haml'
require 'sass/plugin/rack'
require 'cgi'
require 'net/http'
require 'image_size'
require 'base64'
require 'json'
require 'omniauth'
require 'fbgraph'
use Sass::Plugin::Rack
class App < Sinatra::Base
### Main Index
get '/' do
# Set lock to true if you wish to lock the stream behind a *tweet to listen*
haml :index, :locals => { :lock => false }
end
### Waveform Data
get '/waveform' do
content_type 'json'
# Get the URL and decode to remove any %20, etc
url = params[:url]
# url = CGI::unescape(params[:url])
# Get the contents of the URL
image = Net::HTTP.get_response(URI.parse(url)).body
# Get the image information
size = ImageSize.new(image)
# Image type
type = size.get_type
# Dimensions
width = size.w
height = size.h
# Setup the data URL
type_prefix = "data:image/" + type.downcase + ";base64,"
# Encode the image into base64
base64file = Base64.encode64(image)
# Combine the prefix and the image
data_url = type_prefix + base64file
# Setup the return data
return_arr = {
:width => width,
:height => height,
:data => data_url
}
# Encode it into JSON
return_val = MultiJson.encode(return_arr)
# Wrap the callback around the JSON
return_val = params[:callback] + '(' + return_val + ');'
end
### Social Locks
## Facebook Like to Unlock
# If you wish to have users like your Facebook page in order to listen to the stream
# you must first register a new Facebook app [here](https://www.facebook.com/developers/createapp.php).
# Once registered, drop the application secret and set lock to true in the post method below.
# Then, follow the instructions [here](https://github.com/soundcloud/soundcloud-premiere/wiki/Like-to-Unlock).
post '/' do
@signed_request = FBGraph::Canvas.parse_signed_request('app_secret', params[:signed_request])
# Set lock to true if you wish to lock the stream behind a *like to listen*
haml :index, :locals => { :lock => false }
end
## Twitter Tweet to Unlock
# If you wish to have users tweet in order to listen to the stream
# you must first register a new Twitter app [here](http://twitter.com/apps/new).
# Once registered, simply supply the app consumer key and secret 5 lines below in the configure block.
# Then, edit the *message* javascript variable in index.haml
enable :sessions
configure do
set :key => 'consumer_key', :secret => 'consumer_secret'
use OmniAuth::Strategies::Twitter, key, secret
end
# Post & Unlock
post '/unlock' do
if session[:unlocked] == nil
consumer = OAuth::Consumer.new(options.key, options.secret, :site => "https://twitter.com")
token = OAuth::AccessToken.new(consumer, session[:user][:token], session[:user][:secret])
token.post('/statuses/update.json', {:status => params[:message]})
session[:unlocked] = true
end
"unlocked"
end
# Login
get '/auth/:strategy/callback' do
auth = request.env['omniauth.auth']
session[:user] = {:token => auth['credentials']['token'], :secret => auth['credentials']['secret']}
redirect "/"
end
# Logout
get '/logout' do
session[:user], session[:unlocked] = nil, nil
redirect '/'
end
end
use Rack::Static, :urls => ["/stylesheets", "/images", "/js", "/swfs", "/docs", "/example"], :root => "public"
run App