ruby_sms 1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea160872cb23ddfa9480048f56c90401c1ec78fb
4
+ data.tar.gz: 07fb92cc9f35ecb64ec76ee4aa834ceb90213386
5
+ SHA512:
6
+ metadata.gz: 737b03479a6b4f9779c265261ca9e3053437160e5dc73450ada6bb1b955429212d0bf34c53a42c86b468a0a150d1837b151469e7e57e03de9c1a02b59ad928a7
7
+ data.tar.gz: 7e2af8bec903eab9889c5525e97cc65603b20267bae32b3bd328c63030dba073618a9485256d28c4bcb4f50eb75e99b975b330e022a24ea3a65303afb806946a
@@ -0,0 +1,51 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+ .rubocop.yml
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 carnifun
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # ruby_sms
2
+ simple way to send sms using sms77 or any other short message api provider
3
+ A Ruby client library for [Sms77][more to come].
4
+
5
+ ## Getting started
6
+
7
+ To install **ruby_sms**, run the following command:
8
+
9
+ ```
10
+ gem install ruby_sms
11
+ ```
12
+
13
+ Or if you are using **bundler**, add
14
+
15
+ ```
16
+ gem 'ruby-sms', '~>1.0'
17
+ ```
18
+
19
+ to your `Gemfile`, and run `bundle install`
20
+
21
+ ```ruby
22
+ require "ruby_sms"
23
+ sms = RubySms.new(api_key: "1234123", user: "user@email.com")
24
+ response = sms.send(message: "your message", to: "+49178223", delay: false)
25
+ if response.success?
26
+ puts "Sms deliverd "
27
+ else
28
+ puts response.errors
29
+ end
30
+ ```
@@ -0,0 +1,50 @@
1
+ module RubySms
2
+ module Gateway
3
+ class Response
4
+ attr_accessor :errors
5
+ def initialize
6
+ self.errors = []
7
+ end
8
+
9
+ def success?
10
+ errors.empty?
11
+ end
12
+ end
13
+
14
+ class Sms77Response < Response
15
+ attr_accessor :pin
16
+ SMS77_ERROR_CODES = {
17
+ '100' => '100: SMS delivered successfully',
18
+ '101' => '101: Delivery to at least one recipient failed',
19
+ '201' => '201: Sender illegal',
20
+ '202' => '202: Recipient number illegal',
21
+ '300' => '300: Missing username or password',
22
+ '301' => '301: Argument "to" missing',
23
+ '304' => '304: Argument "type" missing',
24
+ '305' => '305: Argument "text" missing',
25
+ '306' => '306: Sender number illegal',
26
+ '307' => '307: Argument "url" missing',
27
+ '400' => '400: Argument "type" invalid',
28
+ '401' => '401: Argument "text" too long',
29
+ '402' => '402: Reload lock - same SMS sent within 90 seconds',
30
+ '500' => '500: Not enough credits',
31
+ '600' => '600: Carrier delivery failed',
32
+ '700' => '700: Unknown error',
33
+ '801' => '801: Logo file not set',
34
+ '802' => '802: Logo file does not exist',
35
+ '803' => '803: Ring tone not set',
36
+ '900' => '900: Given credentials not valid',
37
+ '901' => '901: Message ID invalid',
38
+ '902' => '902: HTTP API not activated for this account',
39
+ '903' => '903: Server IP invalid',
40
+ '11' => '11: SMS carrier temporarily not available',
41
+ '0' => 'Error: Status code does not exist'
42
+ }.freeze
43
+
44
+ def add_error(error_code, _options = {})
45
+ error_message = SMS77_ERROR_CODES[error_code] || error_code.to_s
46
+ errors << error_message
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,73 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'uri'
4
+
5
+ module RubySms
6
+ module Gateway
7
+ class Sms77
8
+ attr_accessor :api_key, :user
9
+
10
+ SMS77_GATEWAY_URL = 'https://gateway.sms77.io/api/sms'.freeze
11
+ SUCCESS_CODE = '100'.freeze
12
+ DEFAULT_PIN_SIZE = 4
13
+
14
+ def initialize(options)
15
+ return if options[:user].nil?
16
+ return if options[:api_key].nil?
17
+
18
+ self.user = options[:user]
19
+ self.api_key = options[:api_key]
20
+ end
21
+
22
+ def send(options)
23
+ response = Sms77Response.new
24
+ (response.add_error(:empty_options) && (return response)) if options.nil?
25
+ code = post_request(options)
26
+ return response if code == SUCCESS_CODE
27
+ response.add_error(code)
28
+ response
29
+ end
30
+
31
+ # generate a simple random 4 digits pin
32
+ def send_pin(options)
33
+ response = Sms77Response.new
34
+ (response.add_error(:empty_options) && (return response)) if options.nil?
35
+ # we may use SecureRandom.hex(size) if you need a more secure pin
36
+ response.pin = rand.to_s[2..(DEFAULT_PIN_SIZE + 1)]
37
+ options[:text].gsub!('%PIN%', response.pin)
38
+ code = post_request(options)
39
+ return response if code == SUCCESS_CODE
40
+ response.add_error(code)
41
+ response
42
+ end
43
+
44
+ private
45
+
46
+ def post_request(options)
47
+ uri = URI.parse(SMS77_GATEWAY_URL)
48
+ request = Net::HTTP::Post.new(uri.to_s)
49
+ request.set_form_data(
50
+ text: options[:text].force_encoding('utf-8'),
51
+ to: options[:to],
52
+ delay: options[:delay] || 0,
53
+ debug: 0,
54
+ utf8: 1,
55
+ u: user,
56
+ p: api_key
57
+ )
58
+ response = https(uri).request(request)
59
+ response.body
60
+ rescue StandardError => e
61
+ RubySms.logger.error("Error while sending post request => #{e}")
62
+ :connection_error
63
+ end
64
+
65
+ def https(uri)
66
+ Net::HTTP.new(uri.host, uri.port).tap do |http|
67
+ http.use_ssl = true
68
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'logger'
3
+ require 'gateway/sms77'
4
+ require 'gateway/response'
5
+
6
+ module RubySms
7
+ class << self
8
+ def logger
9
+ @logger = Logger.new(STDOUT)
10
+ @logger.level = Logger::ERROR
11
+ @logger
12
+ end
13
+
14
+ def logger=(log_instance)
15
+ raise ArgumentError, 'Logger parameter must be a Logger object' unless log_instance.is_a?(Logger)
16
+ @logger = log_instance
17
+ end
18
+
19
+ def new(options = {})
20
+ case options[:gw]
21
+ when :sms99
22
+ 'NOT IMPLEMENTED'
23
+ else
24
+ RubySms::Gateway::Sms77.new(options)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'ruby_sms'
3
+ s.version = '1.0.1'
4
+ s.date = '2017-07-12'
5
+ s.summary = "A simple Sms client "
6
+ s.description = "simple way to send sms using sms77 or any other short message api provider"
7
+ s.authors = ["Mohamed Elassadi"]
8
+ s.email = 'mohamed.elassadi@gmail.com'
9
+ s.files = `git ls-files`.split($/)
10
+ s.homepage = 'https://github.com/carnifun/ruby_sms'
11
+ s.license = 'MIT'
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'ruby_sms'
3
+ s.version = '1.0.0'
4
+ s.date = '2017-07-12'
5
+ s.summary = "A simple Sms client "
6
+ s.description = "simple way to send sms using sms77 or any other short message api provider"
7
+ s.authors = ["Mohamed Elassadi"]
8
+ s.email = 'mohamed.elassadi@gmail.com'
9
+ s.files = `git ls-files`.split($/)
10
+ s.homepage = 'https://github.com/carnifun/ruby_sms'
11
+ s.license = 'MIT'
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mohamed Elassadi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: simple way to send sms using sms77 or any other short message api provider
14
+ email: mohamed.elassadi@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".gitignore"
20
+ - LICENSE
21
+ - README.md
22
+ - lib/gateway/response.rb
23
+ - lib/gateway/sms77.rb
24
+ - lib/ruby_sms.rb
25
+ - ruby_sms.gemspec
26
+ - rubysms.gemspec
27
+ homepage: https://github.com/carnifun/ruby_sms
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.6.11
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: A simple Sms client
51
+ test_files: []