msg91ruby 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +22 -22
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +55 -47
- data/Rakefile +2 -2
- data/lib/generators/msg91ruby/install_generator.rb +24 -24
- data/lib/generators/msg91ruby/templates/msg91ruby.rb +2 -2
- data/lib/msg91ruby.rb +50 -50
- data/lib/msg91ruby/api.rb +36 -36
- data/lib/msg91ruby/integration/rails.rb +24 -24
- data/lib/msg91ruby/options.rb +118 -118
- data/lib/msg91ruby/sources/yaml_source.rb +23 -23
- data/lib/msg91ruby/version.rb +3 -3
- data/msg91ruby.gemspec +23 -23
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 489f709a089ee11f7293f4c184b3343fffabb3ac
|
4
|
+
data.tar.gz: 6682118f44b88a1345d3e9ea9880434c6b7147ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa3849954c046b49b7ccd478ee7bcc16ac72f5f5630e799a5ab49c991fc1f6cd3d42825b325841aebeef5f0f733cde3af9b038ed1b988d1e2e67ee28f21a6f9a
|
7
|
+
data.tar.gz: 5eb4954591a9628fe5db2485acd6e149ff12ca745d9b9ac2bbe77d68b9141df7f083571f581b974106452dde71d13f32628c9caa83cc9cd9be413bcb4da7c508
|
data/.gitignore
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
*.bundle
|
19
|
-
*.so
|
20
|
-
*.o
|
21
|
-
*.a
|
22
|
-
mkmf.log
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in msg91ruby.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in msg91ruby.gemspec
|
4
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2014 Rajesh Reddy
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2014 Rajesh Reddy
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,47 +1,55 @@
|
|
1
|
-
# Msg91ruby
|
2
|
-
|
3
|
-
A Ruby Gem to communicate with Msg91 Api to send Messages
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'msg91ruby'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install msg91ruby
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
## To connect to Msg91 Api
|
22
|
-
|
23
|
-
require 'msg91ruby'
|
24
|
-
api = Msg91ruby::API.new(auth_key,senderid)
|
25
|
-
api.send(mobileno, message)
|
26
|
-
|
27
|
-
eg:
|
28
|
-
|
29
|
-
require 'msg91ruby'
|
30
|
-
api = Msg91ruby::API.new("2552515255255255252","113388")
|
31
|
-
api.send(1234567890, "Test Message")
|
32
|
-
api.send([1234567890,9012345678], "Test Message")
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
1
|
+
# Msg91ruby
|
2
|
+
|
3
|
+
A Ruby Gem to communicate with Msg91 Api to send Messages
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'msg91ruby'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install msg91ruby
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
## To connect to Msg91 Api
|
22
|
+
|
23
|
+
require 'msg91ruby'
|
24
|
+
api = Msg91ruby::API.new(auth_key,senderid)
|
25
|
+
api.send(mobileno, message, route)
|
26
|
+
|
27
|
+
eg:
|
28
|
+
|
29
|
+
require 'msg91ruby'
|
30
|
+
api = Msg91ruby::API.new("2552515255255255252","113388")
|
31
|
+
api.send(1234567890, "Test Message", 1)
|
32
|
+
api.send([1234567890,9012345678], "Test Message", 1)
|
33
|
+
|
34
|
+
you can find your Auth-key here: http://help.msg91.com/article/177-where-can-i-find-my-authentication-key
|
35
|
+
|
36
|
+
## SMS Settings
|
37
|
+
|
38
|
+
You can generate a Yaml file to store the Sms Settings required for your application with following command
|
39
|
+
|
40
|
+
rails g msg91ruby:install
|
41
|
+
|
42
|
+
## MSG91 Account Details
|
43
|
+
|
44
|
+
You can create your account on MSG91 by simply singing up here: https://msg91.com/signup/msg91ruby
|
45
|
+
|
46
|
+
If you are an startup company, you can avail sms credits for your Startup app. For more details visit: https://msg91.com/startups/
|
47
|
+
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/deeproot/msg91ruby/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
data/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
@@ -1,25 +1,25 @@
|
|
1
|
-
module Msg91ruby
|
2
|
-
module Generators
|
3
|
-
class InstallGenerator < ::Rails::Generators::Base
|
4
|
-
|
5
|
-
def self.source_root
|
6
|
-
@_rails_config_source_root ||= File.expand_path("../templates", __FILE__)
|
7
|
-
end
|
8
|
-
|
9
|
-
def copy_initializer
|
10
|
-
template "msg91ruby.rb", "config/initializers/msg91ruby.rb"
|
11
|
-
end
|
12
|
-
|
13
|
-
def copy_settings
|
14
|
-
template "sms_settings.yml", "config/sms_settings.yml"
|
15
|
-
end
|
16
|
-
|
17
|
-
def modify_gitignore
|
18
|
-
append_to_file '.gitignore' do
|
19
|
-
"\n" +
|
20
|
-
"config/settings/*_settings.yml\n"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
module Msg91ruby
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < ::Rails::Generators::Base
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
@_rails_config_source_root ||= File.expand_path("../templates", __FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
def copy_initializer
|
10
|
+
template "msg91ruby.rb", "config/initializers/msg91ruby.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_settings
|
14
|
+
template "sms_settings.yml", "config/sms_settings.yml"
|
15
|
+
end
|
16
|
+
|
17
|
+
def modify_gitignore
|
18
|
+
append_to_file '.gitignore' do
|
19
|
+
"\n" +
|
20
|
+
"config/settings/*_settings.yml\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
25
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
Msg91ruby.setup do |config|
|
2
|
-
config.const_name = "SmsSettings"
|
1
|
+
Msg91ruby.setup do |config|
|
2
|
+
config.const_name = "SmsSettings"
|
3
3
|
end
|
data/lib/msg91ruby.rb
CHANGED
@@ -1,50 +1,50 @@
|
|
1
|
-
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
-
require "msg91ruby/version"
|
3
|
-
require "msg91ruby/options"
|
4
|
-
require "msg91ruby/sources/yaml_source"
|
5
|
-
require "msg91ruby/api"
|
6
|
-
require "net/http"
|
7
|
-
require "net/https"
|
8
|
-
require "uri"
|
9
|
-
|
10
|
-
|
11
|
-
module Msg91ruby
|
12
|
-
# ensures the setup only gets run once
|
13
|
-
@@_ran_once = false
|
14
|
-
|
15
|
-
mattr_accessor :const_name, :use_env
|
16
|
-
@@const_name = "SmsSettings"
|
17
|
-
@@use_env = false
|
18
|
-
|
19
|
-
def self.setup
|
20
|
-
yield self if @@_ran_once == false
|
21
|
-
@@_ran_once = true
|
22
|
-
end
|
23
|
-
|
24
|
-
# Create a populated Options instance from a yaml file. If a second yaml file is given, then the sections of that file will overwrite the sections
|
25
|
-
# if the first file if they exist in the first file.
|
26
|
-
def self.load_files(*files)
|
27
|
-
config = Options.new
|
28
|
-
|
29
|
-
# add yaml sources
|
30
|
-
[files].flatten.compact.uniq.each do |file|
|
31
|
-
config.add_source!(file.to_s)
|
32
|
-
end
|
33
|
-
|
34
|
-
config.load!
|
35
|
-
config.load_env! if @@use_env
|
36
|
-
config
|
37
|
-
end
|
38
|
-
|
39
|
-
# Loads and sets the settings constant!
|
40
|
-
def self.load_and_set_settings(*files)
|
41
|
-
Kernel.send(:remove_const, Msg91ruby.const_name) if Kernel.const_defined?(Msg91ruby.const_name)
|
42
|
-
Kernel.const_set(Msg91ruby.const_name, Msg91ruby.load_files(files))
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.reload!
|
46
|
-
Kernel.const_get(Msg91ruby.const_name).reload!
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
require('msg91ruby/integration/rails') if defined?(::Rails)
|
1
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
+
require "msg91ruby/version"
|
3
|
+
require "msg91ruby/options"
|
4
|
+
require "msg91ruby/sources/yaml_source"
|
5
|
+
require "msg91ruby/api"
|
6
|
+
require "net/http"
|
7
|
+
require "net/https"
|
8
|
+
require "uri"
|
9
|
+
|
10
|
+
|
11
|
+
module Msg91ruby
|
12
|
+
# ensures the setup only gets run once
|
13
|
+
@@_ran_once = false
|
14
|
+
|
15
|
+
mattr_accessor :const_name, :use_env
|
16
|
+
@@const_name = "SmsSettings"
|
17
|
+
@@use_env = false
|
18
|
+
|
19
|
+
def self.setup
|
20
|
+
yield self if @@_ran_once == false
|
21
|
+
@@_ran_once = true
|
22
|
+
end
|
23
|
+
|
24
|
+
# Create a populated Options instance from a yaml file. If a second yaml file is given, then the sections of that file will overwrite the sections
|
25
|
+
# if the first file if they exist in the first file.
|
26
|
+
def self.load_files(*files)
|
27
|
+
config = Options.new
|
28
|
+
|
29
|
+
# add yaml sources
|
30
|
+
[files].flatten.compact.uniq.each do |file|
|
31
|
+
config.add_source!(file.to_s)
|
32
|
+
end
|
33
|
+
|
34
|
+
config.load!
|
35
|
+
config.load_env! if @@use_env
|
36
|
+
config
|
37
|
+
end
|
38
|
+
|
39
|
+
# Loads and sets the settings constant!
|
40
|
+
def self.load_and_set_settings(*files)
|
41
|
+
Kernel.send(:remove_const, Msg91ruby.const_name) if Kernel.const_defined?(Msg91ruby.const_name)
|
42
|
+
Kernel.const_set(Msg91ruby.const_name, Msg91ruby.load_files(files))
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.reload!
|
46
|
+
Kernel.const_get(Msg91ruby.const_name).reload!
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
require('msg91ruby/integration/rails') if defined?(::Rails)
|
data/lib/msg91ruby/api.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
module Msg91ruby
|
2
|
-
class API
|
3
|
-
attr_accessor :auth_key, :senderid
|
4
|
-
URL = "http://control.msg91.com"
|
5
|
-
def initialize(auth_key, senderid)
|
6
|
-
@auth_key = auth_key
|
7
|
-
@senderid = senderid
|
8
|
-
@url = URL
|
9
|
-
end
|
10
|
-
|
11
|
-
def send(mobilenos,msg)
|
12
|
-
mobile_nos = mobilenos.is_a?(Array) ? mobilenos.join(',') : mobilenos
|
13
|
-
params = {:authkey => auth_key, :mobiles => mobile_nos, :message => msg , :sender => senderid ,:route =>
|
14
|
-
uri = full_path('/api/sendhttp.php', params)
|
15
|
-
response = Net::HTTP.get(uri)
|
16
|
-
end
|
17
|
-
|
18
|
-
def change_password(passwd, newpasswd)
|
19
|
-
params = {:authkey => auth_key, :password => passwd, :newpass => newpasswd, :response => "json"}
|
20
|
-
uri = full_path('/api/password.php', params)
|
21
|
-
response = Net::HTTP.get(uri)
|
22
|
-
end
|
23
|
-
|
24
|
-
def balance
|
25
|
-
params = {:authkey => auth_key, :type => 1, :response => "json"}
|
26
|
-
uri = full_path('/api/balance.php', params)
|
27
|
-
response = Net::HTTP.get(uri)
|
28
|
-
end
|
29
|
-
|
30
|
-
def full_path(path, params)
|
31
|
-
encoded_params = URI.encode_www_form(params)
|
32
|
-
params_string = [path, encoded_params].join("?")
|
33
|
-
URI.parse(@url + params_string)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
1
|
+
module Msg91ruby
|
2
|
+
class API
|
3
|
+
attr_accessor :auth_key, :senderid
|
4
|
+
URL = "http://control.msg91.com"
|
5
|
+
def initialize(auth_key, senderid)
|
6
|
+
@auth_key = auth_key
|
7
|
+
@senderid = senderid
|
8
|
+
@url = URL
|
9
|
+
end
|
10
|
+
|
11
|
+
def send(mobilenos,msg,route)
|
12
|
+
mobile_nos = mobilenos.is_a?(Array) ? mobilenos.join(',') : mobilenos
|
13
|
+
params = {:authkey => auth_key, :mobiles => mobile_nos, :message => msg , :sender => senderid ,:route => route, :response => "json"}
|
14
|
+
uri = full_path('/api/sendhttp.php', params)
|
15
|
+
response = Net::HTTP.get(uri)
|
16
|
+
end
|
17
|
+
|
18
|
+
def change_password(passwd, newpasswd)
|
19
|
+
params = {:authkey => auth_key, :password => passwd, :newpass => newpasswd, :response => "json"}
|
20
|
+
uri = full_path('/api/password.php', params)
|
21
|
+
response = Net::HTTP.get(uri)
|
22
|
+
end
|
23
|
+
|
24
|
+
def balance
|
25
|
+
params = {:authkey => auth_key, :type => 1, :response => "json"}
|
26
|
+
uri = full_path('/api/balance.php', params)
|
27
|
+
response = Net::HTTP.get(uri)
|
28
|
+
end
|
29
|
+
|
30
|
+
def full_path(path, params)
|
31
|
+
encoded_params = URI.encode_www_form(params)
|
32
|
+
params_string = [path, encoded_params].join("?")
|
33
|
+
URI.parse(@url + params_string)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
module Msg91ruby
|
2
|
-
module Integration
|
3
|
-
module Rails
|
4
|
-
if defined?(::Rails::Railtie)
|
5
|
-
class Railtie < ::Rails::Railtie
|
6
|
-
# Load rake tasks (eg. Heroku)
|
7
|
-
rake_tasks do
|
8
|
-
Dir[File.join(File.dirname(__FILE__),'../tasks/*.rake')].each { |f| load f }
|
9
|
-
end
|
10
|
-
|
11
|
-
ActiveSupport.on_load :before_configuration, :yield => true do
|
12
|
-
# Manually load the custom initializer before everything else
|
13
|
-
initializer = ::Rails.root.join("config", "initializers", "msg91ruby.rb")
|
14
|
-
require initializer if File.exist?(initializer)
|
15
|
-
|
16
|
-
# Parse the settings before any of the initializers
|
17
|
-
Msg91ruby.load_and_set_settings(
|
18
|
-
::Rails.root.join("config", "sms_settings.yml").to_s
|
19
|
-
)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
module Msg91ruby
|
2
|
+
module Integration
|
3
|
+
module Rails
|
4
|
+
if defined?(::Rails::Railtie)
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
# Load rake tasks (eg. Heroku)
|
7
|
+
rake_tasks do
|
8
|
+
Dir[File.join(File.dirname(__FILE__),'../tasks/*.rake')].each { |f| load f }
|
9
|
+
end
|
10
|
+
|
11
|
+
ActiveSupport.on_load :before_configuration, :yield => true do
|
12
|
+
# Manually load the custom initializer before everything else
|
13
|
+
initializer = ::Rails.root.join("config", "initializers", "msg91ruby.rb")
|
14
|
+
require initializer if File.exist?(initializer)
|
15
|
+
|
16
|
+
# Parse the settings before any of the initializers
|
17
|
+
Msg91ruby.load_and_set_settings(
|
18
|
+
::Rails.root.join("config", "sms_settings.yml").to_s
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
25
|
end
|
data/lib/msg91ruby/options.rb
CHANGED
@@ -1,119 +1,119 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
module Msg91ruby
|
3
|
-
class Options < OpenStruct
|
4
|
-
|
5
|
-
include Enumerable
|
6
|
-
|
7
|
-
def empty?
|
8
|
-
marshal_dump.empty?
|
9
|
-
end
|
10
|
-
|
11
|
-
def add_source!(source)
|
12
|
-
# handle yaml file paths
|
13
|
-
source = (Sources::YAMLSource.new(source)) if source.is_a?(String)
|
14
|
-
|
15
|
-
@config_sources ||= []
|
16
|
-
@config_sources << source
|
17
|
-
end
|
18
|
-
|
19
|
-
def reload_env!
|
20
|
-
return self if ENV.nil? || ENV.empty?
|
21
|
-
conf = Hash.new
|
22
|
-
ENV.each do |key, value|
|
23
|
-
next unless key.to_s.index(Msg91ruby.const_name) == 0
|
24
|
-
hash = value
|
25
|
-
key.to_s.split('.').reverse.each do |element|
|
26
|
-
hash = {element => hash}
|
27
|
-
end
|
28
|
-
DeepMerge.deep_merge!(hash, conf, :preserve_unmergeables => false)
|
29
|
-
end
|
30
|
-
|
31
|
-
merge!(conf[Msg91ruby.const_name] || {})
|
32
|
-
end
|
33
|
-
|
34
|
-
alias :load_env! :reload_env!
|
35
|
-
|
36
|
-
# look through all our sources and rebuild the configuration
|
37
|
-
def reload!
|
38
|
-
conf = {}
|
39
|
-
@config_sources.each do |source|
|
40
|
-
source_conf = source.load
|
41
|
-
|
42
|
-
if conf.empty?
|
43
|
-
conf = source_conf
|
44
|
-
else
|
45
|
-
DeepMerge.deep_merge!(source_conf, conf, :preserve_unmergeables => false)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# swap out the contents of the OStruct with a hash (need to recursively convert)
|
50
|
-
marshal_load(__convert(conf).marshal_dump)
|
51
|
-
|
52
|
-
reload_env! if Msg91ruby.use_env
|
53
|
-
|
54
|
-
return self
|
55
|
-
end
|
56
|
-
|
57
|
-
alias :load! :reload!
|
58
|
-
|
59
|
-
def reload_from_files(*files)
|
60
|
-
Msg91ruby.load_and_set_settings(files)
|
61
|
-
reload!
|
62
|
-
end
|
63
|
-
|
64
|
-
def to_hash
|
65
|
-
result = {}
|
66
|
-
marshal_dump.each do |k, v|
|
67
|
-
result[k] = v.instance_of?(Msg91ruby::Options) ? v.to_hash : v
|
68
|
-
end
|
69
|
-
result
|
70
|
-
end
|
71
|
-
|
72
|
-
def each(*args, &block)
|
73
|
-
marshal_dump.each(*args, &block)
|
74
|
-
end
|
75
|
-
|
76
|
-
def to_json(*args)
|
77
|
-
require "json" unless defined?(JSON)
|
78
|
-
to_hash.to_json(*args)
|
79
|
-
end
|
80
|
-
|
81
|
-
def merge!(hash)
|
82
|
-
current = to_hash
|
83
|
-
DeepMerge.deep_merge!(hash.dup, current)
|
84
|
-
marshal_load(__convert(current).marshal_dump)
|
85
|
-
self
|
86
|
-
end
|
87
|
-
|
88
|
-
# An alternative mechanism for property access.
|
89
|
-
# This let's you do foo['bar'] along with foo.bar.
|
90
|
-
def [](param)
|
91
|
-
send("#{param}")
|
92
|
-
end
|
93
|
-
|
94
|
-
def []=(param, value)
|
95
|
-
send("#{param}=", value)
|
96
|
-
end
|
97
|
-
|
98
|
-
protected
|
99
|
-
|
100
|
-
# Recursively converts Hashes to Options (including Hashes inside Arrays)
|
101
|
-
def __convert(h) #:nodoc:
|
102
|
-
s = self.class.new
|
103
|
-
|
104
|
-
h.each do |k, v|
|
105
|
-
k = k.to_s if !k.respond_to?(:to_sym) && k.respond_to?(:to_s)
|
106
|
-
s.new_ostruct_member(k)
|
107
|
-
|
108
|
-
if v.is_a?(Hash)
|
109
|
-
v = v["type"] == "hash" ? v["contents"] : __convert(v)
|
110
|
-
elsif v.is_a?(Array)
|
111
|
-
v = v.collect { |e| e.instance_of?(Hash) ? __convert(e) : e }
|
112
|
-
end
|
113
|
-
|
114
|
-
s.send("#{k}=".to_sym, v)
|
115
|
-
end
|
116
|
-
s
|
117
|
-
end
|
118
|
-
end
|
1
|
+
require 'ostruct'
|
2
|
+
module Msg91ruby
|
3
|
+
class Options < OpenStruct
|
4
|
+
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def empty?
|
8
|
+
marshal_dump.empty?
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_source!(source)
|
12
|
+
# handle yaml file paths
|
13
|
+
source = (Sources::YAMLSource.new(source)) if source.is_a?(String)
|
14
|
+
|
15
|
+
@config_sources ||= []
|
16
|
+
@config_sources << source
|
17
|
+
end
|
18
|
+
|
19
|
+
def reload_env!
|
20
|
+
return self if ENV.nil? || ENV.empty?
|
21
|
+
conf = Hash.new
|
22
|
+
ENV.each do |key, value|
|
23
|
+
next unless key.to_s.index(Msg91ruby.const_name) == 0
|
24
|
+
hash = value
|
25
|
+
key.to_s.split('.').reverse.each do |element|
|
26
|
+
hash = {element => hash}
|
27
|
+
end
|
28
|
+
DeepMerge.deep_merge!(hash, conf, :preserve_unmergeables => false)
|
29
|
+
end
|
30
|
+
|
31
|
+
merge!(conf[Msg91ruby.const_name] || {})
|
32
|
+
end
|
33
|
+
|
34
|
+
alias :load_env! :reload_env!
|
35
|
+
|
36
|
+
# look through all our sources and rebuild the configuration
|
37
|
+
def reload!
|
38
|
+
conf = {}
|
39
|
+
@config_sources.each do |source|
|
40
|
+
source_conf = source.load
|
41
|
+
|
42
|
+
if conf.empty?
|
43
|
+
conf = source_conf
|
44
|
+
else
|
45
|
+
DeepMerge.deep_merge!(source_conf, conf, :preserve_unmergeables => false)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# swap out the contents of the OStruct with a hash (need to recursively convert)
|
50
|
+
marshal_load(__convert(conf).marshal_dump)
|
51
|
+
|
52
|
+
reload_env! if Msg91ruby.use_env
|
53
|
+
|
54
|
+
return self
|
55
|
+
end
|
56
|
+
|
57
|
+
alias :load! :reload!
|
58
|
+
|
59
|
+
def reload_from_files(*files)
|
60
|
+
Msg91ruby.load_and_set_settings(files)
|
61
|
+
reload!
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_hash
|
65
|
+
result = {}
|
66
|
+
marshal_dump.each do |k, v|
|
67
|
+
result[k] = v.instance_of?(Msg91ruby::Options) ? v.to_hash : v
|
68
|
+
end
|
69
|
+
result
|
70
|
+
end
|
71
|
+
|
72
|
+
def each(*args, &block)
|
73
|
+
marshal_dump.each(*args, &block)
|
74
|
+
end
|
75
|
+
|
76
|
+
def to_json(*args)
|
77
|
+
require "json" unless defined?(JSON)
|
78
|
+
to_hash.to_json(*args)
|
79
|
+
end
|
80
|
+
|
81
|
+
def merge!(hash)
|
82
|
+
current = to_hash
|
83
|
+
DeepMerge.deep_merge!(hash.dup, current)
|
84
|
+
marshal_load(__convert(current).marshal_dump)
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
# An alternative mechanism for property access.
|
89
|
+
# This let's you do foo['bar'] along with foo.bar.
|
90
|
+
def [](param)
|
91
|
+
send("#{param}")
|
92
|
+
end
|
93
|
+
|
94
|
+
def []=(param, value)
|
95
|
+
send("#{param}=", value)
|
96
|
+
end
|
97
|
+
|
98
|
+
protected
|
99
|
+
|
100
|
+
# Recursively converts Hashes to Options (including Hashes inside Arrays)
|
101
|
+
def __convert(h) #:nodoc:
|
102
|
+
s = self.class.new
|
103
|
+
|
104
|
+
h.each do |k, v|
|
105
|
+
k = k.to_s if !k.respond_to?(:to_sym) && k.respond_to?(:to_s)
|
106
|
+
s.new_ostruct_member(k)
|
107
|
+
|
108
|
+
if v.is_a?(Hash)
|
109
|
+
v = v["type"] == "hash" ? v["contents"] : __convert(v)
|
110
|
+
elsif v.is_a?(Array)
|
111
|
+
v = v.collect { |e| e.instance_of?(Hash) ? __convert(e) : e }
|
112
|
+
end
|
113
|
+
|
114
|
+
s.send("#{k}=".to_sym, v)
|
115
|
+
end
|
116
|
+
s
|
117
|
+
end
|
118
|
+
end
|
119
119
|
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'erb'
|
3
|
-
|
4
|
-
module Msg91ruby
|
5
|
-
module Sources
|
6
|
-
class YAMLSource
|
7
|
-
|
8
|
-
attr_accessor :path
|
9
|
-
|
10
|
-
def initialize(path)
|
11
|
-
@path = path
|
12
|
-
end
|
13
|
-
|
14
|
-
# returns a config hash from the YML file
|
15
|
-
def load
|
16
|
-
if @path and File.exists?(@path.to_s)
|
17
|
-
result = YAML.load(ERB.new(IO.read(@path.to_s)).result)
|
18
|
-
end
|
19
|
-
result || {}
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Msg91ruby
|
5
|
+
module Sources
|
6
|
+
class YAMLSource
|
7
|
+
|
8
|
+
attr_accessor :path
|
9
|
+
|
10
|
+
def initialize(path)
|
11
|
+
@path = path
|
12
|
+
end
|
13
|
+
|
14
|
+
# returns a config hash from the YML file
|
15
|
+
def load
|
16
|
+
if @path and File.exists?(@path.to_s)
|
17
|
+
result = YAML.load(ERB.new(IO.read(@path.to_s)).result)
|
18
|
+
end
|
19
|
+
result || {}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
24
|
end
|
data/lib/msg91ruby/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Msg91ruby
|
2
|
-
VERSION = "1.0.
|
3
|
-
end
|
1
|
+
module Msg91ruby
|
2
|
+
VERSION = "1.0.2"
|
3
|
+
end
|
data/msg91ruby.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$:.unshift(lib) unless $:.include?(lib)
|
4
|
-
require 'msg91ruby/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "msg91ruby"
|
8
|
-
spec.version = Msg91ruby::VERSION
|
9
|
-
spec.authors = ["rajesh"]
|
10
|
-
spec.email = ["rajeshnecg@gmail.com"]
|
11
|
-
spec.summary = %q{A Ruby gem to connect with Msg91 Api to send messages}
|
12
|
-
spec.description = %q{Connects to Msg91 api to send messages}
|
13
|
-
spec.homepage = "https://github.com/deeproot/msg91ruby"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$:.unshift(lib) unless $:.include?(lib)
|
4
|
+
require 'msg91ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "msg91ruby"
|
8
|
+
spec.version = Msg91ruby::VERSION
|
9
|
+
spec.authors = ["rajesh"]
|
10
|
+
spec.email = ["rajeshnecg@gmail.com"]
|
11
|
+
spec.summary = %q{A Ruby gem to connect with Msg91 Api to send messages}
|
12
|
+
spec.description = %q{Connects to Msg91 api to send messages}
|
13
|
+
spec.homepage = "https://github.com/deeproot/msg91ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msg91ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rajesh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,9 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.4.5.1
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: A Ruby gem to connect with Msg91 Api to send messages
|
87
87
|
test_files: []
|
88
|
-
has_rdoc:
|