active_sms 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a8d1dd6ad22373355ea92034148d7c7372236d84
4
+ data.tar.gz: 4efc65029b7a1ea4692ce9d89184e6c3f02cae5c
5
+ SHA512:
6
+ metadata.gz: 793130b952a78ed1c5fe860aa3c1c35820ca5e0f65dc1bb6dca2a90dc91d2553e1f4fa606353054c5fbb69819934fac62e3672d2e8fe3219ab8af9f666689006
7
+ data.tar.gz: e7cbb4c1f177f929fbd64f31071686adf4df787df3d99d09a9b22566264c5710854c52a5d77b88302fb80fa40134fb8d78c03ce05989c64fad527ce58b4c1d54
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ Style/StringLiterals:
2
+ EnforcedStyle: double_quotes
3
+ ConsistentQuotesInMultiline: true
4
+
5
+ Metrics/LineLength:
6
+ Max: 90
7
+
8
+ Style/ClassAndModuleChildren:
9
+ Enabled: false
10
+
11
+ # I need to use singleton so gem stays simple
12
+ Style/ClassVars:
13
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ rvm: 2.3.1
5
+ install:
6
+ - bundle install --retry=3
7
+ script:
8
+ - bundle exec rake
9
+ - bundle exec rubocop
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,15 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Lib files
12
+ watch(%r{^lib/active_sms.rb$}) { rspec.spec_dir }
13
+ watch(%r{^lib/(.+)\.rb$}) { |m| rspec.spec.call(m[1]) }
14
+ watch(%r{^spec/support/(.+)\.rb$}) { |m| rspec.spec.call(m[1]) }
15
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Fedcomp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # ActiveSMS
2
+
3
+ [![Build Status](https://travis-ci.org/Fedcomp/active_sms.svg?branch=master)](https://travis-ci.org/Fedcomp/active_sms)
4
+
5
+ Easily send sms using various sms backends!
6
+ The gem is work in progress now.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'active_sms'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install active_sms
23
+
24
+ ## Usage
25
+
26
+ To be done.
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Fedcomp/active_sms.
31
+
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,53 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "active_sms/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_sms"
8
+ spec.version = ActiveSMS::VERSION
9
+ spec.authors = ["Fedcomp"]
10
+ spec.email = ["aglergen@gmail.com"]
11
+
12
+ spec.summary = "Easily send sms using various sms backends!"
13
+ spec.description = <<-DESCRIPTION
14
+ Say you want to send sms in your app.
15
+ You think it's simple.
16
+ What (most likely) you do?
17
+ you create simple class to do it.
18
+ Then you need to mock it in tests,
19
+ and need to use different backend
20
+ in different environments, or even
21
+ use multiple backends in single environment.
22
+ This gems aims at solving most common cases
23
+ for sending sms in your app
24
+ DESCRIPTION
25
+
26
+ spec.homepage = "https://github.com/Fedcomp/active_sms"
27
+ spec.license = "MIT"
28
+
29
+ # Prevent pushing this gem to RubyGems.org.
30
+ # To allow pushes either set the 'allowed_push_host'
31
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
32
+ if spec.respond_to?(:metadata)
33
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
34
+ else
35
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
36
+ end
37
+
38
+ spec.files = `git ls-files -z`
39
+ .split("\x0")
40
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
41
+ spec.bindir = "exe"
42
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
43
+ spec.require_paths = ["lib"]
44
+
45
+ spec.add_development_dependency "bundler", "~> 1.12"
46
+ spec.add_development_dependency "rake", "~> 10.0"
47
+ spec.add_development_dependency "rspec", "~> 3.0"
48
+
49
+ spec.add_development_dependency "guard", "~> 2.14"
50
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
51
+ spec.add_development_dependency "pry-byebug", "~> 3.4"
52
+ spec.add_development_dependency "rubocop"
53
+ end
data/lib/active_sms.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "active_sms/version"
2
+ require "active_sms/backend/base"
3
+ require "active_sms/backend/null_sender"
4
+ require "active_sms/configuration"
5
+ require "active_sms/response"
6
+ require "active_sms/sending"
7
+
8
+ # rubocop:ignore Style/Documentation
9
+ module ActiveSMS
10
+ end
@@ -0,0 +1,19 @@
1
+ module ActiveSMS::Backend
2
+ # TODO: Documentation
3
+ # rubocop:ignore Style/Documentation
4
+ class Base
5
+ def initialize(params = {})
6
+ end
7
+
8
+ def send_sms(_phone, _text)
9
+ raise NotImplementedError,
10
+ "You should create your own class for every sms service you use"
11
+ end
12
+
13
+ protected
14
+
15
+ def respond_with_status(status)
16
+ ActiveSMS::Response.new(status: status)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ # Sms backend to not send anything.
2
+ # Purely for usage in tests
3
+ class ActiveSMS::Backend::NullSender < ActiveSMS::Backend::Base
4
+ def send_sms(_phone, _text)
5
+ respond_with_status :success
6
+ end
7
+ end
@@ -0,0 +1,69 @@
1
+ # rubocop:ignore Style/Documentation
2
+ module ActiveSMS
3
+ def self.config
4
+ @@config ||= Configuration.new
5
+ end
6
+
7
+ def self.configure
8
+ yield(config)
9
+ end
10
+
11
+ def self.reset!
12
+ @@config = nil
13
+ end
14
+
15
+ # TODO: Documentation
16
+ # rubocop:ignore Style/Documentation
17
+ class Configuration
18
+ attr_reader :default_backend
19
+ attr_reader :backends
20
+
21
+ def initialize
22
+ register_backend :null_sender, ActiveSMS::Backend::NullSender
23
+ self.default_backend = :null_sender
24
+ end
25
+
26
+ def default_backend=(value)
27
+ raise ArgumentError, "default_backend must be a symbol!" unless value.is_a? Symbol
28
+
29
+ unless @backends.keys.include? value
30
+ raise ArgumentError, "Unregistered backend cannot be set as default!"
31
+ end
32
+
33
+ @default_backend = value
34
+ end
35
+
36
+ def register_backend(key, classname, params = {})
37
+ raise ArgumentError, "backend key must be a symbol!" unless key.is_a? Symbol
38
+
39
+ unless classname.class == Class
40
+ raise ArgumentError, "backend class must be class (not instance or string)"
41
+ end
42
+
43
+ unless classname.method_defined? :send_sms
44
+ raise ArgumentError, "backend must provide method send_sms"
45
+ end
46
+
47
+ define_backend(key, classname, params)
48
+ end
49
+
50
+ def remove_backend(key)
51
+ if key == default_backend
52
+ raise ArgumentError, "Removing default_backend is prohibited"
53
+ end
54
+
55
+ @backends.delete key
56
+ true
57
+ end
58
+
59
+ private
60
+
61
+ def define_backend(key, classname, params)
62
+ @backends ||= {}
63
+ @backends[key] = {
64
+ class: classname,
65
+ params: params
66
+ }
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,16 @@
1
+ # rubocop:ignore Style/Documentation
2
+ class ActiveSMS::Response
3
+ attr_reader :status
4
+
5
+ def initialize(args = {})
6
+ @status = args.delete(:status)
7
+ end
8
+
9
+ def success?
10
+ @status == :success
11
+ end
12
+
13
+ def failed?
14
+ !success?
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ # rubocop:ignore Style/Documentation
2
+ module ActiveSMS
3
+ class << self
4
+ def send_sms(phone, text)
5
+ current_backend.new(current_backend_params)
6
+ .send_sms(phone, text)
7
+ end
8
+
9
+ def current_backend
10
+ ActiveSMS.config.backends[ActiveSMS.config.default_backend][:class]
11
+ end
12
+
13
+ private
14
+
15
+ def current_backend_params
16
+ ActiveSMS.config.backends[ActiveSMS.config.default_backend][:params]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveSMS
2
+ VERSION = "0.0.1".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fedcomp
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: |2
112
+ Say you want to send sms in your app.
113
+ You think it's simple.
114
+ What (most likely) you do?
115
+ you create simple class to do it.
116
+ Then you need to mock it in tests,
117
+ and need to use different backend
118
+ in different environments, or even
119
+ use multiple backends in single environment.
120
+ This gems aims at solving most common cases
121
+ for sending sms in your app
122
+ email:
123
+ - aglergen@gmail.com
124
+ executables: []
125
+ extensions: []
126
+ extra_rdoc_files: []
127
+ files:
128
+ - ".gitignore"
129
+ - ".rspec"
130
+ - ".rubocop.yml"
131
+ - ".travis.yml"
132
+ - Gemfile
133
+ - Guardfile
134
+ - LICENSE.txt
135
+ - README.md
136
+ - Rakefile
137
+ - active_sms.gemspec
138
+ - lib/active_sms.rb
139
+ - lib/active_sms/backend/base.rb
140
+ - lib/active_sms/backend/null_sender.rb
141
+ - lib/active_sms/configuration.rb
142
+ - lib/active_sms/response.rb
143
+ - lib/active_sms/sending.rb
144
+ - lib/active_sms/version.rb
145
+ homepage: https://github.com/Fedcomp/active_sms
146
+ licenses:
147
+ - MIT
148
+ metadata:
149
+ allowed_push_host: https://rubygems.org
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.5.1
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Easily send sms using various sms backends!
170
+ test_files: []