merb_signupto 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 YOUR NAME
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,4 @@
1
+ merb_signupto
2
+ =================
3
+
4
+ A plugin for the Merb framework that provides ....
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'lib/merb_signupto/version'
4
+
5
+ PLUGIN = "merb_signupto"
6
+ NAME = "merb_signupto"
7
+ AUTHOR = "Tim Perrett"
8
+ EMAIL = "hello@timperrett.com"
9
+ HOMEPAGE = "http://blog.timperrett.com"
10
+ SUMMARY = "Merb plugin that provides intergrated connectivity to the signupto SMS gateway"
11
+
12
+ spec = Gem::Specification.new do |s|
13
+ s.name = NAME
14
+ s.version = MerbSignupto::Version::STRING
15
+ s.platform = Gem::Platform::RUBY
16
+ s.has_rdoc = true
17
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
18
+ s.summary = SUMMARY
19
+ s.description = s.summary
20
+ s.author = AUTHOR
21
+ s.email = EMAIL
22
+ s.homepage = HOMEPAGE
23
+ s.add_dependency('merb', '>= 0.4.0')
24
+ s.add_dependency('signupto', '>= 0.0.2')
25
+ s.require_path = 'lib'
26
+ s.autorequire = PLUGIN
27
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec,merb_generators}/**/*")
28
+ end
29
+
30
+ Rake::GemPackageTask.new(spec) do |pkg|
31
+ pkg.gem_spec = spec
32
+ end
33
+
34
+ task :install => [:package] do
35
+ sh %{sudo gem install pkg/#{NAME}-#{VERSION}}
36
+ end
data/TODO ADDED
@@ -0,0 +1,5 @@
1
+ TODO:
2
+ Fix LICENSE with your name
3
+ Fix Rakefile with your name and contact info
4
+ Add your code to lib/merb_signupto.rb
5
+ Add your Merb rake tasks to lib/merb_signupto/merbtasks.rb
@@ -0,0 +1,79 @@
1
+ module Merb
2
+
3
+ # The SMS controller lets you send text messages seamlessly from within merb
4
+ # to get started add a dependency to your new merb application then do:
5
+ #
6
+ # $ rake signupto:setup
7
+ #
8
+ # This then generates a configuration file where you must fill it in with
9
+ # your signup.to account details. These are global configurations for the applications.
10
+ #
11
+ # Next, generate a new sms controller like so:
12
+ #
13
+ # $ script/generate signupto_controller Demo my_method some_thing another
14
+ #
15
+ # In the above command, "Demo" is the name of the class, and the others are actions
16
+ # within our controller. Once you have your newly created class, you can call the sms
17
+ # methods from your main controllers.
18
+ #
19
+ # def index
20
+ # send_sms(ExampleMessenger, :some_method, { :from => '02UK', :to => '4445265485' })
21
+ # end
22
+ #
23
+ # send_sms(KlassYouWantToCall, :method_on_class, {})
24
+ #
25
+ # paramater 3 is an options hash, of which valid options are:
26
+ # :to => "recipeitns phone number" (string, -)
27
+ # :from => 'from' that will appear on recipient mobile (string, 12)
28
+ #
29
+ class SmsController < AbstractController
30
+
31
+ self._template_root = File.expand_path(self._template_root / "../messages/views")
32
+ class_inheritable_accessor :_sms_klass
33
+ self._sms_klass = Signupto::Action::Sender
34
+
35
+ attr_accessor :params, :mailer, :mail
36
+ attr_reader :session, :base_controller
37
+
38
+ # You can initialize an SmsController with a series of parameters that can
39
+ # be used by methods in the class. You can also pass in a controller
40
+ # object, which will be available to the SmsController methods as
41
+ # base_controller.
42
+ def initialize(params = {}, controller = nil)
43
+ @params = params
44
+ @base_controller = controller
45
+ @session = (controller && controller.session) || {}
46
+ super
47
+ end
48
+
49
+ def render_sms(options = @method)
50
+ @_missing_templates = false # used to make sure that at least one template was found
51
+ value = render({:format=>:text, :clean_context=>true, :text => @method, :layout => :none})
52
+ @message_options = {:body => value}
53
+ end
54
+
55
+ # Builds the message and account objects from the global configs
56
+ # and merges them with the paramates passed in from the main
57
+ # application controller send_sms call.
58
+ def dispatch_and_deliver(method, sms_params)
59
+ @method = method
60
+ # run the method in the subclass which in turn calls
61
+ # the render_sms method defined above
62
+ dispatch(method)
63
+ # take ther result and merge it with the options passed
64
+ # in from the application controller subclass
65
+ @message_options.merge!(sms_params)
66
+ sms_message = Signupto::Message.new(@message_options[:to], @message_options[:body], @message_options[:from])
67
+ global_config = Merb::Plugins.config[:merb_signupto]
68
+ sms_account = Signupto::Account.new(global_config[:account_hash], global_config[:customer_number])
69
+ if sms_message
70
+ begin
71
+ self.class._sms_klass.new(sms_account, sms_message)
72
+ rescue => e
73
+ MERB_LOGGER.error(e)
74
+ end
75
+ end
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,26 @@
1
+ module MerbSignupto
2
+ class Configurator
3
+
4
+ # Attempt to load in the YAML formated configuration file which
5
+ # should be located in config/uproduce.yml. If no file exsists,
6
+ # you will need to run rake xmpie_icp:setup to get the stub configuration
7
+ def self.load_config_from_file
8
+ if defined?(::Merb::Server)
9
+ if ::Merb::Server.config[:merb_root]
10
+ signupto_file_path = File.join(::Merb::Server.config[:merb_root],'config','signupto.yml')
11
+ if FileTest.exist?(signupto_file_path)
12
+ return YAML.load_file(signupto_file_path)
13
+ else
14
+ puts "##############################"
15
+ puts "Signupto configuration missing"
16
+ puts "##############################"
17
+ # exit()
18
+ end
19
+ else
20
+ puts "[signupto] Running outside of the merb container..."
21
+ end
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ module MerbSignupto
2
+ module ControllerExtension
3
+
4
+ # you can now call this in any of your ordinary controllers like so:
5
+ #
6
+ # def index
7
+ # send_sms(ExampleMessenger, :some_method, { :from => '02UK', :to => '4445265485' })
8
+ # end
9
+ #
10
+ # You must use international format for your phone numbers, rather than using +44 or 078
11
+ # for example.
12
+ #
13
+ # for more information on how to use the SmsController please see the docs
14
+ # in sms_controller.rb
15
+ def send_sms(klass, method, mail_params, send_params = nil)
16
+ klass.new(send_params || params, self).dispatch_and_deliver(method, mail_params)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ namespace :signupto do
2
+ desc "Create a stub uProduce config file"
3
+ task :setup do
4
+ uproduce_config = File.join(MERB_ROOT, 'config','signupto.yml')
5
+ unless File.exist?(uproduce_config)
6
+ File.open(uproduce_config, 'w') do |f|
7
+ f.puts %{# Please fill in valid details below, and ensure
8
+ # that you have set your IP in the signup.to dashboard before you
9
+ # attempt to start sending SMS from your application
10
+ account_hash: "your_account_has"
11
+ customer_number: "your_customer_number"
12
+ }
13
+
14
+ puts "############################"
15
+ puts "CONFIG FILE HAS BEEN CREATED"
16
+ puts "############################"
17
+
18
+ end
19
+ else
20
+ puts "############################"
21
+ puts "CONFIG FILE ALREADY EXSISTS"
22
+ puts "############################"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ module MerbSignupto
2
+ module Version #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 4
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
10
+
@@ -0,0 +1,28 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ # make sure we're running inside Merb
5
+ if defined?(Merb::Plugins)
6
+ if defined?(MERB_PATHS)
7
+ MERB_PATHS.pop
8
+ MERB_PATHS << '/app/messages/**/*.rb'
9
+ MERB_PATHS << "/config/router.rb"
10
+ end
11
+
12
+ require 'merb_signupto/controller_extension'
13
+ require 'merb/sms_controller'
14
+ require 'merb_signupto/configurator'
15
+
16
+ Merb::Controller.class_eval do
17
+ include MerbSignupto::ControllerExtension
18
+ end
19
+
20
+ # load in the configuration from the YAML file
21
+ merb_comfig = MerbSignupto::Configurator.load_config_from_file()
22
+ Merb::Plugins.config[:merb_signupto] = {
23
+ :account_hash => merb_comfig['account_hash'],
24
+ :customer_number => merb_comfig['customer_number']
25
+ }
26
+
27
+ Merb::Plugins.add_rakefiles "merb_signupto/tasks/merbtasks"
28
+ end
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,59 @@
1
+ class SignuptoControllerGenerator < RubiGen::Base
2
+
3
+ attr_reader :name
4
+
5
+ def initialize(*runtime_args)
6
+ super
7
+ usage if runtime_args.empty?
8
+ argument_array = runtime_args.flatten
9
+ input_name = argument_array.slice!(0).snake_case.to_const_string
10
+ @class_name = "#{input_name}Messenger"
11
+ @actions = argument_array.delete_if {|i| i.is_a?(Hash) }
12
+ end
13
+
14
+ def manifest
15
+ record do |m|
16
+ filename = @class_name.snake_case
17
+ # Ensure appropriate folder(s) exists
18
+ m.directory File.join('app','messages','views')
19
+ m.directory File.join('app','messages','views', filename)
20
+ m.template 'signupto_controller_template.rb',
21
+ File.join('app','messages',"#{filename}.rb"),
22
+ :assigns => { :class_name => @class_name, :actions => @actions }
23
+ for method in @actions
24
+ m.template 'sms_message_template.text.erb',
25
+ File.join('app','messages','views',filename,"#{method.snake_case}.text.erb"),
26
+ :assigns => { :method_name => method }
27
+ end
28
+
29
+
30
+ end
31
+ end
32
+
33
+ protected
34
+ def banner
35
+ <<-EOS
36
+ Creates a ...
37
+
38
+ USAGE: #{$0} #{spec.name} name"
39
+ EOS
40
+ end
41
+
42
+ def add_options!(opts)
43
+ # opts.separator ''
44
+ # opts.separator 'Options:'
45
+ # For each option below, place the default
46
+ # at the top of the file next to "default_options"
47
+ # opts.on("-a", "--author=\"Your Name\"", String,
48
+ # "Some comment about this option",
49
+ # "Default: none") { |options[:author]| }
50
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
51
+ end
52
+
53
+ def extract_options
54
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
55
+ # Templates can access these value via the attr_reader-generated methods, but not the
56
+ # raw instance variable value.
57
+ # @author = options[:author]
58
+ end
59
+ end
@@ -0,0 +1,7 @@
1
+ class <%= class_name %> < Merb::SmsController
2
+ <% for method in actions %>
3
+ def <%=method%>
4
+ render_sms
5
+ end
6
+ <% end %>
7
+ end
@@ -0,0 +1 @@
1
+ Stub message for <%= method_name %>
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "merb_signupto" do
4
+ it "should do nothing" do
5
+ true.should == true
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: merb_signupto
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.4
7
+ date: 2008-01-04 00:00:00 +00:00
8
+ summary: Merb plugin that provides intergrated connectivity to the signupto SMS gateway
9
+ require_paths:
10
+ - lib
11
+ email: hello@timperrett.com
12
+ homepage: http://blog.timperrett.com
13
+ rubyforge_project:
14
+ description: Merb plugin that provides intergrated connectivity to the signupto SMS gateway
15
+ autorequire: merb_signupto
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Tim Perrett
31
+ files:
32
+ - LICENSE
33
+ - README
34
+ - Rakefile
35
+ - TODO
36
+ - lib/merb
37
+ - lib/merb/sms_controller.rb
38
+ - lib/merb_signupto
39
+ - lib/merb_signupto/configurator.rb
40
+ - lib/merb_signupto/controller_extension.rb
41
+ - lib/merb_signupto/tasks
42
+ - lib/merb_signupto/tasks/merbtasks.rb
43
+ - lib/merb_signupto/version.rb
44
+ - lib/merb_signupto.rb
45
+ - spec/merb_signupto_spec.rb
46
+ - spec/spec_helper.rb
47
+ - merb_generators/signupto_controller
48
+ - merb_generators/signupto_controller/signupto_controller_generator.rb
49
+ - merb_generators/signupto_controller/templates
50
+ - merb_generators/signupto_controller/templates/signupto_controller_template.rb
51
+ - merb_generators/signupto_controller/templates/sms_message_template.text.erb
52
+ - merb_generators/signupto_controller/USAGE
53
+ test_files: []
54
+
55
+ rdoc_options: []
56
+
57
+ extra_rdoc_files:
58
+ - README
59
+ - LICENSE
60
+ - TODO
61
+ executables: []
62
+
63
+ extensions: []
64
+
65
+ requirements: []
66
+
67
+ dependencies:
68
+ - !ruby/object:Gem::Dependency
69
+ name: merb
70
+ version_requirement:
71
+ version_requirements: !ruby/object:Gem::Version::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.4.0
76
+ version:
77
+ - !ruby/object:Gem::Dependency
78
+ name: signupto
79
+ version_requirement:
80
+ version_requirements: !ruby/object:Gem::Version::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 0.0.2
85
+ version: