wiser_sms 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NWMwMzY1NjQ1MWEzNTE4ZTE4YTVhN2FhNDYzNDExOWQzMWU5Y2YxNg==
5
+ data.tar.gz: !binary |-
6
+ NTZmY2Q4OTUyNTFiY2Y5NmQ2NWJjNDBlMTJiMTY3Mjk2MTYwMDFlNg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZWE5YjY0N2FiMjk4MDE3ZmRkZDg5ZmUwZWMyNDliOGQ5NTgzMDQ3MTVhZDZm
10
+ ODFjZjVkMDJmMTE5OTZmYWVkNjJmNDAwMWNlMDIxNzRjN2MyNGMxZmFmZGY4
11
+ ZDA1OTQ4YjYzOGQwMWU3MDc4NWNkNjZjZDI0ZmI3YWI3NGI5Y2Y=
12
+ data.tar.gz: !binary |-
13
+ YTMwMTU2ZDIzMDRlY2EzODJhOWNkOGRmOTYzNzQ0YzQ1YjY5YWM2MTAwNjc0
14
+ Y2UzNmYxNGJiYzJlNjgyOWZiNDIyODgyMWM5YmNlMTQ4ZTQ0ODMxZGU2YmMz
15
+ ZTEzZjQ4ZTBmN2YyOTgzOWU1YzQzOTI2MDk5MjMzYjBlMjUwYjI=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kenneth John Balgos
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # WiserSms
2
+
3
+ Medium Rare Outgoing SMS
4
+
5
+ ## Requirements
6
+
7
+ _WiserSms_ only support Rails >= 3.x.
8
+
9
+ ## Networks
10
+
11
+ `WiserSms::Ph` only supports Globe Telecom, Smart Communications, and Sun Cellular networks.
12
+
13
+ _..more to come.._
14
+
15
+ ## Setup
16
+
17
+ You can do normal gem installation in terminal:
18
+
19
+ ```ruby
20
+ $ gem install wiser_sms
21
+ ```
22
+
23
+ or include it in your Gemfile:
24
+
25
+ ```ruby
26
+ gem 'wiser_sms', '~> 0.1.1'
27
+ ```
28
+
29
+ Then restart your application.
30
+
31
+ ## Usage
32
+
33
+ ### Security
34
+
35
+ To avoid abuse, the `key` string parameter is now requred for all requests. It serves as a password to successfully send SMS.
36
+
37
+ _Note: To request for password, email the purpose of usage to kennethjohnbalgos@gmail.com._
38
+
39
+ ### Request
40
+
41
+ To send SMS for single receiver, pass the string 11-digit string mobile mobile number and message using the `send` method:
42
+
43
+ ```ruby
44
+ WiserSms::Ph.send("password_hash", "091711292013", "You really did it!")
45
+ ```
46
+
47
+ To send SMS for multiple receivers, pass the array of 11-digit string mobile number instead:
48
+
49
+ ```ruby
50
+ WiserSms::Ph.send("password_hash", ["091711292013","091711302013"], "You guys really did it!")
51
+ ```
52
+
53
+ _Note: If you send the receiver's mobile number more than once, the message will still be sent once._
54
+
55
+ ### Response
56
+
57
+ All responses will come in hash with the status for each mobile number passed to the `send` method.
58
+
59
+ Here's an example:
60
+
61
+ ```ruby
62
+ {"091711292013" => true, "091711302013" => true, "123" => nil}
63
+ ```
64
+
65
+ #### Statuses
66
+
67
+ Response | Which Means
68
+ --- | ---
69
+ (BOOL) true | Message Sent
70
+ (BOOL) false | Sending Failed
71
+ (NULL) nil | Invalid Mobile Number
72
+ (INTEGER) 0 | Invalid Key/Password
73
+
74
+
75
+ ## Contributing
76
+
77
+ 1. Fork it
78
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
79
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
80
+ 4. Push to the branch (`git push origin my-new-feature`)
81
+ 5. Create new Pull Request
82
+
83
+ ## Support
84
+ Open an issue in https://github.com/kennethjohnbalgos/wiser_sms if you need further support or want to report a bug.
85
+
86
+ ## License
87
+
88
+ The MIT License (MIT) Copyright (c)
89
+
90
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
91
+
92
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
93
+
94
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake'
@@ -0,0 +1,119 @@
1
+ require 'openssl'
2
+ require 'open-uri'
3
+ require 'cgi'
4
+
5
+ module WiserSms
6
+ class Ph
7
+ ADDRESS = "121.97.123.218:13013"
8
+ VTR = "9a3a70173b00fd265aa0a9b79163a5bb1f0e157b"
9
+ PASSWORD = "zEQBwfcPD9RsB6OqBGLAVg==\n"
10
+ GLOBE_USER = "ydbrX+oiguoLAWKAGsWHyg==\n"
11
+ GLOBE_MIN = "9L9UYGiJiZku+m7lZgsGBg==\n"
12
+ SMART_USER = "xOhnX3pSw02OJ6FzD2LyCQ==\n"
13
+ SMART_MIN = "k9rGz/TMCiZZOmJT8S6yFg==\n"
14
+ SUN_USER = "xIIXdSOgjnpGUT8Baqum9A==\n"
15
+ SUN_MIN = "tigoy2Tzx6OiVKuyMZ5ViQ==\n"
16
+
17
+ def self.get_network?(min)
18
+ return nil if min.size != 11
19
+ prefix = min.to_s[0..3]
20
+ if ['0813', '0907', '0908', '0909', '0910', '0912', '0918', '0919', '0920', '0921', '0928', '0929', '0930', '0938', '0939', '0946', '0947', '0948', '0949', '0989', '0998', '0999'].include?(prefix)
21
+ return "smart"
22
+ elsif ['0817', '0905', '0906', '0915', '0916', '0917', '0926', '0927', '0935', '0936', '0937', '0994', '0996', '0997'].include?(prefix)
23
+ return "globe"
24
+ elsif ['0922', '0923', '0925', '0932', '0933', '0934', '0942', '0943'].include?(prefix)
25
+ return "sun"
26
+ else
27
+ return "invalid"
28
+ end
29
+ end
30
+
31
+ def self.escape(msg)
32
+ return CGI::escape(msg)
33
+ end
34
+
35
+ def self.send(key, mins, msg)
36
+ return 0 unless key.to_s.strip.present?
37
+ mins = [mins] unless mins.is_a?(Array)
38
+ escaped_msg = self.escape(msg)
39
+ response = {}
40
+ mins.each do |min|
41
+ case self.get_network?(min)
42
+ when "globe"
43
+ resp = self.send_globe(key, min, escaped_msg)
44
+ when "smart"
45
+ resp = self.send_smart(key, min, escaped_msg)
46
+ when "sun"
47
+ resp = self.send_sun(key, min, escaped_msg)
48
+ else
49
+ resp = nil
50
+ end
51
+ return resp
52
+ response[min] = resp
53
+ end
54
+ return response
55
+ end
56
+
57
+ def self.send_globe(key, min, msg)
58
+ return nil if min.size != 11
59
+ user = GLOBE_USER
60
+ pass = PASSWORD
61
+ src = GLOBE_MIN
62
+ return self.request(key, user, pass, src, min, msg)
63
+ end
64
+
65
+ def self.send_smart(key, min, msg)
66
+ return nil if min.size != 11
67
+ user = SMART_USER
68
+ pass = PASSWORD
69
+ src = SMART_MIN
70
+ return self.request(key, user, pass, src, min, msg)
71
+ end
72
+
73
+ def self.send_sun(key, min, msg)
74
+ return nil if min.size != 11
75
+ user = SUN_USER
76
+ pass = PASSWORD
77
+ src = SUN_MIN
78
+ return self.request(key, user, pass, src, min, msg)
79
+ end
80
+
81
+ def self.request(key, username, password, source, destination, message)
82
+ begin
83
+ username = self.validate(key, username)
84
+ password = self.validate(key, password)
85
+ source = self.validate(key, source)
86
+
87
+ url = "http://#{ADDRESS}/cgi-bin/sendsms"
88
+ authorize = "?username=#{username}&password=#{password}&from=#{source}"
89
+ payload = "&to=#{destination}&text=#{message}"
90
+ request = "#{url}#{authorize}#{payload}"
91
+ response = open(request).read
92
+ return response.split(":")[0] == "0"
93
+ rescue
94
+ return 0
95
+ end
96
+ end
97
+
98
+ def self.encrypt(key, str)
99
+ aes = OpenSSL::Cipher::Cipher.new('AES-256-CBC')
100
+ aes.encrypt
101
+ aes.key = key
102
+ aes.iv = VTR
103
+ cipher = aes.update(str)
104
+ cipher = aes.final
105
+ enc = [cipher].pack('m')
106
+ return enc
107
+ end
108
+
109
+ def self.validate(key, str)
110
+ aes = OpenSSL::Cipher::Cipher.new('AES-256-CBC')
111
+ aes.decrypt
112
+ aes.key = key
113
+ aes.iv = VTR
114
+ cipher = aes.update(str.unpack('m')[0])
115
+ cipher << aes.final
116
+ return cipher
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,3 @@
1
+ module WiserSms
2
+ VERSION = '0.1.1'
3
+ end
data/lib/wiser_sms.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'wiser_sms/version'
2
+ require 'active_support'
3
+
4
+ module WiserSms
5
+ extend ActiveSupport::Autoload
6
+ autoload :Ph
7
+ autoload :VERSION
8
+ end
data/wiser_sms.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wiser_sms/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wiser_sms"
8
+ spec.version = WiserSms::VERSION
9
+ spec.authors = ["Kenneth John Balgos"]
10
+ spec.email = ["kennethjohnbalgos@gmail.com"]
11
+ spec.description = "Medium Rare Outgoing SMS"
12
+ spec.summary = ""
13
+ spec.homepage = "https://github.com/kennethjohnbalgos/wiser_sms"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files`.split($/)
16
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wiser_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kenneth John Balgos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Medium Rare Outgoing SMS
14
+ email:
15
+ - kennethjohnbalgos@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - LICENSE.txt
22
+ - README.md
23
+ - Rakefile
24
+ - lib/wiser_sms.rb
25
+ - lib/wiser_sms/ph.rb
26
+ - lib/wiser_sms/version.rb
27
+ - wiser_sms.gemspec
28
+ homepage: https://github.com/kennethjohnbalgos/wiser_sms
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.0.3
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: ''
52
+ test_files: []