Last active
August 29, 2015 13:56
-
-
Save zorbash/9198362 to your computer and use it in GitHub Desktop.
experiment with sinatra
This file contains hidden or 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
| require 'sinatra' | |
| require 'json' | |
| require 'sqlite3' | |
| get '/songs/random' do | |
| db = SQLite3::Database.new '/var/www/apps/shared/songs.db' | |
| row = db.execute('SELECT * FROM songs ORDER BY RANDOM() LIMIT 1;')[0] | |
| song = { | |
| id: row[0], | |
| artist: row[1], | |
| title: row[2], | |
| listen_url: row[3], | |
| post_url: row[4], | |
| tags: row[5], | |
| created_at: row[6] | |
| } | |
| JSON::generate song | |
| end | |
| get '/words/random' do | |
| JSON::generate word: `shuf /usr/share/dict/words | head -1`.chomp | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment