commit 200d95588b777bdb9baf66fba531d3bdd76c4354 Author: Mark Moser Date: Sat May 16 21:47:18 2015 -0500 init and spike diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..a93b4de --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +gem 'thin' +gem 'sinatra' + +gem 'json' + diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..1be42a3 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..1f65134 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +## HEllo Slack + +Yet another gif generating slackbot, more to come. diff --git a/app/workers/animations.rb b/app/workers/animations.rb new file mode 100644 index 0000000..211277c --- /dev/null +++ b/app/workers/animations.rb @@ -0,0 +1,7 @@ +class Animations + + def find string + "looking for a gif related to: #{string}" + end + +end diff --git a/app/workers/random_salutation.rb b/app/workers/random_salutation.rb new file mode 100644 index 0000000..6f73ebc --- /dev/null +++ b/app/workers/random_salutation.rb @@ -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 diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..9496cf6 --- /dev/null +++ b/config.ru @@ -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 diff --git a/meme_bot.rb b/meme_bot.rb new file mode 100644 index 0000000..e9235b0 --- /dev/null +++ b/meme_bot.rb @@ -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