action_sms 0.0.1
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/.gitignore +3 -0
- data/MIT-LICENSE +21 -0
- data/README.markdown +45 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/action_sms.gemspec +54 -0
- data/lib/action_sms.rb +5 -0
- data/lib/action_sms/base.rb +11 -0
- data/lib/action_sms/connection_adapters.rb +2 -0
- data/lib/action_sms/connection_adapters/abstract_adapter.rb +46 -0
- data/lib/action_sms/connections.rb +64 -0
- data/lib/action_sms/exceptions.rb +24 -0
- data/lib/generators/action_sms/initializer/USAGE +6 -0
- data/lib/generators/action_sms/initializer/initializer_generator.rb +14 -0
- data/lib/generators/action_sms/initializer/templates/action_sms.rb +14 -0
- data/lib/generators/action_sms/notifier/USAGE +6 -0
- data/lib/generators/action_sms/notifier/notifier_generator.rb +14 -0
- data/lib/generators/action_sms/notifier/templates/sms_notifier.rb +3 -0
- data/todo +2 -0
- metadata +82 -0
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2010 David Wilkie
|
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.
|
21
|
+
|
data/README.markdown
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# action_sms
|
2
|
+
|
3
|
+
action_sms is a lightweight wrapper based on [activesms](http://github.com/nofxx/activesms). action_sms allows you to use existing SMS Gateway Adapters and switch between them effortlessly without modifing your application code. Unlike [activesms](http://github.com/nofxx/activesms), action_sms does not implement any SMS Gateway Adapters. For this see [action_sms_gateways](http://github.com/dwilkie/action_sms_gateways)
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
Establish a connection to your SMS Gateway Adapter:
|
7
|
+
|
8
|
+
ActionSms::Base.establish_connection(
|
9
|
+
:adapter => 'your_adapter',
|
10
|
+
# the remaining options are specific to the SMS Gateway Adapter
|
11
|
+
:username => '[username]',
|
12
|
+
:password => '[password]'
|
13
|
+
)
|
14
|
+
The only required option is `:adapter`. This specifies the SMS Gateway adapter you want to use. The remaining options are specific to the adapter.
|
15
|
+
|
16
|
+
Then subclass `ActionSms::Base` to define a notifier
|
17
|
+
|
18
|
+
class SMSNotifier < ActionSms::Base
|
19
|
+
end
|
20
|
+
|
21
|
+
Now you can call:
|
22
|
+
|
23
|
+
SMSNotifier.deliver(sms)
|
24
|
+
|
25
|
+
### Rails
|
26
|
+
For convenience there are a couple of generators that can be used if you are using action_sms within a Rails app.
|
27
|
+
|
28
|
+
rails g initializer
|
29
|
+
Generates an initializer under config/initializers with the `establish_connection` code described above.
|
30
|
+
|
31
|
+
rails g notifier
|
32
|
+
Generates a notifier under app/notifiers with the `SMSNotifier` code described above.
|
33
|
+
|
34
|
+
## Installation
|
35
|
+
|
36
|
+
gem install action_sms
|
37
|
+
### Rails
|
38
|
+
Place the following in your Gemfile:
|
39
|
+
|
40
|
+
gem action_sms
|
41
|
+
## SMS Gateway Adapters
|
42
|
+
See [action_sms_gateways](http://github.com/dwilkie/action_sms_gateways)
|
43
|
+
|
44
|
+
Copyright (c) 2010 David Wilkie, released under the MIT license
|
45
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the ActionSMS plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'spec'
|
12
|
+
t.libs << 'features'
|
13
|
+
t.pattern = 'spec/**/*_spec.rb'
|
14
|
+
t.verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'jeweler'
|
19
|
+
Jeweler::Tasks.new do |gemspec|
|
20
|
+
gemspec.name = "action_sms"
|
21
|
+
gemspec.summary = "Lightweight SMS wrapper which can use any gateway"
|
22
|
+
gemspec.email = "dwilkie@gmail.com"
|
23
|
+
gemspec.homepage = "http://github.com/dwilkie/action_sms"
|
24
|
+
gemspec.authors = ["David Wilkie"]
|
25
|
+
end
|
26
|
+
rescue LoadError
|
27
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Generate documentation for the ActionSMS plugin.'
|
31
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
32
|
+
rdoc.rdoc_dir = 'rdoc'
|
33
|
+
rdoc.title = 'ActionSMS'
|
34
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
35
|
+
rdoc.rdoc_files.include('README')
|
36
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
+
end
|
38
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/action_sms.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{action_sms}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["David Wilkie"]
|
12
|
+
s.date = %q{2010-07-07}
|
13
|
+
s.email = %q{dwilkie@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"README.markdown"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
".gitignore",
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README.markdown",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"action_sms.gemspec",
|
24
|
+
"lib/action_sms.rb",
|
25
|
+
"lib/action_sms/base.rb",
|
26
|
+
"lib/action_sms/connection_adapters.rb",
|
27
|
+
"lib/action_sms/connection_adapters/abstract_adapter.rb",
|
28
|
+
"lib/action_sms/connections.rb",
|
29
|
+
"lib/action_sms/exceptions.rb",
|
30
|
+
"lib/generators/action_sms/initializer/USAGE",
|
31
|
+
"lib/generators/action_sms/initializer/initializer_generator.rb",
|
32
|
+
"lib/generators/action_sms/initializer/templates/action_sms.rb",
|
33
|
+
"lib/generators/action_sms/notifier/USAGE",
|
34
|
+
"lib/generators/action_sms/notifier/notifier_generator.rb",
|
35
|
+
"lib/generators/action_sms/notifier/templates/sms_notifier.rb",
|
36
|
+
"todo"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/dwilkie/action_sms}
|
39
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.3.7}
|
42
|
+
s.summary = %q{Lightweight SMS wrapper which can use any gateway}
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
else
|
50
|
+
end
|
51
|
+
else
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/lib/action_sms.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
|
3
|
+
module ActionSms #:nodoc:
|
4
|
+
module ConnectionAdapters #:nodoc:
|
5
|
+
# All the concrete gateway adapters follow the interface laid down in this
|
6
|
+
# class. You can use this interface directly by borrowing the gateway
|
7
|
+
# connection from the Base with Base.connection.
|
8
|
+
class AbstractAdapter
|
9
|
+
|
10
|
+
@logger = nil
|
11
|
+
attr_accessor :logger
|
12
|
+
|
13
|
+
def initialize(logger = nil) #:nodoc:
|
14
|
+
@logger = logger
|
15
|
+
end
|
16
|
+
|
17
|
+
def deliver(sms)
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse(sms)
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
# Helper method to send an HTTP request to +url+ with paramaters
|
26
|
+
# specified by the +params+ hash.
|
27
|
+
def send_http_request(url, params)
|
28
|
+
uri = URI.parse(url)
|
29
|
+
req = Net::HTTP::Post.new(uri.path)
|
30
|
+
req.set_form_data(params)
|
31
|
+
|
32
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
33
|
+
http.use_ssl = true if uri.scheme == 'https'
|
34
|
+
resp = http.start do
|
35
|
+
http.request(req)
|
36
|
+
end
|
37
|
+
@logger.info "Response: #{resp.body}" unless @logger.nil?
|
38
|
+
|
39
|
+
return resp.body
|
40
|
+
rescue Exception => e
|
41
|
+
raise e
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module ActionSms #:nodoc#
|
2
|
+
|
3
|
+
class Base
|
4
|
+
@@connection = nil
|
5
|
+
|
6
|
+
class << self
|
7
|
+
# Returns true if a connection that's accessible to this class has already
|
8
|
+
# been opened.
|
9
|
+
def connected?
|
10
|
+
return !@@connection.nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the connection currently associated with the class. This can
|
14
|
+
# also be used to "borrow" the connection to do work that is specific to
|
15
|
+
# a particular SMS gateway.
|
16
|
+
def connection
|
17
|
+
raise ConnectionNotEstablished unless @@connection
|
18
|
+
return @@connection
|
19
|
+
end
|
20
|
+
|
21
|
+
# Set the gateway connection for the class.
|
22
|
+
def connection=(spec) #:nodoc:
|
23
|
+
raise ConnectionNotEstablished unless spec
|
24
|
+
@@connection = spec
|
25
|
+
end
|
26
|
+
|
27
|
+
# Establishes the connection to the SMS gateway. Accepts a hash as input
|
28
|
+
# where the :adapter key must be specified with the name of a gateway
|
29
|
+
# adapter (in lower-case)
|
30
|
+
#
|
31
|
+
# ActionSms::Base.establish_connection(
|
32
|
+
# :adapter => "clickatell",
|
33
|
+
# :username => "myusername",
|
34
|
+
# :password => "mypassword"
|
35
|
+
# :api_id => "myapiid"
|
36
|
+
# )
|
37
|
+
#
|
38
|
+
# Also accepts keys as strings (for parsing from YAML, for example).
|
39
|
+
#
|
40
|
+
# The exceptions AdapterNotSpecified, AdapterNotFound, and ArgumentError
|
41
|
+
# may be returned.
|
42
|
+
def establish_connection(config)
|
43
|
+
config = config.symbolize_keys
|
44
|
+
unless config.key?(:adapter)
|
45
|
+
raise AdapterNotSpecified, "#{config} adapter is not configured"
|
46
|
+
end
|
47
|
+
adapter_method = "#{config[:adapter]}_connection"
|
48
|
+
unless respond_to?(adapter_method)
|
49
|
+
raise AdapterNotFound,
|
50
|
+
"configuration specifies nonexistent #{config[:adapter]} adapter"
|
51
|
+
end
|
52
|
+
self.connection = self.send(adapter_method, config)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the connection currently associated with the class. This can
|
57
|
+
# also be used to "borrow" the connection to do work that is specific to
|
58
|
+
# a particular SMS gateway.
|
59
|
+
def connection
|
60
|
+
self.class.connection
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActionSms #:nodoc:
|
2
|
+
|
3
|
+
# Generic error class and superclass of all other errors raised by
|
4
|
+
# Active SMS
|
5
|
+
class ActionSmsError < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
# The configuration hash used in <tt>establish_connection</tt> didn't include
|
9
|
+
# <tt>:adapter</tt> key
|
10
|
+
class AdapterNotSpecified < ActionSmsError
|
11
|
+
end
|
12
|
+
|
13
|
+
# The <tt>adapter</tt> key used in <tt>establish_connection</tt> specified a
|
14
|
+
# nonexistent adapter.
|
15
|
+
class AdapterNotFound < ActionSmsError
|
16
|
+
end
|
17
|
+
|
18
|
+
# No connection has been established. Use <tt>establish_connection</tt>
|
19
|
+
# before sending a message.
|
20
|
+
class ConnectionNotEstablished < ActionSmsError
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module ActionSms
|
3
|
+
class InitializerGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
7
|
+
end
|
8
|
+
|
9
|
+
def copy_conversation_file
|
10
|
+
copy_file "action_sms.rb", "config/initializers/action_sms.rb"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# see http://github.com/dwilkie/action_sms_gateways
|
2
|
+
# for preconfigured sms gateways
|
3
|
+
|
4
|
+
# see http://github.com/dwilkie/action_sms
|
5
|
+
# for more details on how to make your own adapter for an sms gateway
|
6
|
+
|
7
|
+
# Then uncomment the following code and replace :adapter with your adapter
|
8
|
+
|
9
|
+
#ActionSms::Base.establish_connection(
|
10
|
+
# :adapter => 'your_adapter',
|
11
|
+
# :username => '[username]',
|
12
|
+
# :password => '[password]'
|
13
|
+
#)
|
14
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module ActionSms
|
3
|
+
class NotifierGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
7
|
+
end
|
8
|
+
|
9
|
+
def copy_notifier_file
|
10
|
+
copy_file "sms_notifier.rb", "app/notifiers/sms_notifier.rb"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: action_sms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- David Wilkie
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-07 00:00:00 +07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email: dwilkie@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README.markdown
|
29
|
+
files:
|
30
|
+
- .gitignore
|
31
|
+
- MIT-LICENSE
|
32
|
+
- README.markdown
|
33
|
+
- Rakefile
|
34
|
+
- VERSION
|
35
|
+
- action_sms.gemspec
|
36
|
+
- lib/action_sms.rb
|
37
|
+
- lib/action_sms/base.rb
|
38
|
+
- lib/action_sms/connection_adapters.rb
|
39
|
+
- lib/action_sms/connection_adapters/abstract_adapter.rb
|
40
|
+
- lib/action_sms/connections.rb
|
41
|
+
- lib/action_sms/exceptions.rb
|
42
|
+
- lib/generators/action_sms/initializer/USAGE
|
43
|
+
- lib/generators/action_sms/initializer/initializer_generator.rb
|
44
|
+
- lib/generators/action_sms/initializer/templates/action_sms.rb
|
45
|
+
- lib/generators/action_sms/notifier/USAGE
|
46
|
+
- lib/generators/action_sms/notifier/notifier_generator.rb
|
47
|
+
- lib/generators/action_sms/notifier/templates/sms_notifier.rb
|
48
|
+
- todo
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/dwilkie/action_sms
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options:
|
55
|
+
- --charset=UTF-8
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.7
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Lightweight SMS wrapper which can use any gateway
|
81
|
+
test_files: []
|
82
|
+
|