Permalink
Browse files

Introducing Marvin

  • Loading branch information...
1 parent 7cd2b57 commit 2be0cde96a303cf9f9c1eba7ce51ff7dbf5c50ab @avinasha committed Mar 3, 2012
Showing with 65 additions and 19 deletions.
  1. +3 −1 Gemfile
  2. +5 −0 Gemfile.lock
  3. +22 −0 app.rb
  4. +3 −2 config.ru
  5. +5 −0 config/initializers/campfire.rb
  6. +27 −0 lib/campfire.rb
  7. +0 −16 web_hook_to_campfire.rb
View
@@ -1,5 +1,7 @@
source :rubygems
gem 'sinatra'
+gem 'sinatra-initializers'
gem 'tinder'
-gem 'heroku', :group => :development
+gem 'heroku', :group => :development
+gem 'shotgun', :group => :development
View
@@ -34,11 +34,14 @@ GEM
rest-client (1.6.7)
mime-types (>= 1.16)
rubyzip (0.9.4)
+ shotgun (0.9)
+ rack (>= 1.0)
simple_oauth (0.1.5)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
+ sinatra-initializers (0.1.4)
term-ansicolor (1.0.7)
tilt (1.3.3)
tinder (1.8.0)
@@ -61,5 +64,7 @@ PLATFORMS
DEPENDENCIES
heroku
+ shotgun
sinatra
+ sinatra-initializers
tinder
View
@@ -0,0 +1,22 @@
+require 'sinatra/base'
+require 'sinatra-initializers'
+require 'json'
+
+module Marvin
+ class App < Sinatra::Base
+
+ register Sinatra::Initializers
+
+ post '/supportbee' do
+ json = JSON.parse(request.body.read.to_s)
+ payload = json['payload']
+ if payload['action_type'] == 'ticket_created'
+ speech = "[#{payload['company']['name']}:New Ticket] #{payload['ticket']['subject']}\n https://#{payload['company']['subdomain']}.supportbee.com/tickets/#{payload['ticket']['id']}"
+ CAMPFIRE.speak speech
+ end
+ body ''
+ end
+
+ run! if app_file == $0
+ end
+end
View
@@ -1,2 +1,3 @@
-require 'web_hook_to_campfire'
-run Sinatra::Application
+require './lib/campfire'
+require './app'
+run Marvin::App
@@ -0,0 +1,5 @@
+CAMPFIRE = Marvin::Campfire.new ({
+ :account => ENV['MARVIN_CAMPFIRE_ACCOUNT'],
+ :token => ENV['MARVIN_CAMPFIRE_TOKEN'],
+ :room_ids => ENV['MARVIN_CAMPFIRE_ROOM_IDS']
+ })
View
@@ -0,0 +1,27 @@
+require 'tinder'
+
+module Marvin
+ class Campfire
+ def initialize(options={})
+ raise "Campfire Token Required" if options[:token].nil? || options[:token].empty?
+ raise "Campfire Account Required" if options[:account].nil? || options[:account].empty?
+ raise "Campfire Room IDs Required" if options[:room_ids].nil? || options[:room_ids].empty?
+ @connection = Tinder::Campfire.new options[:account], :token => options[:token]
+ @room_ids = options[:room_ids].split(',').collect {|room_str| room_str.to_i }
+ end
+
+ def speak(message)
+ @room_ids.each do |room_id|
+ room = @connection.find_room_by_id(room_id)
+ room.speak(message)
+ end
+ end
+
+ def paste(message)
+ @room_ids.each do |room_id|
+ room = @connection.find_room_by_id(room_id)
+ room.paste(message)
+ end
+ end
+ end
+end
@@ -1,16 +0,0 @@
-require 'sinatra'
-require 'json'
-require 'tinder'
-
-campfire = Tinder::Campfire.new 'supportbee', :token => '3b6227280f2699d4a85144e131bfe73ee85581ba'
-room = campfire.find_room_by_id(356788)
-
-post '/supportbee' do
- puts 'IN POST'
- json = JSON.parse(request.body.read.to_s)
- payload = json['payload']
- if payload['action_type'] == 'ticket_created'
- speech = "[#{payload['company']['name']}:New Ticket] #{payload['ticket']['subject']}\n https://#{payload['company']['subdomain']}.supportbee.com/tickets/#{payload['ticket']['id']}"
- room.speak speech
- end
-end

0 comments on commit 2be0cde

Please sign in to comment.