mo_sms 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9147759aef11b41acfbd1592a5f8159c5cba06a
4
+ data.tar.gz: 7be4ffb69e168a18540722552bd13ccb087542b0
5
+ SHA512:
6
+ metadata.gz: 3a44cdbc5f2ec4abe9d94fc7acc305dc3856bdb860d5c5a580e88e89b096fb9bc0deb30e581973808a901096301f47fa8526136941bcffa338678bd4b879766c
7
+ data.tar.gz: 44c2e582b6d5b303048e3936d26a98d521a57af3138993198847ed597875b034fa3eaed66d004f0a8fb9f98e11029ae97057dc5a723533a37db9bfd7dc34aee6
data/.gitignore ADDED
@@ -0,0 +1,23 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mo_sms.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jone Samra
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,41 @@
1
+ # MoSms
2
+
3
+ A Ruby wrapper class for the SMS sending service API called MO-SMS located in Sweden.
4
+ In order to use the service, you have to register an account. More information can be found on their [site](http://www.mosms.com).
5
+ The development of this gem has been done using MO-SMS's API specification found [here](https://www.mosms.com/se/docs/api_spec.pdf)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'mo_sms'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mo_sms
20
+
21
+ ## Usage
22
+
23
+ To fire the class just
24
+
25
+ sms = MoSms::SMSSender.new("your_username", "your_password")
26
+
27
+ To send a text sms, call the .send() method. **Watch out for the Exceptions that can be thrown here :)**
28
+
29
+ - The first argument is the phone number to send the SMS to.
30
+ - The second one is the type of the message (Can be either :text or :wap).
31
+ - The third argument is the content of the message.
32
+
33
+ sms.send("072123123", :text, "This is my message")
34
+
35
+
36
+ Other attributes are added to the class (read the API specification) like...
37
+
38
+ sms.tariff = false #or true
39
+ sms.allow_long_messages = false #or true
40
+ sms.custom_sender = false #or true
41
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList["test/**/*_test.rb"]
7
+ t.verbose = true
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,73 @@
1
+ require "uri/common"
2
+ require "net/http"
3
+
4
+ module MoSms
5
+ class SMSSender
6
+ attr_accessor :username, :password, :tariff, :allow_long_messages, :custom_sender
7
+
8
+ def initialize(username, password)
9
+ @username = username
10
+ @password = password
11
+ @tariff = false
12
+ @allow_long_messages = false
13
+ @custom_sender = false
14
+ end
15
+
16
+ def send(phone_number, message_type, data)
17
+ set_uri(phone_number, data, message_type)
18
+
19
+ begin
20
+ response = Net::HTTP.get_response(URI.parse(@api_uri))
21
+ rescue Exception => e
22
+ raise e.message
23
+ end
24
+
25
+ result = response.body
26
+ result = code_to_message(result.to_i)
27
+
28
+ raise result unless result.empty?
29
+
30
+ true
31
+
32
+ end
33
+
34
+
35
+ private
36
+ def set_uri(phone_number, data, message_type)
37
+ tariff = ""
38
+ allow_long_messages = ""
39
+ custom_sender
40
+
41
+ tariff = "&tariff=1" if @tariff
42
+ allow_long_messages = "&allowlong=1" if @allow_long_messages
43
+ custom_sender = "&customsender=1" if @custom_sender
44
+
45
+ @api_uri = "http://www.mosms.com/se/sms-send.php?username=#{@username}&password=#{password}&nr=#{phone_number}&type=#{message_type}&data=#{data}#{tariff}#{allow_long_messages}#{custom_sender}"
46
+ @api_uri = URI.escape(@api_uri)
47
+ end
48
+
49
+ def code_to_message(code)
50
+ case code
51
+ when 1
52
+ return "Not send with the right parameters"
53
+ when 2
54
+ return "Wrong username and/or password"
55
+ when 3
56
+ return "Not enough balance in your MS-SMS account to send the SMS"
57
+ when 4
58
+ return "Wrong TYPE. It should be either \"text\" or \"wap\""
59
+ when 5
60
+ return "Could not access the file/URL. Applicable only when the type is \"wap\""
61
+ when 6
62
+ return "No file extention for the file/URL. Applicable only when the type is \"wap\""
63
+ when 7
64
+ return "Wrong input format for the number."
65
+ when 99
66
+ return "Others errors from the (mobile operator)"
67
+ else
68
+ return ""
69
+ end
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module MoSms
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mo_sms.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "mo_sms/version"
2
+ require "mo_sms/sms_sender"
3
+ module MoSms
4
+
5
+ end
data/mo_sms.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mo_sms/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mo_sms"
8
+ spec.version = MoSms::VERSION
9
+ spec.authors = ["Jone Samra"]
10
+ spec.email = ["jonemob@gmail.com"]
11
+ spec.summary = %q{A Ruby wrapper class for the SMS sending service API called MO-SMS located in Sweden.}
12
+ spec.description = %q{A Ruby wrapper class for the SMS sending service API called MO-SMS located in Sweden.}
13
+ spec.homepage = "https://github.com/phenomen2277/mo_sms"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class SMSSenderTest < Test::Unit::TestCase
4
+
5
+ def test_if_runtime_exception_is_thrown_on_wrong_credentials
6
+ sms = MoSms::SMSSender.new("falseUser", "falsePassword")
7
+
8
+ assert_raise RuntimeError do
9
+ sms.send("072123123", :text, "This is my message")
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,2 @@
1
+ require "test/unit"
2
+ require "mo_sms"
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mo_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jone Samra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A Ruby wrapper class for the SMS sending service API called MO-SMS located
42
+ in Sweden.
43
+ email:
44
+ - jonemob@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/mo_sms.rb
55
+ - lib/mo_sms/sms_sender.rb
56
+ - lib/mo_sms/version.rb
57
+ - mo_sms.gemspec
58
+ - test/SMSSender_test.rb
59
+ - test/test_helper.rb
60
+ homepage: https://github.com/phenomen2277/mo_sms
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.1
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: A Ruby wrapper class for the SMS sending service API called MO-SMS located
84
+ in Sweden.
85
+ test_files:
86
+ - test/SMSSender_test.rb
87
+ - test/test_helper.rb