Skip to content

Commit d945ec3

Browse files
committed
initial commit
0 parents  commit d945ec3

File tree

15 files changed

+400
-0
lines changed

15 files changed

+400
-0
lines changed

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in msg91ruby.gemspec
4+
gemspec

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
35+
36+
## Contributing
37+
38+
1. Fork it ( https://github.com/RajeshReddyM/msg91ruby/fork )
39+
2. Create your feature branch (`git checkout -b my-new-feature`)
40+
3. Commit your changes (`git commit -am 'Add some feature'`)
41+
4. Push to the branch (`git push origin my-new-feature`)
42+
5. Create a new Pull Request

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "bundler/gem_tasks"
2+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Msg91ruby.setup do |config|
2+
config.const_name = "SmsSettings"
3+
end

lib/generators/msg91ruby/templates/sms_settings.yml

Whitespace-only changes.

lib/msg91ruby.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

lib/msg91ruby/api.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 commit comments

Comments
 (0)