sms_way 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +83 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +21 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/config/sms_way.yml +16 -0
- data/lib/config.rb +57 -0
- data/lib/sms_way.rb +43 -0
- data/lib/sms_way/base.rb +40 -0
- data/lib/sms_way/registry.rb +7 -0
- data/sms_way.gemspec +78 -0
- data/spec/base_spec.rb +23 -0
- data/spec/config_spec.rb +56 -0
- data/spec/dummy/config/sms_way.yml +28 -0
- data/spec/dummy/lib/sms_way/kannel.rb +3 -0
- data/spec/dummy/lib/sms_way/use_sms.rb +3 -0
- data/spec/dummy/test_registry.rb +7 -0
- data/spec/registry_spec.rb +18 -0
- data/spec/sms_way_spec.rb +68 -0
- data/spec/spec_helper.rb +19 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6d9768c193d052a71c253718610bbdeffee9cd79
|
4
|
+
data.tar.gz: 56dbd4ca5854514b74aace1843273b316860dc95
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e3535ca4e71a35ec4cc6073399c9a15eca3c518a912e5d51dc150f70526c3c0c86fedd13be704eba140c3a6d996f4a92a5e0832065a8cc6382fabb1d238b74a9
|
7
|
+
data.tar.gz: 93cdb3998022f8c068f74c82e8cb016a26810007e63d4945c624f7aac7571ae52d02a9057d4d7df60ddd75fc96176d424575c5ba17712ad0d3129fc4169641fd
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.6)
|
5
|
+
api_smith (1.3.0)
|
6
|
+
hashie (>= 1.0, < 3.0)
|
7
|
+
httparty
|
8
|
+
builder (3.2.2)
|
9
|
+
descendants_tracker (0.0.4)
|
10
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
docile (1.1.3)
|
13
|
+
faraday (0.9.0)
|
14
|
+
multipart-post (>= 1.2, < 3)
|
15
|
+
git (1.2.6)
|
16
|
+
github_api (0.11.3)
|
17
|
+
addressable (~> 2.3)
|
18
|
+
descendants_tracker (~> 0.0.1)
|
19
|
+
faraday (~> 0.8, < 0.10)
|
20
|
+
hashie (>= 1.2)
|
21
|
+
multi_json (>= 1.7.5, < 2.0)
|
22
|
+
nokogiri (~> 1.6.0)
|
23
|
+
oauth2
|
24
|
+
hashie (2.1.1)
|
25
|
+
highline (1.6.21)
|
26
|
+
httparty (0.13.1)
|
27
|
+
json (~> 1.8)
|
28
|
+
multi_xml (>= 0.5.2)
|
29
|
+
jeweler (2.0.1)
|
30
|
+
builder
|
31
|
+
bundler (>= 1.0)
|
32
|
+
git (>= 1.2.5)
|
33
|
+
github_api
|
34
|
+
highline (>= 1.6.15)
|
35
|
+
nokogiri (>= 1.5.10)
|
36
|
+
rake
|
37
|
+
rdoc
|
38
|
+
json (1.8.1)
|
39
|
+
jwt (0.1.11)
|
40
|
+
multi_json (>= 1.5)
|
41
|
+
mini_portile (0.5.3)
|
42
|
+
multi_json (1.9.2)
|
43
|
+
multi_xml (0.5.5)
|
44
|
+
multipart-post (2.0.0)
|
45
|
+
nokogiri (1.6.1)
|
46
|
+
mini_portile (~> 0.5.0)
|
47
|
+
oauth2 (0.9.3)
|
48
|
+
faraday (>= 0.8, < 0.10)
|
49
|
+
jwt (~> 0.1.8)
|
50
|
+
multi_json (~> 1.3)
|
51
|
+
multi_xml (~> 0.5)
|
52
|
+
rack (~> 1.2)
|
53
|
+
rack (1.5.2)
|
54
|
+
rake (10.3.1)
|
55
|
+
rdoc (4.1.1)
|
56
|
+
json (~> 1.4)
|
57
|
+
rspec (2.14.1)
|
58
|
+
rspec-core (~> 2.14.0)
|
59
|
+
rspec-expectations (~> 2.14.0)
|
60
|
+
rspec-mocks (~> 2.14.0)
|
61
|
+
rspec-core (2.14.8)
|
62
|
+
rspec-expectations (2.14.5)
|
63
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
64
|
+
rspec-mocks (2.14.6)
|
65
|
+
settingslogic (2.0.9)
|
66
|
+
simplecov (0.8.2)
|
67
|
+
docile (~> 1.1.0)
|
68
|
+
multi_json
|
69
|
+
simplecov-html (~> 0.8.0)
|
70
|
+
simplecov-html (0.8.0)
|
71
|
+
thread_safe (0.3.3)
|
72
|
+
|
73
|
+
PLATFORMS
|
74
|
+
ruby
|
75
|
+
|
76
|
+
DEPENDENCIES
|
77
|
+
api_smith
|
78
|
+
bundler
|
79
|
+
jeweler
|
80
|
+
rdoc
|
81
|
+
rspec
|
82
|
+
settingslogic
|
83
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Edson de Lima
|
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.rdoc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
= sms_way
|
2
|
+
|
3
|
+
*UNDER CONSTRUCTION - In some days I will add documentation here.
|
4
|
+
*But... if you want, you can use it. I use in production for more than one year, without any known bugs.
|
5
|
+
|
6
|
+
|
7
|
+
== Contributing to sms_way
|
8
|
+
|
9
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
10
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
11
|
+
* Fork the project.
|
12
|
+
* Start a feature/bugfix branch.
|
13
|
+
* Commit and push until you are happy with your contribution.
|
14
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
15
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
16
|
+
|
17
|
+
== Copyright
|
18
|
+
|
19
|
+
Copyright (c) 2013 Edson de Lima. See LICENSE.txt for
|
20
|
+
further details.
|
21
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = 'sms_way'
|
18
|
+
gem.homepage = 'http://github.com/edsonlima/sms_way'
|
19
|
+
gem.license = 'MIT'
|
20
|
+
gem.summary = 'Easy way to send SMS messages through any gateway.'
|
21
|
+
gem.description = 'sms_way helps you to send SMS, WAP or MMS messages trough of api''s of gateways as Kannel, UseSMS or others.'
|
22
|
+
gem.email = 'edsonalima@gmail.com'
|
23
|
+
gem.authors = ['Edson de Lima']
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:coverage) do |spec|
|
35
|
+
ENV['COVERAGE'] = 'true'
|
36
|
+
end
|
37
|
+
|
38
|
+
task :default => :spec
|
39
|
+
|
40
|
+
require 'rdoc/task'
|
41
|
+
Rake::RDocTask.new do |rdoc|
|
42
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ''
|
43
|
+
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = 'sms_way #{version}'
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/config/sms_way.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
common: &common
|
2
|
+
kannel:
|
3
|
+
base_uri: http://localhost:13013/cgi-bin
|
4
|
+
username: kannel
|
5
|
+
password: senha
|
6
|
+
extra_options:
|
7
|
+
charset: UTF-8
|
8
|
+
coding: 2
|
9
|
+
dlr-mask: 31
|
10
|
+
dlr-url: http://localhost:3000/clickatell_calback?status=%d&modem=%i&data=%t&hash_id=hiasafsio4343243
|
11
|
+
|
12
|
+
development:
|
13
|
+
<<: *common
|
14
|
+
|
15
|
+
test:
|
16
|
+
<<: *common
|
data/lib/config.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
##
|
2
|
+
# Monkeypath settingslogic
|
3
|
+
class Settingslogic
|
4
|
+
##
|
5
|
+
# fixes rspec to_ary error according to https://github.com/binarylogic/settingslogic/commit/d623622f7d8b184aebe9fda6c7996c4a44af5ee9
|
6
|
+
def method_missing(name, *args, &block)
|
7
|
+
super if name === :to_ary # delegate to_ary to Hash
|
8
|
+
key = name.to_s
|
9
|
+
return missing_key("Missing setting '#{key}' in #@section") unless has_key? key
|
10
|
+
value = fetch(key)
|
11
|
+
create_accessor_for(key)
|
12
|
+
value.is_a?(Hash) ? self.class.new(value, "'#{key}' section in #@section") : value
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
module SMSWay
|
18
|
+
|
19
|
+
class Config < Settingslogic
|
20
|
+
|
21
|
+
def self.load_configuration
|
22
|
+
source self.config_file
|
23
|
+
namespace self.env
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.new_source(value) #:no-doc:
|
27
|
+
@source = value
|
28
|
+
reload!
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.new_namespace(value) #:no-doc:
|
32
|
+
@namespace = value
|
33
|
+
reload!
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def self.config_file
|
38
|
+
File.join(defined?(Rails) ? Rails.root : Dir.pwd, 'config', 'sms_way.yml')
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.clients_path
|
42
|
+
File.join(defined?(Rails) ? Rails.root : Dir.pwd, 'lib', 'sms_way')
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.env
|
46
|
+
defined?(Rails) ? Rails.env : ENV['SMSWAY_ENV']
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.auth_options_of(client = self.active_client)
|
50
|
+
self[client]['auth_options']
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.base_options_of(client = self.active_client)
|
54
|
+
self[client]['base_options'] || {}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/sms_way.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'api_smith'
|
2
|
+
require 'settingslogic'
|
3
|
+
|
4
|
+
require 'config'
|
5
|
+
|
6
|
+
module SMSWay
|
7
|
+
|
8
|
+
class NoActiveClient < NameError; end
|
9
|
+
|
10
|
+
def self.clients
|
11
|
+
@clients ||= []
|
12
|
+
@clients
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.add_client(client)
|
16
|
+
@clients ||= []
|
17
|
+
@clients << client
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.send_sms(to, text, api_options = {})
|
21
|
+
self.active_client.send_sms(to, text, api_options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.active_client
|
25
|
+
return @active_client unless @active_client.nil?
|
26
|
+
raise(NoActiveClient.new('active_client was not specified')) if SMSWay::Config.active_client.empty?
|
27
|
+
client = @clients.detect {|k| k.to_s.upcase == SMSWay::Config.active_client.upcase}
|
28
|
+
client.nil? ? raise(NameError.new("#{SMSWay::Config.active_client} was not registered as a SMSWay client")) : @active_client = client.new(SMSWay::Config.auth_options_of)
|
29
|
+
@active_client
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.active_client=(client)
|
33
|
+
@active_client = client
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.start!
|
37
|
+
SMSWay::Config.load_configuration
|
38
|
+
Dir.glob(File.join(SMSWay::Config.clients_path, '**', '*.rb')).each {|f| require_relative f}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
require 'sms_way/registry'
|
43
|
+
require 'sms_way/base'
|
data/lib/sms_way/base.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module SMSWay
|
2
|
+
|
3
|
+
# Represents a client API
|
4
|
+
#
|
5
|
+
# All API classes must inherit from this class, and be saved in lib/deliverers directory.
|
6
|
+
class Base
|
7
|
+
include APISmith::Client
|
8
|
+
|
9
|
+
def self.inherited(subclass)
|
10
|
+
subclass.class_eval {
|
11
|
+
include APISmith::Client
|
12
|
+
include SMSWay::Registry
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(auth_options)
|
17
|
+
add_query_options! auth_options
|
18
|
+
end
|
19
|
+
|
20
|
+
# <b>Implement this method in your client implementation.</b>
|
21
|
+
#
|
22
|
+
# Sends a SMS message to clients specified in +to+ param.
|
23
|
+
#
|
24
|
+
# ==== Required parameters
|
25
|
+
# * +to+ - An array with destination addresses
|
26
|
+
# * +text+ - The message text.
|
27
|
+
#
|
28
|
+
# ==== Optional parameters
|
29
|
+
# * +api_options+ An hash with any optional or specific API parameters
|
30
|
+
def send_sms(to, text, api_options = {})
|
31
|
+
raise NotImplementedError.new('Implement send_sms(to, text, api_options = {}) in your client.')
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def base_query_options
|
37
|
+
SMSWay::Config.base_options_of(self.class.to_s)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/sms_way.gemspec
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: sms_way 0.1.2 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "sms_way"
|
9
|
+
s.version = "0.1.2"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Edson de Lima"]
|
14
|
+
s.date = "2014-11-27"
|
15
|
+
s.description = "sms_way helps you to send SMS, WAP or MMS messages trough of apis of gateways as Kannel, UseSMS or others."
|
16
|
+
s.email = "edsonalima@gmail.com"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"config/sms_way.yml",
|
31
|
+
"lib/config.rb",
|
32
|
+
"lib/sms_way.rb",
|
33
|
+
"lib/sms_way/base.rb",
|
34
|
+
"lib/sms_way/registry.rb",
|
35
|
+
"sms_way.gemspec",
|
36
|
+
"spec/base_spec.rb",
|
37
|
+
"spec/config_spec.rb",
|
38
|
+
"spec/dummy/config/sms_way.yml",
|
39
|
+
"spec/dummy/lib/sms_way/kannel.rb",
|
40
|
+
"spec/dummy/lib/sms_way/use_sms.rb",
|
41
|
+
"spec/dummy/test_registry.rb",
|
42
|
+
"spec/registry_spec.rb",
|
43
|
+
"spec/sms_way_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
s.homepage = "http://github.com/edsonlima/sms_way"
|
47
|
+
s.licenses = ["MIT"]
|
48
|
+
s.rubygems_version = "2.4.3"
|
49
|
+
s.summary = "Easy way to send SMS messages through any gateway."
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
s.specification_version = 4
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_runtime_dependency(%q<api_smith>, [">= 0"])
|
56
|
+
s.add_runtime_dependency(%q<settingslogic>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<api_smith>, [">= 0"])
|
63
|
+
s.add_dependency(%q<settingslogic>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
66
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
67
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
68
|
+
end
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<api_smith>, [">= 0"])
|
71
|
+
s.add_dependency(%q<settingslogic>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
73
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
74
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
75
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe SMSWay::Base do
|
4
|
+
|
5
|
+
describe 'When inherit a new class' do
|
6
|
+
require './spec/dummy/lib/sms_way/kannel'
|
7
|
+
|
8
|
+
it 'should add this class to clients list' do
|
9
|
+
expect(SMSWay.clients).to include(Kannel)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'Using to send messages' do
|
15
|
+
require './spec/dummy/lib/sms_way/use_sms'
|
16
|
+
|
17
|
+
it 'should raise NotImplementedError if try to send a sms directly' do
|
18
|
+
expect {
|
19
|
+
SMSWay::Base.new(username: 'test', password: 'pwd').send_sms('554699919199', 'Never sent text')
|
20
|
+
}.to raise_error(NotImplementedError, 'Implement send_sms(to, text, api_options = {}) in your client.')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe SMSWay::Config do
|
4
|
+
|
5
|
+
it 'should return config path' do
|
6
|
+
expect(SMSWay::Config.config_file).to eq(File.join(Dir.pwd, 'config', 'sms_way.yml'))
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should return clients directory' do
|
10
|
+
expect(SMSWay::Config.clients_path).to eq(File.join(Dir.pwd, 'lib', 'sms_way'))
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return auth_options of active_client' do
|
14
|
+
expect(SMSWay::Config).to receive(:active_client).and_return('Kannel')
|
15
|
+
expect(SMSWay::Config.auth_options_of).to eq({'username' => 'kannel', 'password' => 'password'})
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return auth_options of client' do
|
19
|
+
expect(SMSWay::Config.auth_options_of('UseSMS')).to eq({'username' => 'test', 'password' => 'pwd'})
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should retrun base_options of active_client' do
|
23
|
+
expect(SMSWay::Config).to receive(:active_client).and_return('Kannel')
|
24
|
+
expect(SMSWay::Config.base_options_of).to eq({'charset' => 'UTF-8', 'coding' => 2, 'dlr-mask' => 31,
|
25
|
+
'dlr-url' => 'http://localhost:3000/sms_calback?status=%d&modem=%i&date=%t&hash_id=hiasafsio4343243'})
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should return empty base_options if not configured' do
|
29
|
+
expect(SMSWay::Config.base_options_of('UseSMS')).to eq({})
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should return base_options of client' do
|
33
|
+
expect(SMSWay::Config.base_options_of('Kannel')).to eq({'charset' => 'UTF-8', 'coding' => 2, 'dlr-mask' => 31,
|
34
|
+
'dlr-url' => 'http://localhost:3000/sms_calback?status=%d&modem=%i&date=%t&hash_id=hiasafsio4343243'})
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when use it with Rails' do
|
38
|
+
let(:fake_rails) { double('Rails', env: 'production', root: '/my_rails_app/') }
|
39
|
+
before(:each) do
|
40
|
+
stub_const('Rails', fake_rails)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'return config file' do
|
44
|
+
expect(SMSWay::Config.config_file).to eq(File.join('/my_rails_app', 'config', 'sms_way.yml'))
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'return clients path' do
|
48
|
+
expect(SMSWay::Config.clients_path).to eq(File.join('/my_rails_app', 'lib', 'sms_way'))
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'return correct env' do
|
52
|
+
expect(SMSWay::Config.env).to eq('production')
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
common: &common
|
2
|
+
Kannel:
|
3
|
+
auth_options:
|
4
|
+
username: kannel
|
5
|
+
password: password
|
6
|
+
base_uri: http://localhost:13013/cgi-bin
|
7
|
+
base_options:
|
8
|
+
charset: UTF-8
|
9
|
+
coding: 2
|
10
|
+
dlr-mask: 31
|
11
|
+
dlr-url: http://localhost:3000/sms_calback?status=%d&modem=%i&date=%t&hash_id=hiasafsio4343243
|
12
|
+
UseSMS:
|
13
|
+
auth_options:
|
14
|
+
username: test
|
15
|
+
password: pwd
|
16
|
+
base_uri: http://usesms.leosoft.com.br/api
|
17
|
+
|
18
|
+
development:
|
19
|
+
active_client: Kannel
|
20
|
+
<<: *common
|
21
|
+
|
22
|
+
test:
|
23
|
+
<<: *common
|
24
|
+
active_client: not_exists
|
25
|
+
|
26
|
+
production:
|
27
|
+
<<: *common
|
28
|
+
active_client: UseSMS
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe 'When include registry module in a class' do
|
4
|
+
require './spec/dummy/test_registry'
|
5
|
+
|
6
|
+
it 'should include this class in client list' do
|
7
|
+
expect(SMSWay.clients).to include(TestRegistry)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should not include another classes' do
|
11
|
+
expect(SMSWay.clients).to_not include(Unregistred)
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
SMSWay.clients.delete(TestRegistry)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe SMSWay do
|
4
|
+
|
5
|
+
describe 'When start SMSWay' do
|
6
|
+
before(:each) do
|
7
|
+
ENV['SMSWAY_ENV'] = 'development'
|
8
|
+
expect(SMSWay::Config).to receive(:clients_path).and_return(File.join(File.expand_path(File.dirname(__FILE__)), 'spec', 'dummy', 'lib', 'sms_way'))
|
9
|
+
SMSWay.active_client = nil
|
10
|
+
SMSWay.start!
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should detect active_client' do
|
14
|
+
SMSWay::Config['active_client'] = 'Kannel'
|
15
|
+
expect(SMSWay.active_client).to be_instance_of(Kannel)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should detect active_client when it is not a "regular" name' do
|
19
|
+
SMSWay::Config['active_client'] = 'UseSMS'
|
20
|
+
expect(SMSWay.active_client).to be_instance_of(UseSMS)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should load any clients in lib/sms_way directory' do
|
24
|
+
expect(SMSWay.clients).to have(2).items
|
25
|
+
expect(SMSWay.clients).to include(Kannel, UseSMS)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should raise NameError if active_client is unregistred' do
|
29
|
+
SMSWay::Config['active_client'] = 'UnregisteredClient'
|
30
|
+
expect {SMSWay.active_client }.to raise_exception(NameError, 'UnregisteredClient was not registered as a SMSWay client')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise NoActiveClient if active_client is empty' do
|
34
|
+
SMSWay::Config['active_client'] = ''
|
35
|
+
expect { SMSWay.active_client }.to raise_exception(SMSWay::NoActiveClient, 'active_client was not specified')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should configure a new active_client' do
|
39
|
+
c = UseSMS.new(user: 'user', password: 'pwd')
|
40
|
+
SMSWay.active_client = c
|
41
|
+
expect(SMSWay.active_client).to equal(c)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'When try to send a sms' do
|
47
|
+
|
48
|
+
before(:each) do
|
49
|
+
ENV['SMSWAY_ENV'] = 'development'
|
50
|
+
SMSWay::Config.should_receive(:clients_path).and_return(File.join(File.expand_path(File.dirname(__FILE__)), 'spec', 'dummy', 'lib', 'sms_way'))
|
51
|
+
SMSWay::Config['active_client'] = 'Kannel'
|
52
|
+
SMSWay.start!
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should raise a NoActiveClient if active_client was not especified' do
|
56
|
+
SMSWay::Config['active_client'] = ''
|
57
|
+
SMSWay.active_client = nil
|
58
|
+
expect { SMSWay.send_sms('5546991999999', 'Never sent text') }.to raise_error(SMSWay::NoActiveClient, 'active_client was not specified')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should send messages with active_client' do
|
62
|
+
expect_any_instance_of(Kannel).to receive(:send_sms).with(any_args()).and_return('OK!')
|
63
|
+
expect(SMSWay.send_sms('554699190000', 'First message sent!')).to eq('OK!')
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
ENV['SMSWAY_ENV'] = 'development'
|
5
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'sms_way')
|
6
|
+
SMSWay::Config.new_source(File.join(Dir.pwd, 'spec', 'dummy', 'config', 'sms_way.yml'))
|
7
|
+
SMSWay::Config.new_namespace('development')
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.expect_with(:rspec) {|c| c.syntax = :expect}
|
11
|
+
end
|
12
|
+
# Requires supporting files with custom matchers and macros, etc,
|
13
|
+
# in ./support/ and its subdirectories.
|
14
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
15
|
+
|
16
|
+
if ENV['COVERAGE']
|
17
|
+
require 'simplecov'
|
18
|
+
SimpleCov.start
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sms_way
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Edson de Lima
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: api_smith
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: settingslogic
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jeweler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: sms_way helps you to send SMS, WAP or MMS messages trough of apis of
|
98
|
+
gateways as Kannel, UseSMS or others.
|
99
|
+
email: edsonalima@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files:
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.rdoc
|
105
|
+
files:
|
106
|
+
- ".document"
|
107
|
+
- ".rspec"
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.rdoc
|
112
|
+
- Rakefile
|
113
|
+
- VERSION
|
114
|
+
- config/sms_way.yml
|
115
|
+
- lib/config.rb
|
116
|
+
- lib/sms_way.rb
|
117
|
+
- lib/sms_way/base.rb
|
118
|
+
- lib/sms_way/registry.rb
|
119
|
+
- sms_way.gemspec
|
120
|
+
- spec/base_spec.rb
|
121
|
+
- spec/config_spec.rb
|
122
|
+
- spec/dummy/config/sms_way.yml
|
123
|
+
- spec/dummy/lib/sms_way/kannel.rb
|
124
|
+
- spec/dummy/lib/sms_way/use_sms.rb
|
125
|
+
- spec/dummy/test_registry.rb
|
126
|
+
- spec/registry_spec.rb
|
127
|
+
- spec/sms_way_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
homepage: http://github.com/edsonlima/sms_way
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.4.3
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Easy way to send SMS messages through any gateway.
|
153
|
+
test_files: []
|