rannel 0.4.0

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,27 @@
1
+ Currently we can consider Rannel to be on an alpha stage. We have the ability to send requests (via HTTP/GET) to a kannel (http://www.kannel.org) instance in order to send sms messages to a subscriber.
2
+
3
+ Which are the steps (not necessarily versions) of Rannel (i.e. what will it do for us)?
4
+
5
+ I can see for the moment 4 main steps in here:
6
+
7
+ 1. Rannel ---http/get(post)---> Kannel
8
+
9
+ In this first step we will be able to send requests to a Kannel instance in order to be able to send sms messages to a subscriber. It might seem that we have that already (more or less) but I think that there is still a lot work to do here (logs, etc).
10
+
11
+ 2. Rannel <---http/get(post)--- Kannel
12
+
13
+ In this second step we should be able to receive messages from Kannel. I did not include the protocol in the graph as I think that we should be able to do this without thinking first on the protocol. Let me explain:
14
+
15
+ In Kannel there are various ways to send content or call an application, these include http requests (GET and POST), external program calls, or even fetching the content from a flat file. We should be able to respond to any one of these.
16
+
17
+ 3. Rannel ---administer---> Kannel
18
+
19
+ In this 3rd step, we should be able to administer the Kannel instances, being able to change configuration parameters and restarting the whole thing. We should also not be that tied to Kannel any more (in the sense of that we don't need to start Kannel in order to get Rannel working, Kannel (bearerbox and smsbox) will be started from within Rannel when Rannel starts). I.e. we are moving into being a SMS gateway.
20
+
21
+ 4. Rannel --- SMPP ---> SMSC
22
+
23
+ From this moment on we should be able to talk directly to the SMSC (or GSM modem) in order to receive and send messages to the subscribers.
24
+
25
+ I am also considering the option of integrating Rannel with other features of Kannel (OTA & WAP), we should consider these too.
26
+
27
+ Then I was thinking of plugging Rannel into Mbuni too (http://www.mbuni.org). Mbuni is a MMS gateway that sits on top of Kannel. We should take a look at it at some stage to see how we could use this to send not only SMS but also MMS to the subscribers...
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ # == Synopsis
3
+ #
4
+ # Rannel is a set of classes that will interact with the open source
5
+ # SMS Gateway Kannel (http://www.kannel.org) to send SMS messages from
6
+ # a Ruby (or Rails) application.
7
+ #
8
+ # It has been inspired by the ActiveXXX project family for the ease of
9
+ # usage.
10
+ #
11
+ # This file just puts all the needed files found in the Rannel project
12
+ # together so that there is no need to "require" each and every file when
13
+ # using rannel.
14
+ #
15
+ # === Note
16
+ #
17
+ # Per se Rannel will need a working Kannel instance running in order to
18
+ # be able to send the messages through Kannel (that is the bearerbox and
19
+ # smsbox processes) for the moment. Later we might implement either the
20
+ # handles to start the bearer- and sms-box from within Rannel or we will
21
+ # implement the same funcionallity as offered by Kannel.
22
+ #
23
+ # == Author
24
+ # Enrique Comba Riepenhausen
25
+ #
26
+ # == Copyright
27
+ # Copyright (c) 2007. All rights reserved.
28
+ # Licensed under the LGPL
29
+ $:.unshift(File.dirname(__FILE__))
30
+
31
+ require "logger"
32
+
33
+ require "rannel/base"
34
+ require "rannel/exceptions"
35
+ require "rannel/connections"
36
+ require "rannel/sms"
37
+ require "rannel/adapters/abstract_adapter"
38
+ require "rannel/adapters/get_requests"
39
+ require "rannel/adapters/post_requests"
40
+
41
+ @@logger = Logger.new(STDOUT)
42
+ @@logger.level = Logger::WARN
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ # == Synopsis
3
+ #
4
+ # Here you will find common methods to be used by all the adapter
5
+ # implementations.
6
+ #
7
+ # == Author
8
+ # Enrique Comba Riepenhausen
9
+ #
10
+ # == Copyright
11
+ # Copyright (c) 2007. All rights reserved.
12
+ # Licensed under the LGPL
13
+ module Rannel
14
+ class AbstractAdapter
15
+ require 'net/http'
16
+ require 'cgi'
17
+
18
+ def initialize(config)
19
+ @ip = config[:ip]
20
+ @port = config[:port]
21
+ @user = config[:user]
22
+ @password = config[:password]
23
+ @@logger.info("Adapter #{self.class} initialized")
24
+ @@logger.debug("With IP:#{@ip} | PORT:#{@port}" +
25
+ " | USER:#{@user} | PWD: #{@password}")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ # == Synopsis
3
+ #
4
+ # The GetRequestAdapter will make HTTP/GET requests to a Kannel smsbox
5
+ # instance in order to send the messages to Kannel.
6
+ #
7
+ # == Author
8
+ # Enrique Comba Riepenhausen
9
+ #
10
+ # == Copyright
11
+ # Copyright (c) 2007. All rights reserved.
12
+ # Licensed under the LGPL
13
+ module Rannel
14
+ class Base
15
+ def self.get_request_adapter(config)
16
+ return GetRequestAdapter.new(config)
17
+ end
18
+ end
19
+
20
+ class GetRequestAdapter < AbstractAdapter
21
+
22
+ def deliver(sms)
23
+ result = ""
24
+ Net::HTTP.start(@ip, @port) do |http|
25
+ url = "/cgi-bin/sendsms?username=#{@user}" +
26
+ "&password=#{@password}#{sms.to_kannel}"
27
+ @@logger.debug("Sending following rewuest: #{url}")
28
+ response = http.get(url)
29
+ result = response.body
30
+ @@logger.debug("Response from Kannel #{result}")
31
+ end
32
+ result
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+ # == Synopsis
3
+ #
4
+ # The PostRequestAdapter will make HTTP/POST requests to a Kannel smsbox
5
+ # instance in order to send the messages to Kannel.
6
+ #
7
+ # == Author
8
+ # Enrique Comba Riepenhausen
9
+ #
10
+ # == Copyright
11
+ # Copyright (c) 2007. All rights reserved.
12
+ # Licensed under the LGPL
13
+ require "rubygems"
14
+ require "builder"
15
+
16
+ module Rannel
17
+ class Base
18
+ def self.post_request_adapter(config)
19
+ return PostRequestAdapter.new(config)
20
+ end
21
+ end
22
+
23
+ class PostRequestAdapter < AbstractAdapter
24
+
25
+ # TODO implement the post funcionallity for this adapter
26
+ def deliver(sms)
27
+ http = Net::HTTP.new(@ip, @port)
28
+ response = http.post("/cgi-bin/sendsms",
29
+ to_xml(sms).gsub("_", "-"), {'Content-Type'=>'text/xml',
30
+ 'user'=> @user.to_s, 'password' => @password.to_s,
31
+ 'X-Kannel-From' => sms.from.to_s})
32
+ @@logger.debug("Response from Kannel #{response.body}")
33
+ response.body
34
+ end
35
+
36
+ # Will Create the XML that we will need to post to Kannel
37
+ def to_xml(sms)
38
+ xml = ''
39
+ doc = Builder::XmlMarkup.new(:target => xml, :indent => 2)
40
+ doc.instruct!
41
+
42
+ doc.message {|message|
43
+ message.submit {|submit|
44
+ if sms.to_many.nil? || sms.to_many.length < 1
45
+ submit.da{|da| da.number(sms.to)}
46
+ else
47
+ sms.to_many.each do |to|
48
+ submit.da{|da| da.number(to)}
49
+ end
50
+ unless sms.to.nil?
51
+ submit.da{|da| da.number(sms.to)}
52
+ end
53
+ end
54
+ submit.oa{|oa| oa.number(sms.from)}
55
+ submit.ud(sms.text)
56
+ sms.udh.nil? ? '' : submit.udh(sms.udh)
57
+ submit.dcs{|dcs|
58
+ sms.mclass.nil? ? '' : dcs.mclass(sms.mclass)
59
+ sms.coding.nil? ? '' : dcs.coding(sms.coding)
60
+ sms.mwi.nil? ? '' : dcs.mwi(sms.mwi)
61
+ sms.compress.nil? ? '' : dcs.compress(sms.compress)
62
+ sms.alt_dcs.nil? ? '' : dcs.alt_dcs(sms.alt_dcs)
63
+ }
64
+ sms.pid.nil? ? '' : submit.pid(sms.pid)
65
+ sms.rpi.nil? ? '' : submit.rpi(sms.rpi)
66
+ sms.validity.nil? ? '' : submit.vp{|vp| vp.delay(sms.validity)}
67
+ sms.deferred.nil? ? '' : submit.timing{|timing| timing.delay(sms.deferred)}
68
+
69
+ if !(sms.dlr_mask.nil? && sms.dlr_url.nil?)
70
+ submit.statusrequest{|status|
71
+ sms.dlr_mask.nil? ? '' : status.dlr_mask(sms.dlr_mask)
72
+ sms.dlr_url.nil? ? '' : status.dlr_url(sms.dlr_url)
73
+ }
74
+ end
75
+ submit.from {|from|
76
+ from.username(@user.to_s)
77
+ from.password(@password.to_s)
78
+ }
79
+ submit.to(sms.account)
80
+ }
81
+ }
82
+ @@logger.debug("XML for Post: #{xml}")
83
+ xml
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ # == Synopsis
3
+ #
4
+ # Rannel is a set of classes that will interact with the open source
5
+ # SMS Gateway Kannel (http://www.kannel.org) to send SMS messages from
6
+ # a Ruby (or Rails) application.
7
+ #
8
+ # It has been inspired by the ActiveXXX project family for the ease of
9
+ # usage.
10
+ #
11
+ # === Note
12
+ #
13
+ # Per se Rannel will need a working Kannel instance running in order to
14
+ # be able to send the messages through Kannel (that is the bearerbox and
15
+ # smsbox processes) for the moment. Later we might implement either the
16
+ # handles to start the bearer- and sms-box from within Rannel or we will
17
+ # implement the same funcionallity as offered by Kannel.
18
+ #
19
+ # == Author
20
+ # Enrique Comba Riepenhausen
21
+ #
22
+ # == Copyright
23
+ # Copyright (c) 2007. All rights reserved.
24
+ # Licensed under the LGPL
25
+ module Rannel
26
+ class Base
27
+
28
+ class << self
29
+
30
+ # Will deliver the SMS using the provided Adapter.
31
+ def deliver(sms)
32
+ raise "No SMS provided to deliver" unless sms
33
+ begin
34
+ @@logger.debug("Delivering SMS to Kannel")
35
+ self.connection.deliver(sms)
36
+ rescue NoMethodError
37
+ @@logger.warn("Adapter has not been initialized!")
38
+ raise ConnectionNotEstablished
39
+ end
40
+ end
41
+
42
+ def create_sms
43
+ sms = Rannel::Sms.new
44
+ sms
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ # == Synopsis
3
+ #
4
+ # Here you'll find methods on the Base class that work closely with the
5
+ # connections to the Kannel Gateway.
6
+ #
7
+ # == Author
8
+ # Enrique Comba Riepenhausen
9
+ #
10
+ # == Copyright
11
+ # Copyright (c) 2007. All rights reserved.
12
+ # Licensed under the LGPL
13
+ module Rannel
14
+
15
+ class Base
16
+ @connection = nil
17
+
18
+ class << self
19
+
20
+ # Return the current connection object
21
+ # (or an exception if not available)
22
+ def connection
23
+ if @connection.nil?
24
+ raise ConnectionNotEstablished
25
+ end
26
+ @connection
27
+ end
28
+
29
+ # Are we connected? Do we have a connection adapter configured?
30
+ def connected?
31
+ !@connection.nil?
32
+ end
33
+
34
+ # Adds the connection to the Base class
35
+ #
36
+ # TODO: Think about the possibility to add more than one connection.
37
+ #
38
+ def connection=(spec)
39
+ raise ConnectionNotEstablished unless spec
40
+ @connection = spec
41
+ end
42
+
43
+ # Method to explicitly drop the current connection
44
+ def drop_connection
45
+ @connection = nil
46
+ end
47
+
48
+ # To establish a valid connection to a kannel smsbox you will
49
+ # initialize as following:
50
+ #
51
+ # Rannel::Base.establish_connection(
52
+ # :adapter => "get",
53
+ # :ip => "localhost",
54
+ # :port => "123342",
55
+ # :user => "someusr",
56
+ # :password => "foobar")
57
+ #
58
+ # This will open (or prepare the connection to the smsbox so that
59
+ # you are ready to send sms messages)
60
+ def establish_connection(config)
61
+ unless config.key?(:adapter)
62
+ raise AdapterNotSpecified, "#{config} adapter is not configured"
63
+ end
64
+
65
+ adapter_method = "#{config[:adapter]}_request_adapter"
66
+ unless respond_to?(adapter_method)
67
+ raise AdapterNotFound,
68
+ "Configuration specifies nonexistent #{config[:adapter]} adapter"
69
+ end
70
+ @connection = self.send(adapter_method, config)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ # == Synopsis
3
+ #
4
+ # In this file you will find all the Exceptions that will be thrown
5
+ # inside of a Rannel runtime.
6
+ #
7
+ # == Author
8
+ # Enrique Comba Riepenhausen
9
+ #
10
+ # == Copyright
11
+ # Copyright (c) 2007. All rights reserved.
12
+ # Licensed under the LGPL
13
+ module Rannel
14
+
15
+ # Standard Rannel error
16
+ class RannelError < StandardError
17
+ end
18
+
19
+ # When the connection object has not been added.
20
+ class ConnectionNotEstablished < RannelError
21
+ end
22
+
23
+ # When no adapter was specified while configuring
24
+ class AdapterNotSpecified < RannelError
25
+ end
26
+
27
+ # When a wrong adapter was specified
28
+ class AdapterNotFound < RannelError
29
+ end
30
+ end
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+ # == Synopsis
3
+ #
4
+ # In this file you will find the SMS class, that defines a sms message to
5
+ # be consumed by a Kannel Gateway.
6
+ #
7
+ # == Author
8
+ # Enrique Comba Riepenhausen
9
+ #
10
+ # == Copyright
11
+ # Copyright (c) 2007. All rights reserved.
12
+ # Licensed under the LGPL
13
+ module Rannel
14
+
15
+ # Defines a Kannel Internal SMS message (that is with all the parameters
16
+ # accepted by Kannel).
17
+ class Sms
18
+ require 'cgi'
19
+
20
+ @@methods = %w{ from to text charset udh smsc mclass mwi compress coding validity deferred dlr_mask dlr_url pid alt_dcs rpi account bininfo priority }
21
+
22
+ def initialize
23
+ @accessors = Hash.new
24
+ end
25
+
26
+ # When we call a setter (=) or a getter method, or even a xxx_to_kannel
27
+ # method it will be handled by this method in order to allow us to
28
+ # use the kannel specific methods.
29
+ def method_missing(method_id, *args)
30
+ if method_id.to_s=~ /=$/
31
+ includes(method_id.to_s.chop)
32
+ arg = *args
33
+ if arg.instance_of?(String) || (arg.to_s=~ /(\%\d{2})*/) > 0
34
+ arg = CGI.escape(arg)
35
+ end
36
+ @accessors["#{method_id}"] = arg
37
+ elsif method_id.to_s=~/_to_kannel/
38
+ includes($`)
39
+ return "&#{$`}=#{@accessors["#{$`}="]}".gsub("_", "-")
40
+ else
41
+ includes(method_id.to_s)
42
+ return @accessors["#{method_id}="]
43
+ end
44
+ end
45
+
46
+ # Outputs the whole Sms object with the current values as a kannel string
47
+ # to be used when we do a get request.
48
+ #
49
+ # TODO: Think if it makes sense here... or should it go to the get adapter?
50
+ def to_kannel
51
+ kannel = ""
52
+ @accessors.each do |key, value|
53
+ kannel << self.method_missing("#{key.chop}_to_kannel", nil)
54
+ end
55
+ kannel
56
+ end
57
+
58
+ # adds a subscriber to the list of multiple recipients
59
+ # note that it will only be taken into consideration in the POST adapter
60
+ def add_to(to)
61
+ if @to_many.nil?
62
+ @to_many = Array.new
63
+ end
64
+ @to_many.push(to)
65
+ end
66
+
67
+ # Returns the list of subscribers that will receive the SMS
68
+ def to_many
69
+ @to_many
70
+ end
71
+
72
+ private
73
+
74
+ # We want to be sure that the method we are calling is a valid method.
75
+ def includes(method)
76
+ if(!@@methods.include?(method.to_s))
77
+ raise "NoMethodError"
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ # == Synopsis
3
+ # With this rake file you will be able to run the tests found in the test
4
+ # directory and perform other tasks that we will be defining over the time.
5
+ #
6
+ # == Tasks
7
+ # - default: Will just call the test task
8
+ # - dest: Will run the unit tests
9
+ # - clobber_rdoc: Remove the rdocumentation
10
+ # - rdoc: Run the RDoc documentation
11
+ # - rerdoc: Rerun the RDoc documentation
12
+ #
13
+ # == Author
14
+ # Created by Enrique Comba Riepenhausen
15
+ #
16
+ # == Copyright
17
+ # Copyright (c) 2007. All rights reserved.
18
+ # Licensed under the LGPL
19
+ require "rubygems"
20
+ require 'rake'
21
+ require 'rake/testtask'
22
+ require "rake/rdoctask"
23
+ require 'rake/gempackagetask'
24
+
25
+ # Switch off if you don't wan't all that profiling information printed out.
26
+ #require "profile"
27
+
28
+ PKG_VERSION = "0.4.0"
29
+ PKG_NAME = "rannel"
30
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
31
+
32
+ # == Gem Specification
33
+ dist_dirs = [ "lib", "test"]
34
+ spec = Gem::Specification.new do |s|
35
+ s.name = PKG_NAME
36
+ s.version = PKG_VERSION
37
+ s.files = [ "rakefile.rb", "README.txt" ]
38
+ dist_dirs.each do |dir|
39
+ s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
40
+ end
41
+ s.summary = "Rannel framework to send SMS messages through Kannel"
42
+ s.has_rdoc = true
43
+ s.require_path = 'lib'
44
+ s.author = "Enrique Comba Riepenhausen"
45
+ s.email = "ecomba@rubyforge.org"
46
+ s.homepage = "http://rannel.rubyforge.org/"
47
+ s.rubyforge_project = "rannel"
48
+ end
49
+
50
+ # Tasks
51
+ task :default => :test
52
+
53
+ desc "Runs the unit tests"
54
+ Rake::TestTask.new(:test) do |test|
55
+ test.libs << "test"
56
+ test.test_files = FileList['test/test*.rb']
57
+ test.verbose = true
58
+ end
59
+
60
+ desc "Generated the projects api documentation"
61
+ Rake::RDocTask.new do |rdoc|
62
+ rdoc.rdoc_files.include("lib/**/*.rb")
63
+ rdoc.rdoc_dir = "docs/rdoc"
64
+ end
65
+
66
+ desc "Generates the zip, tar and gem packages of the project"
67
+ Rake::GemPackageTask.new(spec) do |p|
68
+ p.gem_spec = spec
69
+ p.need_tar = true
70
+ p.need_zip = true
71
+ end
@@ -0,0 +1,27 @@
1
+ get:
2
+ :adapter: "get"
3
+ :ip: "localhost"
4
+ :port: 13920
5
+ :user: "tester"
6
+ :password: "foobar"
7
+
8
+ post:
9
+ :adapter: "post"
10
+ :ip: "localhost"
11
+ :port: 13920
12
+ :user: "tester"
13
+ :password: "foobar"
14
+
15
+ wrong_user_post:
16
+ :adapter: "post"
17
+ :ip: "localhost"
18
+ :port: 13920
19
+ :user: "austin"
20
+ :password: "foobar"
21
+
22
+ wrong_password_post:
23
+ :adapter: "post"
24
+ :ip: "localhost"
25
+ :port: 13920
26
+ :user: "tester"
27
+ :password: "ahole"
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # == Synopsis
4
+ # Will test the different adapters that communicate with Kannel
5
+ #
6
+ # == Author
7
+ # Created by Enrique Comba Riepenhausen
8
+ #
9
+ # == Copyright
10
+ # Copyright (c) 2007. All rights reserved.
11
+ # Licensed under the LGPL
12
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
13
+ require "rubygems"
14
+ require "test/unit"
15
+ require 'mocha'
16
+
17
+ require 'rannel'
18
+ require "logger"
19
+ require "yaml"
20
+
21
+ class TestAdapters < Test::Unit::TestCase
22
+
23
+ def setup
24
+ @OK = "0: Accepted for delivery"
25
+ @adapters = YAML.load_file("#{File.dirname(__FILE__)}/adapters.yaml")
26
+ end
27
+
28
+ def test_connected
29
+ assert(!Rannel::Base.connected?, "Connection should not be established.")
30
+ end
31
+
32
+ def test_connection_not_established
33
+ assert_raise(Rannel::ConnectionNotEstablished) { Rannel::Base.connection }
34
+ end
35
+
36
+ def test_no_connection_to_deliver_sms
37
+ sms = Rannel::Base.create_sms
38
+ Rannel::Base.drop_connection
39
+ assert_raise(Rannel::ConnectionNotEstablished) { Rannel::Base.deliver(sms) }
40
+ end
41
+
42
+ def test_no_deliver
43
+ assert_raise(RuntimeError) { Rannel::Base.deliver(nil) }
44
+ end
45
+
46
+ def test_get_adapter
47
+ get_request = Rannel::Base.establish_connection(@adapters["get"])
48
+
49
+ assert_equal(get_request, Rannel::Base.connection)
50
+ end
51
+
52
+ def test_send_through_get_adapter
53
+ Rannel::Base.establish_connection(@adapters["get"])
54
+
55
+ sms = Rannel::Base.create_sms
56
+ sms.from = "123124"
57
+ sms.to = 2356556652
58
+ sms.text = "Hello"
59
+
60
+ body = @OK
61
+ response = stub(:body => body)
62
+ http = stub(:get => response)
63
+ Net::HTTP.stubs(:start).yields(http)
64
+
65
+ assert_equal(@OK, Rannel::Base.deliver(sms))
66
+ end
67
+
68
+ def test_send_through_post_adapter
69
+ Rannel::Base.establish_connection(@adapters["post"])
70
+
71
+ sms = Rannel::Base.create_sms
72
+ sms.from = "12345678"
73
+ sms.add_to("23489988923")
74
+ sms.add_to("29930038883")
75
+ sms.text = "Greetings"
76
+
77
+ body = @OK
78
+ response = stub(:body => @OK)
79
+ http = stub(:post => response)
80
+ Net::HTTP.stubs(:new).returns(http)
81
+
82
+ assert_equal(@OK, Rannel::Base.deliver(sms))
83
+ end
84
+
85
+ def test_send_nokia_ringtone
86
+ Rannel::Base.establish_connection(@adapters["get"])
87
+
88
+ sms = Rannel::Base.create_sms
89
+ sms.from = 2345342222
90
+ sms.to = 123123232
91
+ sms.udh = "%06%05%04%15%81%15%81"
92
+
93
+ sms.text = "%02%4A%3A%5D%35%85%B5%85%35%A5%84%04%00%77%1E%96%58%26" +
94
+ "%C3%4C%26%C3%4C%26%C3%4C%26%C3%6C%26%C3%6C%26%C3%6C%26%C3%6C%26" +
95
+ "%C3%4C%26%C3%4C%26%C3%4C%26%C3%4C%26%C3%6C%26%C3%6C%26%C3%6C%26" +
96
+ "%C3%6C%26%C3%4C%34%C3%8C%51%36%17%29%06%17%61%56%17%61%56%13%42" +
97
+ "%4D%30%E3%14%4D%85%CA%41%85%D8%55%85%D8%55%84%D0%00%00%00"
98
+
99
+ body = @OK
100
+ response = stub(:body => body)
101
+ http = stub(:get => response)
102
+ Net::HTTP.stubs(:start).yields(http)
103
+
104
+ assert_equal(@OK, Rannel::Base.deliver(sms))
105
+ end
106
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # == Synopsis
4
+ # Will test the methods located in the base.rb (i.e. the Base class).
5
+ #
6
+ # == Author
7
+ # Created by Enrique Comba Riepenhausen
8
+ #
9
+ # == Copyright
10
+ # Copyright (c) 2007. All rights reserved.
11
+ # Licensed under the LGPL
12
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
13
+
14
+ require "test/unit"
15
+
16
+ require 'rannel'
17
+
18
+ class TestBase < Test::Unit::TestCase
19
+
20
+ def test_create_sms
21
+ sms = Rannel::Base.create_sms
22
+
23
+ assert_instance_of(Rannel::Sms, sms)
24
+ end
25
+
26
+ # TAIWO -- This is the place where to code the test... Thanks!
27
+ def test_regexp
28
+ binary = "%06%05%04%15%81%15%81"
29
+
30
+ assert_equal(binary, /(\%\d{2})*/.match(binary).to_s)
31
+ end
32
+ end
@@ -0,0 +1,178 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # == Synopsis
4
+ # Will test the GetRequestAdapter that "talks" with Kannel using the
5
+ # HTTP GET method.
6
+ #
7
+ # == Author
8
+ # Created by Enrique Comba Riepenhausen
9
+ #
10
+ # == Copyright
11
+ # Copyright (c) 2007. All rights reserved.
12
+ # Licensed under the LGPL
13
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
14
+ require "rubygems"
15
+ require "test/unit"
16
+ require 'mocha'
17
+
18
+ require "rannel"
19
+ require "yaml"
20
+
21
+ class TestGetRequestAdapter < Test::Unit::TestCase
22
+ @@OK = "0: Accepted for delivery"
23
+ def setup
24
+ @adapters = YAML.load_file("#{File.dirname(__FILE__)}/adapters.yaml")
25
+ @kannel = Rannel::GetRequestAdapter.new(@adapters["get"])
26
+ @sms = Rannel::Sms.new
27
+ @sms.from = 1234556
28
+ @sms.to = 345345435
29
+ @sms.text = "Kannel!"
30
+ end
31
+
32
+ def test_get_request_adapter
33
+ body = @@OK
34
+ response = stub(:body => body)
35
+ http = stub(:get => response)
36
+ Net::HTTP.stubs(:start).yields(http)
37
+
38
+ assert_equal(@@OK, @kannel.deliver(@sms))
39
+ end
40
+
41
+ def test_get_with_mclass
42
+ body = @@OK
43
+ response = stub(:body => body)
44
+ http = stub(:get => response)
45
+ Net::HTTP.stubs(:start).yields(http)
46
+
47
+ @sms.mclass = 0
48
+ assert_equal(@@OK, @kannel.deliver(@sms))
49
+ @sms.mclass = 1
50
+ assert_equal(@@OK, @kannel.deliver(@sms))
51
+ @sms.mclass = 2
52
+ assert_equal(@@OK, @kannel.deliver(@sms))
53
+ @sms.mclass = 3
54
+ assert_equal(@@OK, @kannel.deliver(@sms))
55
+ @sms.mclass = 4
56
+ body = "MClass field misformed, rejected"
57
+ response = stub(:body => body)
58
+ http = stub(:get => response)
59
+ Net::HTTP.stubs(:start).yields(http)
60
+ assert_equal("MClass field misformed, rejected", @kannel.deliver(@sms))
61
+ end
62
+
63
+ def test_get_with_mwi
64
+ body = @@OK
65
+ response = stub(:body => body)
66
+ http = stub(:get => response)
67
+ Net::HTTP.stubs(:start).yields(http)
68
+
69
+ @sms.mwi = 0
70
+ assert_equal(@@OK, @kannel.deliver(@sms))
71
+ @sms.mwi = 1
72
+ assert_equal(@@OK, @kannel.deliver(@sms))
73
+ @sms.mwi = 2
74
+ assert_equal(@@OK, @kannel.deliver(@sms))
75
+ @sms.mwi = 3
76
+ assert_equal(@@OK, @kannel.deliver(@sms))
77
+ @sms.mwi = 4
78
+ assert_equal(@@OK, @kannel.deliver(@sms))
79
+ @sms.mwi = 5
80
+ assert_equal(@@OK, @kannel.deliver(@sms))
81
+ @sms.mwi = 6
82
+ assert_equal(@@OK, @kannel.deliver(@sms))
83
+ @sms.mwi = 7
84
+ assert_equal(@@OK, @kannel.deliver(@sms))
85
+ @sms.mwi = 8
86
+ body = "MWI field misformed, rejected"
87
+ response = stub(:body => body)
88
+ http = stub(:get => response)
89
+ Net::HTTP.stubs(:start).yields(http)
90
+ assert_equal("MWI field misformed, rejected", @kannel.deliver(@sms))
91
+ end
92
+
93
+ def test_get_with_coding
94
+ body = @@OK
95
+ response = stub(:body => body)
96
+ http = stub(:get => response)
97
+ Net::HTTP.stubs(:start).yields(http)
98
+
99
+ @sms.coding = 0
100
+ assert_equal(@@OK, @kannel.deliver(@sms))
101
+ @sms.coding = 1
102
+ assert_equal(@@OK, @kannel.deliver(@sms))
103
+ @sms.coding = 2
104
+ assert_equal(@@OK, @kannel.deliver(@sms))
105
+ @sms.coding = 3
106
+ body = "Coding field misformed, rejected"
107
+ response = stub(:body => body)
108
+ http = stub(:get => response)
109
+ Net::HTTP.stubs(:start).yields(http)
110
+ assert_equal("Coding field misformed, rejected", @kannel.deliver(@sms))
111
+ end
112
+
113
+ def test_get_with_validity
114
+ body = @@OK
115
+ response = stub(:body => body)
116
+ http = stub(:get => response)
117
+ Net::HTTP.stubs(:start).yields(http)
118
+
119
+ @sms.validity = 2
120
+ assert_equal(@@OK, @kannel.deliver(@sms))
121
+ @sms.validity = 7812378213782782
122
+ assert_equal(@@OK, @kannel.deliver(@sms))
123
+ end
124
+
125
+ def test_get_with_deffered
126
+ body = @@OK
127
+ response = stub(:body => body)
128
+ http = stub(:get => response)
129
+ Net::HTTP.stubs(:start).yields(http)
130
+
131
+ @sms.deferred = 1
132
+ assert_equal(@@OK, @kannel.deliver(@sms))
133
+ end
134
+
135
+ def test_get_with_alt_dcs
136
+ body = @@OK
137
+ response = stub(:body => body)
138
+ http = stub(:get => response)
139
+ Net::HTTP.stubs(:start).yields(http)
140
+
141
+ @sms.alt_dcs = 0
142
+ assert_equal(@@OK, @kannel.deliver(@sms))
143
+ @sms.alt_dcs = 1
144
+ assert_equal(@@OK, @kannel.deliver(@sms))
145
+ @sms.alt_dcs = 2
146
+
147
+ body = "Alt-DCS field misformed, rejected"
148
+ response = stub(:body => body)
149
+ http = stub(:get => response)
150
+ Net::HTTP.stubs(:start).yields(http)
151
+
152
+ assert_equal("Alt-DCS field misformed, rejected", @kannel.deliver(@sms))
153
+ end
154
+
155
+ def test_get_with_priority
156
+ body = @@OK
157
+ response = stub(:body => body)
158
+ http = stub(:get => response)
159
+ Net::HTTP.stubs(:start).yields(http)
160
+
161
+ @sms.priority = 0
162
+ assert_equal(@@OK, @kannel.deliver(@sms))
163
+ @sms.priority = 1
164
+ assert_equal(@@OK, @kannel.deliver(@sms))
165
+ @sms.priority = 2
166
+ assert_equal(@@OK, @kannel.deliver(@sms))
167
+ @sms.priority = 3
168
+ assert_equal(@@OK, @kannel.deliver(@sms))
169
+ @sms.priority = 4
170
+
171
+ body = "Priority field misformed, rejected"
172
+ response = stub(:body => body)
173
+ http = stub(:get => response)
174
+ Net::HTTP.stubs(:start).yields(http)
175
+
176
+ assert_equal("Priority field misformed, rejected", @kannel.deliver(@sms))
177
+ end
178
+ end
@@ -0,0 +1,206 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Enrique Comba Riepenhausen on 2007-05-23.
4
+ # Copyright (c) 2007. All rights reserved.
5
+
6
+ require "rubygems"
7
+ require "test/unit"
8
+ require 'mocha'
9
+
10
+ require "rannel"
11
+ require "yaml"
12
+
13
+ class TestPostRequestAdapter < Test::Unit::TestCase
14
+ @@OK = "0: Accepted for delivery"
15
+
16
+ def setup
17
+ @adapters = YAML.load_file("#{File.dirname(__FILE__)}/adapters.yaml")
18
+
19
+ @kannel = Rannel::PostRequestAdapter.new(@adapters["post"])
20
+ @sms = Rannel::Sms.new
21
+ @sms.from = 1234556
22
+ @sms.to = 345345435
23
+ @sms.text = "POSTME"
24
+ end
25
+
26
+ def test_xml
27
+ #puts @kannel.to_xml(@sms)
28
+ end
29
+
30
+ def test_deliver
31
+ body = @@OK
32
+ response = stub(:body => body)
33
+ http = stub(:post => response)
34
+ Net::HTTP.stubs(:new).returns(http)
35
+
36
+ assert_equal(@@OK, @kannel.deliver(@sms))
37
+ end
38
+
39
+ def test_wrong_user_deliver
40
+ body = "Authorization failed for sendsms"
41
+ response = stub(:body => body)
42
+ http = stub(:post => response)
43
+ Net::HTTP.stubs(:new).returns(http)
44
+
45
+ kannel = Rannel::PostRequestAdapter.new(@adapters["wrong_user_post"])
46
+
47
+ assert_equal("Authorization failed for sendsms", kannel.deliver(@sms))
48
+ end
49
+
50
+ def test_wrong_password_deliver
51
+ body = "Authorization failed for sendsms"
52
+ response = stub(:body => body)
53
+ http = stub(:post => response)
54
+ Net::HTTP.stubs(:new).returns(http)
55
+
56
+ kannel = Rannel::PostRequestAdapter.new(@adapters["wrong_password_post"])
57
+
58
+ assert_equal("Authorization failed for sendsms", kannel.deliver(@sms))
59
+ end
60
+
61
+ def test_many
62
+ @sms.add_to(3333333333)
63
+ @sms.add_to(4444444444)
64
+
65
+ response = stub(:body => @@OK)
66
+ http = stub(:post => response)
67
+ Net::HTTP.stubs(:new).returns(http)
68
+
69
+ assert_equal(@@OK, @kannel.deliver(@sms))
70
+ end
71
+
72
+ # Testing the fields...
73
+ def test_post_with_mclass
74
+ response = stub(:body => @@OK)
75
+ http = stub(:post => response)
76
+ Net::HTTP.stubs(:new).returns(http)
77
+
78
+ @sms.mclass = 0
79
+ assert_equal(@@OK, @kannel.deliver(@sms))
80
+ @sms.mclass = 1
81
+ assert_equal(@@OK, @kannel.deliver(@sms))
82
+ @sms.mclass = 2
83
+ assert_equal(@@OK, @kannel.deliver(@sms))
84
+ @sms.mclass = 3
85
+ assert_equal(@@OK, @kannel.deliver(@sms))
86
+ @sms.mclass = 4
87
+
88
+ body = "MClass field misformed, rejected"
89
+ response = stub(:body => body)
90
+ http = stub(:post => response)
91
+ Net::HTTP.stubs(:new).returns(http)
92
+
93
+ assert_equal(body, @kannel.deliver(@sms))
94
+ end
95
+
96
+ def test_post_with_mwi
97
+ body = @@OK
98
+ response = stub(:body => body)
99
+ http = stub(:post => response)
100
+ Net::HTTP.stubs(:new).returns(http)
101
+
102
+ @sms.mwi = 0
103
+ assert_equal(@@OK, @kannel.deliver(@sms))
104
+ @sms.mwi = 1
105
+ assert_equal(@@OK, @kannel.deliver(@sms))
106
+ @sms.mwi = 2
107
+ assert_equal(@@OK, @kannel.deliver(@sms))
108
+ @sms.mwi = 3
109
+ assert_equal(@@OK, @kannel.deliver(@sms))
110
+ @sms.mwi = 4
111
+ assert_equal(@@OK, @kannel.deliver(@sms))
112
+ @sms.mwi = 5
113
+ assert_equal(@@OK, @kannel.deliver(@sms))
114
+ @sms.mwi = 6
115
+ assert_equal(@@OK, @kannel.deliver(@sms))
116
+ @sms.mwi = 7
117
+ assert_equal(@@OK, @kannel.deliver(@sms))
118
+ @sms.mwi = 8
119
+
120
+ body = "MWI field misformed, rejected"
121
+ response = stub(:body => body)
122
+ http = stub(:post => response)
123
+ Net::HTTP.stubs(:new).returns(http)
124
+
125
+ assert_equal("MWI field misformed, rejected", @kannel.deliver(@sms))
126
+ end
127
+
128
+ def test_post_with_coding
129
+ body = @@OK
130
+ response = stub(:body => body)
131
+ http = stub(:post => response)
132
+ Net::HTTP.stubs(:new).returns(http)
133
+
134
+ @sms.coding = 0
135
+ assert_equal(@@OK, @kannel.deliver(@sms))
136
+ @sms.coding = 1
137
+ assert_equal(@@OK, @kannel.deliver(@sms))
138
+ @sms.coding = 2
139
+ assert_equal(@@OK, @kannel.deliver(@sms))
140
+ @sms.coding = 3
141
+
142
+ body = "Coding field misformed, rejected"
143
+ response = stub(:body => body)
144
+ http = stub(:post => response)
145
+ Net::HTTP.stubs(:new).returns(http)
146
+
147
+ assert_equal("Coding field misformed, rejected", @kannel.deliver(@sms))
148
+ end
149
+
150
+ def test_post_with_validity
151
+ body = @@OK
152
+ response = stub(:body => body)
153
+ http = stub(:post => response)
154
+ Net::HTTP.stubs(:new).returns(http)
155
+
156
+ @sms.validity = 2
157
+ assert_equal(@@OK, @kannel.deliver(@sms))
158
+ @sms.validity = 7812378213782782
159
+ assert_equal(@@OK, @kannel.deliver(@sms))
160
+ end
161
+
162
+ def test_post_with_deffered
163
+ body = @@OK
164
+ response = stub(:body => body)
165
+ http = stub(:post => response)
166
+ Net::HTTP.stubs(:new).returns(http)
167
+
168
+ @sms.deferred = 1
169
+ assert_equal(@@OK, @kannel.deliver(@sms))
170
+ end
171
+
172
+ def test_post_with_alt_dcs
173
+ response = stub(:body => @@OK)
174
+ http = stub(:post => response)
175
+ Net::HTTP.stubs(:new).returns(http)
176
+
177
+ @sms.alt_dcs = 0
178
+ assert_equal(@@OK, @kannel.deliver(@sms))
179
+ @sms.alt_dcs = 1
180
+ assert_equal(@@OK, @kannel.deliver(@sms))
181
+ @sms.alt_dcs = 2
182
+
183
+ body = "Alt-DCS field misformed, rejected"
184
+ response = stub(:body => body)
185
+ http = stub(:post => response)
186
+ Net::HTTP.stubs(:new).returns(http)
187
+
188
+ assert_equal("Alt-DCS field misformed, rejected", @kannel.deliver(@sms))
189
+ end
190
+
191
+ def test_post_with_priority
192
+ body = @@OK
193
+ response = stub(:body => body)
194
+ http = stub(:post => response)
195
+ Net::HTTP.stubs(:new).returns(http)
196
+
197
+ @sms.priority = 0
198
+ assert_equal(@@OK, @kannel.deliver(@sms))
199
+ @sms.priority = 1
200
+ assert_equal(@@OK, @kannel.deliver(@sms))
201
+ @sms.priority = 2
202
+ assert_equal(@@OK, @kannel.deliver(@sms))
203
+ @sms.priority = 3
204
+ assert_equal(@@OK, @kannel.deliver(@sms))
205
+ end
206
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # == Synopsis
4
+ # Will test the inclusion of the Rannel Module into a class and use it from
5
+ # there.A
6
+ #
7
+ # == Author
8
+ # Created by Enrique Comba Riepenhausen
9
+ #
10
+ # == Copyright
11
+ # Copyright (c) 2007. All rights reserved.
12
+ # Licensed under the LGPL
13
+ require "rubygems"
14
+ require "test/unit"
15
+ require "mocha"
16
+
17
+ require "rannel"
18
+ require "yaml"
19
+
20
+ class TestRannelIncluded < Test::Unit::TestCase
21
+ include Rannel
22
+
23
+ @@OK = "0: Accepted for delivery"
24
+
25
+ def test_case_name
26
+ @adapters = YAML.load_file("#{File.dirname(__FILE__)}/adapters.yaml")
27
+ Base.establish_connection(@adapters["get"])
28
+
29
+ sms = Base.create_sms
30
+ sms.from = "1234233"
31
+ sms.to = "2122121"
32
+ sms.text = "Cool"
33
+
34
+ body = @@OK
35
+ response = stub(:body => body)
36
+ http = stub(:get => response)
37
+ Net::HTTP.stubs(:start).yields(http)
38
+ assert_equal(@@OK, Base.deliver(sms))
39
+ end
40
+ end
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # == Synopsis
4
+ # Will test the Sms class to make sure it's methods work as expected.
5
+ #
6
+ # == Author
7
+ # Created by Enrique Comba Riepenhausen
8
+ #
9
+ # == Copyright
10
+ # Copyright (c) 2007. All rights reserved.
11
+ # Licensed under the LGPL
12
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
13
+
14
+ require "test/unit"
15
+
16
+ require "rannel"
17
+
18
+ class TestSms < Test::Unit::TestCase
19
+ def setup
20
+ @sms = Rannel::Base.create_sms
21
+ end
22
+
23
+ def test_basic_methods
24
+ @sms.from = "me"
25
+ @sms.to = "you"
26
+ @sms.text = "How are you?"
27
+
28
+ assert_equal("me", @sms.from)
29
+ assert_equal("you", @sms.to)
30
+ assert_equal("How+are+you%3F", @sms.text)
31
+ end
32
+
33
+ def test_dynamic_methods
34
+ @sms.mclass= "expected"
35
+ assert_equal("expected", @sms.mclass)
36
+ assert_equal("&mclass=expected", @sms.mclass_to_kannel)
37
+ end
38
+
39
+ def test_wrong_method
40
+ @sms.mclass = 2323
41
+ @sms.smsc = "smscee"
42
+
43
+ assert_raise(RuntimeError) { @sms.nanana=12 }
44
+ assert_raise(RuntimeError) { @sms.nanana }
45
+ assert_raise(RuntimeError) { @sms.nanana_to_kannel }
46
+ assert_raise(RuntimeError) { @sms.nanana_nununu }
47
+ end
48
+
49
+ def test_to_many
50
+ sms = Rannel::Sms.new
51
+ sms.add_to("12344444")
52
+
53
+ assert_equal(1, sms.to_many.length)
54
+
55
+ sms.add_to("12122122")
56
+
57
+ assert_equal(2, sms.to_many.length)
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: rannel
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.4.0
7
+ date: 2007-05-28 00:00:00 +02:00
8
+ summary: Rannel framework to send SMS messages through Kannel
9
+ require_paths:
10
+ - lib
11
+ email: ecomba@rubyforge.org
12
+ homepage: http://rannel.rubyforge.org/
13
+ rubyforge_project: rannel
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Enrique Comba Riepenhausen
31
+ files:
32
+ - rakefile.rb
33
+ - README.txt
34
+ - lib/rannel
35
+ - lib/rannel.rb
36
+ - lib/rannel/adapters
37
+ - lib/rannel/base.rb
38
+ - lib/rannel/connections.rb
39
+ - lib/rannel/exceptions.rb
40
+ - lib/rannel/sms.rb
41
+ - lib/rannel/adapters/abstract_adapter.rb
42
+ - lib/rannel/adapters/get_requests.rb
43
+ - lib/rannel/adapters/post_requests.rb
44
+ - test/adapters.yaml
45
+ - test/test_adapters.rb
46
+ - test/test_base.rb
47
+ - test/test_get_requests.rb
48
+ - test/test_post_request.rb
49
+ - test/test_rannel_included.rb
50
+ - test/test_sms.rb
51
+ test_files: []
52
+
53
+ rdoc_options: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ requirements: []
62
+
63
+ dependencies: []
64
+