Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixing a few things with the webhook adn web app

  • Loading branch information...
commit d636de8cceffe688e267a94ed7c58069a31a41d5 1 parent f4fa8bd
@carimura carimura authored
View
49 ruby_ng/twilio_insanity/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.4)
+ 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.0.0)
+ 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
View
36 ruby_ng/twilio_insanity/README.md
@@ -1,19 +1,37 @@
Setup:
-sudo bundle install (iron_worker_ng has the iron_worker command line interface)
-fill in values in config file
-fill in values in workers/iron.json
-cd workers
-iron_worker upload send_insanity
-iron_worker upload twilio_webhook
+1. Sign up for free accounts at Twilio.com and Iron.io
+2. git clone https://github.com/iron-io/iron_worker_examples.git
+3. cd ruby_ng/twilio_insanity
+4. sudo bundle install (iron_worker_ng has the iron_worker command line interface)
+5. fill in values in config/config.yml file
+6. fill in values in workers/iron.json
+7. cd workers
+8. iron_worker upload send_insanity
+9. iron_worker upload twilio_webhook
+10. go to Twilio.com and in the SMS URL enter URL below (fill in your values) and make sure it's set to POST
+
To Run:
-ruby web.rb
-browse to http://localhost:4567/
-enter your number
+1. return to twilio_insanity directory
+2. ruby web.rb
+3. browse to http://localhost:4567/
+4. enter your number click "Let's get Insane!"
+
+
+Checking that things worked:
+
+- two uploaded code packages: SendInsanity and TwilioWebhook
+- one scheduled task
+- You'll get your first SMS
+- Go to IronCache and you'll see the cache created
+- Respond to the SMS with "done" to move the day forward
+
+NOTE: If you're using a free Twilio account, you'll need to preface all SMS's with your "Sandbox Pin"
+Your response will look like this: "1234-5678 done"
https://worker-aws-us-east-1.iron.io/2/projects/{PROJECT_ID}/tasks/webhook?code_name=TwilioWebhook&oauth={TOKEN}
View
36 ruby_ng/twilio_insanity/web.rb
@@ -16,22 +16,24 @@ def puts(msg)
get '/start' do
number = params[:number]
- cache = get_cache("insanity-#{number}")
- load_schedule(cache)
- cache.put("day", 0)
config = YAML.load_file("config/config.yml")
- client = IronWorkerNG::Client.new(:token => config['iron']['token'], :project_id => config['iron']['project_id'])
+ worker_client = IronWorkerNG::Client.new(:token => config['iron']['token'], :project_id => config['iron']['project_id'])
+ cache_client = IronCache::Client.new(:token => config['iron']['token'], :project_id => config['iron']['project_id'])
+ cache = cache_client.cache("insanity-#{number}")
+
+ load_schedule(cache)
+ cache.put("day", 0)
- client.schedules.create('SendInsanity',
- {
- :number => number
- },
- {
- :start_at => Time.now,
- :run_times => 5,
- :run_every => 60
- })
+ worker_client.schedules.create('SendInsanity',
+ {
+ :number => number
+ },
+ {
+ :start_at => Time.now,
+ :run_times => 60,
+ :run_every => 3600*24
+ })
redirect '/done'
end
@@ -41,17 +43,9 @@ def puts(msg)
end
-
private
-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
View
4 ruby_ng/twilio_insanity/workers/iron.json
@@ -0,0 +1,4 @@
+{
+ "token": "MY_TOKEN",
+ "project_id": "MY_PROJECT_ID"
+ }
View
4 ruby_ng/twilio_insanity/workers/twilio_webhook.rb
@@ -12,11 +12,11 @@
puts "-------------- RECEIVING REQUEST ---------------"
puts "PAYLOAD: #{payload}"
puts "Parsed Payload: #{parsed}"
-puts "FROM: #{from}"
+puts "FROM: #{number}"
puts "BODY: #{body}"
puts "------------------------------------------------"
-number.reverse!.chop!.chop!.reverse! if number[0]="+"
+number.reverse!.chop!.chop!.reverse! if number[0] == "+"
def shaunism
Please sign in to comment.
Something went wrong with that request. Please try again.