sendotp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/send_otp.rb +132 -0
- data/lib/send_otp/version.rb +3 -0
- data/send_otp.gemspec +27 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e442bd426deaf7aa06e0cd068f71953e96a0ff88
|
4
|
+
data.tar.gz: 464d8b0dcf82f41a627b77ee4b2fce70acd171b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8ed24d2ce81349e725f66ff7ceaf9a5c386fe9b236d5bfe7d788ac9a6494db17422c437e42a953ea8c4faf0e511612fca731af91a1be5322a4715b208e9059a7
|
7
|
+
data.tar.gz: '09a86d4a89ffc30a759a2d86b0515af15933573f19f238aab6dbfec9d7619b7dc7a19c773fd56b3b93f7aeae1f7f212d37c9da02b5ca615ded04de3c4671412f'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at utkarsh@walkover.in. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Utkarsh
|
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,68 @@
|
|
1
|
+
# SendOtp
|
2
|
+
|
3
|
+
This SDK enables sendOTP and allows you to send OTP
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'send_otp'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install send_otp
|
20
|
+
|
21
|
+
### Requests
|
22
|
+
```
|
23
|
+
sendotp = SendOtp::Otp.new('AuthKey')
|
24
|
+
sendotp.send_otp(contact_number, sender_id, otp); //otp is optional if not sent it'll be generated automatically
|
25
|
+
sendotp.retry(contact_number, retry_voice);
|
26
|
+
sendotp.verify(contact_number, otp);
|
27
|
+
```
|
28
|
+
### Usage
|
29
|
+
|
30
|
+
To send OTP, without optional parameters
|
31
|
+
```
|
32
|
+
sendotp.send_otp("919999999999", "PRIIND")
|
33
|
+
```
|
34
|
+
|
35
|
+
To send OTP, with optional parameters
|
36
|
+
```
|
37
|
+
sendotp.send_otp("919999999999", "PRIIND", "4635")
|
38
|
+
```
|
39
|
+
|
40
|
+
To retry OTP
|
41
|
+
```
|
42
|
+
sendotp.retry("919999999999", false)
|
43
|
+
```
|
44
|
+
**Note:** Set retry_voice false if you want to retry otp via text, default value is true
|
45
|
+
|
46
|
+
To verify OTP
|
47
|
+
|
48
|
+
```
|
49
|
+
sendotp.verify("919999999999", "4635");
|
50
|
+
```
|
51
|
+
**Options**:
|
52
|
+
|
53
|
+
By default SendOtp uses default message template, but custom message template can also set in constructor like
|
54
|
+
```
|
55
|
+
sendotp = SendOtp::Otp.new('AuthKey', 'Otp for your order is {{otp}}, please do not share it with anybody')
|
56
|
+
```
|
57
|
+
{{otp}} expression is used to inject generated otp in message.
|
58
|
+
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/MSG91/sendotp-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
63
|
+
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
68
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "send_otp"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/send_otp.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'send_otp/version'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
module SendOtp
|
5
|
+
|
6
|
+
class Otp
|
7
|
+
|
8
|
+
|
9
|
+
#variable auth_key; //MSG91 auth key
|
10
|
+
#variable message_template = "Your otp is {{otp}}. Please do not share it with anybody" //message template to send, {{otp}} is required to inject generated otp
|
11
|
+
|
12
|
+
# Creates a new SendOtp instance
|
13
|
+
# @param {string} auth_jey Authentication key
|
14
|
+
# @param {string, optional} message_template
|
15
|
+
|
16
|
+
def initialize(auth_key, message_template=nil)
|
17
|
+
@auth_key = auth_key
|
18
|
+
if message_template
|
19
|
+
@message_template = message_template
|
20
|
+
else
|
21
|
+
@message_template = 'Your otp is {{otp}}. Please do not share it with anybody'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Send Otp to given mobile number
|
26
|
+
# @param {string} contact_number receiver's mobile number along with country code
|
27
|
+
# @param {string} sender_id
|
28
|
+
# @param {string, optional} otp
|
29
|
+
# @param {string, optional} n number of digits of Otp
|
30
|
+
|
31
|
+
def send_otp(contact_number, sender_id, otp = '', n = 4)
|
32
|
+
otp = generate_otp(n) if otp.to_s.empty?
|
33
|
+
@message_template.gsub! '{{otp}}', otp.to_s
|
34
|
+
args = {
|
35
|
+
authkey: @auth_key,
|
36
|
+
mobile: contact_number,
|
37
|
+
sender: sender_id,
|
38
|
+
message: @message_template,
|
39
|
+
otp: otp
|
40
|
+
}
|
41
|
+
|
42
|
+
do_request('sendotp.php', args)
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# Retry Otp to given mobile number
|
47
|
+
# @param {string} contact_number receiver's mobile number along with country code
|
48
|
+
# @param {boolean} retry_voice, false to retry otp via text call, default true
|
49
|
+
|
50
|
+
def retry(contact_number, retry_voice)
|
51
|
+
# if retry voice is false, set `retry_type` as `text` else set it to `voice` call msg91 API to retry otp
|
52
|
+
# return msg91 API response
|
53
|
+
retry_type = 'voice'
|
54
|
+
retry_type = 'text' unless retry_voice
|
55
|
+
args = {
|
56
|
+
authkey: @auth_key,
|
57
|
+
mobile: contact_number,
|
58
|
+
retrytype: retry_type
|
59
|
+
}
|
60
|
+
do_request('retryotp.php', args)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
# Verify Otp to given mobile number
|
65
|
+
# @param {string} contact_number receiver's mobile number along with country code
|
66
|
+
# @param {string} otp otp to verify
|
67
|
+
# Return true if OTP verified successfully
|
68
|
+
# @returns {boolean} true if otp verified successfully else false
|
69
|
+
|
70
|
+
def verify(contact_number, otp)
|
71
|
+
args = {
|
72
|
+
authkey: @auth_key,
|
73
|
+
mobile: contact_number,
|
74
|
+
otp: otp
|
75
|
+
}
|
76
|
+
|
77
|
+
response = do_request('verifyRequestOTP.php', args)
|
78
|
+
body = eval(response.body)
|
79
|
+
|
80
|
+
if body[:type] == 'success'
|
81
|
+
true
|
82
|
+
else
|
83
|
+
false
|
84
|
+
end
|
85
|
+
rescue
|
86
|
+
false
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
|
93
|
+
# Returns the base URL for MSG91 api call
|
94
|
+
# @returns {string} Base URL for MSG91 api call
|
95
|
+
|
96
|
+
def get_base_url
|
97
|
+
'https://control.msg91.com/api/'
|
98
|
+
end
|
99
|
+
|
100
|
+
def generate_random_number(upper_limit, lower_limit)
|
101
|
+
Random.rand(upper_limit-lower_limit)+lower_limit
|
102
|
+
end
|
103
|
+
|
104
|
+
# returns a n digit random number
|
105
|
+
def generate_otp(n = 4)
|
106
|
+
smallest_num_of_n_plus1_digits = 10 ** n
|
107
|
+
smallest_num_of_n_digits = 10 ** (n-1)
|
108
|
+
rand_number = generate_random_number(smallest_num_of_n_plus1_digits, smallest_num_of_n_digits)
|
109
|
+
while rand_number > smallest_num_of_n_plus1_digits || rand_number < smallest_num_of_n_digits
|
110
|
+
rand_number = generate_random_number(smallest_num_of_n_plus1_digits, smallest_num_of_n_digits)
|
111
|
+
end
|
112
|
+
|
113
|
+
rand_number
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
# Common private method to make HTTP request
|
118
|
+
# call this in above three methods (send, retry, verify)
|
119
|
+
# @param {string} path, MSG91 API's endpoint
|
120
|
+
# @param {json} params, arguments to send in API
|
121
|
+
|
122
|
+
def do_request(url, args)
|
123
|
+
uri = URI.parse(get_base_url + url)
|
124
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
125
|
+
http.use_ssl = true
|
126
|
+
request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' => 'application/json'})
|
127
|
+
request.set_form_data(args)
|
128
|
+
http.request(request)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
data/send_otp.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'send_otp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sendotp"
|
8
|
+
spec.version = SendOtp::VERSION
|
9
|
+
spec.authors = ["Utkarsh"]
|
10
|
+
spec.email = ["utkarsh@walkover.in"]
|
11
|
+
|
12
|
+
spec.summary = %q{This gem allows to send otp, verify otp and retry otp}
|
13
|
+
spec.description = %q{This gem enables sendOTP and allows you to send OTP}
|
14
|
+
spec.homepage = "https://sendotp.msg91.com/"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sendotp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Utkarsh
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-13 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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
|
+
description: This gem enables sendOTP and allows you to send OTP
|
56
|
+
email:
|
57
|
+
- utkarsh@walkover.in
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/send_otp.rb
|
73
|
+
- lib/send_otp/version.rb
|
74
|
+
- send_otp.gemspec
|
75
|
+
homepage: https://sendotp.msg91.com/
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.5.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: This gem allows to send otp, verify otp and retry otp
|
99
|
+
test_files: []
|