jsmestad-merb-slice-sms 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Justin Smestad
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 ADDED
@@ -0,0 +1,170 @@
1
+ MerbSliceSms
2
+ ============
3
+
4
+ A slice for the Merb framework.
5
+
6
+ ------------------------------------------------------------------------------
7
+
8
+ merb-slice-sms
9
+ |-- LICENSE
10
+ |-- README
11
+ |-- Rakefile [1]
12
+ |-- TODO
13
+ |-- app [2]
14
+ | |-- controllers
15
+ | | |-- application.rb
16
+ | | `-- main.rb
17
+ | |-- helpers
18
+ | | `-- application_helper.rb
19
+ | `-- views
20
+ | |-- layout
21
+ | | `-- merb-slice-sms.html.erb [3]
22
+ | `-- main
23
+ | `-- index.html.erb
24
+ |-- lib
25
+ | |-- merb-slice-sms
26
+ | | |-- merbtasks.rb [4]
27
+ | | `-- slicetasks.rb [5]
28
+ | `-- merb-slice-sms.rb [6]
29
+ |-- log
30
+ | `-- merb_test.log
31
+ |-- public [7]
32
+ | |-- javascripts
33
+ | | `-- master.js
34
+ | `-- stylesheets
35
+ | `-- master.css
36
+ |-- spec [8]
37
+ | |-- merb-slice-sms_spec.rb
38
+ | |-- controllers
39
+ | | `-- main_spec.rb
40
+ | `-- spec_helper.rb
41
+ `-- stubs [9]
42
+ `-- app
43
+ `-- controllers
44
+ |-- application.rb
45
+ `-- main.rb
46
+
47
+
48
+ 1. Rake tasks to package/install the gem - edit this to modify the manifest.
49
+ 2. The slice application: controllers, models, helpers, views.
50
+ 3. The default layout, as specified in Merb::Slices::config[:merb_slice_sms][:layout]
51
+ change this to :application to use the app's layout.
52
+ 4. Standard rake tasks available to your application.
53
+ 5. Your custom application rake tasks.
54
+ 6. The main slice file - contains all slice setup logic/config.
55
+ 7. Public assets you (optionally) install using rake slices:merb_slice_sms:install
56
+ 8. Specs for basis slice behaviour - you usually adapt these for your slice.
57
+ 9. Stubs of classes/views/files for the end-user to override - usually these
58
+ mimic the files in app/ and/or public/; use rake slices:merb_slice_sms:stubs to
59
+ get started with the override stubs. Also, slices:merb_slice_sms:patch will
60
+ copy over views to override in addition to the files found in /stubs.
61
+
62
+
63
+ To see all available tasks for MerbSliceSms run:
64
+
65
+ rake -T slices:merb_slice_sms
66
+
67
+ ------------------------------------------------------------------------------
68
+
69
+ Instructions for installation:
70
+
71
+ file: config/init.rb
72
+
73
+ # add the slice as a regular dependency
74
+
75
+ dependency 'merb-slice-sms'
76
+
77
+ # if needed, configure which slices to load and in which order
78
+
79
+ Merb::Plugins.config[:merb_slices] = { :queue => ["MerbSliceSms", ...] }
80
+
81
+ # optionally configure the plugins in a before_app_loads callback
82
+
83
+ Merb::BootLoader.before_app_loads do
84
+
85
+ Merb::Slices::config[:merb_slice_sms][:option] = value
86
+
87
+ end
88
+
89
+ file: config/router.rb
90
+
91
+ # example: /merb_slice_sms/:controller/:action/:id
92
+
93
+ add_slice(:MerbSliceSms)
94
+
95
+ # example: /foo/:controller/:action/:id
96
+
97
+ add_slice(:MerbSliceSms, 'foo') # same as :path => 'foo'
98
+
99
+ # example: /:lang/:controller/:action/:id
100
+
101
+ add_slice(:MerbSliceSms, :path => ':lang')
102
+
103
+ # example: /:controller/:action/:id
104
+
105
+ slice(:MerbSliceSms)
106
+
107
+ Normally you should also run the following rake task:
108
+
109
+ rake slices:merb_slice_sms:install
110
+
111
+ ------------------------------------------------------------------------------
112
+
113
+ You can put your application-level overrides in:
114
+
115
+ host-app/slices/merb-slice-sms/app - controllers, models, views ...
116
+
117
+ Templates are located in this order:
118
+
119
+ 1. host-app/slices/merb-slice-sms/app/views/*
120
+ 2. gems/merb-slice-sms/app/views/*
121
+ 3. host-app/app/views/*
122
+
123
+ You can use the host application's layout by configuring the
124
+ merb-slice-sms slice in a before_app_loads block:
125
+
126
+ Merb::Slices.config[:merb_slice_sms] = { :layout => :application }
127
+
128
+ By default :merb_slice_sms is used. If you need to override
129
+ stylesheets or javascripts, just specify your own files in your layout
130
+ instead/in addition to the ones supplied (if any) in
131
+ host-app/public/slices/merb-slice-sms.
132
+
133
+ In any case don't edit those files directly as they may be clobbered any time
134
+ rake merb_slice_sms:install is run.
135
+
136
+ ------------------------------------------------------------------------------
137
+
138
+ About Slices
139
+ ============
140
+
141
+ Merb-Slices is a Merb plugin for using and creating application 'slices' which
142
+ help you modularize your application. Usually these are reuseable extractions
143
+ from your main app. In effect, a Slice is just like a regular Merb MVC
144
+ application, both in functionality as well as in structure.
145
+
146
+ When you generate a Slice stub structure, a module is setup to serve as a
147
+ namespace for your controller, models, helpers etc. This ensures maximum
148
+ encapsulation. You could say a Slice is a mixture between a Merb plugin (a
149
+ Gem) and a Merb application, reaping the benefits of both.
150
+
151
+ A host application can 'mount' a Slice inside the router, which means you have
152
+ full over control how it integrates. By default a Slice's routes are prefixed
153
+ by its name (a router :namespace), but you can easily provide your own prefix
154
+ or leave it out, mounting it at the root of your url-schema. You can even
155
+ mount a Slice multiple times and give extra parameters to customize an
156
+ instance's behaviour.
157
+
158
+ A Slice's Application controller uses controller_for_slice to setup slice
159
+ specific behaviour, which mainly affects cascaded view handling. Additionaly,
160
+ this method is available to any kind of controller, so it can be used for
161
+ Merb Mailer too for example.
162
+
163
+ There are many ways which let you customize a Slice's functionality and
164
+ appearance without ever touching the Gem-level code itself. It's not only easy
165
+ to add template/layout overrides, you can also add/modify controllers, models
166
+ and other runtime code from within the host application.
167
+
168
+ To create your own Slice run this (somewhere outside of your merb app):
169
+
170
+ $ merb-gen slice <your-lowercase-slice-name>
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ require 'merb-core'
5
+ require 'merb-core/tasks/merb'
6
+
7
+ GEM_NAME = "merb-slice-sms"
8
+ AUTHOR = "Justin Smestad"
9
+ EMAIL = "justin.smestad@gmail.com"
10
+ HOMEPAGE = "http://www.evalcode.com/"
11
+ SUMMARY = "Merb Slice that provides ability to send sms messages to mobile devices"
12
+ GEM_VERSION = "0.1"
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.rubyforge_project = 'merb'
16
+ s.name = GEM_NAME
17
+ s.version = GEM_VERSION
18
+ s.platform = Gem::Platform::RUBY
19
+ s.has_rdoc = true
20
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
21
+ s.summary = SUMMARY
22
+ s.description = s.summary
23
+ s.author = AUTHOR
24
+ s.email = EMAIL
25
+ s.homepage = HOMEPAGE
26
+ s.add_dependency('merb-slices', '>= 1.0.4')
27
+ s.require_path = 'lib'
28
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec,app,public,stubs}/**/*")
29
+ end
30
+
31
+ Rake::GemPackageTask.new(spec) do |pkg|
32
+ pkg.gem_spec = spec
33
+ end
34
+
35
+ desc "Install the gem"
36
+ task :install do
37
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
38
+ end
39
+
40
+ desc "Uninstall the gem"
41
+ task :uninstall do
42
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
43
+ end
44
+
45
+ desc "Create a gemspec file"
46
+ task :gemspec do
47
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
48
+ file.puts spec.to_ruby
49
+ end
50
+ end
51
+
52
+ require 'spec/rake/spectask'
53
+ require 'merb-core/test/tasks/spectasks'
54
+ desc 'Default: run spec examples'
55
+ task :default => 'spec'
data/TODO ADDED
@@ -0,0 +1,12 @@
1
+ TODO:
2
+
3
+ - Add your code to lib/merb-slice-sms.rb
4
+ - Add your Merb rake tasks to lib/merb-slice-sms/merbtasks.rb
5
+
6
+ Remove anything that you don't need:
7
+
8
+ - app/controllers/main.rb MerbSliceSms::Main controller
9
+ - app/views/layout/merb-slice-sms.html.erb
10
+ - spec/controllers/main_spec.rb controller specs
11
+ - public/* any public files
12
+ - stubs/* any stub files
@@ -0,0 +1,5 @@
1
+ class MerbSliceSms::Application < Merb::Controller
2
+
3
+ controller_for_slice
4
+
5
+ end
@@ -0,0 +1,64 @@
1
+ module Merb
2
+ module MerbSliceSms
3
+ module ApplicationHelper
4
+
5
+ # @param *segments<Array[#to_s]> Path segments to append.
6
+ #
7
+ # @return <String>
8
+ # A path relative to the public directory, with added segments.
9
+ def image_path(*segments)
10
+ public_path_for(:image, *segments)
11
+ end
12
+
13
+ # @param *segments<Array[#to_s]> Path segments to append.
14
+ #
15
+ # @return <String>
16
+ # A path relative to the public directory, with added segments.
17
+ def javascript_path(*segments)
18
+ public_path_for(:javascript, *segments)
19
+ end
20
+
21
+ # @param *segments<Array[#to_s]> Path segments to append.
22
+ #
23
+ # @return <String>
24
+ # A path relative to the public directory, with added segments.
25
+ def stylesheet_path(*segments)
26
+ public_path_for(:stylesheet, *segments)
27
+ end
28
+
29
+ # Construct a path relative to the public directory
30
+ #
31
+ # @param <Symbol> The type of component.
32
+ # @param *segments<Array[#to_s]> Path segments to append.
33
+ #
34
+ # @return <String>
35
+ # A path relative to the public directory, with added segments.
36
+ def public_path_for(type, *segments)
37
+ ::MerbSliceSms.public_path_for(type, *segments)
38
+ end
39
+
40
+ # Construct an app-level path.
41
+ #
42
+ # @param <Symbol> The type of component.
43
+ # @param *segments<Array[#to_s]> Path segments to append.
44
+ #
45
+ # @return <String>
46
+ # A path within the host application, with added segments.
47
+ def app_path_for(type, *segments)
48
+ ::MerbSliceSms.app_path_for(type, *segments)
49
+ end
50
+
51
+ # Construct a slice-level path.
52
+ #
53
+ # @param <Symbol> The type of component.
54
+ # @param *segments<Array[#to_s]> Path segments to append.
55
+ #
56
+ # @return <String>
57
+ # A path within the slice source (Gem), with added segments.
58
+ def slice_path_for(type, *segments)
59
+ ::MerbSliceSms.slice_path_for(type, *segments)
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,10 @@
1
+ class MerbSliceSms::SmsMailer < Merb::MailController
2
+
3
+ #controller_for_slice MerbSliceSms, :templates_for => :mailer, :path => 'views'
4
+
5
+ def alert
6
+ @message = params[:body]
7
+ Merb.logger.info "Text message sent."
8
+ render_mail
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ <%= @message %>
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5
+ <title>Fresh MerbSliceSms Slice</title>
6
+ <link href="<%= public_path_for :stylesheet, 'master.css' %>" type="text/css" charset="utf-8" rel="stylesheet" media="all" />
7
+ <script src="<%= public_path_for :javascript, 'master.js' %>" type="text/javascript" charset="utf-8"></script>
8
+ </head>
9
+ <!-- you can override this layout at slices/merb-slice-sms/app/views/layout/merb-slice-sms.html.erb -->
10
+ <body class="merb-slice-sms-slice">
11
+ <div id="container">
12
+ <h1>MerbSliceSms Slice</h1>
13
+ <div id="main"><%= catch_content :for_layout %></div>
14
+ </div>
15
+ </body>
16
+ </html>
@@ -0,0 +1,88 @@
1
+ if defined?(Merb::Plugins)
2
+
3
+ $:.unshift File.dirname(__FILE__)
4
+ dependency 'merb-slices', :immediate => true
5
+ dependency 'merb-mailer', "~> 1.0"
6
+
7
+ Merb::Plugins.add_rakefiles "merb-slice-sms/merbtasks", "merb-slice-sms/slicetasks", "merb-slice-sms/spectasks"
8
+
9
+ # Register the Slice for the current host application
10
+ Merb::Slices::register(__FILE__)
11
+
12
+ # Slice configuration - set this in a before_app_loads callback.
13
+ # By default a Slice uses its own layout, so you can swicht to
14
+ # the main application layout or no layout at all if needed.
15
+ #
16
+ # Configuration options:
17
+ # :layout - the layout to use; defaults to :merb-slice-sms
18
+ # :mirror - which path component types to use on copy operations; defaults to all
19
+ Merb::Slices::config[:merb_slice_sms][:layout] ||= :application
20
+
21
+ Merb::BootLoader.before_app_loads do
22
+ # require code that must be loaded before the application
23
+ require(File.expand_path(File.dirname(__FILE__) / "merb-slice-sms") / "sms_helper")
24
+ end
25
+
26
+ # All Slice code is expected to be namespaced inside a module
27
+ module MerbSliceSms
28
+
29
+ # Slice metadata
30
+ self.description = "MerbSliceSms adds SMS messaging to mobile devices for any merb-powered application."
31
+ self.version = "0.2"
32
+ self.author = "Justin Smestad"
33
+
34
+ # Stub classes loaded hook - runs before LoadClasses BootLoader
35
+ # right after a slice's classes have been loaded internally.
36
+ def self.loaded
37
+ end
38
+
39
+ # Initialization hook - runs before AfterAppLoads BootLoader
40
+ def self.init
41
+ end
42
+
43
+ # Activation hook - runs after AfterAppLoads BootLoader
44
+ def self.activate
45
+ end
46
+
47
+ # Deactivation hook - triggered by Merb::Slices.deactivate(MerbSliceSms)
48
+ def self.deactivate
49
+ end
50
+
51
+ # Setup routes inside the host application
52
+ #
53
+ # @param scope<Merb::Router::Behaviour>
54
+ # Routes will be added within this scope (namespace). In fact, any
55
+ # router behaviour is a valid namespace, so you can attach
56
+ # routes at any level of your router setup.
57
+ #
58
+ # @note prefix your named routes with :merb_slice_sms_
59
+ # to avoid potential conflicts with global named routes.
60
+ def self.setup_router(scope)
61
+ # example of a named route
62
+ # scope.match('/index(.:format)').to(:controller => 'main', :action => 'index').name(:index)
63
+ # the slice is mounted at /merb-slice-sms - note that it comes before default_routes
64
+ # scope.match('/').to(:controller => 'main', :action => 'index').name(:home)
65
+ # enable slice-level default routes by default
66
+ # scope.default_routes
67
+ end
68
+
69
+ end
70
+
71
+ # Setup the slice layout for MerbSliceSms
72
+ #
73
+ # Use MerbSliceSms.push_path and MerbSliceSms.push_app_path
74
+ # to set paths to merb-slice-sms-level and app-level paths. Example:
75
+ #
76
+ # MerbSliceSms.push_path(:application, MerbSliceSms.root)
77
+ # MerbSliceSms.push_app_path(:application, Merb.root / 'slices' / 'merb-slice-sms')
78
+ # ...
79
+ #
80
+ # Any component path that hasn't been set will default to MerbSliceSms.root
81
+ #
82
+ # Or just call setup_default_structure! to setup a basic Merb MVC structure.
83
+ MerbSliceSms.setup_default_structure!
84
+
85
+ # Add dependencies for other MerbSliceSms classes below. Example:
86
+ # dependency "merb-slice-sms/other"
87
+
88
+ end
@@ -0,0 +1,103 @@
1
+ namespace :slices do
2
+ namespace :merb_slice_sms do
3
+
4
+ desc "Install MerbSliceSms"
5
+ task :install => [:preflight, :setup_directories, :copy_assets, :migrate]
6
+
7
+ desc "Test for any dependencies"
8
+ task :preflight do # see slicetasks.rb
9
+ end
10
+
11
+ desc "Setup directories"
12
+ task :setup_directories do
13
+ puts "Creating directories for host application"
14
+ MerbSliceSms.mirrored_components.each do |type|
15
+ if File.directory?(MerbSliceSms.dir_for(type))
16
+ if !File.directory?(dst_path = MerbSliceSms.app_dir_for(type))
17
+ relative_path = dst_path.relative_path_from(Merb.root)
18
+ puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}"
19
+ mkdir_p(dst_path)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ desc "Copy stub files to host application"
26
+ task :stubs do
27
+ puts "Copying stubs for MerbSliceSms - resolves any collisions"
28
+ copied, preserved = MerbSliceSms.mirror_stubs!
29
+ puts "- no files to copy" if copied.empty? && preserved.empty?
30
+ copied.each { |f| puts "- copied #{f}" }
31
+ preserved.each { |f| puts "! preserved override as #{f}" }
32
+ end
33
+
34
+ desc "Copy stub files and views to host application"
35
+ task :patch => [ "stubs", "freeze:views" ]
36
+
37
+ desc "Copy public assets to host application"
38
+ task :copy_assets do
39
+ puts "Copying assets for MerbSliceSms - resolves any collisions"
40
+ copied, preserved = MerbSliceSms.mirror_public!
41
+ puts "- no files to copy" if copied.empty? && preserved.empty?
42
+ copied.each { |f| puts "- copied #{f}" }
43
+ preserved.each { |f| puts "! preserved override as #{f}" }
44
+ end
45
+
46
+ desc "Migrate the database"
47
+ task :migrate do # see slicetasks.rb
48
+ end
49
+
50
+ desc "Freeze MerbSliceSms into your app (only merb-slice-sms/app)"
51
+ task :freeze => [ "freeze:app" ]
52
+
53
+ namespace :freeze do
54
+
55
+ desc "Freezes MerbSliceSms by installing the gem into application/gems"
56
+ task :gem do
57
+ ENV["GEM"] ||= "merb-slice-sms"
58
+ Rake::Task['slices:install_as_gem'].invoke
59
+ end
60
+
61
+ desc "Freezes MerbSliceSms by copying all files from merb-slice-sms/app to your application"
62
+ task :app do
63
+ puts "Copying all merb-slice-sms/app files to your application - resolves any collisions"
64
+ copied, preserved = MerbSliceSms.mirror_app!
65
+ puts "- no files to copy" if copied.empty? && preserved.empty?
66
+ copied.each { |f| puts "- copied #{f}" }
67
+ preserved.each { |f| puts "! preserved override as #{f}" }
68
+ end
69
+
70
+ desc "Freeze all views into your application for easy modification"
71
+ task :views do
72
+ puts "Copying all view templates to your application - resolves any collisions"
73
+ copied, preserved = MerbSliceSms.mirror_files_for :view
74
+ puts "- no files to copy" if copied.empty? && preserved.empty?
75
+ copied.each { |f| puts "- copied #{f}" }
76
+ preserved.each { |f| puts "! preserved override as #{f}" }
77
+ end
78
+
79
+ desc "Freeze all models into your application for easy modification"
80
+ task :models do
81
+ puts "Copying all models to your application - resolves any collisions"
82
+ copied, preserved = MerbSliceSms.mirror_files_for :model
83
+ puts "- no files to copy" if copied.empty? && preserved.empty?
84
+ copied.each { |f| puts "- copied #{f}" }
85
+ preserved.each { |f| puts "! preserved override as #{f}" }
86
+ end
87
+
88
+ desc "Freezes MerbSliceSms as a gem and copies over merb-slice-sms/app"
89
+ task :app_with_gem => [:gem, :app]
90
+
91
+ desc "Freezes MerbSliceSms by unpacking all files into your application"
92
+ task :unpack do
93
+ puts "Unpacking MerbSliceSms files to your application - resolves any collisions"
94
+ copied, preserved = MerbSliceSms.unpack_slice!
95
+ puts "- no files to copy" if copied.empty? && preserved.empty?
96
+ copied.each { |f| puts "- copied #{f}" }
97
+ preserved.each { |f| puts "! preserved override as #{f}" }
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,18 @@
1
+ namespace :slices do
2
+ namespace :merb_slice_sms do
3
+
4
+ # add your own merb-slice-sms tasks here
5
+
6
+ # implement this to test for structural/code dependencies
7
+ # like certain directories or availability of other files
8
+ desc "Test for any dependencies"
9
+ task :preflight do
10
+ end
11
+
12
+ # implement this to perform any database related setup steps
13
+ desc "Migrate the database"
14
+ task :migrate do
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ require 'yaml'
2
+
3
+ module Merb
4
+ module SmsHelper
5
+ include Merb::MailerMixin
6
+ carriers_file = File.dirname(__FILE__) / ".." / ".." / "config" / "carriers.yml"
7
+ $CARRIERS ||= YAML::load_file(carriers_file)['carriers']
8
+
9
+ def self.send_sms(number, provider, message, options = {})
10
+ raise SMSException.new("Cannot send blank messages") if message.nil? || message.empty?
11
+
12
+ options[:from] ||= MerbSliceSms[:from_address]
13
+ options[:limit] ||= message.length
14
+ message = message[0..options[:limit]-1]
15
+
16
+ number = number.gsub("-","").strip
17
+ raise SMSException.new("Invalid number, must be 10 digits") if number.length != 10
18
+
19
+ address = generate_email(number, provider)
20
+
21
+ ::MerbSliceSms::SmsMailer.dispatch_and_deliver(
22
+ :alert, {
23
+ #:from => options[:from],
24
+ :to => address,
25
+ :html => message
26
+ })
27
+ end
28
+
29
+ def self.generate_email(number, provider)
30
+ if $CARRIERS.has_key?(provider.downcase)
31
+ "#{number}#{$CARRIERS[provider.downcase]}"
32
+ else
33
+ raise SMSException.new("Provider, #{provider}, was not found.")
34
+ end
35
+ end
36
+
37
+ class SMSException < StandardError; end
38
+ end
39
+ end
@@ -0,0 +1,65 @@
1
+ namespace :slices do
2
+ namespace :merb_slice_sms do
3
+
4
+ desc "Run slice specs within the host application context"
5
+ task :spec => [ "spec:explain", "spec:default" ]
6
+
7
+ namespace :spec do
8
+
9
+ slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
10
+
11
+ task :explain do
12
+ puts "\nNote: By running MerbSliceSms specs inside the application context any\n" +
13
+ "overrides could break existing specs. This isn't always a problem,\n" +
14
+ "especially in the case of views. Use these spec tasks to check how\n" +
15
+ "well your application conforms to the original slice implementation."
16
+ end
17
+
18
+ Spec::Rake::SpecTask.new('default') do |t|
19
+ t.spec_opts = ["--format", "specdoc", "--colour"]
20
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
21
+ end
22
+
23
+ desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel"
24
+ Spec::Rake::SpecTask.new('model') do |t|
25
+ t.spec_opts = ["--format", "specdoc", "--colour"]
26
+ if(ENV['MODEL'])
27
+ t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort
28
+ else
29
+ t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort
30
+ end
31
+ end
32
+
33
+ desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController"
34
+ Spec::Rake::SpecTask.new('controller') do |t|
35
+ t.spec_opts = ["--format", "specdoc", "--colour"]
36
+ if(ENV['CONTROLLER'])
37
+ t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort
38
+ else
39
+ t.spec_files = Dir["#{slice_root}/spec/controllers/**/*_spec.rb"].sort
40
+ end
41
+ end
42
+
43
+ desc "Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)"
44
+ Spec::Rake::SpecTask.new('view') do |t|
45
+ t.spec_opts = ["--format", "specdoc", "--colour"]
46
+ if(ENV['CONTROLLER'] and ENV['VIEW'])
47
+ t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb"].sort
48
+ elsif(ENV['CONTROLLER'])
49
+ t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb"].sort
50
+ else
51
+ t.spec_files = Dir["#{slice_root}/spec/views/**/*_spec.rb"].sort
52
+ end
53
+ end
54
+
55
+ desc "Run all specs and output the result in html"
56
+ Spec::Rake::SpecTask.new('html') do |t|
57
+ t.spec_opts = ["--format", "html"]
58
+ t.libs = ['lib', 'server/lib' ]
59
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ html, body { margin: 0; padding: 0; }
2
+ #container { width: 800px; margin: 4em auto; padding: 4em 4em 6em 4em; background: #DDDDDD; }
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
+
3
+ describe MerbSliceSms::SmsMailer do
4
+ include MailControllerTestHelper
5
+ include Merb::SmsHelper
6
+
7
+ before :each do
8
+ clear_mail_deliveries
9
+ end
10
+
11
+ describe "defined helper methods" do
12
+
13
+ it 'generate_email should generate valid emails' do
14
+ result = Merb::SmsHelper.generate_email('8476519755', 'verizon')
15
+ result.should == '8476519755@vtext.com'
16
+ end
17
+
18
+ it 'send_sms should send email' do
19
+ @mail = Merb::SmsHelper.send_sms('8476519755', 'verizon', 'hey dude', {:from => 'justin@smestad.com'})
20
+ Merb::Mailer.deliveries.should_not be_empty
21
+ #@mail = last_delivered_mail
22
+ #@mail.to.should_not be_nil #== '8476519755@vtext.com'
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "MerbSliceSms (module)" do
4
+
5
+ # Implement your MerbSliceSms specs here
6
+
7
+ # it "should have proper specs"
8
+
9
+ # To spec MerbSliceSms you need to hook it up to the router like this:
10
+
11
+ # before :all do
12
+ # Merb::Router.prepare { add_slice(:MerbSliceSms) } if standalone?
13
+ # end
14
+ #
15
+ # after :all do
16
+ # Merb::Router.reset! if standalone?
17
+ # end
18
+
19
+ end
@@ -0,0 +1,75 @@
1
+ require 'rubygems'
2
+ require 'merb-core'
3
+ require 'spec'
4
+ dependency 'merb-slices'
5
+ dependency 'merb-mailer'
6
+
7
+ # Add merb-slice-sms.rb to the search path
8
+ Merb::Plugins.config[:merb_slices][:auto_register] = true
9
+ Merb::Plugins.config[:merb_slices][:search_path] = File.join(File.dirname(__FILE__), '..', 'lib', 'merb-slice-sms.rb')
10
+
11
+ # Require merb-slice-sms.rb explicitly so any dependencies are loaded
12
+ require Merb::Plugins.config[:merb_slices][:search_path]
13
+
14
+ # Using Merb.root below makes sure that the correct root is set for
15
+ # - testing standalone, without being installed as a gem and no host application
16
+ # - testing from within the host application; its root will be used
17
+ Merb.start_environment(
18
+ :testing => true,
19
+ :adapter => 'runner',
20
+ :environment => ENV['MERB_ENV'] || 'test',
21
+ :session_store => 'memory'
22
+ )
23
+
24
+ Merb::Mailer.config = {:sendmail_path => '/usr/sbin/sendmail'}
25
+ Merb::Mailer.delivery_method = :sendmail
26
+
27
+ class Merb::Mailer
28
+ self.delivery_method = :test_send
29
+ end
30
+
31
+ module Merb
32
+ module Test
33
+ module SliceHelper
34
+ #include Merb::SmsHelper
35
+
36
+ # The absolute path to the current slice
37
+ def current_slice_root
38
+ @current_slice_root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
39
+ end
40
+
41
+ # Whether the specs are being run from a host application or standalone
42
+ def standalone?
43
+ Merb.root == ::MerbSliceSms.root
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+
50
+ module MailControllerTestHelper
51
+ # Helper to clear mail deliveries.
52
+ def clear_mail_deliveries
53
+ Merb::Mailer.deliveries.clear
54
+ end
55
+
56
+ # Helper to access last delivered mail.
57
+ # In test mode merb-mailer puts email to
58
+ # collection accessible as Merb::Mailer.deliveries.
59
+ def last_delivered_mail
60
+ Merb::Mailer.deliveries.last
61
+ end
62
+
63
+ # Helper to deliver
64
+ def deliver(action, mail_params = {}, send_params = {})
65
+ MerbSliceSms::SmsMailer.dispatch_and_deliver(action, { :from => "no-reply@webapp.com", :to => "recepient@person.com" }.merge(mail_params), send_params)
66
+ @delivery = last_delivered_mail
67
+ end
68
+ end
69
+
70
+ Spec::Runner.configure do |config|
71
+ config.include(Merb::Test::ViewHelper)
72
+ config.include(Merb::Test::RouteHelper)
73
+ config.include(Merb::Test::ControllerHelper)
74
+ config.include(Merb::Test::SliceHelper)
75
+ end
@@ -0,0 +1,2 @@
1
+ class MerbSliceSms::Application < Merb::Controller
2
+ end
@@ -0,0 +1,2 @@
1
+ class MerbSliceSms::Main < MerbSliceSms::Application
2
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsmestad-merb-slice-sms
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Justin Smestad
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-10 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-slices
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.4
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: merb-mailer
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: "1.0"
32
+ version:
33
+ description: Merb Slice that provides ability to send sms messages to mobile devices
34
+ email: justin.smestad@gmail.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README
41
+ - LICENSE
42
+ - TODO
43
+ files:
44
+ - LICENSE
45
+ - README
46
+ - Rakefile
47
+ - TODO
48
+ - lib/merb-slice-sms
49
+ - lib/merb-slice-sms/merbtasks.rb
50
+ - lib/merb-slice-sms/slicetasks.rb
51
+ - lib/merb-slice-sms/sms_helper.rb
52
+ - lib/merb-slice-sms/spectasks.rb
53
+ - lib/merb-slice-sms.rb
54
+ - spec/controllers
55
+ - spec/log
56
+ - spec/log/merb.main.pid
57
+ - spec/log/merb_test.log
58
+ - spec/mailers
59
+ - spec/mailers/sms_mailer_spec.rb
60
+ - spec/merb-slice-sms_spec.rb
61
+ - spec/spec_helper.rb
62
+ - app/controllers
63
+ - app/controllers/application.rb
64
+ - app/helpers
65
+ - app/helpers/application_helper.rb
66
+ - app/mailers
67
+ - app/mailers/sms_mailer.rb
68
+ - app/mailers/views
69
+ - app/mailers/views/sms_mailer
70
+ - app/mailers/views/sms_mailer/alert.text.erb
71
+ - app/views
72
+ - app/views/layout
73
+ - app/views/layout/merb_slice_sms.html.erb
74
+ - public/javascripts
75
+ - public/javascripts/master.js
76
+ - public/stylesheets
77
+ - public/stylesheets/master.css
78
+ - stubs/app
79
+ - stubs/app/controllers
80
+ - stubs/app/controllers/application.rb
81
+ - stubs/app/controllers/main.rb
82
+ has_rdoc: true
83
+ homepage: http://www.evalcode.com/
84
+ post_install_message:
85
+ rdoc_options: []
86
+
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
100
+ version:
101
+ requirements: []
102
+
103
+ rubyforge_project: merb
104
+ rubygems_version: 1.2.0
105
+ signing_key:
106
+ specification_version: 2
107
+ summary: Merb Slice that provides ability to send sms messages to mobile devices
108
+ test_files: []
109
+