sms_misr 0.1.4

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: db387fc62afa51a82047c88600c0c9cc19d5293d4bffdfca414d0cccb0a82935
4
+ data.tar.gz: 97e328333fb1cb4bff664a4fedfbddeb4847ba515df350734473d688704c0aaa
5
+ SHA512:
6
+ metadata.gz: c5d3886b8c847a3201f1d93e55f1c895d5dce8abeebc17012c2092bc75a2ea7d251446e6dd876503ff5cdcea7b6096a41d6e78778746c474662c2debe087fe71
7
+ data.tar.gz: 5bb3f00d7f6d94a309670e0e8b14ccd0368ec64e2a916a85b55b67b77b968d1a7650437254f21c6120ae430f38b43cfc1936137fbb141d07a8330dd2c7098205
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.8
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sms_misr.gemspec
4
+ gemspec
5
+
6
+ gem "rake", ">= 0.8.7"
7
+ gem "rspec", ">= 3.0"
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sms_misr (0.1.4)
5
+ httparty
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.4.4)
11
+ httparty (0.18.1)
12
+ mime-types (~> 3.0)
13
+ multi_xml (>= 0.5.2)
14
+ mime-types (3.3.1)
15
+ mime-types-data (~> 3.2015)
16
+ mime-types-data (3.2020.1104)
17
+ multi_xml (0.6.0)
18
+ rake (12.3.3)
19
+ rspec (3.10.0)
20
+ rspec-core (~> 3.10.0)
21
+ rspec-expectations (~> 3.10.0)
22
+ rspec-mocks (~> 3.10.0)
23
+ rspec-core (3.10.0)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-expectations (3.10.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-mocks (3.10.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-support (3.10.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ rake (>= 0.8.7)
38
+ rspec (>= 3.0)
39
+ sms_misr!
40
+
41
+ BUNDLED WITH
42
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 mohamedmmahfouz
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.
@@ -0,0 +1,68 @@
1
+ # Sms Misr Gem
2
+ A ruby gem for integration with sms misr services
3
+ PLEASE NOTE THAT this integrates with SMS MISR API ONLY https://smsmisr.com/
4
+ Ruby GEM: https://rubygems.org/gems/sms_misr
5
+ # This GEM is still under testing
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sms_misr'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sms_misr
22
+
23
+ ## CREDENTIALS SETUP
24
+
25
+ add the following credentials into your ENV file
26
+
27
+ ````ruby
28
+ SEND_SMS_ENABLED=<must be set to true to allow sending messages, set to false prevent sending any messages>
29
+ SMS_USERNAME=<user name for your sms misr account>
30
+ SMS_PASSWORD=<password for your sms misr account>
31
+ FIXED_OTP_SMS_TOKEN=<Fixed message token for OTP API>
32
+ FIXED_OTP_SMS_SIGNATURE=<Fixed message signature for OTP API>
33
+ ````
34
+ ## SMS API
35
+
36
+ to use the sms api:
37
+ ````ruby
38
+ handler = SmsMisr::Handler.new('010XXXXXXXX')
39
+ parsed_response = handler.send_message("message", "SENDER") ## Sender is the sender value of your sms misr account
40
+ ## language is English by default, to specify arabic language use the following
41
+ parsed_response = handler.send_message("message", "SENDER", 2)
42
+ ````
43
+
44
+ ## OTP API
45
+ to use OTP API make sure FIXED_OTP_SMS_TOKEN & FIXED_OTP_SMS_SIGNATURE are set in your env file
46
+ ````ruby
47
+ handler = SmsMisr::Handler.new('010XXXXXXXX')
48
+ parsed_response = handler.send_otp('123456')
49
+ ````
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Future work
58
+ - convert sms misr api responses to readable message
59
+ - add backgrounding with sidekiq
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sms_misr.
64
+
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sms_misr"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,85 @@
1
+ require "sms_misr/version"
2
+ require 'httparty'
3
+ # This class is responsible for sending the sms for the whole app
4
+ #
5
+ ## `send_message` uses sms misr SMS API which takes a longer time to receive the message
6
+ ###########
7
+ ## `send_otp` uses sms misr OTP API which has a pre-set message identified by `token` and `Msignature` fields
8
+ ## which is found on their website
9
+ ###########
10
+
11
+ class SmsMisr::Handler
12
+ include HTTParty
13
+ base_uri 'https://smsmisr.com/api'
14
+ attr_reader :options
15
+
16
+ def initialize(phone_number)
17
+ @options = {
18
+ query:
19
+ {
20
+ username: username,
21
+ password: password,
22
+ mobile: phone_number,
23
+ },
24
+ }
25
+ end
26
+
27
+ def send_message(message, sender, language = 1)
28
+ return unenabled_message unless send_sms_enabled?
29
+
30
+ @options[:query].merge!(message_params(message, sender, language))
31
+ result = self.class.post('/webapi', @options)
32
+ result.parsed_response
33
+ end
34
+
35
+ def send_otp(otp)
36
+ return unenabled_message unless send_sms_enabled?
37
+
38
+ @options[:query].merge!(otp_params(otp))
39
+ result = self.class.post('/vSMS', @options)
40
+ result.parsed_response
41
+ end
42
+
43
+ private
44
+
45
+ def message_params(message, sender, language)
46
+ {
47
+ language: language,
48
+ sender: sender,
49
+ message: message,
50
+ }
51
+ end
52
+
53
+ def otp_params(otp)
54
+ {
55
+ code: otp,
56
+ token: fixed_message_token,
57
+ Msignature: fixed_message_signature,
58
+ }
59
+ end
60
+
61
+ def username
62
+ ENV.fetch('SMS_USERNAME')
63
+ end
64
+
65
+ def password
66
+ ENV.fetch('SMS_PASSWORD')
67
+ end
68
+
69
+ def send_sms_enabled?
70
+ ENV.fetch('SEND_SMS_ENABLED') == 'true'
71
+ end
72
+
73
+ def fixed_message_token
74
+ ENV.fetch('FIXED_OTP_SMS_TOKEN')
75
+ end
76
+
77
+ def fixed_message_signature
78
+ ENV.fetch('FIXED_OTP_SMS_SIGNATURE')
79
+ end
80
+
81
+ def unenabled_message
82
+ { message: 'sending sms is not enabled' }
83
+ end
84
+ end
85
+
@@ -0,0 +1,3 @@
1
+ module SmsMisr
2
+ VERSION = "0.1.4"
3
+ end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,30 @@
1
+ require_relative 'lib/sms_misr/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "sms_misr"
5
+ spec.version = SmsMisr::VERSION
6
+ spec.authors = ["mohamedmmahfouz"]
7
+ spec.email = ["mohamedmmahfouz24@gmail.com"]
8
+
9
+ spec.summary = %q{SMS misr api handler.}
10
+ spec.description = %q{SMS misr api handler.}
11
+ spec.homepage = "https://github.com/MohamedMMahfouz/sms_misr_gem"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ # spec.metadata["homepage_uri"] = spec.homepage
18
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ spec.add_runtime_dependency "httparty"
30
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sms_misr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - mohamedmmahfouz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: SMS misr api handler.
28
+ email:
29
+ - mohamedmmahfouz24@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - lib/sms_misr.rb
45
+ - lib/sms_misr/version.rb
46
+ - sms_misr-0.1.0.gem
47
+ - sms_misr-0.1.1.gem
48
+ - sms_misr-0.1.2.gem
49
+ - sms_misr-0.1.3.gem
50
+ - sms_misr.gemspec
51
+ homepage: https://github.com/MohamedMMahfouz/sms_misr_gem
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.3.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.7.6.2
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: SMS misr api handler.
75
+ test_files: []