Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first commit

  • Loading branch information...
commit 111d8d9d6817c46b5e4804b421f8d4c5aee4ee45 0 parents
@carimura carimura authored
2  .gitignore
@@ -0,0 +1,2 @@
+config_chad.yml
+.idea
6 Gemfile
@@ -0,0 +1,6 @@
+source :rubygems
+gem 'sinatra', '1.1.0'
+gem 'thin'
+gem 'iron_cache'
+gem 'iron_worker_ng'
+gem 'twilio-ruby'
49 Gemfile.lock
@@ -0,0 +1,49 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ builder (3.0.0)
+ daemons (1.1.8)
+ eventmachine (0.12.10)
+ iron_cache (1.0.0)
+ iron_core (>= 0.1.4)
+ iron_core (0.1.6)
+ bundler (> 1.0.0)
+ rest
+ rest-client
+ iron_worker_ng (0.7.4)
+ bundler (> 1.0.0)
+ iron_core (>= 0.1.4)
+ zip
+ json (1.7.3)
+ jwt (0.1.4)
+ json (>= 1.2.4)
+ mime-types (1.19)
+ multi_json (1.3.6)
+ rack (1.4.1)
+ rest (1.2.2)
+ rest-client (>= 0.3.0)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ sinatra (1.1.0)
+ rack (~> 1.1)
+ tilt (~> 1.1)
+ thin (1.4.1)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ tilt (1.3.3)
+ twilio-ruby (3.7.0)
+ builder (>= 2.1.2)
+ jwt (>= 0.1.2)
+ multi_json (>= 1.3.0)
+ zip (2.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ iron_cache
+ iron_worker_ng
+ sinatra (= 1.1.0)
+ thin
+ twilio-ruby
1  Procfile
@@ -0,0 +1 @@
+web: bundle exec ruby web.rb -p $PORT
10 README.md
@@ -0,0 +1,10 @@
+
+1. fill in values in config file
+2. iron_worker upload send_insanity
+3. deploy app to heroku
+
+To receive Twilio SMS's back:
+
+https://devcenter.heroku.com/articles/ruby
+
+Deploy the Heroku app to your own account
10 config.yml
@@ -0,0 +1,10 @@
+twilio:
+ account_sid: TWILIO_ACCOUNT_SID
+ auth_token: TWILIO_AUTH_TOKEN
+
+iron:
+ token: IRON_TOKEN
+ project_id: IRON_PROJECT_ID
+
+app:
+ from: VALID_TWILIO_NUMBER
63 insanity_schedule.txt
@@ -0,0 +1,63 @@
+Fit Test
+Plyometric Cardio Circuit
+Cardio Power & Resistance
+Cardio Recovery
+Pure Cardio
+Plyometric Cardio Circuit
+Off
+Cardio Power & Resistance
+Pure Cardio
+Cardio Circuit
+Cardio Recovery
+Cardio Power & Resistance
+Pure Cardio & Cardio Abs
+Off
+Fit Test
+Cardio Circuit
+Pure Cardio & Cardio Abs
+Cardio Recovery
+Cardio Power & Resistance
+Plyometric Cardio Circuit
+Off
+Pure Cardio & Cardio Abs
+Cardio Power & Resistance
+Plyometric Cardio Circuit
+Cardio Recovery
+Pure Cardio & Cardio Abs
+Plyometric Cardio Circuit
+Off
+Core Cardio and Balance
+Core Cardio and Balance
+Core Cardio and Balance
+Core Cardio and Balance
+Core Cardio and Balance
+Core Cardio and Balance
+Off
+Fit Test & Max Interval Circuit
+Max Interval Plyo
+Max Cardio Conditioning
+Max Recovery
+Max Interval Circuit
+Max Interval Plyo
+Off
+Max Cardio Conditioning
+Max Interval Circuit
+Max Interval Plyo
+Max Recovery
+Max Cardio Conditioning & Cardio Abs
+Core Cardio and Balance
+Off
+Fit Test & Max Interval Circuit
+Max INterval Plyo
+Max Cardio Conditioning & Cardio Abs
+Max Recovery
+Max Interval Circuit
+Core Cardio and Balance
+Off
+Max Interval Plyo
+Max Cardio Conditioning & Cardio Abs
+Max Interval Circuit
+Core Cardio and Balance
+Max Interval Plyo
+Max Cardio Conditioning & Cardio Abs
+Fit Test
7 shaunisms.txt
@@ -0,0 +1,7 @@
+You can frikin do it!!
+This is insanity!
+I'm talkin spit.
+Boom! Just like that.
+And I’m smilin cause I love it!
+That sh*t is bananas yo!
+Shaun T is startin' to sweat!
4 views/done.erb
@@ -0,0 +1,4 @@
+
+You're all set! You should receive your first workout reminder in moments. <br /><br />Respond with "<strong>done</strong>" when you start or finish!<br /><br />
+
+<img src="http://1.bp.blogspot.com/-iPxFPVxeFds/TcF6IALqEfI/AAAAAAAAAzM/jwiYZCA5X9A/s1600/shaun_t.png" /><br /><br/>
8 views/index.erb
@@ -0,0 +1,8 @@
+<h2>Insanity Reminder yo!</h2>
+
+<img src="http://morehappyhealth.com/wp-content/uploads/2009/07/logo.png" /><br /><br /><br />
+
+<form action="/start">
+ <label for="number">Your Number: </label> <input type="text" name="number" id="number" /> <br />(eg. "4151112222")<br /><br />
+ <input type="submit" value="Let's get Insane!" />
+</form>
106 web.rb
@@ -0,0 +1,106 @@
+require 'sinatra'
+require 'iron_cache'
+require 'iron_worker_ng'
+require 'twilio-ruby'
+use Rack::Logger
+
+helpers do
+ def puts(msg)
+ request.logger.info msg
+ end
+end
+
+get '/' do
+ erb :index
+end
+
+get '/start' do
+ number = params[:number]
+ cache = get_cache("insanity-#{number}")
+ load_schedule(cache)
+ cache.put("day", 0)
+
+ config = YAML.load_file("config.yml")
+ client = IronWorkerNG::Client.new(:token => config['iron']['token'], :project_id => config['iron']['project_id'])
+
+ client.schedules.create('SendInsanity',
+ {
+ :number => number
+ },
+ {
+ :start_at => Time.now,
+ :run_times => 5,
+ :run_every => 60
+ })
+
+ redirect '/done'
+end
+
+get '/done' do
+ erb :done
+end
+
+
+get '/receive' do
+ puts "-------------- RECEIVING REQUEST ---------------"
+ puts "FROM: #{params[:From]}"
+ puts "BODY: #{params[:Body]}"
+ puts "------------------------------------------------"
+
+ number = params[:From].reverse.chop.chop.reverse
+
+ move_day_forward(number) if params[:Body].downcase == "done"
+end
+
+
+private
+
+def move_day_forward(number)
+ config = YAML.load_file("config.yml")
+ twilio = Twilio::REST::Client.new config['twilio']['account_sid'], config['twilio']['auth_token']
+
+ cache = get_cache("insanity-#{number}")
+ cache.increment("day")
+
+ message = "Great job today. As Shaun T would say \"#{shaunism.chomp}\""
+
+ puts "Sending Shaunism"
+ twilio.account.sms.messages.create(
+ :from => config['app']['from'],
+ :to => number,
+ :body => message
+ )
+ puts "Congratulations! We've moved your workout forward one day!"
+end
+
+
+def shaunism
+ all = []
+ File.open('shaunisms.txt', 'r') do |f|
+ while line = f.gets
+ all << line.chomp
+ end
+ end
+ all[rand(all.size)]
+end
+
+
+def get_cache(name)
+ puts "Creating or Getting Cache...."
+ ironcache = IronCache::Client.new
+ ironcache.cache(name)
+end
+
+
+def load_schedule(cache)
+ puts "Loading Cache Up...."
+ i=0
+ File.open('insanity_schedule.txt', 'r') do |f|
+ while line = f.gets
+ cache.put(i.to_s, line)
+ i+=1
+ end
+ end
+end
+
+
1  workers/.gitignore
@@ -0,0 +1 @@
+iron.json
30 workers/send_insanity.rb
@@ -0,0 +1,30 @@
+require 'twilio-ruby'
+require 'iron_cache'
+require 'yaml'
+
+config = YAML.load_file("config.yml")
+account_sid = config['twilio']['account_sid']
+auth_token = config['twilio']['auth_token']
+project_id = config['iron']['project_id']
+token = config['iron']['token']
+number = params[:number]
+
+twilio = Twilio::REST::Client.new account_sid, auth_token
+ironcache = IronCache::Client.new(:project_id => project_id, :token => token)
+
+puts "Found number #{number}"
+
+cache = ironcache.cache("insanity-#{number}")
+
+day = cache.get("day")
+
+next_workout = cache.get(day.value.to_s).value
+
+message = "Today's workout is: #{next_workout}"
+
+twilio.account.sms.messages.create(
+ :from => config['app']['from'],
+ :to => number,
+ :body => message
+)
+
8 workers/send_insanity.worker
@@ -0,0 +1,8 @@
+runtime "ruby"
+exec "send_insanity.rb"
+name "SendInsanity"
+
+gem "twilio-ruby"
+gem "iron_cache"
+
+file "config.yml"
Please sign in to comment.
Something went wrong with that request. Please try again.