Skip to content
This repository

fixing a few things with the webhook adn web app #62

Merged
merged 1 commit into from almost 2 years ago

1 participant

Chad Arimura
Chad Arimura
Owner

No description provided.

Chad Arimura carimura merged commit 76b1141 into from July 15, 2012
Chad Arimura carimura closed this July 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 15, 2012
Chad Arimura fixing a few things with the webhook adn web app d636de8
This page is out of date. Refresh to see the latest.
49  ruby_ng/twilio_insanity/Gemfile.lock
... ...
@@ -0,0 +1,49 @@
  1
+GEM
  2
+  remote: http://rubygems.org/
  3
+  specs:
  4
+    builder (3.0.0)
  5
+    daemons (1.1.8)
  6
+    eventmachine (0.12.10)
  7
+    iron_cache (1.0.0)
  8
+      iron_core (>= 0.1.4)
  9
+    iron_core (0.1.4)
  10
+      bundler (> 1.0.0)
  11
+      rest
  12
+      rest-client
  13
+    iron_worker_ng (0.7.4)
  14
+      bundler (> 1.0.0)
  15
+      iron_core (>= 0.1.4)
  16
+      zip
  17
+    json (1.7.3)
  18
+    jwt (0.1.4)
  19
+      json (>= 1.2.4)
  20
+    mime-types (1.19)
  21
+    multi_json (1.3.6)
  22
+    rack (1.4.1)
  23
+    rest (1.0.0)
  24
+      rest-client (>= 0.3.0)
  25
+    rest-client (1.6.7)
  26
+      mime-types (>= 1.16)
  27
+    sinatra (1.1.0)
  28
+      rack (~> 1.1)
  29
+      tilt (~> 1.1)
  30
+    thin (1.4.1)
  31
+      daemons (>= 1.0.9)
  32
+      eventmachine (>= 0.12.6)
  33
+      rack (>= 1.0.0)
  34
+    tilt (1.3.3)
  35
+    twilio-ruby (3.7.0)
  36
+      builder (>= 2.1.2)
  37
+      jwt (>= 0.1.2)
  38
+      multi_json (>= 1.3.0)
  39
+    zip (2.0.2)
  40
+
  41
+PLATFORMS
  42
+  ruby
  43
+
  44
+DEPENDENCIES
  45
+  iron_cache
  46
+  iron_worker_ng
  47
+  sinatra (= 1.1.0)
  48
+  thin
  49
+  twilio-ruby
36  ruby_ng/twilio_insanity/README.md
Source Rendered
... ...
@@ -1,19 +1,37 @@
1 1
 
2 2
 Setup:
3 3
 
4  
-sudo bundle install (iron_worker_ng has the iron_worker command line interface)
5  
-fill in values in config file
6  
-fill in values in workers/iron.json
7  
-cd workers
8  
-iron_worker upload send_insanity
9  
-iron_worker upload twilio_webhook
  4
+1. Sign up for free accounts at Twilio.com and Iron.io
  5
+2. git clone https://github.com/iron-io/iron_worker_examples.git
  6
+3. cd ruby_ng/twilio_insanity
  7
+4. sudo bundle install (iron_worker_ng has the iron_worker command line interface)
  8
+5. fill in values in config/config.yml file
  9
+6. fill in values in workers/iron.json
  10
+7. cd workers
  11
+8. iron_worker upload send_insanity
  12
+9. iron_worker upload twilio_webhook
  13
+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
  14
+
10 15
 
11 16
 To Run:
12 17
 
13  
-ruby web.rb
14  
-browse to http://localhost:4567/
15  
-enter your number
  18
+1. return to twilio_insanity directory
  19
+2. ruby web.rb
  20
+3. browse to http://localhost:4567/
  21
+4. enter your number click "Let's get Insane!"
  22
+
  23
+
  24
+Checking that things worked:
  25
+
  26
+- two uploaded code packages: SendInsanity and TwilioWebhook
  27
+- one scheduled task
  28
+- You'll get your first SMS
  29
+- Go to IronCache and you'll see the cache created
  30
+- Respond to the SMS with "done" to move the day forward
  31
+
16 32
 
  33
+NOTE: If you're using a free Twilio account, you'll need to preface all SMS's with your "Sandbox Pin"
  34
+Your response will look like this: "1234-5678 done"
17 35
 
18 36
 
19 37
 https://worker-aws-us-east-1.iron.io/2/projects/{PROJECT_ID}/tasks/webhook?code_name=TwilioWebhook&oauth={TOKEN}
36  ruby_ng/twilio_insanity/web.rb
@@ -16,22 +16,24 @@ def puts(msg)
16 16
 
17 17
 get '/start' do
18 18
   number = params[:number]
19  
-  cache = get_cache("insanity-#{number}")
20  
-  load_schedule(cache)
21  
-  cache.put("day", 0)
22 19
 
23 20
   config = YAML.load_file("config/config.yml")
24  
-  client = IronWorkerNG::Client.new(:token => config['iron']['token'], :project_id => config['iron']['project_id'])
  21
+  worker_client = IronWorkerNG::Client.new(:token => config['iron']['token'], :project_id => config['iron']['project_id'])
  22
+  cache_client = IronCache::Client.new(:token => config['iron']['token'], :project_id => config['iron']['project_id'])
  23
+  cache = cache_client.cache("insanity-#{number}")
  24
+
  25
+  load_schedule(cache)
  26
+  cache.put("day", 0)
25 27
 
26  
-  client.schedules.create('SendInsanity',
27  
-                          {
28  
-                            :number => number
29  
-                          },
30  
-                          {
31  
-                            :start_at => Time.now,
32  
-                            :run_times => 5,
33  
-                            :run_every => 60
34  
-                          })
  28
+  worker_client.schedules.create('SendInsanity',
  29
+                                 {
  30
+                                   :number => number
  31
+                                 },
  32
+                                 {
  33
+                                   :start_at => Time.now,
  34
+                                   :run_times => 60,
  35
+                                   :run_every => 3600*24
  36
+                                 })
35 37
 
36 38
   redirect '/done'
37 39
 end
@@ -41,17 +43,9 @@ def puts(msg)
41 43
 end
42 44
 
43 45
 
44  
-
45 46
 private
46 47
 
47 48
 
48  
-def get_cache(name)
49  
-  puts "Creating or Getting Cache...."
50  
-  ironcache = IronCache::Client.new
51  
-  ironcache.cache(name)
52  
-end
53  
-
54  
-
55 49
 def load_schedule(cache)
56 50
   puts "Loading Cache Up...."
57 51
   i=0
4  ruby_ng/twilio_insanity/workers/iron.json
... ...
@@ -0,0 +1,4 @@
  1
+{
  2
+    "token": "MY_TOKEN",
  3
+    "project_id": "MY_PROJECT_ID"
  4
+ }
4  ruby_ng/twilio_insanity/workers/twilio_webhook.rb
@@ -12,11 +12,11 @@
12 12
 puts "-------------- RECEIVING REQUEST ---------------"
13 13
 puts "PAYLOAD: #{payload}"
14 14
 puts "Parsed Payload: #{parsed}"
15  
-puts "FROM: #{from}"
  15
+puts "FROM: #{number}"
16 16
 puts "BODY: #{body}"
17 17
 puts "------------------------------------------------"
18 18
 
19  
-number.reverse!.chop!.chop!.reverse! if number[0]="+"
  19
+number.reverse!.chop!.chop!.reverse! if number[0] == "+"
20 20
 
21 21
 
22 22
 def shaunism
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.