smstraderb 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,5 +1,8 @@
1
1
  smstraderb - ChangeLog
2
2
  ======================
3
+ # 0.1.0
4
+ * Ensure escaping of the phone number and the message.
5
+ * The rack server app now provides the call params for inspection.
3
6
 
4
7
  # 0.0.1
5
8
  * Initial release.
@@ -27,7 +27,7 @@ class SMSTradeRB
27
27
  end
28
28
 
29
29
  def send(options)
30
- @to = options[:to]
30
+ @to = escape(check_phone_number(options[:to]))
31
31
  @message = escape(options[:message])
32
32
 
33
33
  uri = URI.parse(SMSTradeRB::HTTP_GATEWAY)
@@ -1,5 +1,5 @@
1
1
  class SMSTradeRB
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
 
4
4
  HTTP_GATEWAY = 'http://gateway.smstrade.de/'
5
5
  HTTPS_GATEWAY = 'https://gateway.smstrade.de/'
@@ -5,6 +5,8 @@ require 'smstraderb/constants'
5
5
 
6
6
  class SMSTradeRB
7
7
  class Server
8
+ attr_reader :params
9
+
8
10
  def initialize(options = {})
9
11
  @options = options
10
12
  end
@@ -14,40 +16,40 @@ class SMSTradeRB
14
16
  end
15
17
 
16
18
  def call(env)
17
- params = Rack::Request.new(env).params
19
+ @params = Rack::Request.new(env).params
18
20
 
19
21
  # The route param is mandatory.
20
- unless params['route']
22
+ unless @params['route']
21
23
  return respond_with('40')
22
24
  end
23
25
 
24
26
  # There are only a few valid route values.
25
- unless SMSTradeRB::ROUTES.include?(params['route'].to_sym)
27
+ unless SMSTradeRB::ROUTES.include?(@params['route'].to_sym)
26
28
  return respond_with('40')
27
29
  end
28
30
 
29
31
  # The to params is mandatory.
30
- unless params['to']
32
+ unless @params['to']
31
33
  return respond_with('10')
32
34
  end
33
35
 
34
36
  # The to params needs to be in a valid format.
35
- unless params['to'] =~ /^\+?\d+/
37
+ unless @params['to'] =~ /^\+?\d+/
36
38
  return respond_with('10')
37
39
  end
38
40
 
39
41
  # The key param is mandatory.
40
- unless params['key']
42
+ unless @params['key']
41
43
  return respond_with('50')
42
44
  end
43
45
 
44
46
  # The message params is mandatory.
45
- unless params['message']
47
+ unless @params['message']
46
48
  return respond_with('30')
47
49
  end
48
50
 
49
51
  # Check if the messagetype is valid.
50
- if params['messagetype'] and !SMSTradeRB::MESSAGE_TYPES.include?(params['messagetype'].to_sym)
52
+ if @params['messagetype'] and !SMSTradeRB::MESSAGE_TYPES.include?(@params['messagetype'].to_sym)
51
53
  return respond_with('31')
52
54
  end
53
55
 
@@ -55,15 +57,15 @@ class SMSTradeRB
55
57
  ret = [@options[:code] || 100]
56
58
 
57
59
  # Some optional parameters which modify the return value.
58
- if params['message_id'] == '1'
60
+ if @params['message_id'] == '1'
59
61
  ret[1] = '123456789'
60
62
  end
61
63
 
62
- if params['cost'] == '1'
64
+ if @params['cost'] == '1'
63
65
  ret[2] = '0.055'
64
66
  end
65
67
 
66
- if params['count'] == '1'
68
+ if @params['count'] == '1'
67
69
  ret[3] = '1'
68
70
  end
69
71
 
@@ -114,4 +114,16 @@ describe SMSTradeRB::Server do
114
114
  end
115
115
  end
116
116
  end
117
+
118
+ describe "call inspection" do
119
+ it "provides access to the received params" do
120
+ @rack_app = SMSTradeRB::Server.new
121
+ def app
122
+ @rack_app
123
+ end
124
+ get '/', @params
125
+
126
+ @rack_app.params['message'].should == @params[:message]
127
+ end
128
+ end
117
129
  end
@@ -110,11 +110,31 @@ describe SMSTradeRB do
110
110
  end
111
111
 
112
112
  describe "#send" do
113
+ it "will encode and sanitize the phone number correctly" do
114
+ app = SMSTradeRB::Server.new(:code => 999)
115
+ Artifice.activate_with(app) do
116
+ sms = SMSTradeRB.new(:route => :basic, :key => 'mykey', :debug => false)
117
+ sms.send(:to => '+12 34-567', :message => 'my message')
118
+ end
119
+
120
+ app.params['to'].should == '+1234567'
121
+ end
122
+
123
+ it "will encode the message correctly" do
124
+ app = SMSTradeRB::Server.new(:code => 999)
125
+ Artifice.activate_with(app) do
126
+ sms = SMSTradeRB.new(:route => :basic, :key => 'mykey', :debug => false)
127
+ sms.send(:to => '+12 34-567', :message => 'my message $foo+bar')
128
+ end
129
+
130
+ app.params['to'].should == '+1234567'
131
+ end
132
+
113
133
  context "success" do
114
134
  it "returns a response object" do
115
135
  Artifice.activate_with(SMSTradeRB::Server.new(:code => 999)) do
116
136
  sms = SMSTradeRB.new(:route => :basic, :key => 'mykey', :debug => false)
117
- sms.send(:to => '1234', :message => 'my message').code.should be(999)
137
+ sms.send(:to => '+1234', :message => 'my message').code.should be(999)
118
138
  end
119
139
  end
120
140
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smstraderb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bernd Ahlers
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-22 00:00:00 +02:00
18
+ date: 2010-10-23 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency