-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
41 lines (30 loc) · 773 Bytes
/
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
#!/usr/bin/env ruby
# Encoding: UTF-8
require 'sinatra'
require 'yaml'
require 'haml'
require 'net/http'
require 'net/https'
require 'uri'
require 'json'
set :bind, '0.0.0.0'
set :port, 3000
enable :dump_errors, :raise_errors, :show_exceptionss
set :haml, :format => :html5
config = YAML.load_file('config.yml')
puts config.inspect
##
# Default to turnin page
#
get '/' do
stream = false
uri = URI.parse "https://api.twitch.tv/kraken/streams/#{config[:user]}"
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.get(uri.request_uri)
json = JSON.parse(response.body)
puts json['stream'].inspect
stream = json['stream'] != nil
haml :index, :locals => { stream: stream }
end