sms_gate 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +83 -0
- data/README.md +40 -0
- data/Rakefile +23 -0
- data/lib/generators/sms_gate/install_generator.rb +20 -0
- data/lib/generators/sms_gate/resque_rake_tasks_generator.rb +16 -0
- data/lib/generators/sms_gate/templates/config.yml +14 -0
- data/lib/generators/sms_gate/templates/initializer.rb +10 -0
- data/lib/generators/sms_gate/templates/resque.rake +30 -0
- data/lib/sms_gate.rb +8 -0
- data/lib/sms_gate/adapters/sms_sluzba.rb +35 -0
- data/lib/sms_gate/adapters/test.rb +20 -0
- data/lib/sms_gate/base.rb +43 -0
- data/lib/sms_gate/jobs/sms_job.rb +27 -0
- data/lib/sms_gate/sms.rb +24 -0
- data/lib/sms_gate/version.rb +3 -0
- data/sms_gate.gemspec +31 -0
- data/test/configuration_test.rb +35 -0
- data/test/sms_gate_test.rb +23 -0
- data/test/sms_job_test.rb +64 -0
- data/test/test_helper.rb +14 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a35ed0b49a2421bddf746eaed5832b335dc3363
|
4
|
+
data.tar.gz: b1c0fb8dfe3ec6ef71c3b435eb7e44a1cc204fc9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 238467fff463b1801b273418e5b7a7d9d4a035412ca6ef98256c38dbcf35a6ade04d63687b70c1a362c82257600d766d4d4ff724f08449cac02efc0e80da5ba5
|
7
|
+
data.tar.gz: edb809ff8e14e394198c75096a79bb2232c921003ac2a344502a658190749ce7602dde254673e6d1b66b04894a2333e3a10e7e74b5339301af2117181c506ce5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sms_gate (0.1.1)
|
5
|
+
httparty (~> 0.13)
|
6
|
+
resque (~> 1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (4.1.5)
|
12
|
+
i18n (~> 0.6, >= 0.6.9)
|
13
|
+
json (~> 1.7, >= 1.7.7)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
thread_safe (~> 0.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
addressable (2.3.6)
|
18
|
+
ansi (1.4.3)
|
19
|
+
builder (3.2.2)
|
20
|
+
crack (0.4.2)
|
21
|
+
safe_yaml (~> 1.0.0)
|
22
|
+
httparty (0.13.1)
|
23
|
+
json (~> 1.8)
|
24
|
+
multi_xml (>= 0.5.2)
|
25
|
+
i18n (0.6.11)
|
26
|
+
json (1.8.1)
|
27
|
+
minitest (5.4.0)
|
28
|
+
minitest-reporters (1.0.5)
|
29
|
+
ansi
|
30
|
+
builder
|
31
|
+
minitest (>= 5.0)
|
32
|
+
ruby-progressbar
|
33
|
+
mono_logger (1.1.0)
|
34
|
+
multi_json (1.10.1)
|
35
|
+
multi_xml (0.5.5)
|
36
|
+
rack (1.5.2)
|
37
|
+
rack-protection (1.5.3)
|
38
|
+
rack
|
39
|
+
rake (10.3.2)
|
40
|
+
redis (3.1.0)
|
41
|
+
redis-namespace (1.5.1)
|
42
|
+
redis (~> 3.0, >= 3.0.4)
|
43
|
+
resque (1.25.2)
|
44
|
+
mono_logger (~> 1.0)
|
45
|
+
multi_json (~> 1.0)
|
46
|
+
redis-namespace (~> 1.3)
|
47
|
+
sinatra (>= 0.9.2)
|
48
|
+
vegas (~> 0.1.2)
|
49
|
+
resque_unit (0.4.8)
|
50
|
+
json (>= 1.4.6)
|
51
|
+
ruby-progressbar (1.5.1)
|
52
|
+
safe_yaml (1.0.3)
|
53
|
+
shoulda (3.5.0)
|
54
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
55
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
56
|
+
shoulda-context (1.2.1)
|
57
|
+
shoulda-matchers (2.6.2)
|
58
|
+
activesupport (>= 3.0.0)
|
59
|
+
sinatra (1.4.5)
|
60
|
+
rack (~> 1.4)
|
61
|
+
rack-protection (~> 1.4)
|
62
|
+
tilt (~> 1.3, >= 1.3.4)
|
63
|
+
thread_safe (0.3.4)
|
64
|
+
tilt (1.4.1)
|
65
|
+
tzinfo (1.2.2)
|
66
|
+
thread_safe (~> 0.1)
|
67
|
+
vegas (0.1.11)
|
68
|
+
rack (>= 1.0.0)
|
69
|
+
webmock (1.18.0)
|
70
|
+
addressable (>= 2.3.6)
|
71
|
+
crack (>= 0.3.2)
|
72
|
+
|
73
|
+
PLATFORMS
|
74
|
+
ruby
|
75
|
+
|
76
|
+
DEPENDENCIES
|
77
|
+
minitest (~> 5.4)
|
78
|
+
minitest-reporters (~> 1)
|
79
|
+
rake (~> 10)
|
80
|
+
resque_unit (~> 0.4)
|
81
|
+
shoulda
|
82
|
+
sms_gate!
|
83
|
+
webmock (~> 1)
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
sms_gate
|
2
|
+
========
|
3
|
+
|
4
|
+
Simple SMS gate gem, currently supporting Czech SMS gate provider [SMS Sluzba](https://sms.sluzba.cz/)
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
Synchronous:
|
10
|
+
|
11
|
+
```
|
12
|
+
sms = SmsGate::Sms.new(to: '0420724111222', text: "hello")
|
13
|
+
sms.deliver
|
14
|
+
```
|
15
|
+
|
16
|
+
Asynchronous:
|
17
|
+
|
18
|
+
```
|
19
|
+
sms = SmsGate::Sms.new(to: '0420724111222', text: "hello", model_id: 13)
|
20
|
+
sms.deliver_later
|
21
|
+
```
|
22
|
+
|
23
|
+
SmsGate response (Httparty response object) and ```model_id``` is returned to asynchonous response hooks.
|
24
|
+
Useful if you want to do some change on a related model according to SMS delivery status.
|
25
|
+
|
26
|
+
Rails configuration generator
|
27
|
+
-----------------------------
|
28
|
+
|
29
|
+
```rails g sms_gate:install```
|
30
|
+
|
31
|
+
Creates config/sms_gate.yml and config/initializers/sms_gate.rb in your application directory.
|
32
|
+
Replace contents of those files with your configuration values.
|
33
|
+
|
34
|
+
Resque rake file template
|
35
|
+
-------------------------
|
36
|
+
|
37
|
+
```rails g sms_gate:resque_rake```
|
38
|
+
|
39
|
+
Creates lib/tasks/resque.rake in your application directory.
|
40
|
+
Replace contents of this file with your configuration values.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
task default: :test
|
8
|
+
|
9
|
+
desc 'Run unit tests'
|
10
|
+
Rake::TestTask.new(:test) do |test|
|
11
|
+
test.libs << 'lib' << 'test'
|
12
|
+
test.pattern = 'test/**/*_test.rb'
|
13
|
+
test.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate Documentation'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'SmsGate'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline_source'
|
21
|
+
rdoc.rdoc_files.include('README.md')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module SmsGate
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
desc "Generates initializer and config file template for your application."
|
9
|
+
|
10
|
+
def copy_initializer_file
|
11
|
+
copy_file "initializer.rb", "config/initializers/sms_gate.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
def copy_config_file
|
15
|
+
copy_file "config.yml", "config/sms_gate.yml"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module SmsGate
|
4
|
+
module Generators
|
5
|
+
class ResqueRakeTasksGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
desc "Generates rake file template with resque tasks and configuration hooks for your application."
|
9
|
+
|
10
|
+
def copy_initializer_file
|
11
|
+
copy_file "resque.rake", "lib/tasks/resque.rake"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
SMS_SETTINGS = YAML.load(File.open(File.join(Rails.root, 'config', 'sms_gate.yml')))[Rails.env].symbolize_keys
|
2
|
+
|
3
|
+
SmsGate::Base.configure do |config|
|
4
|
+
config.user = SMS_SETTINGS[:user]
|
5
|
+
config.password = SMS_SETTINGS[:password]
|
6
|
+
config.from = SMS_SETTINGS[:from]
|
7
|
+
config.adapter = SMS_SETTINGS[:adapter]
|
8
|
+
# Optional list of Proc, Method or something with similiar .call() method. Httparty response will be sent to them as an argument.
|
9
|
+
# config.async_response_hooks = [ lambda { |l| .. }, String.method(:puts) ]
|
10
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'resque/tasks'
|
2
|
+
require 'sms_gate'
|
3
|
+
|
4
|
+
task 'resque:setup' => :environment do
|
5
|
+
|
6
|
+
# initialize logger
|
7
|
+
Resque.before_fork = Proc.new {
|
8
|
+
ActiveRecord::Base.establish_connection
|
9
|
+
|
10
|
+
# Open the new separate log file
|
11
|
+
logfile = File.open(File.join(Rails.root, 'log', 'resque.log'), 'a')
|
12
|
+
|
13
|
+
# Activate file synchronization
|
14
|
+
logfile.sync = true
|
15
|
+
|
16
|
+
# Create a new logger
|
17
|
+
Resque.logger = ActiveSupport::Logger.new(logfile)
|
18
|
+
Resque.logger.level = Logger::INFO
|
19
|
+
Resque.logger.info 'Resque Logger Initialized!'
|
20
|
+
Resque.logger.formatter = Resque::VerboseFormatter.new
|
21
|
+
}
|
22
|
+
|
23
|
+
# setting response hooks example
|
24
|
+
Resque.after_fork do |job|
|
25
|
+
Resque.logger.info job.to_s
|
26
|
+
SmsGate::Base.async_response_hooks = [
|
27
|
+
lambda { |response, model_id| Resque.logger.info "## LAMBDA ## RESPONSE: #{response} || MODEL_ID: #{model_id}" }
|
28
|
+
]
|
29
|
+
end
|
30
|
+
end
|
data/lib/sms_gate.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module SmsGate
|
2
|
+
module Adapters
|
3
|
+
|
4
|
+
class SmsSluzba
|
5
|
+
require 'httparty'
|
6
|
+
include HTTParty
|
7
|
+
base_uri 'https://smsgateapi.sluzba.cz'
|
8
|
+
|
9
|
+
ERROR_RESPONSE_CODES = {
|
10
|
+
'400;1' => 'Wrong phone number',
|
11
|
+
'400;2' => 'Message text missing',
|
12
|
+
'400' => 'Unknown action',
|
13
|
+
'401' => 'Invalid login',
|
14
|
+
'402' => 'Insufficient credit',
|
15
|
+
'503' => 'SMS gate error'
|
16
|
+
}
|
17
|
+
|
18
|
+
def initialize(config = {})
|
19
|
+
@params = { user: ::SmsGate::Base.user, password: ::SmsGate::Base.password }
|
20
|
+
@params.merge!(config)
|
21
|
+
end
|
22
|
+
|
23
|
+
def send_sms(sms)
|
24
|
+
options = { act: 'send', msisdn: sms.to, msg: sms.text, login: @params[:user], auth: sms_gate_auth_hash(sms.text) }
|
25
|
+
self.class.post('/apipost30/sms', query: options)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def sms_gate_auth_hash(message)
|
30
|
+
Digest::MD5.hexdigest(Digest::MD5.hexdigest(@params[:password]) + @params[:user] + 'send' + message.to_s[0..30])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SmsGate
|
2
|
+
|
3
|
+
class Base
|
4
|
+
class << self
|
5
|
+
attr_accessor :deliveries
|
6
|
+
end
|
7
|
+
|
8
|
+
@deliveries = []
|
9
|
+
end
|
10
|
+
|
11
|
+
module Adapters
|
12
|
+
class Test
|
13
|
+
attr_accessor :deliveries
|
14
|
+
|
15
|
+
def send_sms(sms)
|
16
|
+
::SmsGate::Base.deliveries << sms
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module SmsGate
|
2
|
+
|
3
|
+
class Base
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :from, :user, :password, :async_response_hooks
|
7
|
+
attr_reader :adapter
|
8
|
+
|
9
|
+
def configure
|
10
|
+
yield(self)
|
11
|
+
end
|
12
|
+
|
13
|
+
def adapter=(underscore_name)
|
14
|
+
klassname = underscore_name.split("_").map(&:capitalize).join
|
15
|
+
klass = ::SmsGate::Adapters.const_get(klassname)
|
16
|
+
@adapter = klass.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def config
|
20
|
+
@config
|
21
|
+
end
|
22
|
+
|
23
|
+
def config=(options)
|
24
|
+
@config = options
|
25
|
+
adapter = @config.delete(:adapter)
|
26
|
+
@config.each do |k,v|
|
27
|
+
self.send "#{k}=", v
|
28
|
+
end
|
29
|
+
self.adapter = adapter
|
30
|
+
end
|
31
|
+
|
32
|
+
def deliver(options)
|
33
|
+
self.adapter.send_sms(::SmsGate::Sms.new(options))
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.deliver_later(text, to, from = Base.config[:from], model_id = -1)
|
37
|
+
Resque.enqueue(::SmsGate::Jobs::SmsJob, text: text, to: to, from: from, model_id: model_id)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SmsGate
|
2
|
+
module Jobs
|
3
|
+
class SmsJob
|
4
|
+
QUEUE = :sms
|
5
|
+
@queue = QUEUE
|
6
|
+
@response = nil
|
7
|
+
|
8
|
+
# sends sms
|
9
|
+
def self.perform(options)
|
10
|
+
Resque.logger.debug "ENTERED SmsJob.perform method" if defined? Resque.logger # test logger availability because of tests
|
11
|
+
@response = ::SmsGate::Sms.new(Hash[options.map{|(k,v)| [k.to_sym,v]}]).deliver
|
12
|
+
Resque.logger.debug "RESPONSE: #{@response.code}, #{@response.body}" if defined? Resque.logger
|
13
|
+
end
|
14
|
+
|
15
|
+
# calls response hooks
|
16
|
+
def self.after_perform(options)
|
17
|
+
Resque.logger.debug "HOOKS: #{::SmsGate::Base.async_response_hooks.to_s}" if defined? Resque.logger
|
18
|
+
unless ::SmsGate::Base.async_response_hooks.nil?
|
19
|
+
::SmsGate::Base.async_response_hooks.each do |hook|
|
20
|
+
hook.call(@response, options['model_id'])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/sms_gate/sms.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module SmsGate
|
2
|
+
class Sms < Struct.new(:from, :to, :text, :model_id)
|
3
|
+
|
4
|
+
def initialize(params)
|
5
|
+
self.from = params[:from] || ::SmsGate::Base.from
|
6
|
+
self.to = params[:to]
|
7
|
+
self.text = params[:text]
|
8
|
+
self.model_id = params[:model_id]
|
9
|
+
end
|
10
|
+
|
11
|
+
def deliver
|
12
|
+
::SmsGate::Base.deliver(to: self.to, from: self.from, text: self.text)
|
13
|
+
end
|
14
|
+
|
15
|
+
def deliver_later
|
16
|
+
Resque.enqueue(::SmsGate::Jobs::SmsJob, to: self.to, from: self.from, text: self.text, model_id: self.model_id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
"SMS: from:#{self.from}, to:#{self.to}, text:#{self.text}, model_id:#{self.model_id}"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/sms_gate.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "sms_gate/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "sms_gate"
|
7
|
+
gem.version = SmsGate::VERSION
|
8
|
+
gem.platform = Gem::Platform::RUBY
|
9
|
+
gem.authors = ["Jiri Kaipr"]
|
10
|
+
gem.email = ["jiri.kaipr@virtualmaster.com"]
|
11
|
+
gem.homepage = ""
|
12
|
+
gem.summary = %q{Simple interface to SMS Gateways}
|
13
|
+
gem.description = %q{An interface to SMS Gateways. Currently supports only sms.sluzba.cz.}
|
14
|
+
|
15
|
+
gem.rubyforge_project = "sms_gate"
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split("\n")
|
18
|
+
gem.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
19
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
|
22
|
+
gem.add_dependency('httparty', '~> 0.13')
|
23
|
+
gem.add_dependency('resque', '~> 1')
|
24
|
+
|
25
|
+
gem.add_development_dependency('rake', '~> 10')
|
26
|
+
gem.add_development_dependency('webmock', '~> 1')
|
27
|
+
gem.add_development_dependency('minitest', '~> 5.4')
|
28
|
+
gem.add_development_dependency('minitest-reporters', '~> 1')
|
29
|
+
gem.add_development_dependency('resque_unit', '~> 0.4')
|
30
|
+
gem.add_development_dependency('shoulda')
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SmsGate::ConfigurationTest < MiniTest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
SmsGate::Base.configure do |config|
|
7
|
+
config.from = '123456789'
|
8
|
+
config.user = 'foo'
|
9
|
+
config.password = 'secret'
|
10
|
+
config.adapter = 'test'
|
11
|
+
config.async_response_hooks = [ lambda { |l| l + 1 } ]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_read_user
|
16
|
+
assert_equal 'foo', SmsGate::Base.user
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_read_password
|
20
|
+
assert_equal 'secret', SmsGate::Base.password
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_read_adapter
|
24
|
+
assert_equal 'SmsGate::Adapters::Test', SmsGate::Base.adapter.class.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_read_from_from_sms
|
28
|
+
sms = SmsGate::Sms.new(text: 'test')
|
29
|
+
assert_equal '123456789', sms.from
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_run_async_response_hooks
|
33
|
+
assert_equal 2, SmsGate::Base.async_response_hooks[0].call(1)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SmsGate::Adapters::SmsGateTest < Minitest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
SmsGate::Base.config = {
|
7
|
+
from: '0420777888999',
|
8
|
+
user: 'id',
|
9
|
+
password: 'secret',
|
10
|
+
adapter: 'sms_sluzba'
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_sms_sluzba
|
15
|
+
stub_request(:post, "https://smsgateapi.sluzba.cz/apipost30/sms?act=send&msisdn=0420724111222&msg=hello&auth=712802ff8fc71a4e6ad349165fff8a58&login=id").
|
16
|
+
to_return(status: 200, body: "OK: 0;", headers: {})
|
17
|
+
|
18
|
+
sms = SmsGate::Sms.new(to: '0420724111222', text: "hello")
|
19
|
+
sms.deliver
|
20
|
+
assert_requested(:post, 'https://smsgateapi.sluzba.cz/apipost30/sms?act=send&msisdn=0420724111222&msg=hello&auth=712802ff8fc71a4e6ad349165fff8a58&login=id')
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe SmsGate::Jobs::SmsJob do
|
4
|
+
|
5
|
+
context "A task that schedules a SMS to be sent later with a resque job" do
|
6
|
+
setup {
|
7
|
+
Resque.reset!
|
8
|
+
Resque.enable_hooks!
|
9
|
+
|
10
|
+
SmsGate::Base.config = {
|
11
|
+
from: '0420777888999',
|
12
|
+
user: 'id',
|
13
|
+
password: 'secret',
|
14
|
+
adapter: 'sms_sluzba',
|
15
|
+
async_response_hooks: [ lambda { |response, model_id| @response, @model_id = response, model_id } ]
|
16
|
+
}
|
17
|
+
|
18
|
+
@response = nil
|
19
|
+
@model_id = nil
|
20
|
+
|
21
|
+
sms = SmsGate::Sms.new(to: '0420724111222', text: "hello", model_id: 13)
|
22
|
+
sms.deliver_later
|
23
|
+
}
|
24
|
+
should "pass the assert_queued(job) assertion" do
|
25
|
+
assert_queued(SmsGate::Jobs::SmsJob)
|
26
|
+
assert_job_created(SmsGate::Jobs::SmsJob::QUEUE, SmsGate::Jobs::SmsJob)
|
27
|
+
assert_equal 1, Resque.queue(SmsGate::Jobs::SmsJob::QUEUE).length
|
28
|
+
end
|
29
|
+
|
30
|
+
context ", when Resque.run! is called," do
|
31
|
+
setup do
|
32
|
+
stub_request(:post, "https://smsgateapi.sluzba.cz/apipost30/sms?act=send&msisdn=0420724111222&msg=hello&auth=712802ff8fc71a4e6ad349165fff8a58&login=id").
|
33
|
+
to_return(status: 200, body: "OK: 0;", headers: {})
|
34
|
+
|
35
|
+
assert @response.nil?, "The job should not have been run yet"
|
36
|
+
Resque.run!
|
37
|
+
end
|
38
|
+
|
39
|
+
teardown do
|
40
|
+
@response = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
should "run the job" do
|
44
|
+
assert_equal 200, @response.code, "The job should have run"
|
45
|
+
end
|
46
|
+
|
47
|
+
should "clear the job from the queue" do
|
48
|
+
assert_not_queued(SmsGate::Jobs::SmsJob)
|
49
|
+
end
|
50
|
+
|
51
|
+
should "smsgateapi.sluzba.cz should have been called" do
|
52
|
+
assert_requested(:post, 'https://smsgateapi.sluzba.cz/apipost30/sms?act=send&msisdn=0420724111222&msg=hello&auth=712802ff8fc71a4e6ad349165fff8a58&login=id')
|
53
|
+
end
|
54
|
+
|
55
|
+
should "return response through async_response_hook lambda" do
|
56
|
+
assert_equal 200, @response.code
|
57
|
+
end
|
58
|
+
|
59
|
+
should "return model_id through async_response_hook lambda" do
|
60
|
+
assert_equal 13, @model_id
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gem 'minitest'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'webmock/minitest'
|
6
|
+
require 'shoulda'
|
7
|
+
require 'resque_unit'
|
8
|
+
require "minitest/reporters"
|
9
|
+
require 'sms_gate'
|
10
|
+
|
11
|
+
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
|
12
|
+
|
13
|
+
class MiniTest::Test
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sms_gate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jiri Kaipr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.13'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: resque
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-reporters
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: resque_unit
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.4'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: shoulda
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: An interface to SMS Gateways. Currently supports only sms.sluzba.cz.
|
126
|
+
email:
|
127
|
+
- jiri.kaipr@virtualmaster.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- Gemfile
|
134
|
+
- Gemfile.lock
|
135
|
+
- README.md
|
136
|
+
- Rakefile
|
137
|
+
- lib/generators/sms_gate/install_generator.rb
|
138
|
+
- lib/generators/sms_gate/resque_rake_tasks_generator.rb
|
139
|
+
- lib/generators/sms_gate/templates/config.yml
|
140
|
+
- lib/generators/sms_gate/templates/initializer.rb
|
141
|
+
- lib/generators/sms_gate/templates/resque.rake
|
142
|
+
- lib/sms_gate.rb
|
143
|
+
- lib/sms_gate/adapters/sms_sluzba.rb
|
144
|
+
- lib/sms_gate/adapters/test.rb
|
145
|
+
- lib/sms_gate/base.rb
|
146
|
+
- lib/sms_gate/jobs/sms_job.rb
|
147
|
+
- lib/sms_gate/sms.rb
|
148
|
+
- lib/sms_gate/version.rb
|
149
|
+
- sms_gate.gemspec
|
150
|
+
- test/configuration_test.rb
|
151
|
+
- test/sms_gate_test.rb
|
152
|
+
- test/sms_job_test.rb
|
153
|
+
- test/test_helper.rb
|
154
|
+
homepage: ''
|
155
|
+
licenses: []
|
156
|
+
metadata: {}
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project: sms_gate
|
173
|
+
rubygems_version: 2.2.2
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: Simple interface to SMS Gateways
|
177
|
+
test_files: []
|