ychaker-zeep_it 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +65 -0
- data/Rakefile +54 -0
- data/generators/zeep_it_route/zeep_it_route_generator.rb +7 -0
- data/install.rb +1 -0
- data/lib/app/controllers/zeep_sms_controller.rb +104 -0
- data/lib/app/helpers/zeep_sms_helper.rb +11 -0
- data/lib/app/models/zeep_sms.rb +101 -0
- data/lib/app/views/zeep_sms/_form.erb +10 -0
- data/lib/app/views/zeep_sms/incoming.erb +0 -0
- data/lib/app/views/zeep_sms/index.erb +6 -0
- data/lib/db/migrate/20090719024916_create_zeep_sms.rb +13 -0
- data/lib/zeep/LICENSE +18 -0
- data/lib/zeep/README +42 -0
- data/lib/zeep/auth.rb +51 -0
- data/lib/zeep/messaging.rb +79 -0
- data/lib/zeep/responses.rb +122 -0
- data/lib/zeep_it.rb +15 -0
- data/lib/zeep_it/commands.rb +39 -0
- data/lib/zeep_it/routing.rb +11 -0
- data/rails/init.rb +1 -0
- data/tasks/zeep_it_tasks.rake +51 -0
- data/test/database.yml +22 -0
- data/test/debug.log +2459 -0
- data/test/route_generator_test.rb +51 -0
- data/test/routing_test.rb +20 -0
- data/test/schema.rb +8 -0
- data/test/test_helper.rb +33 -0
- data/test/zeep_it_test.rb +13 -0
- data/test/zeep_sms_controller_test.rb +28 -0
- data/test/zeep_sms_helper_test.rb +12 -0
- data/test/zeep_sms_test.rb +41 -0
- data/uninstall.rb +1 -0
- metadata +85 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Youssef Chaker
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
= ZeepIt
|
2
|
+
|
3
|
+
ZeepIt is a plugin that leverages the zeep-messaging gem to create the models/controllers/views required to get your app ready to use the Zeep Mobile SMS service.
|
4
|
+
|
5
|
+
All you need to do is install the plugin, run the setup and sign up for an account at http://zeepmobile.com. Then make sure that your callback URL in your Zeep Mobile account point to http://www.yourdomain.com/zeep_sms/incoming and you add your api_key and you secret_key to config/zeep_it.yml and you'll be good to go.
|
6
|
+
|
7
|
+
|
8
|
+
== Prerequisites
|
9
|
+
|
10
|
+
A Zeep Mobile (http://zeepmobile.com) account and the respective API and SECRET keys.
|
11
|
+
|
12
|
+
|
13
|
+
== Install
|
14
|
+
|
15
|
+
Install from gihub:
|
16
|
+
gem sources -a http://gems.github.com
|
17
|
+
sudo gem install ychaker-zeep_it
|
18
|
+
|
19
|
+
you only have to update your gem sources once
|
20
|
+
|
21
|
+
== Setup
|
22
|
+
|
23
|
+
From your Rails App root directory run:
|
24
|
+
|
25
|
+
rake zeep_it:setup
|
26
|
+
|
27
|
+
(make sure your db is already created!)
|
28
|
+
|
29
|
+
Then edit config/zeep_it.yml with the correct API and SECRET keys.
|
30
|
+
|
31
|
+
|
32
|
+
== Examples
|
33
|
+
|
34
|
+
Example of using the helper method for displaying the Zeep Mobile:
|
35
|
+
|
36
|
+
<%= zeep_form(user_id) %>
|
37
|
+
|
38
|
+
Example of sending an SMSL
|
39
|
+
|
40
|
+
ZeepSms::send_sms('user_id', 'body of SMS')
|
41
|
+
|
42
|
+
Example of creating a ZeepSms and sending it:
|
43
|
+
|
44
|
+
sms = ZeepSms.new(:login=> 'user_id', :raw =>'body of SMS')
|
45
|
+
sms.send_text
|
46
|
+
|
47
|
+
Examples of parsing an SMS:
|
48
|
+
|
49
|
+
sms = ZeepSms.new(:login=> 'user_id', :raw =>'body of SMS')
|
50
|
+
sms.parse_for(:keyword => 'user:')
|
51
|
+
#=> returns the text found after the keywork and before the next space
|
52
|
+
sms.parse_for(:pattern => /[0-9]/)
|
53
|
+
#=> returns the text found after the first digit and before the next space
|
54
|
+
sms.parse_for(:common => 'twitter')
|
55
|
+
#=> returns the text found after the first '@' and before the next space
|
56
|
+
sms.parse_for({:common => 'bang'}, true)
|
57
|
+
#=> returns the text found between the previous space and the next space
|
58
|
+
#=> removing the '!' in between
|
59
|
+
|
60
|
+
Also returns the rest of the SMS omitting the 5-8 code in the beginning
|
61
|
+
|
62
|
+
|
63
|
+
== Copyright
|
64
|
+
|
65
|
+
Copyright (c) 2009 Youssef Chaker, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/gempackagetask'
|
6
|
+
|
7
|
+
desc 'Default: run unit tests.'
|
8
|
+
task :default => :test
|
9
|
+
|
10
|
+
desc 'Test the zeep_it plugin.'
|
11
|
+
Rake::TestTask.new(:test) do |t|
|
12
|
+
t.libs << 'lib'
|
13
|
+
t.libs << 'test'
|
14
|
+
t.pattern = 'test/**/*_test.rb'
|
15
|
+
t.verbose = true
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Generate documentation for the zeep_it plugin.'
|
19
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'ZeepIt'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README.rdoc')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
26
|
+
|
27
|
+
PKG_FILES = FileList[
|
28
|
+
'[a-zA-Z]*',
|
29
|
+
'generators/**/*',
|
30
|
+
'lib/**/*',
|
31
|
+
'rails/**/*',
|
32
|
+
'tasks/**/*',
|
33
|
+
'test/**/*'
|
34
|
+
]
|
35
|
+
|
36
|
+
spec = Gem::Specification.new do |s|
|
37
|
+
s.name = "zeep_it"
|
38
|
+
s.version = "0.0.4"
|
39
|
+
s.author = "Youssef Chaker"
|
40
|
+
s.email = "youssefchaker@youhhoo.com"
|
41
|
+
s.homepage = "http://github.com/ychaker/zeep_it"
|
42
|
+
s.platform = Gem::Platform::RUBY
|
43
|
+
s.summary = "Get your app Zeep Mobile ready"
|
44
|
+
s.description = "Get your app Zeep Mobile ready"
|
45
|
+
s.files = PKG_FILES.to_a
|
46
|
+
s.require_path = "lib"
|
47
|
+
s.has_rdoc = true
|
48
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'Turn this plugin into a gem.'
|
52
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
53
|
+
pkg.gem_spec = spec
|
54
|
+
end
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,104 @@
|
|
1
|
+
class ZeepSmsController < ApplicationController
|
2
|
+
|
3
|
+
# GET /zeep_sms
|
4
|
+
# GET /zeep_sms.xml
|
5
|
+
def index
|
6
|
+
respond_to do |format|
|
7
|
+
format.html # index.html.erb
|
8
|
+
format.xml { render :xml => @sms }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /zeep_sms/incoming
|
13
|
+
# GET /zeep_sms/incoming.xml
|
14
|
+
#
|
15
|
+
# Callback URL
|
16
|
+
# When users send SMS messages to your website, Zeep Mobile send the requests to this URL.
|
17
|
+
# I.e. http://example.com/zeep_sms/incoming
|
18
|
+
def incoming
|
19
|
+
response.headers["Content-Type"] = "text/plain; charset=utf-8"
|
20
|
+
#Read params from the text message
|
21
|
+
|
22
|
+
if (params[:uid] && params[:body])
|
23
|
+
@userid = params[:uid]
|
24
|
+
@body = params[:body]
|
25
|
+
sms = ZeepSms.new(:raw => @body, :login => @userid)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# CRUD method templates:
|
31
|
+
|
32
|
+
# GET /zeep_sms/1
|
33
|
+
# GET /zeep_sms/1.xml
|
34
|
+
# def show
|
35
|
+
# @sms = ZeepSms.find(params[:id])
|
36
|
+
#
|
37
|
+
# respond_to do |format|
|
38
|
+
# format.html # show.html.erb
|
39
|
+
# format.xml { render :xml => @sms }
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
|
43
|
+
# GET /zeep_sms/new
|
44
|
+
# GET /zeep_sms/new.xml
|
45
|
+
# def new
|
46
|
+
# @sms = ZeepSms.new
|
47
|
+
#
|
48
|
+
# respond_to do |format|
|
49
|
+
# format.html # new.html.erb
|
50
|
+
# format.xml { render :xml => @sms }
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
|
54
|
+
# GET /zeep_sms/1/edit
|
55
|
+
# def edit
|
56
|
+
# @sms = ZeepSms.find(params[:id])
|
57
|
+
# end
|
58
|
+
|
59
|
+
# POST /zeep_sms
|
60
|
+
# POST /zeep_sms.xml
|
61
|
+
# def create
|
62
|
+
# @sms = ZeepSms.new(params[:sms])
|
63
|
+
#
|
64
|
+
# respond_to do |format|
|
65
|
+
# if @sms.save
|
66
|
+
# flash[:notice] = 'Sms was successfully created.'
|
67
|
+
# format.html { redirect_to(@sms) }
|
68
|
+
# format.xml { render :xml => @sms, :status => :created, :location => @sms }
|
69
|
+
# else
|
70
|
+
# format.html { render :action => "new" }
|
71
|
+
# format.xml { render :xml => @sms.errors, :status => :unprocessable_entity }
|
72
|
+
# end
|
73
|
+
# end
|
74
|
+
# end
|
75
|
+
|
76
|
+
# PUT /zeep_sms/1
|
77
|
+
# PUT /zeep_sms/1.xml
|
78
|
+
# def update
|
79
|
+
# @sms = ZeepSms.find(params[:id])
|
80
|
+
#
|
81
|
+
# respond_to do |format|
|
82
|
+
# if @sms.update_attributes(params[:sms])
|
83
|
+
# flash[:notice] = 'Sms was successfully updated.'
|
84
|
+
# format.html { redirect_to(@sms) }
|
85
|
+
# format.xml { head :ok }
|
86
|
+
# else
|
87
|
+
# format.html { render :action => "edit" }
|
88
|
+
# format.xml { render :xml => @sms.errors, :status => :unprocessable_entity }
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
# end
|
92
|
+
|
93
|
+
# DELETE /zeep_sms/1
|
94
|
+
# DELETE /zeep_sms/1.xml
|
95
|
+
# def destroy
|
96
|
+
# @sms = ZeepSms.find(params[:id])
|
97
|
+
# @sms.destroy
|
98
|
+
#
|
99
|
+
# respond_to do |format|
|
100
|
+
# format.html { redirect_to(sms_url) }
|
101
|
+
# format.xml { head :ok }
|
102
|
+
# end
|
103
|
+
# end
|
104
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'zeep/messaging'
|
3
|
+
|
4
|
+
class ZeepSms < ActiveRecord::Base
|
5
|
+
RAILS_ROOT ||= File.dirname(__FILE__) + '/../../../..'
|
6
|
+
file = YAML::load(IO.read("#{RAILS_ROOT}/config/zeep_it.yml"))
|
7
|
+
|
8
|
+
# Zeep Mobile keys extracted from config/zeep_it.yml
|
9
|
+
SECRET_KEY = file['SECRET_KEY']
|
10
|
+
API_KEY = file['API_KEY']
|
11
|
+
|
12
|
+
# Send any SMS by providing the user loging and body
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
# ZeepSms::send_sms('user_id', 'body of SMS')
|
16
|
+
def self.send_sms(login, body)
|
17
|
+
Zeep::Base.configure_credentials(self::API_KEY, self::SECRET_KEY)
|
18
|
+
Zeep::Messaging.send_message(login, body)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Send the SMS
|
22
|
+
#
|
23
|
+
# Example:
|
24
|
+
# sms = ZeepSms.new(:login=> 'user_id', :raw =>'body of SMS')
|
25
|
+
# sms.send_text
|
26
|
+
def send_text
|
27
|
+
Zeep::Base.configure_credentials(self::API_KEY, self::SECRET_KEY)
|
28
|
+
Zeep::Messaging.send_message(self.login, self.raw)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Parse an SMS for a particular keyword or pattern
|
32
|
+
#
|
33
|
+
# Examples:
|
34
|
+
# parse_for(:keyword => 'user:')
|
35
|
+
# => returns the text found after the keywork and before the next space
|
36
|
+
# parse_for(:pattern => /[0-9]/)
|
37
|
+
# => returns the text found after the first digit and before the next space
|
38
|
+
# parse_for(:common => 'twitter')
|
39
|
+
# => returns the text found after the first '@' and before the next space
|
40
|
+
# parse_for({:common => 'bang'}, true)
|
41
|
+
# => returns the text found between the previous space and the next space
|
42
|
+
# => removing the '!' in between
|
43
|
+
#
|
44
|
+
# Also returns the rest of the SMS omitting the 5-8 code in the beginning
|
45
|
+
def parse_sms(hash={}, keepPrevious=false)
|
46
|
+
prev = /.*/
|
47
|
+
if keepPrevious
|
48
|
+
prev = ''
|
49
|
+
end
|
50
|
+
key, rest = ''
|
51
|
+
result = {:key => key, :rest => rest}
|
52
|
+
keyword = extract_keyword(hash)
|
53
|
+
key = parse_for(self.raw, keyword, keepPrevious)
|
54
|
+
rest = self.raw.sub(/#{keyword}#{key}\s+/, '')
|
55
|
+
rest.sub!(/[\w]+\s+{1}/, '').chomp!
|
56
|
+
result = {:key => key, :rest => rest}
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def extract_keyword(hash={}) #:nodoc:
|
61
|
+
keyword = ''
|
62
|
+
if !hash[:keyword].blank?
|
63
|
+
keyword = hash[:keyword]
|
64
|
+
elsif !hash[:pattern].blank?
|
65
|
+
keyword = hash[:pattern]
|
66
|
+
elsif !hash[:common].blank?
|
67
|
+
if hash[:common] == 'twitter'
|
68
|
+
keyword = '@'
|
69
|
+
elsif hash[:common] == 'hashtag'
|
70
|
+
keyword = '#'
|
71
|
+
elsif hash[:common] == 'USD'
|
72
|
+
keyword = '$'
|
73
|
+
elsif hash[:common] == 'percent'
|
74
|
+
keyword = '%'
|
75
|
+
elsif hash[:common] == 'bang'
|
76
|
+
keyword = '!'
|
77
|
+
elsif hash[:common] == 'colon'
|
78
|
+
keyword = ':'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
keyword
|
82
|
+
end
|
83
|
+
|
84
|
+
def parse_for(body, keyword, keepPrevious=false) #:nodoc:
|
85
|
+
prev = /.*/
|
86
|
+
if keepPrevious
|
87
|
+
prev = ''
|
88
|
+
end
|
89
|
+
result = ''
|
90
|
+
unless keyword.blank?
|
91
|
+
body.split(/\s+/).each do |word|
|
92
|
+
regex = /#{keyword}/
|
93
|
+
if regex.match(word)
|
94
|
+
result = word.sub(/#{prev}#{keyword}/, '')
|
95
|
+
break
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
result
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% user_id ||= ' ' %>
|
2
|
+
|
3
|
+
<div class="zeep-help">
|
4
|
+
To receive text messages please make sure you have created a zeepmobile account below (widget may take a few seconds to load). Ads may be inserted with your text messages, but you will not be spammed.
|
5
|
+
</div>
|
6
|
+
<iframe
|
7
|
+
style="width: 100%; height: 300px; border: none;"
|
8
|
+
id="zeep_mobile_settings_panel"
|
9
|
+
src="https://secure.zeepmobile.com/subscription/settings?api_key=<%= ZeepSms::API_KEY %>&user_id=<%= user_id %>">
|
10
|
+
</iframe>
|
File without changes
|
data/lib/zeep/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2008 Zeep Mobile (zeepmobile.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/zeep/README
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
= Zeep Mobile Messaging - SMS Made Easy.
|
2
|
+
|
3
|
+
With just a few lines of code, Zeep Mobile's API lets your web app communicate with your users over SMS. Zeep Mobile makes it easy to:
|
4
|
+
|
5
|
+
* Manage your users' mobile content subscriptions
|
6
|
+
* Send and receive SMS content
|
7
|
+
|
8
|
+
These libraries take care of the HTTP Header signing and posting to the HTTP endpoint.
|
9
|
+
|
10
|
+
= Development
|
11
|
+
|
12
|
+
http://code.google.com/p/zeep-messaging/ is the home of this project. For read-only access to the subversion repo; this should sort you out:
|
13
|
+
|
14
|
+
$ svn checkout http://zeep-messaging.googlecode.com/svn/ruby/ trunk/ zeep-messaging-read-only
|
15
|
+
|
16
|
+
= Installing zeep-messaging
|
17
|
+
|
18
|
+
Until we start publishing to rubyforge (coming soon) you'll have to get the latest gem from here:
|
19
|
+
|
20
|
+
http://code.google.com/p/zeep-messaging/downloads/list
|
21
|
+
|
22
|
+
Download it and then:
|
23
|
+
|
24
|
+
$ gem install zeep-messaging-0.1.X.gem
|
25
|
+
|
26
|
+
= Getting Started
|
27
|
+
|
28
|
+
* Head to http://zeepmobile.com/ and get a developer account.
|
29
|
+
* Open your account page: https://secure.zeepmobile.com/account/
|
30
|
+
* Register a new application.
|
31
|
+
* Note your API_KEY and SECRET_KEY
|
32
|
+
|
33
|
+
require 'rubygems' # Only required if you've installed the gem version
|
34
|
+
require 'zeep/messaging'
|
35
|
+
|
36
|
+
Zeep::Base.configure_credentials(<your api key>, <your secret key>)
|
37
|
+
|
38
|
+
Zeep::send_message(<user_id>, "'Art thou not Romeo, and a Montague?'")
|
39
|
+
|
40
|
+
Wasn't that easy?
|
41
|
+
|
42
|
+
As always, any and all feedback is appreciated. You can find me at simon@zeepmobile.com.
|