sms_gateway 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03a54a6eeddebf3a65ff4cbcc689f7516332bd0f
4
- data.tar.gz: d22ce1156c432c0fe8a44df5696911c6d60cb0b3
3
+ metadata.gz: 226fdbc0abcf8fcd5939ffb73aa5cc2285875867
4
+ data.tar.gz: a15faae3f38a8e0aed2bfae92770592299f369d4
5
5
  SHA512:
6
- metadata.gz: cbd74262c9f4396b08d34e725da84a4919f78f850e97e42881555659a601e808c3afca681b7dd0c967c4602608515059f5c343e475fdcc1ae7e9e0d9d459eb46
7
- data.tar.gz: 228739afcdaa6b13a52e91edc3b3ad298a8f259ef879e601c9bf73881e80bbe199da50f47ca48186f916d252023fe09b2243c2d4fd75ba3be8841342d977effd
6
+ metadata.gz: 5e9c1f059505b190e5f9241280ce860a3edbcc63d27100c7fb5fdba76c18a5ef79de4f858c1363ba777916cf2a13cd8945f73eb09b0908b1d35816ec7680abeb
7
+ data.tar.gz: 4e587f03217d8ebb0dec302a5c6d49be87aefca34b504bf0f04e919b95be4280d5015e3ab2f13b8ad825f19ac760560ba18e88170de2fcc20751a3a44f313119
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in sms_gateway.gemspec
4
4
  gemspec
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rdoc/task'
4
4
 
5
5
  Bundler::GemHelper.install_tasks
6
6
 
7
- task :default => :test
7
+ task default: :test
8
8
 
9
9
  desc 'Run unit tests'
10
10
  Rake::TestTask.new(:test) do |test|
@@ -21,6 +21,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
21
21
  rdoc.rdoc_files.include('README.rdoc')
22
22
  rdoc.rdoc_files.include('lib/**/*.rb')
23
23
  end
24
-
25
-
26
-
@@ -7,6 +7,3 @@ require 'sms_gateway/jobs/sms_job'
7
7
 
8
8
  module SmsGateway
9
9
  end
10
-
11
-
12
-
@@ -1,23 +1,15 @@
1
1
  module SmsGateway
2
-
3
2
  module Adapters
4
-
5
3
  class BetterOpener
6
-
7
- def initialize(config={})
8
- @config = {:from => SmsGateway::Base.from}
4
+ def initialize(config = {})
5
+ @config = { from: SmsGateway::Base.from }
9
6
  @config.merge!(config)
10
7
  end
11
8
 
12
9
  def send_sms(sms)
13
- options = @config.merge({:to => sms.to, :message => sms.text})
14
- BetterOpener.add_notification("sms", sms.text, sms.text)
10
+ options = @config.merge(to: sms.to, message: sms.text)
11
+ BetterOpener.add_notification('sms', sms.text, sms.text)
15
12
  end
16
-
17
13
  end
18
-
19
14
  end
20
-
21
15
  end
22
-
23
-
@@ -1,27 +1,20 @@
1
1
  module SmsGateway
2
-
3
2
  module Adapters
4
-
5
3
  class SmsGlobal
6
4
  require 'httparty'
7
5
  include HTTParty
8
6
  base_uri 'http://www.smsglobal.com'
9
7
 
10
- def initialize(config={})
11
- @config = {:user => SmsGateway::Base.user, :password => SmsGateway::Base.password,
12
- :from => SmsGateway::Base.from}
8
+ def initialize(config = {})
9
+ @config = { user: SmsGateway::Base.user, password: SmsGateway::Base.password,
10
+ from: SmsGateway::Base.from }
13
11
  @config.merge!(config)
14
12
  end
15
13
 
16
14
  def send_sms(sms)
17
- options = @config.merge({:action => "sendsms", :from => sms.from, :to => sms.to, :text => sms.text})
18
- self.class.post('/http-api.php', :query => options)
15
+ options = @config.merge(action: 'sendsms', from: sms.from, to: sms.to, text: sms.text)
16
+ self.class.post('/http-api.php', query: options)
19
17
  end
20
-
21
18
  end
22
-
23
19
  end
24
-
25
20
  end
26
-
27
-
@@ -1,28 +1,22 @@
1
1
  module SmsGateway
2
-
3
2
  module Adapters
4
-
5
3
  class SmsTrade
6
4
  require 'httparty'
7
5
  include HTTParty
8
6
  base_uri 'http://gateway.smstrade.de'
9
7
 
10
- def initialize(config={})
11
- @config = {:key => SmsGateway::Base.key, :from => SmsGateway::Base.from, :route => SmsGateway::Base.route}
8
+ def initialize(config = {})
9
+ @config = { key: SmsGateway::Base.key, from: SmsGateway::Base.from, route: SmsGateway::Base.route }
12
10
  @config.merge!(config)
13
11
  self.class.base_uri SmsGateway::Base.base_uri
14
12
  end
15
13
 
16
14
  def send_sms(sms)
17
- options = @config.merge({:from => sms.from, :to => sms.to, :message => sms.text, :charset => "UTF-8"})
18
- options.merge!({:route => sms.route}) if sms.route
19
- self.class.get('/', :query => options)
15
+ options = @config.merge(from: sms.from, to: sms.to, message: sms.text, charset: 'UTF-8')
16
+ options.merge!(route: sms.route) if sms.route
17
+ options.merge!(dlr: 1) if sms.delivery_report
18
+ self.class.get('/', query: options)
20
19
  end
21
-
22
20
  end
23
-
24
21
  end
25
-
26
22
  end
27
-
28
-
@@ -1,8 +1,6 @@
1
1
 
2
2
  module SmsGateway
3
-
4
3
  class Base
5
-
6
4
  class << self
7
5
  attr_accessor :deliveries
8
6
  end
@@ -10,23 +8,17 @@ module SmsGateway
10
8
  @deliveries = []
11
9
  end
12
10
 
13
-
14
11
  module Adapters
15
-
16
12
  class Test
17
-
18
13
  attr_accessor :deliveries
19
14
 
20
- def initialize(config={})
21
- #@logger = Logger.new(STDOUT)
15
+ def initialize(_config = {})
16
+ # @logger = Logger.new(STDOUT)
22
17
  end
23
18
 
24
19
  def send_sms(sms)
25
20
  SmsGateway::Base.deliveries << sms
26
21
  end
27
-
28
22
  end
29
23
  end
30
24
  end
31
-
32
-
@@ -1,7 +1,5 @@
1
1
  module SmsGateway
2
-
3
2
  class Base
4
-
5
3
  class << self
6
4
  attr_accessor :from, :user, :password, :key, :route, :base_uri
7
5
  attr_reader :adapter
@@ -11,36 +9,29 @@ module SmsGateway
11
9
  end
12
10
 
13
11
  def adapter=(underscore_name)
14
- klassname = underscore_name.split("_").map(&:capitalize).join
15
- klass = SmsGateway::Adapters.const_get(klassname)
16
- @adapter = klass.new
12
+ klassname = underscore_name.split('_').map(&:capitalize).join
13
+ klass = SmsGateway::Adapters.const_get(klassname)
14
+ @adapter = klass.new
17
15
  end
18
16
 
19
- def config
20
- @config
21
- end
17
+ attr_reader :config
22
18
 
23
19
  def config=(options)
24
20
  @config = options
25
21
  adapter = @config.delete(:adapter)
26
- @config.each do |k,v|
27
- self.send "#{k}=", v
22
+ @config.each do |k, v|
23
+ send "#{k}=", v
28
24
  end
29
- self.adapter = adapter
25
+ self.adapter = adapter
30
26
  end
31
27
 
32
28
  def deliver(sms)
33
- self.adapter.send_sms(sms)
29
+ adapter.send_sms(sms)
34
30
  end
35
31
 
36
- def self.deliver_later(text, to, from=Base.config[:from])
37
- Resque.enqueue(SmsGateway::Workers::SmsJob, text, to, from)
32
+ def self.deliver_later(text, to, from = Base.config[:from])
33
+ Resque.enqueue(SmsGateway::Workers::SmsJob, text, to, from)
38
34
  end
39
-
40
35
  end
41
36
  end
42
-
43
37
  end
44
-
45
-
46
-
@@ -2,26 +2,19 @@ require 'rails'
2
2
  require 'rails/generators'
3
3
 
4
4
  module SmsGateway
5
-
6
5
  module Generators
7
-
8
6
  class InstallGenerator < Rails::Generators::Base
9
- source_root File.expand_path("../templates", __FILE__)
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ desc 'Creates the initializer and config file template.'
10
10
 
11
- desc "Creates the initializer and config file template."
12
-
13
11
  def copy_initializer_file
14
- copy_file "initializer.rb", "config/initializers/setup_sms_gateway.rb"
12
+ copy_file 'initializer.rb', 'config/initializers/setup_sms_gateway.rb'
15
13
  end
16
14
 
17
15
  def copy_config_file
18
- copy_file "setup.yml", "config/sms_gateway.yml"
16
+ copy_file 'setup.yml', 'config/sms_gateway.yml'
19
17
  end
20
-
21
18
  end
22
-
23
19
  end
24
-
25
20
  end
26
-
27
-
@@ -1,6 +1,4 @@
1
- SMS_SETTINGS =
1
+ SMS_SETTINGS =
2
2
  YAML.load(File.open(File.join(Rails.root, 'config', 'sms_gateway.yml')))[Rails.env].symbolize_keys
3
3
 
4
4
  SmsGateway::Base.config = SMS_SETTINGS.symbolize_keys
5
-
6
-
@@ -1,16 +1,9 @@
1
1
 
2
2
  module SmsGateway
3
-
4
3
  class SmsJob
5
-
6
4
  @queue = :sms_queue
7
5
  def self.perform(options)
8
6
  SmsGateway::Sms.new(options.symbolize_keys).deliver
9
7
  end
10
-
11
8
  end
12
-
13
9
  end
14
-
15
-
16
-
@@ -1,12 +1,12 @@
1
1
  ## The SMS-Object
2
2
  module SmsGateway
3
- class Sms < Struct.new(:from, :to, :text, :route)
4
-
3
+ class Sms < Struct.new(:from, :to, :text, :route, :delivery_report)
5
4
  def initialize(params)
6
- self.from = params[:from]||SmsGateway::Base.from
5
+ self.from = params[:from] || SmsGateway::Base.from
7
6
  self.to = params[:to]
8
7
  self.text = params[:text]
9
8
  self.route = params[:route]
9
+ self.delivery_report = params[:delivery_report]
10
10
  end
11
11
 
12
12
  def deliver
@@ -14,11 +14,7 @@ module SmsGateway
14
14
  end
15
15
 
16
16
  def to_s
17
- "SMS: from:#{self.from}, to:#{self.to}, text:#{self.text}"
17
+ "SMS: from:#{from}, to:#{to}, text:#{text}"
18
18
  end
19
-
20
19
  end
21
20
  end
22
-
23
-
24
-
@@ -1,4 +1,3 @@
1
1
  module SmsGateway
2
- VERSION = "0.2.1"
2
+ VERSION = '0.3.0'
3
3
  end
4
-
@@ -1,23 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "sms_gateway/version"
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+ require 'sms_gateway/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "sms_gateway"
6
+ s.name = 'sms_gateway'
7
7
  s.version = SmsGateway::VERSION
8
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 and smstrade.de}
9
+ s.authors = ['Kai Rubarth']
10
+ s.email = ['kai@doxter.de']
11
+ s.homepage = ''
12
+ s.summary = 'Simple and flexible interface to SMS Gateways'
13
+ s.description = 'Provides an interface to SMS Gateways. So far it supports smsglobal.com and smstrade.de'
14
14
 
15
- s.rubyforge_project = "sms_gateway"
15
+ s.rubyforge_project = 'sms_gateway'
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
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"]
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
+ s.require_paths = ['lib']
21
21
 
22
22
  s.add_dependency('httparty')
23
23
 
@@ -25,7 +25,4 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency('minitest')
26
26
  s.add_development_dependency('pry')
27
27
  s.add_development_dependency('webmock')
28
-
29
28
  end
30
-
31
-
@@ -1,31 +1,24 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe SmsGateway::Adapters do
4
-
5
4
  before do
6
- SmsGateway::Base.config = {
7
- :from => '493011111111',
8
- :user => 'userid',
9
- :password => 'secret',
10
- :adapter => 'sms_global'
5
+ SmsGateway::Base.config = {
6
+ from: '493011111111',
7
+ user: 'userid',
8
+ password: 'secret',
9
+ adapter: 'sms_global'
11
10
  }
12
11
  end
13
12
 
14
13
  it 'works with sms global' do
14
+ stub_request(:post, 'http://www.smsglobal.com/http-api.php?action=sendsms&from=4930123456&password=secret&text=hello&to=493088888888&user=userid')
15
+ .to_return(status: 200, body: 'OK: 0;', headers: {})
15
16
 
16
- stub_request(:post, "http://www.smsglobal.com/http-api.php?action=sendsms&from=4930123456&password=secret&text=hello&to=493088888888&user=userid").
17
- to_return(:status => 200, :body => "OK: 0;", :headers => {})
18
-
19
- sms = SmsGateway::Sms.new(:from => '4930123456', :to => '493088888888',
20
- :text => "hello")
17
+ sms = SmsGateway::Sms.new(from: '4930123456', to: '493088888888',
18
+ text: 'hello')
21
19
 
22
20
  sms.deliver
23
21
 
24
- assert_requested(:post, "http://www.smsglobal.com/http-api.php?action=sendsms&from=4930123456&password=secret&text=hello&to=493088888888&user=userid")
22
+ assert_requested(:post, 'http://www.smsglobal.com/http-api.php?action=sendsms&from=4930123456&password=secret&text=hello&to=493088888888&user=userid')
25
23
  end
26
-
27
24
  end
28
-
29
-
30
-
31
-
@@ -1,23 +1,21 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe SmsGateway::Adapters::SmsGlobal do
4
-
5
4
  before do
6
5
  SmsGateway::Base.config = {
7
- :adapter => 'sms_trade',
8
- :route => 'direct',
9
- :key => 'KEY',
10
- :from => 'SMSTRADE',
11
- :base_uri => 'http://gateway.smspromote.de'
6
+ adapter: 'sms_trade',
7
+ route: 'direct',
8
+ key: 'KEY',
9
+ from: 'SMSTRADE',
10
+ base_uri: 'http://gateway.smspromote.de'
12
11
  }
13
12
  end
14
13
 
15
14
  it 'works with smstrade' do
15
+ sms = SmsGateway::Sms.new(to: '491701234567', text: 'Hallö Ümläut.', from: 'SENDER')
16
16
 
17
- sms = SmsGateway::Sms.new(:to => '491701234567', :text => "Hallö Ümläut.", :from => 'SENDER')
18
-
19
- stub_request(:get, "http://gateway.smspromote.de/?charset=UTF-8&from=SENDER&key=KEY&message=#{URI.encode(sms.text)}&route=direct&to=491701234567").
20
- to_return(:status => 200, :body => "", :headers => {})
17
+ stub_request(:get, "http://gateway.smspromote.de/?charset=UTF-8&from=SENDER&key=KEY&message=#{URI.encode(sms.text)}&route=direct&to=491701234567")
18
+ .to_return(status: 200, body: '', headers: {})
21
19
 
22
20
  sms.deliver
23
21
 
@@ -25,20 +23,24 @@ describe SmsGateway::Adapters::SmsGlobal do
25
23
  end
26
24
 
27
25
  it 'allows changing the route on the fly' do
26
+ sms = SmsGateway::Sms.new(to: '491701234567', text: 'SMSTEXT', from: 'SENDER', route: 'basic')
28
27
 
29
- sms = SmsGateway::Sms.new(:to => '491701234567', :text => "SMSTEXT", :from => 'SENDER', :route => 'basic')
30
-
31
- stub_request(:get, "http://gateway.smspromote.de/?charset=UTF-8&from=SENDER&key=KEY&message=#{URI.encode(sms.text)}&route=basic&to=491701234567").
32
- to_return(:status => 200, :body => "", :headers => {})
28
+ stub_request(:get, "http://gateway.smspromote.de/?charset=UTF-8&from=SENDER&key=KEY&message=#{URI.encode(sms.text)}&route=basic&to=491701234567")
29
+ .to_return(status: 200, body: '', headers: {})
33
30
 
34
31
  sms.deliver
35
32
 
36
33
  assert_requested(:get, "http://gateway.smspromote.de/?key=KEY&to=491701234567&message=#{URI.encode(sms.text)}&route=basic&from=SENDER&charset=UTF-8")
37
-
38
34
  end
39
35
 
40
- end
41
-
36
+ it 'request reports when configured' do
37
+ sms = SmsGateway::Sms.new(to: '491701234567', text: 'SMSTEXT', from: 'SENDER', route: 'basic', delivery_report: true)
42
38
 
39
+ stub_request(:get, 'http://gateway.smspromote.de/?charset=UTF-8&dlr=1&from=SENDER&key=KEY&message=SMSTEXT&route=basic&to=491701234567')
40
+ .to_return(status: 200, body: '', headers: {})
43
41
 
42
+ sms.deliver
44
43
 
44
+ assert_requested(:get, "http://gateway.smspromote.de/?key=KEY&to=491701234567&message=#{URI.encode(sms.text)}&route=basic&from=SENDER&charset=UTF-8&dlr=1")
45
+ end
46
+ end
@@ -1,17 +1,15 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe SmsGateway::Adapters::Test do
4
-
5
4
  it 'works with the test adapter' do
6
-
7
- SmsGateway::Base.config = {
8
- :from => '493011111111',
9
- :user => 'userid',
10
- :password => 'secret',
11
- :adapter => 'test'
5
+ SmsGateway::Base.config = {
6
+ from: '493011111111',
7
+ user: 'userid',
8
+ password: 'secret',
9
+ adapter: 'test'
12
10
  }
13
11
 
14
- sms = SmsGateway::Sms.new(:to => '493088888888', :text => "hello")
12
+ sms = SmsGateway::Sms.new(to: '493088888888', text: 'hello')
15
13
 
16
14
  assert_equal 0, SmsGateway::Base.deliveries.size
17
15
  sms.deliver
@@ -19,12 +17,5 @@ describe SmsGateway::Adapters::Test do
19
17
 
20
18
  SmsGateway::Base.deliveries = []
21
19
  assert_equal [], SmsGateway::Base.deliveries
22
-
23
20
  end
24
-
25
-
26
21
  end
27
-
28
-
29
-
30
-
@@ -1,13 +1,12 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe SmsGateway::Base do
4
-
5
4
  before do
6
- SmsGateway::Base.configure do |config|
5
+ SmsGateway::Base.configure do |config|
7
6
  config.from = '123456789'
8
7
  config.user = 'some_user'
9
8
  config.password = 'secret'
10
- config.adapter = 'test'
9
+ config.adapter = 'test'
11
10
  end
12
11
  end
13
12
 
@@ -20,13 +19,7 @@ describe SmsGateway::Base do
20
19
  end
21
20
 
22
21
  def test_parse_from
23
- sms = SmsGateway::Sms.new(:text => 'test')
22
+ sms = SmsGateway::Sms.new(text: 'test')
24
23
  assert_equal '123456789', sms.from
25
24
  end
26
-
27
25
  end
28
-
29
-
30
-
31
-
32
-
@@ -5,3 +5,4 @@ require 'minitest/autorun'
5
5
  require 'webmock/minitest'
6
6
  require 'pry'
7
7
 
8
+ include WebMock::API
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms_gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kai Rubarth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-01 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  requirements: []
132
132
  rubyforge_project: sms_gateway
133
- rubygems_version: 2.2.2
133
+ rubygems_version: 2.4.6
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: Simple and flexible interface to SMS Gateways
@@ -140,3 +140,4 @@ test_files:
140
140
  - test/adapters/test_adapter_test.rb
141
141
  - test/configuration_test.rb
142
142
  - test/test_helper.rb
143
+ has_rdoc: