meta_sms 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +23 -0
- data/lib/generators/meta_sms/install_generator.rb +22 -0
- data/lib/generators/meta_sms/migrations_for_logger_generator.rb +25 -0
- data/lib/generators/meta_sms/templates/meta_sms_initializer.rb +19 -0
- data/lib/generators/meta_sms/templates/migrations/create_sms_loggings.rb +13 -0
- data/lib/meta_sms/configuration.rb +25 -0
- data/lib/meta_sms/meta_sms_error.rb +15 -0
- data/lib/meta_sms/providers/i_sms_provider.rb +56 -0
- data/lib/meta_sms/providers/provider_utility.rb +59 -0
- data/lib/meta_sms/providers/smsbox.rb +68 -0
- data/lib/meta_sms/sms_logging.rb +35 -0
- data/lib/meta_sms/sms_provider_selector.rb +32 -0
- data/lib/meta_sms/utility.rb +18 -0
- data/lib/meta_sms/version.rb +3 -0
- data/lib/meta_sms.rb +67 -0
- data/lib/tasks/meta_sms_tasks.rake +4 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 80961d4503e372186a20a6d562bf239e52b1c96f
|
4
|
+
data.tar.gz: c32ae42928d4cfd813fbfe29698ce7bd06f34b05
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0a66906b88fdc4638d1c5159937a2d95eff6a5efb0eeb901d735dba5a162defc463b2a42695e459b544d4b2175be83b5f0156b5f43ebefead2869bef981e25f7
|
7
|
+
data.tar.gz: b19ec1ad55cd053ae44a6913af2ced49173f2432b9f3ae37d15692244db32fd0771781d61deffe6307fbd31bd9bc388a488bcb9cd6cc9ea4c04155a4075f4068
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Shobhit Dixit
|
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
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'MetaSms'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
module MetaSms
|
5
|
+
|
6
|
+
|
7
|
+
# This creates MetaSms initializer for your application
|
8
|
+
# It will copy the config file template in config/initializers/meta_sms.rb
|
9
|
+
#
|
10
|
+
# @author Shobhit Dixit
|
11
|
+
class InstallGenerator < ::Rails::Generators::Base
|
12
|
+
include ::Rails::Generators::Migration
|
13
|
+
source_root File.expand_path("../templates", __FILE__)
|
14
|
+
desc "Creates MetaSms initializer for your application"
|
15
|
+
|
16
|
+
def copy_initializer
|
17
|
+
template "meta_sms_initializer.rb", "config/initializers/meta_sms.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
module MetaSms
|
5
|
+
|
6
|
+
# This is a generator for SmsLogging migration
|
7
|
+
# It Generates (but does not run) a migration to add a sms_loggings table
|
8
|
+
#
|
9
|
+
# @author Shobhit Dixit
|
10
|
+
class MigrationsForLoggerGenerator < ::Rails::Generators::Base
|
11
|
+
include ::Rails::Generators::Migration
|
12
|
+
source_root File.expand_path("../templates/migrations", __FILE__)
|
13
|
+
desc "Generates (but does not run) a migration to add a sms_loggings table"
|
14
|
+
|
15
|
+
def create_migration_file
|
16
|
+
migration_template 'create_sms_loggings.rb', 'db/migrate/create_sms_loggings.rb'
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.next_migration_number(dirname)
|
20
|
+
::ActiveRecord::Generators::Base.next_migration_number(dirname)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
MetaSms.configure do |config|
|
2
|
+
|
3
|
+
# This gem is a wrapper to use smsbox api in rails to send sms.
|
4
|
+
|
5
|
+
|
6
|
+
# make this true if logging is required
|
7
|
+
# also run 'rails g meta_sms:migrations_for_logger' in order to add migrations for sms logger
|
8
|
+
# currently this gem supports only pg adapter for database
|
9
|
+
config.logging = false
|
10
|
+
|
11
|
+
# config.sms_provider_name = :smsbox
|
12
|
+
# config.smsbox_user_name = ''
|
13
|
+
# config.smsbox_key = ''
|
14
|
+
# config.route = 'Transactional'
|
15
|
+
# config.from = 'tpohub'
|
16
|
+
# config.type = 'TextSMS'
|
17
|
+
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module MetaSms
|
2
|
+
class << self
|
3
|
+
attr_accessor :config
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configure
|
7
|
+
self.config ||= Config.new
|
8
|
+
yield(config)
|
9
|
+
end
|
10
|
+
|
11
|
+
# TODO: write dynamic attr_accessor. as currently it is written only for smsbox
|
12
|
+
class Config
|
13
|
+
attr_accessor :sms_provider_name,:logging, :smsbox_user_name, :smsbox_key, :route,:from,:type
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@logging = false
|
17
|
+
@type = 'TextSMS'
|
18
|
+
@sms_provider_name = nil
|
19
|
+
@smsbox_user_name = nil
|
20
|
+
@smsbox_key = nil
|
21
|
+
@route = nil
|
22
|
+
@from = nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MetaSms
|
2
|
+
|
3
|
+
# This is a class for custom error in meta_sms.
|
4
|
+
# This method will be used to raise exceptions regarding meta_sms gem.
|
5
|
+
#
|
6
|
+
# @author Shobhit Dixit
|
7
|
+
class MetaSmsError < StandardError
|
8
|
+
|
9
|
+
def initialize(msg="")
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'meta_sms/providers/provider_utility'
|
2
|
+
|
3
|
+
module MetaSms
|
4
|
+
|
5
|
+
# ISmsProvider acts as an interface for all sms providers in this gem.
|
6
|
+
# It has a method send_sms, which every sms provider class must override or else error will be thrown.
|
7
|
+
# There is a constant REQUIRED_OPTIONS, which represents the required options in order to send message.
|
8
|
+
# for now, message_text and mobile_number is the only options that are required.
|
9
|
+
#
|
10
|
+
#
|
11
|
+
# => 'Sms provider class' refers to the class which is a sms service provider and which inherits ISmsProvider. eg: providers/sms_box.rb
|
12
|
+
# @author Shobhit Dixit
|
13
|
+
class ISmsProvider
|
14
|
+
|
15
|
+
REQUIRED_OPTIONS = [:message_text, :mobile_number]
|
16
|
+
|
17
|
+
# Initialize options
|
18
|
+
#
|
19
|
+
# @param [Hash] options
|
20
|
+
# @example {:message_text* => "Some text message", :mobile_number* => 7894561237, :logging => boolean, :metadata =>json }
|
21
|
+
# @note here message_text and mobile_number are required params and others are optional
|
22
|
+
# @author Shobhit Dixit
|
23
|
+
def initialize(options)
|
24
|
+
@options = options
|
25
|
+
end
|
26
|
+
|
27
|
+
# Method to overide in every sms provider class in order to send sms
|
28
|
+
#
|
29
|
+
# @raise NotImplementedError
|
30
|
+
# @author Shobhit Dixit
|
31
|
+
def send_sms
|
32
|
+
raise NotImplementedError, "send_sms"
|
33
|
+
end
|
34
|
+
|
35
|
+
# This method checks the presence of the value of the required options key
|
36
|
+
# This is called in sms provider class.
|
37
|
+
#
|
38
|
+
# @param [Symbol] required_option_key one of the keys of @options whose presence needs to be checked.
|
39
|
+
# @return [Object] returned object can be string or object depending upon the value of the key in @options.
|
40
|
+
# @author Shobhit Dixit
|
41
|
+
def check_required_option(required_option_key)
|
42
|
+
value = @options[required_option_key]
|
43
|
+
if value.blank?
|
44
|
+
ProviderUtility.raise_error_for_blank_value(required_option_key)
|
45
|
+
else
|
46
|
+
value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def check_for_valid_mobile_number(mobile_number)
|
51
|
+
mobile_number
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "meta_sms/meta_sms_error"
|
2
|
+
|
3
|
+
module MetaSms
|
4
|
+
|
5
|
+
# This is a utility class for sms providers. This encapsulates some common class methods as
|
6
|
+
# => raise_low_balance_exception
|
7
|
+
# This method will be used to raise an exception if the balance in sms service provider account is low.
|
8
|
+
# This method can be called in the respective sms provider class. eg: sms_box.rb.
|
9
|
+
# => raise_error_for_blank_value
|
10
|
+
# This method is used to raise ArgumentError. This can be called in the sms_provider_interface (i_sms_provider) in order to raise the exception is value of any
|
11
|
+
# required option is blank.
|
12
|
+
# => check_required_config_param
|
13
|
+
# This method is used to check presence of required config variables. It can be called in the respective sms provider class. eg: sms_box.rb.
|
14
|
+
#
|
15
|
+
# @author Shobhit Dixit
|
16
|
+
class ProviderUtility
|
17
|
+
|
18
|
+
# This method is used to check presence of required config variables
|
19
|
+
#
|
20
|
+
# @param [String/Symbol] config_param parameters define in config file
|
21
|
+
# @raise ArgumentError if the value of the config param is blank
|
22
|
+
# @return [Object] Value can be string or an object depending upon the value config variable
|
23
|
+
# @author Shobhit Dixit
|
24
|
+
def self.check_required_config_param(config_param)
|
25
|
+
value = eval "MetaSms.config.#{config_param}"
|
26
|
+
if value.blank?
|
27
|
+
raise ArgumentError.new "Property #{config_param} is not found. Please check required parameters in initializer file (config/initializers/meta_sms.rb)."
|
28
|
+
end
|
29
|
+
value
|
30
|
+
end
|
31
|
+
|
32
|
+
# This method will raise ArgumentError
|
33
|
+
#
|
34
|
+
# @param [Symbol/String] key of the @options in i_sms_provider
|
35
|
+
# @raise ArgumentError
|
36
|
+
# @author Shobhit Dixit
|
37
|
+
def self.raise_error_for_blank_value(key)
|
38
|
+
raise ArgumentError.new "No #{key} found."
|
39
|
+
end
|
40
|
+
|
41
|
+
# This method will raise low balance error
|
42
|
+
#
|
43
|
+
# @raise StandardError
|
44
|
+
# @author Shobhit Dixit
|
45
|
+
def self.raise_low_balance_exception
|
46
|
+
raise MetaSmsError.new "Your balance is low for sending message."
|
47
|
+
end
|
48
|
+
|
49
|
+
# This method will raise authentication error
|
50
|
+
#
|
51
|
+
# @raise SecurityError
|
52
|
+
# @author Shobhit Dixit
|
53
|
+
def self.authentication_error
|
54
|
+
raise SecurityError.new 'Authentication Failed. Please Try Again.'
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module MetaSms
|
4
|
+
|
5
|
+
# This is a sms provider class which inherits ISmsProvider.
|
6
|
+
#
|
7
|
+
# @author Shobhit Dixit
|
8
|
+
class Smsbox < ISmsProvider
|
9
|
+
|
10
|
+
SMSBOX_PUBLIC_API_URI = "http://smsbox.in/SecureApi.aspx?"
|
11
|
+
|
12
|
+
# Smsbox required config params = smsbox_user_name, smsbox_key, route, from
|
13
|
+
# Smsbox optional config params = type, logging
|
14
|
+
|
15
|
+
REQ_CONFIG_PARAMS = [:smsbox_user_name, :smsbox_key, :route, :from]
|
16
|
+
|
17
|
+
# Description of method
|
18
|
+
# @overide
|
19
|
+
# @return [Type] description of returned object
|
20
|
+
# @author Shobhit Dixit
|
21
|
+
def send_sms
|
22
|
+
res = Net::HTTP.get parsed_uri
|
23
|
+
case res
|
24
|
+
when "Error : Authentication Failed. Please Try Again"
|
25
|
+
ProviderUtility.authentication_error
|
26
|
+
when "Error : Your balance is low for sending message."
|
27
|
+
ProviderUtility.raise_low_balance_exception
|
28
|
+
end
|
29
|
+
res
|
30
|
+
end
|
31
|
+
|
32
|
+
def parsed_uri
|
33
|
+
URI.parse(URI.encode(api_url.strip))
|
34
|
+
end
|
35
|
+
|
36
|
+
# This method will make an api url
|
37
|
+
#
|
38
|
+
# @return [String] api_url
|
39
|
+
# @author Shobhit Dixit
|
40
|
+
def api_url
|
41
|
+
"#{SMSBOX_PUBLIC_API_URI}usr=#{smsbox_user_name}&key=#{smsbox_key}&smstype=#{MetaSms.config.type}&to=#{mobile_number}&msg=#{message_text}&rout=#{route}&from=#{from}"
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
# This will dynamically generate methods at run time. Method name will be same as the REQ_CONFIG_PARAMS key.
|
46
|
+
# These methods are used in .api_url
|
47
|
+
#
|
48
|
+
# @see ProviderUtility.check_required_config_param
|
49
|
+
# @author Shobhit Dixit
|
50
|
+
REQ_CONFIG_PARAMS.each do |param|
|
51
|
+
define_method "#{param}" do
|
52
|
+
ProviderUtility.check_required_config_param param
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# This will dynamically generate methods. Method name will be same as the REQUIRED_OPTIONS key.
|
57
|
+
# These methods are used in .api_url
|
58
|
+
#
|
59
|
+
# @see .check_required_option
|
60
|
+
# @author Shobhit Dixit
|
61
|
+
REQUIRED_OPTIONS.each do |option|
|
62
|
+
define_method "#{option}" do
|
63
|
+
check_required_option option
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module MetaSms
|
2
|
+
|
3
|
+
# This is an ActiveRecord class. It is used to save sms log in db.
|
4
|
+
#
|
5
|
+
# @author Shobhit Dixit
|
6
|
+
class SmsLogging < ActiveRecord::Base
|
7
|
+
|
8
|
+
# Description of method
|
9
|
+
#
|
10
|
+
# @param [String] result of .send_sms method in provider class
|
11
|
+
# @param [Hash] options provided in ISmsProvider
|
12
|
+
# @param [Error] error raised by .send_sms method in provider class
|
13
|
+
# @author Shobhit Dixit
|
14
|
+
def self.log_sms(result, options, error)
|
15
|
+
if ActiveRecord::Base.connection.table_exists? self.table_name
|
16
|
+
SmsLogging.create( SmsLogging.get_sms_logging_object(result, options, error) )
|
17
|
+
else
|
18
|
+
raise StandardError.new "No table exists. Please run 'rails g meta_sms:migrations_for_logger' and then run 'rake db:migrate'. To disable this warning, make config.logging=false, in config/initializers/meta_sms.rb."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get_sms_logging_object(result, options, error)
|
23
|
+
sms_logging_object = {
|
24
|
+
message_text: options[:message_text],
|
25
|
+
mobile_number: options[:mobile_number],
|
26
|
+
error_message: error.try(:message)
|
27
|
+
}
|
28
|
+
metadata = options[:metadata]
|
29
|
+
sms_logging_object[:metadata] = {:response => result}.as_json
|
30
|
+
sms_logging_object[:metadata].merge(metadata) if metadata.present?
|
31
|
+
sms_logging_object
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module MetaSms
|
2
|
+
|
3
|
+
# This class is to select sms service provider. Requiring of the provider class is also done dynamically.
|
4
|
+
# Selection and dynamic require is done on the basis of config variable MetaSms.config.sms_provider_name.
|
5
|
+
#
|
6
|
+
# @author Shobhit Dixit
|
7
|
+
class SmsProviderSelector
|
8
|
+
|
9
|
+
# constant to keep track of sms providers
|
10
|
+
# naming convention: keys of SMS_PROVIDERS shall be used in config of meta_sms.rb initializer
|
11
|
+
# and value should be same as the name of the class of sms provider.
|
12
|
+
# also, the name of the class will be snake cased to require the class file
|
13
|
+
# for eg, for smsbox, there is a file named smsbox.rb in providers folder and the name of the class is Smsbox.
|
14
|
+
# @author Shobhit Dixit
|
15
|
+
SMS_PROVIDERS = {
|
16
|
+
:smsbox => "Smsbox"
|
17
|
+
}
|
18
|
+
|
19
|
+
#
|
20
|
+
# @author Shobhit Dixit
|
21
|
+
def initialize
|
22
|
+
@sms_provider_class_name = SMS_PROVIDERS[MetaSms.config.sms_provider_name]
|
23
|
+
raise ArgumentError.new 'No or wrong provider found. Please add a correct provider name in config/initializers/meta_sms.rb' if @sms_provider_class_name.blank?
|
24
|
+
require "meta_sms/providers/#{@sms_provider_class_name.underscore}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def provider_class
|
28
|
+
(eval @sms_provider_class_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module MetaSms
|
2
|
+
|
3
|
+
# This is a utility class for meta_sms. This encapsulates some common class methods as
|
4
|
+
# #logging?
|
5
|
+
# This method will be used to check whether logging of sms is required or not.
|
6
|
+
#
|
7
|
+
# @author Shobhit Dixit
|
8
|
+
class Utility
|
9
|
+
|
10
|
+
# @return [Boolean] true if logging is true in config initializer or in @options, else false
|
11
|
+
# @author Shobhit Dixit
|
12
|
+
def self.logging?(logging=nil)
|
13
|
+
logging == true || MetaSms.config.logging == true
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/meta_sms.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'meta_sms/sms_provider_selector'
|
2
|
+
require 'meta_sms/providers/i_sms_provider'
|
3
|
+
require 'meta_sms/providers/smsbox'
|
4
|
+
require 'meta_sms/configuration'
|
5
|
+
require 'meta_sms/sms_logging'
|
6
|
+
require 'meta_sms/utility'
|
7
|
+
|
8
|
+
# This module is use to send sms through sms providers as sms box.
|
9
|
+
# It contains a class method #send_sms which takes a hash as argument.
|
10
|
+
# #send_sms will send sms, log sms if logging is enabled ((in options or config.logging) and migrations_for_logger is generated and migrated.)
|
11
|
+
# Some inportant classes of module MetaSms are:
|
12
|
+
# => Config
|
13
|
+
# Config is for containg the config variables required in the process of sending sms and logging results in db.
|
14
|
+
# => SmsProviderSelector
|
15
|
+
# MetaSms#send_sms uses SmsProviderSelector class to select the provider from the given lists of provider in the gem
|
16
|
+
# on the basis of the configuration variable, sms_provider_name.
|
17
|
+
# => ISmsProvider
|
18
|
+
# It acts as an interface for all the providers. So, in order to use sms provider class, we shall create an object
|
19
|
+
# of sms provider, which in turn use the constructor of ISmsProvider. This constructor takes options as an argument.
|
20
|
+
# options is a hash in which :message_text and :mobile_number is the required keys. Other optional keys can be
|
21
|
+
# :logging, :metadata. Here, :message_text will be the message sen to the user with mobile number as :mobile_number.
|
22
|
+
# :logging represents whether logging of this message is required in the database or not. There is a config variable
|
23
|
+
# logging, which also determines the same. So, logging will be true, if any of these value is true. :metadata can be
|
24
|
+
# any json data that client wants to save in the db along with the log.
|
25
|
+
# => Smsbox
|
26
|
+
# Smsbox is the sms provider class. It will have a method send_sms, which overrides the method of its parent class, ISmsProvider.
|
27
|
+
# Smsbox.send_sms will send message if required options and required configuration variable are present else, it will
|
28
|
+
# raise error. MetaSms#send_sms will rescue the error, write the log and then throw the rescued error.
|
29
|
+
# @note Here error from sms_logging is not handled.
|
30
|
+
# => SmsLogging
|
31
|
+
# This is an active record responsible to log data into database. It will save the sms log into a sms_loggings table.
|
32
|
+
# SmsLogging#log_sms is the method which does saving job. This method will raise StandardError if
|
33
|
+
# config.logging or options[:logging] is true and you have not executed, 'rails g meta_sms:migrations_for_logger'.
|
34
|
+
#
|
35
|
+
#
|
36
|
+
# @author Shobhit Dixit
|
37
|
+
module MetaSms
|
38
|
+
|
39
|
+
# This class method is use to send sms through this gem.
|
40
|
+
#
|
41
|
+
# @param [Hash] options
|
42
|
+
# @example {:message_text* => "Some text message", :mobile_number* => 7894561237, :logging => boolean, :metadata =>json }
|
43
|
+
# @note here message_text and mobile_number are required params and others are optional
|
44
|
+
#
|
45
|
+
# @raise MetaSmsError (for now, only-if balance is low)
|
46
|
+
# @raise SecurityError (for when service provider Authentication Failed)
|
47
|
+
# @raise StandardError (for when logging is true but no table for sms_loggings)
|
48
|
+
# @return [Type] description of returned object
|
49
|
+
# @author Shobhit Dixit
|
50
|
+
def self.send_sms(options)
|
51
|
+
provider_class = SmsProviderSelector.new.provider_class
|
52
|
+
pc = provider_class.new(options)
|
53
|
+
error = nil
|
54
|
+
begin
|
55
|
+
result = pc.send_sms
|
56
|
+
rescue MetaSmsError => meta_sms_error
|
57
|
+
error = meta_sms_error
|
58
|
+
rescue SecurityError => security_error
|
59
|
+
error = security_error
|
60
|
+
end
|
61
|
+
# This will raise an standard error if no table is present and logging is true.
|
62
|
+
SmsLogging.log_sms(result, options, error) if Utility.logging?(options[:logging])
|
63
|
+
raise error if error.present?
|
64
|
+
result
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: meta_sms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shobhit Dixit
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.6
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.6
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.0'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 12.0.0
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '12.0'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 12.0.0
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rubycritic
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.2'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.2'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: pg
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - '='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.19.0
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - '='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.19.0
|
103
|
+
description: Description of MetaSms.
|
104
|
+
email:
|
105
|
+
- shobhit.dixit@metacube.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- MIT-LICENSE
|
111
|
+
- README.rdoc
|
112
|
+
- Rakefile
|
113
|
+
- lib/generators/meta_sms/install_generator.rb
|
114
|
+
- lib/generators/meta_sms/migrations_for_logger_generator.rb
|
115
|
+
- lib/generators/meta_sms/templates/meta_sms_initializer.rb
|
116
|
+
- lib/generators/meta_sms/templates/migrations/create_sms_loggings.rb
|
117
|
+
- lib/meta_sms.rb
|
118
|
+
- lib/meta_sms/configuration.rb
|
119
|
+
- lib/meta_sms/meta_sms_error.rb
|
120
|
+
- lib/meta_sms/providers/i_sms_provider.rb
|
121
|
+
- lib/meta_sms/providers/provider_utility.rb
|
122
|
+
- lib/meta_sms/providers/smsbox.rb
|
123
|
+
- lib/meta_sms/sms_logging.rb
|
124
|
+
- lib/meta_sms/sms_provider_selector.rb
|
125
|
+
- lib/meta_sms/utility.rb
|
126
|
+
- lib/meta_sms/version.rb
|
127
|
+
- lib/tasks/meta_sms_tasks.rake
|
128
|
+
homepage: https://github.com/shobhit-m/meta_sms
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.6.12
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: MetaSms is a gem used to send sms via rails application.
|
152
|
+
test_files: []
|