sms_gateway 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 ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sms_gateway.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,76 @@
1
+ = SMS Gateway
2
+
3
+ The SMS Gateway gem provides a simple and extensible interface for
4
+ various SMS Gateways. It is loosely oriented on Action Mailer. The
5
+ gem allows you to create a SMS and deliver it synchronously or
6
+ asynchronously. So far it only ships with the following adapters.
7
+
8
+ * smsglobal.com
9
+ * a dummy adapter for testing purposes
10
+
11
+
12
+ = Installation
13
+
14
+ You install the gem in your rails app by adding it your +Gemfile+:
15
+
16
+ gem "sms_gateway"
17
+
18
+
19
+ After that you run the <tt>bundle:install</tt> task and then invoke the
20
+ gem's generator:
21
+
22
+ rails g sms_gateway:install
23
+
24
+ The generator installs an initializer and a yml file which you will need
25
+ to configure before sending a SMS.
26
+
27
+
28
+ == Resque and Redis
29
+
30
+ To deliver SMS asynchronously this gem makes use of resque, a
31
+ popular queing system basd on the key-value data store redis. You need
32
+ to have a working resque and redis setup if you want to use
33
+ the aynchronous feature. For more information on resque visit
34
+ https://github.com/defunkt/resque.
35
+
36
+
37
+ = Usage
38
+
39
+ Similar to action mailer you create the message object first:
40
+
41
+ m = SmsGateway::Sms.new(:from => '493088888888, :to => '49309999999',
42
+ :text => 'my sms must not be longer than 160 characters.')
43
+
44
+
45
+ And then deliver it with:
46
+
47
+ m.deliver
48
+
49
+
50
+ This will block until the the HTTP call is complete. As with email it's
51
+ better practice to enqueue the call:
52
+
53
+ m.deliver_later
54
+
55
+ This will be non-blocking and is the recommended way of sending an SMS.
56
+ This requires a resque worker, though, to get actually sent (see the
57
+ resque documentation):
58
+
59
+ rake resque:work
60
+
61
+
62
+
63
+ = Outlook and Todo
64
+
65
+ So far the gem is pretty limited. Ideas for following version are:
66
+
67
+ * unit tests
68
+ * other sms gateway providers
69
+ * decoupling of resque
70
+
71
+ = License
72
+
73
+ GPLv3. Copyright 2011 Kai Rubarth.
74
+
75
+
76
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,25 @@
1
+ module SmsGateway
2
+
3
+ module Adapters
4
+
5
+ class SmsGlobal
6
+ require 'httparty'
7
+ include HTTParty
8
+ base_uri 'http://www.smsglobal.com'
9
+ def initialize(config={})
10
+ @config = SmsGateway::Base.config
11
+ end
12
+
13
+ def send_sms(sms)
14
+ options = @config.merge({:action => "sendsms", :to => sms.to, :text => sms.text})
15
+ puts options.inspect
16
+ self.class.post('/http-api.php', :query => options)
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+
@@ -0,0 +1,18 @@
1
+
2
+ module SmsGateway
3
+ module Adapters
4
+
5
+ class Test
6
+ def initialize(config={})
7
+ @logger = Logger.new(STDOUT)
8
+ end
9
+
10
+ def send_sms(sms)
11
+ @logger.info "would be sending sms: #{sms.to_s}"
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+
18
+
@@ -0,0 +1,30 @@
1
+ module SmsGateway
2
+
3
+ class Base
4
+
5
+ class << self
6
+ attr_accessor :connection
7
+ attr_reader :config
8
+
9
+ def config=(options)
10
+ @config = options.symbolize_keys
11
+ klassname = @config[:adapter].to_s.split("_").map(&:capitalize).join
12
+ klass = SmsGateway::Adapters.const_get(klassname)
13
+ self.connection = klass.new
14
+ end
15
+
16
+ def deliver(options)
17
+ self.connection.send_sms(SmsGateway::Sms.new(options.symbolize_keys))
18
+ end
19
+
20
+ def self.deliver_later(text, to, from=Base.config[:from])
21
+ Resque.enqueue(SmsGateway::Workers::SmsJob, text, to, from)
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+
30
+
@@ -0,0 +1,24 @@
1
+ module SmsGateway
2
+
3
+ module Generators
4
+
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ desc "Creates the initializer and config file template."
9
+
10
+ def copy_initializer_file
11
+ copy_file "initializer.rb", "config/initializers/setup_sms_gateway.rb"
12
+ end
13
+
14
+ def copy_config_file
15
+ copy_file "setup.yml", "config/sms_gateway.yml"
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+
@@ -0,0 +1,6 @@
1
+ SMS_SETTINGS =
2
+ YAML.load(File.open(File.join(Rails.root, 'config', 'sms_gateway.yml')))[Rails.env].symbolize_keys
3
+
4
+ SmsGateway::Base.config = SMS_SETTINGS.symbolize_keys
5
+
6
+
@@ -0,0 +1,18 @@
1
+ ---
2
+
3
+ development:
4
+ user: username
5
+ password: secret
6
+ from: 493088888888
7
+ adapter: :sms_global
8
+
9
+ test:
10
+ adapter: :test
11
+
12
+ development:
13
+ user: username
14
+ password: secret
15
+ from: 493088888888
16
+ adapter: :sms_global
17
+
18
+
@@ -0,0 +1,16 @@
1
+
2
+ module SmsGateway
3
+
4
+ class SmsJob
5
+
6
+ @queue = :sms_queue
7
+ def self.perform(options)
8
+ SmsGateway::Sms.new(options.symbolize_keys).deliver
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+
15
+
16
+
@@ -0,0 +1,28 @@
1
+
2
+ ## The SMS-Object
3
+ module SmsGateway
4
+ class Sms < Struct.new(:from, :to, :text)
5
+
6
+ def initialize(params)
7
+ self.from = params[:from]||SmsGateway::Base.config[:from]
8
+ self.to = params[:to]
9
+ self.text = params[:text]
10
+ end
11
+
12
+ def deliver
13
+ SmsGateway::Base.deliver(:to=>self.to, :from=>self.from, :text=>self.text)
14
+ end
15
+
16
+ def deliver_later
17
+ Resque.enqueue(SmsGateway::SmsJob, :to=>self.to, :from=>self.from, :text=>self.text)
18
+ end
19
+
20
+ def to_s
21
+ "SMS: from:#{self.from}, to:#{self.to}, text:#{self.text}"
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+
28
+
@@ -0,0 +1,3 @@
1
+ module SmsGateway
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails'
2
+ require 'rails/generators'
3
+
4
+ require 'sms_gateway/base'
5
+ require 'sms_gateway/sms'
6
+ require 'sms_gateway/adapters/sms_global'
7
+ require 'sms_gateway/jobs/sms_job'
8
+ require 'sms_gateway/generators/install/install_generator'
9
+
10
+ module SmsGateway
11
+ end
12
+
13
+
14
+
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sms_gateway/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sms_gateway"
7
+ s.version = SmsGateway::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Kai Rubarth"]
10
+ s.email = ["kai@doxter.de"]
11
+ s.homepage = ""
12
+ s.summary = %q{Simple and flexible interface to SMS Gateways}
13
+ s.description = %q{Provides an interface to SMS Gateways. So far it supports smsglobal.com.}
14
+
15
+ s.rubyforge_project = "sms_gateway"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('httparty')
23
+ s.add_dependency('resque')
24
+
25
+ end
26
+
27
+
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sms_gateway
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Kai Rubarth
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-06 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: resque
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description: Provides an interface to SMS Gateways. So far it supports smsglobal.com.
50
+ email:
51
+ - kai@doxter.de
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - .gitignore
60
+ - Gemfile
61
+ - README.rdoc
62
+ - Rakefile
63
+ - lib/sms_gateway.rb
64
+ - lib/sms_gateway/adapters/sms_global.rb
65
+ - lib/sms_gateway/adapters/test_adapter.rb
66
+ - lib/sms_gateway/base.rb
67
+ - lib/sms_gateway/generators/install/install_generator.rb
68
+ - lib/sms_gateway/generators/install/templates/initializer.rb
69
+ - lib/sms_gateway/generators/install/templates/setup.yml
70
+ - lib/sms_gateway/jobs/sms_job.rb
71
+ - lib/sms_gateway/sms.rb
72
+ - lib/sms_gateway/version.rb
73
+ - sms_gateway.gemspec
74
+ has_rdoc: true
75
+ homepage: ""
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options: []
80
+
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project: sms_gateway
104
+ rubygems_version: 1.3.7
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Simple and flexible interface to SMS Gateways
108
+ test_files: []
109
+