gl_sms 0.0.1

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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/lib/client/main.rb +73 -0
  3. data/lib/entity.rb +7 -0
  4. data/lib/main.rb +20 -0
  5. metadata +46 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44d13b73560a57926fde4bf66edeaa96f21c39b5
4
+ data.tar.gz: aa5bc23c07ec678c071b9dc4db87305c00f4fa96
5
+ SHA512:
6
+ metadata.gz: 5cc1b5a82b26dbabb19ea730b3f29664eb441e0d531243c674adfc6e9eae4954f490249d6ad10d0462313e0d16f9afd5486aafe8bf639060ac4b38ff67d71ee3
7
+ data.tar.gz: fbea3554ddf389379ab0517a71221f976d6292efe2a8a62549cc31c4033bd32d2134ae153cb3e13f570413d677fbcb0c8f184a216b5cae2b429b821820834182
@@ -0,0 +1,73 @@
1
+ class MSG91
2
+
3
+ require 'uri'
4
+ require 'net/http'
5
+ require "json"
6
+
7
+ #Upstream Specific data
8
+ @access_token =''
9
+ @sender_id = ''
10
+ @flow_id = ''
11
+
12
+ #Upstream Specific constants
13
+ CONTENT_TYPE = 'application/json'.freeze
14
+ HOST ='https://api.msg91.com/api'.freeze
15
+ enum RESPONSE_STATUS = {
16
+ error: 'error',
17
+ success:'success'
18
+ }
19
+
20
+ def initialize(opts = {})
21
+
22
+ raise StandardError.new "MSG91::connect.Unexpected nil opts provided." if opts.nil?
23
+ raise StandardError.new "MSG91::connect.Unexpected nil sender id provided." if opts[:sender_id].nil?
24
+ raise StandardError.new "MSG91::connect.Unexpected nil access token provided." if opts[:access_token].nil?
25
+ raise StandardError.new "MSG91::connect.Unexpected nil flow id provided." if opts[:flow_id].nil?
26
+ @access_token, @sender_id, @flow_id = opts[:access_token], opts[:sender_id], opts[:flow_id]
27
+
28
+ end
29
+
30
+ def send_in_bulk ( msg = "", users = [], opts = {})
31
+
32
+ #checking up the base conditions
33
+ return false, "MSG91::send_in_bulk.Unexpected nil opts found in msg91" if opts.nil?
34
+ return false, "MSG91::send_in_bulk.Unexpected nil users info found in msg91" if users.nil? || users.length.zero?
35
+
36
+ #Setting up the request payload
37
+ payload = {}
38
+ payload[:flow_id] = @flow_id unless @flow_id.nil?
39
+ payload[:sender] = @sender_id unless @sender_id.nil?
40
+ payload[:recipients] = users unless users.nil?
41
+
42
+ # calling the upstream to post the request
43
+ response = post_to_upstream("#{HOST}/v5/flow", payload)
44
+
45
+ #checking the error stats
46
+ return false, "MSG91::send_in_bulk.Unable to post request to upstream" if response.nil? || response[:type].nil?
47
+ return false,response[:message] if response[:type].eql?(RESPONSE_STATUS.error)
48
+
49
+ [true,nil]
50
+ end
51
+
52
+ private
53
+
54
+ def post_to_upstream (url = "", body = {})
55
+ #Setting up the HTTP Client
56
+ url = URI.parse(url)
57
+ http = Net::HTTP.new(url.host, url.port)
58
+ http.use_ssl = true
59
+
60
+ #Setting up the request
61
+ request = Net::HTTP::Post.new(url.request_uri)
62
+ request['content-type'] = CONTENT_TYPE
63
+ request['authkey'] = @access_token
64
+ request.body = body.to_json unless body.nil?
65
+
66
+ # sending request to upstream
67
+ response = http.request(request)
68
+
69
+ #processing the response string
70
+ JSON.parse(response.body)
71
+ end
72
+
73
+ end
@@ -0,0 +1,7 @@
1
+ module Client
2
+
3
+ def send_in_bulk ( msg = "", users = [], opts = {})
4
+ raise NoMethodError "Not implemented"
5
+ end
6
+
7
+ end
@@ -0,0 +1,20 @@
1
+ module GLSMS
2
+
3
+ require_relative './client/main'
4
+
5
+ CL_MSG91 = "msg_91".freeze
6
+
7
+ class Adapter
8
+
9
+ def self.connect(client_name = "", opts = {})
10
+ case client_name
11
+ when CL_MSG91
12
+ MSG91.new opts
13
+ else
14
+ raise StandardError.new "No Client found for #{client_name}"
15
+ end
16
+ end
17
+ end
18
+
19
+
20
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gl_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rajan Kumar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem can be used for sending sms
14
+ email: rajan.kumar@greatlearning
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/client/main.rb
20
+ - lib/entity.rb
21
+ - lib/main.rb
22
+ homepage:
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.5.1
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: GL SMS
46
+ test_files: []