smstrade_de 0.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,4 @@
1
+ doc
2
+ pkg
3
+ coverage
4
+ tags
@@ -0,0 +1,6 @@
1
+ For use with http://www.smstrade.de
2
+
3
+ = Configuration
4
+ # config/intializers/smstrade.rb
5
+ Smstrade.key = "YOUR_KEY"
6
+ Smstrade.route = "ROUTE"
@@ -0,0 +1,41 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "smstrade_de"
7
+ gem.summary = 'Gem for sending SMS via smstrade.de Gateway.'
8
+ gem.email = "maikel@urlitzki.de"
9
+ gem.homepage = "http://github.com/maikelcoke/smstrade_de"
10
+ gem.authors = ["Maikel Urlitzki"]
11
+
12
+ gem.has_rdoc = true
13
+ gem.extra_rdoc_files = [ "README.rdoc" ]
14
+
15
+ gem.test_files = Dir.glob('test/test_*.rb')
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ # Test
23
+ require 'rake/testtask'
24
+ desc 'Default: run unit tests.'
25
+ task :default => :test
26
+ task :test => :check_dependencies
27
+
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.test_files = FileList.new('test/test_*.rb')
30
+ test.libs << 'test'
31
+ test.verbose = true
32
+ end
33
+
34
+ # RDoc
35
+ require 'rake/rdoctask'
36
+ Rake::RDocTask.new do |rd|
37
+ rd.title = "Valuedate"
38
+ rd.main = "README.rdoc"
39
+ rd.rdoc_files.include("README.rdoc", "lib/*.rb")
40
+ rd.rdoc_dir = "doc"
41
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,102 @@
1
+ # Copyright (c) 2010 Maikel Urlitzki <maikel@urlitzki.de>
2
+ #
3
+ # Thanks to http://github.com/splattael
4
+ #
5
+ # http://github.com/maikelcoke/smstrade_de
6
+ #
7
+ # For use with http://www.smstrade.de
8
+ #
9
+ # = Configuration
10
+ #
11
+ # # config/intializers/smstrade.rb
12
+ # Smstrade.key = "YOUR_KEY"
13
+ # Smstrade.route = "ROUTE"
14
+ #
15
+ class Smstrade
16
+
17
+ require "net/http"
18
+ require "cgi"
19
+
20
+ # API-Key
21
+ cattr_accessor :key
22
+ self.key ||= ""
23
+
24
+ # Gateway-URL
25
+ cattr_accessor :gateway
26
+ self.gateway ||= "gateway.smstrade.de"
27
+
28
+ # SMS-Route (basic, economy, gold, direct)
29
+ cattr_accessor :route
30
+ self.route ||= "basic"
31
+
32
+ # Source identifier
33
+ cattr_accessor :from
34
+ self.from ||= "smstrade_de"
35
+
36
+ # Testmode, default off
37
+ cattr_accessor :debug
38
+ self.debug ||= 0
39
+
40
+ # Encoding
41
+ cattr_accessor :charset
42
+ self.charset ||= "UTF-8"
43
+
44
+ # Example:
45
+ #
46
+ # # Controller
47
+ # Smstrade.new do |sms|
48
+ # @result, @response = sms.send(:number => "+491601234567", :text => "This is a dummy text.")
49
+ # end
50
+ def initialize(&block)
51
+ yield(self) if block_given?
52
+ end
53
+
54
+ # Required +options+ are:
55
+ # <tt>:number</tt>:: Mobile number e.g. +49160123456
56
+ # <tt>:text</tt>:: SMS-Text e.g. "Hello mate, all right?"
57
+ #
58
+ # Optional +options+ are:
59
+ # <tt>:debug</tt>:: Debug mode
60
+ # 0 = send the message
61
+ # 1 = sms will not send and not charged
62
+ def send(options={})
63
+ string = prepare_string(options)
64
+ begin
65
+ response = Net::HTTP::get(gateway, "#{string}")
66
+ rescue
67
+ response = 0
68
+ end
69
+ return (response.to_i == 100), response(response.to_i)
70
+ end
71
+
72
+ private
73
+
74
+ def prepare_string(options)
75
+ message = encode_message(options[:text])
76
+ str = "/?key=#{key}&to=#{options[:number]}&message=#{message}&route=#{route}&from=#{from}&charset=#{charset}&debug=#{debug}"
77
+ return str
78
+ end
79
+
80
+ def encode_message(message)
81
+ CGI::escape(message)
82
+ end
83
+
84
+ def response(code)
85
+ res = Array.new
86
+ res[0] = "No connection to the gateway"
87
+ res[10] = "Recipient invalid"
88
+ res[20] = "Source identifier too long"
89
+ res[30] = "Message text too long"
90
+ res[31] = "Message type not correct"
91
+ res[40] = "Wrong SMS type"
92
+ res[50] = "Login error"
93
+ res[60] = "No funds"
94
+ res[70] = "Network not supported for this route"
95
+ res[71] = "Feature not possible for this route"
96
+ res[80] = "Can't send the SMS"
97
+ res[90] = "Transmission not possible"
98
+ res[100] = "The SMS was sent successful"
99
+ return res[code.to_i]
100
+ end
101
+
102
+ end
@@ -0,0 +1,42 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{smstrade_de}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Maikel Urlitzki"]
12
+ s.date = %q{2010-05-31}
13
+ s.email = %q{maikel@urlitzki.de}
14
+ s.extra_rdoc_files = [
15
+ "README.rdoc"
16
+ ]
17
+ s.files = [
18
+ ".gitignore",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/smstrade.rb",
23
+ "smstrade_de.gemspec",
24
+ "test.rb"
25
+ ]
26
+ s.homepage = %q{http://github.com/maikelcoke/smstrade_de}
27
+ s.rdoc_options = ["--charset=UTF-8"]
28
+ s.require_paths = ["lib"]
29
+ s.rubygems_version = %q{1.3.7}
30
+ s.summary = %q{Gem for sending SMS via smstrade.de Gateway.}
31
+
32
+ if s.respond_to? :specification_version then
33
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
34
+ s.specification_version = 3
35
+
36
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
37
+ else
38
+ end
39
+ else
40
+ end
41
+ end
42
+
data/test.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "active_support"
2
+ require "lib/smstrade"
3
+
4
+ Smstrade.key = "YOUR_KEY"
5
+ Smstrade.route = "economy"
6
+
7
+ # lets go
8
+ Smstrade.new do |sms|
9
+ @result, @response = sms.send(:number => "", :text => "This is a test SMS.", :debug => 1)
10
+ end
11
+
12
+ p("Result '#{@result}' with response '#{@response}'")
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smstrade_de
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Maikel Urlitzki
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-05-31 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: maikel@urlitzki.de
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - .gitignore
32
+ - README.rdoc
33
+ - Rakefile
34
+ - VERSION
35
+ - lib/smstrade.rb
36
+ - smstrade_de.gemspec
37
+ - test.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/maikelcoke/smstrade_de
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --charset=UTF-8
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.7
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Gem for sending SMS via smstrade.de Gateway.
72
+ test_files: []
73
+