send_otp_dev 0.1.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/README.md +52 -0
- data/lib/send_otp_dev/client.rb +65 -0
- data/lib/send_otp_dev/configuration.rb +9 -0
- data/lib/send_otp_dev.rb +13 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 58f06bad2d310f7b65416bfccaa5701a20e5eb2a5107cbe15a49586f892bc151
|
4
|
+
data.tar.gz: eea04c97fc2cda966ab4f0f4de8fb447aa62bbbd464d11fb98b16b909b186bda
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45f6009c183621878a136a1f275ce4cccaad53f4580d31c8f6403aa7f80f6933432cc4023511a1ade1b9daf0d834c31da58fa91b32092cb859c979fb3a549910
|
7
|
+
data.tar.gz: d9b7e5c9f95b9bc5b37b05f5c3a9d3ae9ffd76a771d8b13da0dee30b86b03c8e73acfa37fecbccffebeb1a98c7b50c3a206341a9c487305306ae7471f4d8fde5
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# SendOtpDev
|
2
|
+
|
3
|
+
Welcome to SendOtpDev! This gem allows you to easily send and confirm One-Time Passwords (OTP) for email, SMS, or voice authentication.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'send_otp_dev'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
gem install send_otp_dev
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage / Configuration
|
26
|
+
|
27
|
+
To use the SendOtpDev gem, you'll need to configure it using your API key with an initializer in your Rails application:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# config/initializers/send_otp_dev.rb
|
31
|
+
|
32
|
+
SendOtpDev.configure do |config|
|
33
|
+
config.api_key = 'your_sendotp.dev_api_key'
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
Then, you can send an OTP like so:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
SendOtpDev::Client.send_otp(email: 'user@example.com', phone_number: '1234567890', app_name: 'YourAppName')
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
You can also confirm an OTP like so:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
SendOtpDev::Client.confirm_otp(token:1234, email: 'user@example.com', phone_number: '1234567890', app_name: 'YourAppName')
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module SendOtpDev
|
6
|
+
class Client
|
7
|
+
|
8
|
+
BASE_URL = 'https://api.sendotp.dev/v1'
|
9
|
+
|
10
|
+
def self.send_otp(phone_number: nil, email: nil, app_name:, delivery_method: 'sms')
|
11
|
+
uri = URI("#{BASE_URL}/send_otp")
|
12
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
13
|
+
http.use_ssl = (uri.scheme == 'https')
|
14
|
+
|
15
|
+
form_data = {
|
16
|
+
'app_name' => app_name,
|
17
|
+
'delivery_method' => delivery_method # Can be 'sms' or 'email'
|
18
|
+
}
|
19
|
+
form_data['phone_number'] = phone_number if phone_number
|
20
|
+
form_data['email'] = email if email
|
21
|
+
|
22
|
+
request = Net::HTTP::Post.new(uri)
|
23
|
+
request.set_form_data(form_data)
|
24
|
+
|
25
|
+
request['Authorization'] = "Bearer #{SendOtpDev.configuration.api_key}"
|
26
|
+
request['Content-Type'] = 'application/x-www-form-urlencoded'
|
27
|
+
|
28
|
+
response = http.request(request)
|
29
|
+
|
30
|
+
# Correctly handling the response based on your instructions
|
31
|
+
response.code == '204' || response.body == '1'
|
32
|
+
rescue JSON::ParserError => e
|
33
|
+
puts "Error parsing response: #{e.message}"
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.confirm_otp(phone_number: nil, email: nil, otp_token:, app_name:)
|
38
|
+
uri = URI("#{BASE_URL}/confirm_otp")
|
39
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
40
|
+
http.use_ssl = (uri.scheme == 'https')
|
41
|
+
|
42
|
+
form_data = {
|
43
|
+
'app_name' => app_name,
|
44
|
+
'token' => otp_token
|
45
|
+
}
|
46
|
+
form_data['phone_number'] = phone_number if phone_number
|
47
|
+
form_data['email'] = email if email
|
48
|
+
|
49
|
+
request = Net::HTTP::Post.new(uri)
|
50
|
+
request.set_form_data(form_data)
|
51
|
+
|
52
|
+
request['Authorization'] = "Bearer #{SendOtpDev.configuration.api_key}"
|
53
|
+
request['Content-Type'] = 'application/x-www-form-urlencoded'
|
54
|
+
|
55
|
+
response = http.request(request)
|
56
|
+
|
57
|
+
response_body = JSON.parse(response.body)
|
58
|
+
response.code == '200' && response_body['success']
|
59
|
+
rescue JSON::ParserError => e
|
60
|
+
puts "Error parsing response: #{e.message}"
|
61
|
+
false
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/lib/send_otp_dev.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "send_otp_dev/configuration"
|
2
|
+
require_relative "send_otp_dev/client"
|
3
|
+
|
4
|
+
module SendOtpDev
|
5
|
+
class << self
|
6
|
+
attr_accessor :configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.configure
|
10
|
+
self.configuration ||= Configuration.new
|
11
|
+
yield(configuration)
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: send_otp_dev
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Formulate Labs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-02-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
description: Easily Send and Confirm Email/SMS/Voice OTP Authentication
|
28
|
+
email:
|
29
|
+
- hello@formulatelabs.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- lib/send_otp_dev.rb
|
36
|
+
- lib/send_otp_dev/client.rb
|
37
|
+
- lib/send_otp_dev/configuration.rb
|
38
|
+
homepage: http://sendotp.dev
|
39
|
+
licenses: []
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.0.9
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Easily Send and Confirm Email/SMS/Voice OTP Authentication
|
60
|
+
test_files: []
|