init and spike

This commit is contained in:
Mark Moser 2015-05-16 21:47:18 -05:00
commit 200d95588b
7 changed files with 91 additions and 0 deletions

5
Gemfile Normal file
View File

@ -0,0 +1,5 @@
gem 'thin'
gem 'sinatra'
gem 'json'

25
Gemfile.lock Normal file
View File

@ -0,0 +1,25 @@
GEM
specs:
daemons (1.2.2)
eventmachine (1.0.7)
json (1.8.2)
rack (1.6.0)
rack-protection (1.5.3)
rack
sinatra (1.4.6)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
thin (1.6.3)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0)
rack (~> 1.0)
tilt (1.4.1)
PLATFORMS
ruby
DEPENDENCIES
json
sinatra
thin

3
README.md Normal file
View File

@ -0,0 +1,3 @@
## HEllo Slack
Yet another gif generating slackbot, more to come.

View File

@ -0,0 +1,7 @@
class Animations
def find string
"looking for a gif related to: #{string}"
end
end

View File

@ -0,0 +1,15 @@
class RandomSalutation
def short
'Hi there!'
end
def medium
"Well hello! So nice to see you here."
end
def long
"My, what a wonderful day. Wouldn't you agree? I mean, it's even better now that you are here! Amirite?"
end
end

13
config.ru Normal file
View File

@ -0,0 +1,13 @@
require 'rubygems'
require 'bundler'
require 'thin'
require 'sinatra'
$LOAD_PATH.unshift( File.join( File.dirname(__FILE__), 'app' ) )
Bundler.require
require './meme_bot'
#\ -p 3000
run Sinatra::Application

23
meme_bot.rb Normal file
View File

@ -0,0 +1,23 @@
require 'json'
require 'workers/random_salutation'
require 'workers/animations'
get '/?' do
content_type :json
greeting = RandomSalutation.new
{ message: greeting.short }.to_json
end
get '/greet/:length/?' do
content_type :json
greeting = RandomSalutation.new
{ message: greeting.send(params[:length]) }.to_json
end
post '/animate/?' do
content_type :json
gif = Animations.new
@json = JSON.parse(request.body.read)
{ message: gif.find( @json['search'] ) }.to_json
end