msg91ruby 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +2 -0
- data/lib/generators/msg91ruby/install_generator.rb +25 -0
- data/lib/generators/msg91ruby/templates/msg91ruby.rb +3 -0
- data/lib/generators/msg91ruby/templates/sms_settings.yml +0 -0
- data/lib/msg91ruby/api.rb +36 -0
- data/lib/msg91ruby/integration/rails.rb +25 -0
- data/lib/msg91ruby/options.rb +119 -0
- data/lib/msg91ruby/sources/yaml_source.rb +24 -0
- data/lib/msg91ruby/version.rb +3 -0
- data/lib/msg91ruby.rb +50 -0
- data/msg91ruby.gemspec +23 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e49d4e6c02f51d81add0edcd5bd80f6fd3def10d
|
4
|
+
data.tar.gz: 4324b6c8a1632515f26657f87022b06d4974cb02
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 87a27b8f7cd5f9f2ceee6516aa24a56a295a30593a4c1e3b07ae49d20aeb50481bc30d57f1351370a2d65e070ad720ad8ca45ba6696a4df287def080e5c08ae0
|
7
|
+
data.tar.gz: 9aca2e29422f962f40e578f3c9f968283bd07950ac05e81041d0e9e8d0e3a72c3e6ba79bbc05cf125b31cd3c282d522b999301f0235fb5aecac300f76f8c82e0
|
data/.gitignore
ADDED
@@ -0,0 +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
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +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.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Msg91ruby
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
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
|
+
## SMS Settings
|
35
|
+
|
36
|
+
You can generate a Yaml file to store the Sms Settings required for your application with following command
|
37
|
+
|
38
|
+
rails g msg91ruby:install
|
39
|
+
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it ( https://github.com/RajeshReddyM/msg91ruby/fork )
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +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/*api.yml\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
File without changes
|
@@ -0,0 +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 => 1, :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
|
@@ -0,0 +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
|
25
|
+
end
|
@@ -0,0 +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
|
119
|
+
end
|
@@ -0,0 +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
|
24
|
+
end
|
data/lib/msg91ruby.rb
ADDED
@@ -0,0 +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)
|
data/msg91ruby.gemspec
ADDED
@@ -0,0 +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
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: msg91ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rajesh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-17 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Connects to Msg91 api to send messages
|
42
|
+
email:
|
43
|
+
- rajeshnecg@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/generators/msg91ruby/install_generator.rb
|
54
|
+
- lib/generators/msg91ruby/templates/msg91ruby.rb
|
55
|
+
- lib/generators/msg91ruby/templates/sms_settings.yml
|
56
|
+
- lib/msg91ruby.rb
|
57
|
+
- lib/msg91ruby/api.rb
|
58
|
+
- lib/msg91ruby/integration/rails.rb
|
59
|
+
- lib/msg91ruby/options.rb
|
60
|
+
- lib/msg91ruby/sources/yaml_source.rb
|
61
|
+
- lib/msg91ruby/version.rb
|
62
|
+
- msg91ruby.gemspec
|
63
|
+
homepage: https://github.com/deeproot/msg91ruby
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.2.2
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: A Ruby gem to connect with Msg91 Api to send messages
|
87
|
+
test_files: []
|
88
|
+
has_rdoc:
|