msg91 0.2.2 → 0.3.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 +4 -4
- data/Gemfile +1 -0
- data/README.md +2 -3
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/lib/generators/msg91/install_generator.rb +4 -4
- data/lib/generators/templates/msg91_initializer.rb +5 -7
- data/lib/msg91/configuration.rb +2 -2
- data/lib/msg91/http_client.rb +25 -0
- data/lib/msg91/message.rb +18 -22
- data/lib/msg91/otp.rb +27 -0
- data/lib/msg91/version.rb +1 -1
- data/lib/msg91.rb +5 -5
- data/msg91.gemspec +15 -16
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 692b401577be967ec41e6c02866f64ed10d8a8c1490b94deddca9b7d88a0ff46
|
4
|
+
data.tar.gz: f4bf2e6f2cbfa24e2087243ac6a82f548c8ddac9f5dba3f15ee2233398f841e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c25af19392f3c505b07bbd19ca26f8c1c713f6b08f7e5d6207c5ae7719d77e6307f4a243e5cd02806965b77ffb706e638d52859a619bd8b9888171b53fe1029
|
7
|
+
data.tar.gz: 2d2bf6c1ba3fd157a85391f89715c65dc26aea95e832055b63a70b388b4bb5769d925a964426240be45d88bbefbdb03eb958963757eb211bb457d2b29a44d33d
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
# Msg91
|
2
|
-
|
1
|
+
# Msg91 [](https://badge.fury.io/rb/msg91)
|
3
2
|
This is a wrapper gem to the MSG91 SMS service. You can find more about MSG91
|
4
3
|
here [msg91.com](https://msg91.com)
|
5
4
|
|
@@ -52,7 +51,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
52
51
|
|
53
52
|
## Contributing
|
54
53
|
|
55
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sureshprasanna70/msg91. 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.
|
56
55
|
|
57
56
|
|
58
57
|
## License
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'msg91'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "msg91"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Msg91
|
2
2
|
module Generators
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path(
|
5
|
-
|
4
|
+
source_root File.expand_path('../templates', __dir__)
|
5
|
+
|
6
6
|
def copy_initializer
|
7
|
-
template
|
7
|
+
template 'msg91_initializer.rb', 'config/initializers/msg91.rb'
|
8
8
|
|
9
|
-
puts
|
9
|
+
puts 'Install complete! Please visit https://github.com/sureshprasanna70/msg91 for documentation'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
Msg91.configure do |config|
|
2
|
-
|
3
2
|
# Set your auth key here. You can get one from https://msg91.com
|
4
3
|
# config.auth_key = <%=ENV['MSG91_AUTH_KEY']%>
|
5
|
-
|
6
|
-
#Your default route
|
7
|
-
#config.route =
|
8
|
-
|
9
|
-
#Your sender id
|
10
|
-
#config.sender_id =
|
11
4
|
|
5
|
+
# Your default route
|
6
|
+
# config.route =
|
7
|
+
|
8
|
+
# Your sender id
|
9
|
+
# config.sender_id =
|
12
10
|
end
|
data/lib/msg91/configuration.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Msg91
|
2
|
+
class HttpClient
|
3
|
+
attr_accessor :request, :client
|
4
|
+
attr_reader :headers, :base_url
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@base_url = URI('https://api.msg91.com/')
|
8
|
+
@client = Net::HTTP.new(@base_url.host, @base_url.port)
|
9
|
+
@client.use_ssl = true
|
10
|
+
@client.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
11
|
+
@headers = { 'authkey' => Msg91.configuration.auth_key, 'Content-Type' => 'application/json' }
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(uri, params)
|
15
|
+
@base_url.query = URI.encode_www_form(params)
|
16
|
+
response = client.get(@base_url + uri)
|
17
|
+
JSON.parse(response.read_body)
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(_uri, params)
|
21
|
+
response = client.post(@base_url, params, @headers)
|
22
|
+
JSON.parse(response.read_body)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/msg91/message.rb
CHANGED
@@ -1,37 +1,33 @@
|
|
1
1
|
module Msg91
|
2
2
|
class Message
|
3
|
-
|
4
|
-
def self.send_text(sender_id,route,country,recepients,text)
|
3
|
+
def self.send_text(sender_id, route, country, recepients, text)
|
5
4
|
auth_key = Msg91.configuration.auth_key
|
6
|
-
url = URI(
|
5
|
+
url = URI('http://api.msg91.com/')
|
7
6
|
http = Net::HTTP.new(url.host, url.port)
|
8
7
|
path = '/api/v2/sendsms'
|
9
|
-
headers = {'authkey' => auth_key,'Content-Type' => 'application/json'
|
10
|
-
body_json = build_json(sender_id,route,text,recepients,country)
|
11
|
-
response = http.post(path,body_json,headers)
|
12
|
-
|
13
|
-
return parsed_response
|
8
|
+
headers = { 'authkey' => auth_key, 'Content-Type' => 'application/json' }
|
9
|
+
body_json = build_json(sender_id, route, text, recepients, country)
|
10
|
+
response = http.post(path, body_json, headers)
|
11
|
+
JSON.parse(response.read_body)
|
14
12
|
end
|
15
13
|
|
16
14
|
class << self
|
17
|
-
|
18
15
|
private
|
19
16
|
|
20
|
-
def build_json(sender_id,route,country,recepients,text)
|
21
|
-
body_hash =
|
22
|
-
content =
|
23
|
-
sms =
|
24
|
-
body_hash[
|
25
|
-
body_hash[
|
26
|
-
body_hash[
|
27
|
-
content[
|
28
|
-
content[
|
17
|
+
def build_json(sender_id, route, country, recepients, text)
|
18
|
+
body_hash = {}
|
19
|
+
content = {}
|
20
|
+
sms = []
|
21
|
+
body_hash['sender'] = sender_id
|
22
|
+
body_hash['route'] = route
|
23
|
+
body_hash['country'] = country
|
24
|
+
content['message'] = text
|
25
|
+
content['to'] = recepients
|
29
26
|
sms = sms.push(content)
|
30
|
-
body_hash[
|
31
|
-
|
32
|
-
|
27
|
+
body_hash['sms'] = sms
|
28
|
+
body_hash['unicode'] = 1
|
29
|
+
JSON.generate(body_hash, quirks_mode: true)
|
33
30
|
end
|
34
|
-
|
35
31
|
end
|
36
32
|
end
|
37
33
|
end
|
data/lib/msg91/otp.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Msg91
|
2
|
+
class Otp
|
3
|
+
def self.send_otp(template_id, mobile, optional_params = {})
|
4
|
+
auth_key = Msg91.configuration.auth_key
|
5
|
+
params = { template_id: template_id, mobile: mobile, authkey: auth_key }
|
6
|
+
params.merge!(optional_params) unless optional_params.empty?
|
7
|
+
path = '/api/v5/otp'
|
8
|
+
Msg91::HttpClient.new.get(path, params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.verify_otp(mobile, optional_params = {})
|
12
|
+
auth_key = Msg91.configuration.auth_key
|
13
|
+
params = { mobile: mobile, authkey: auth_key }
|
14
|
+
params.merge!(optional_params) unless optional_params.empty?
|
15
|
+
path = 'api/v5/otp/verify'
|
16
|
+
Msg91::HttpClient.new.get(path, params)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.resend_otp(retrytype, mobile, optional_params = {})
|
20
|
+
auth_key = Msg91.configuration.auth_key
|
21
|
+
params = { retrytype: retrytype, mobile: mobile, authkey: auth_key }
|
22
|
+
params.merge!(optional_params) unless optional_params.empty?
|
23
|
+
path = 'api/v5/otp/retry'
|
24
|
+
Msg91::HttpClient.new.get(path, params)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/msg91/version.rb
CHANGED
data/lib/msg91.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'msg91/version'
|
2
|
+
require 'msg91/configuration'
|
3
|
+
require 'msg91/message'
|
4
|
+
require 'msg91/otp'
|
5
|
+
require 'msg91/http_client'
|
4
6
|
require 'uri'
|
5
7
|
require 'net/http'
|
6
8
|
require 'json'
|
7
9
|
|
8
10
|
module Msg91
|
9
|
-
|
10
11
|
class << self
|
11
12
|
attr_accessor :configuration
|
12
13
|
end
|
@@ -18,5 +19,4 @@ module Msg91
|
|
18
19
|
def self.configure
|
19
20
|
yield(configuration)
|
20
21
|
end
|
21
|
-
|
22
22
|
end
|
data/msg91.gemspec
CHANGED
@@ -1,35 +1,34 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'msg91/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'msg91'
|
8
7
|
spec.version = Msg91::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['sureshprasanna70@gmail.com']
|
9
|
+
spec.email = ['sureshprasanna70+github@gmail.com']
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
11
|
+
spec.summary = 'Send SMS using MSG91'
|
12
|
+
spec.homepage = 'https://github.com/sureshprasanna70/msg91'
|
13
|
+
spec.license = 'MIT'
|
15
14
|
|
16
15
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
16
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
17
|
if spec.respond_to?(:metadata)
|
19
18
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
19
|
else
|
21
|
-
raise
|
22
|
-
|
20
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
21
|
+
'public gem pushes.'
|
23
22
|
end
|
24
23
|
|
25
|
-
spec.files
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
25
|
f.match(%r{^(test|spec|features)/})
|
27
26
|
end
|
28
|
-
spec.bindir =
|
27
|
+
spec.bindir = 'exe'
|
29
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
-
spec.require_paths = [
|
29
|
+
spec.require_paths = ['lib']
|
31
30
|
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
31
|
+
spec.add_development_dependency 'bundler', '~> 2.2.10'
|
32
|
+
spec.add_development_dependency 'rake', '~> 12.3.3'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
35
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msg91
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sureshprasanna70@gmail.com
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.10
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.10
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description:
|
55
|
+
description:
|
56
56
|
email:
|
57
57
|
- sureshprasanna70+github@gmail.com
|
58
58
|
executables: []
|
@@ -73,7 +73,9 @@ files:
|
|
73
73
|
- lib/generators/templates/msg91_initializer.rb
|
74
74
|
- lib/msg91.rb
|
75
75
|
- lib/msg91/configuration.rb
|
76
|
+
- lib/msg91/http_client.rb
|
76
77
|
- lib/msg91/message.rb
|
78
|
+
- lib/msg91/otp.rb
|
77
79
|
- lib/msg91/version.rb
|
78
80
|
- msg91.gemspec
|
79
81
|
homepage: https://github.com/sureshprasanna70/msg91
|
@@ -81,7 +83,7 @@ licenses:
|
|
81
83
|
- MIT
|
82
84
|
metadata:
|
83
85
|
allowed_push_host: https://rubygems.org
|
84
|
-
post_install_message:
|
86
|
+
post_install_message:
|
85
87
|
rdoc_options: []
|
86
88
|
require_paths:
|
87
89
|
- lib
|
@@ -96,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
98
|
- !ruby/object:Gem::Version
|
97
99
|
version: '0'
|
98
100
|
requirements: []
|
99
|
-
rubygems_version: 3.
|
100
|
-
signing_key:
|
101
|
+
rubygems_version: 3.2.3
|
102
|
+
signing_key:
|
101
103
|
specification_version: 4
|
102
104
|
summary: Send SMS using MSG91
|
103
105
|
test_files: []
|