smstraderb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/CHANGES.md ADDED
@@ -0,0 +1,5 @@
1
+ smstraderb - ChangeLog
2
+ ======================
3
+
4
+ # 0.0.1
5
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in smstraderb.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ smstraderb (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ artifice (0.5)
10
+ rack-test
11
+ rack (1.2.1)
12
+ rack-test (0.5.6)
13
+ rack (>= 1.0)
14
+ rake (0.8.7)
15
+ rspec (1.3.1)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ artifice
22
+ rack-test
23
+ rake
24
+ rspec (~> 1.3.0)
25
+ smstraderb!
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2010 Bernd Ahlers <bernd@tuneafish.de>
2
+
3
+ Permission to use, copy, modify, and distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ smstraderb
2
+ ==========
3
+
4
+ # Description
5
+
6
+ This gem provides a Ruby client library for the smstrade.de HTTP API.
7
+
8
+ # Installation
9
+
10
+ # gem install smstraderb
11
+
12
+ # Usage
13
+
14
+ require 'smstraderb'
15
+
16
+ key = 'you-smstrade-api-key'
17
+
18
+ sms = SMSTradeRB.new(:route => :basic, :key => key, :debug => true)
19
+ res = sms.send(:to => '123 456789', :message => 'hello api')
20
+
21
+ if res.ok?
22
+ puts "success!"
23
+ else
24
+ puts "error:"
25
+ puts res.response_message
26
+ end
27
+
28
+ # Contribute
29
+
30
+ * Fork the project.
31
+ * Make your feature addition or bug fix.
32
+ * Add tests for it. This is important so I don't break it in a
33
+ future version unintentionally.
34
+ * Commit, do not mess with rakefile, version, or history.
35
+ (if you want to have your own version, that is fine but bump version
36
+ in a commit by itself I can ignore when I pull)
37
+ * Send me a pull request. Bonus points for topic branches.
38
+
39
+ # Copyright
40
+
41
+ Copyright (c) 2010 Bernd Ahlers. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'spec/rake/spectask'
5
+
6
+ Spec::Rake::SpecTask.new do |t|
7
+ t.warning = true
8
+ t.rcov = false
9
+ end
@@ -0,0 +1,26 @@
1
+ class SMSTradeRB
2
+ VERSION = '0.0.1'
3
+
4
+ HTTP_GATEWAY = 'http://gateway.smstrade.de/'
5
+ HTTPS_GATEWAY = 'https://gateway.smstrade.de/'
6
+
7
+ ROUTES = [:basic, :economy, :gold, :direct]
8
+ DEFAULT_ROUTE = :basic
9
+
10
+ MESSAGE_TYPES = [:flash, :unicode, :binary, :voice]
11
+
12
+ RESPONSE_CODES = {
13
+ 10 => 'Invalid recipient number',
14
+ 20 => 'Invalid sender number',
15
+ 30 => 'Invalid message format',
16
+ 31 => 'Invalid message type',
17
+ 40 => 'Invalid route',
18
+ 50 => 'Authentication failed',
19
+ 60 => 'Insufficient funds',
20
+ 70 => 'Network not covered by route',
21
+ 71 => 'Invalid feature for selected route',
22
+ 80 => 'Handover to SMS-C failed',
23
+ 100 => 'Message accepted and sent',
24
+ 999 => 'Internal test response'
25
+ }.freeze
26
+ end
@@ -0,0 +1,65 @@
1
+ require 'smstraderb/constants'
2
+
3
+ class SMSTradeRB
4
+ class InvalidResponse < Exception; end
5
+ class UnknownResponse < Exception; end
6
+
7
+ class Response
8
+ def initialize(response)
9
+ check_response_string(response)
10
+ @code, @message_id, @cost, @count = response.split("\n")
11
+ check_response_code
12
+ end
13
+
14
+ def code
15
+ @code.to_i
16
+ end
17
+
18
+ def message_id
19
+ blank?(@message_id) ? nil : @message_id
20
+ end
21
+
22
+ def cost
23
+ blank?(@cost) ? nil : @cost.to_f
24
+ end
25
+
26
+ def count
27
+ blank?(@count) ? nil : @count.to_i
28
+ end
29
+
30
+ def ok?
31
+ code == 100
32
+ end
33
+
34
+ def error?
35
+ !ok?
36
+ end
37
+
38
+ def response_message
39
+ SMSTradeRB::RESPONSE_CODES[code]
40
+ end
41
+
42
+ private
43
+ def check_response_string(value)
44
+ if value.nil?
45
+ raise SMSTradeRB::InvalidResponse, 'Response string is nil.'
46
+ end
47
+ if value.empty?
48
+ raise SMSTradeRB::InvalidResponse, 'Response string is empty.'
49
+ end
50
+ if value !~ %r{^\d+}
51
+ raise SMSTradeRB::InvalidResponse, "Invalid response string: #{value}."
52
+ end
53
+ end
54
+
55
+ def check_response_code
56
+ unless SMSTradeRB::RESPONSE_CODES.key?(code)
57
+ raise SMSTradeRB::UnknownResponse
58
+ end
59
+ end
60
+
61
+ def blank?(value)
62
+ value.nil? || value.empty? ? true : false
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,78 @@
1
+ require 'smstraderb/constants'
2
+
3
+ # This class tries to emulate the smstrade.de HTTP API v2.2.
4
+ # It provides a valid Rack endpoint.
5
+
6
+ class SMSTradeRB
7
+ class Server
8
+ def initialize(options = {})
9
+ @options = options
10
+ end
11
+
12
+ def [](key)
13
+ @options[key]
14
+ end
15
+
16
+ def call(env)
17
+ params = Rack::Request.new(env).params
18
+
19
+ # The route param is mandatory.
20
+ unless params['route']
21
+ return respond_with('40')
22
+ end
23
+
24
+ # There are only a few valid route values.
25
+ unless SMSTradeRB::ROUTES.include?(params['route'].to_sym)
26
+ return respond_with('40')
27
+ end
28
+
29
+ # The to params is mandatory.
30
+ unless params['to']
31
+ return respond_with('10')
32
+ end
33
+
34
+ # The to params needs to be in a valid format.
35
+ unless params['to'] =~ /^\+?\d+/
36
+ return respond_with('10')
37
+ end
38
+
39
+ # The key param is mandatory.
40
+ unless params['key']
41
+ return respond_with('50')
42
+ end
43
+
44
+ # The message params is mandatory.
45
+ unless params['message']
46
+ return respond_with('30')
47
+ end
48
+
49
+ # Check if the messagetype is valid.
50
+ if params['messagetype'] and !SMSTradeRB::MESSAGE_TYPES.include?(params['messagetype'].to_sym)
51
+ return respond_with('31')
52
+ end
53
+
54
+ # Everything is fine so far. We return 100.
55
+ ret = [@options[:code] || 100]
56
+
57
+ # Some optional parameters which modify the return value.
58
+ if params['message_id'] == '1'
59
+ ret[1] = '123456789'
60
+ end
61
+
62
+ if params['cost'] == '1'
63
+ ret[2] = '0.055'
64
+ end
65
+
66
+ if params['count'] == '1'
67
+ ret[3] = '1'
68
+ end
69
+
70
+ respond_with(*ret)
71
+ end
72
+
73
+ private
74
+ def respond_with(*values)
75
+ [200, {'Content-Type' => 'text/plain'}, [values.join("\n")]]
76
+ end
77
+ end
78
+ end
data/lib/smstraderb.rb ADDED
@@ -0,0 +1,107 @@
1
+ require 'net/https'
2
+ require 'smstraderb/constants'
3
+ require 'smstraderb/response'
4
+
5
+ class SMSTradeRB
6
+ class InvalidRoute < Exception; end
7
+ class InvalidOption < Exception; end
8
+ class InvalidFormat < Exception; end
9
+
10
+ attr_reader :key, :message, :to, :from, :route, :debug, :charset
11
+
12
+ def initialize(options = {})
13
+ @charset = 'UTF-8'
14
+
15
+ @key = options[:key]
16
+ @message = options[:message]
17
+ @to = check_phone_number(options[:to])
18
+ @route = check_route(options[:route]) || SMSTradeRB::DEFAULT_ROUTE
19
+ @from = options[:from]
20
+ @debug = options[:debug] ? 1 : 0
21
+
22
+ check_from_allowed(@from, @route)
23
+ check_value_length(@from, 11) if @from
24
+
25
+ @message = escape(@message)
26
+ @from = escape(@from)
27
+ end
28
+
29
+ def send(options)
30
+ @to = options[:to]
31
+ @message = escape(options[:message])
32
+
33
+ uri = URI.parse(SMSTradeRB::HTTP_GATEWAY)
34
+ http = Net::HTTP.new(uri.host, uri.port)
35
+ #http.use_ssl = true if uri.scheme == "https" # enable SSL/TLS
36
+
37
+ response = http.start do
38
+ http.request_get(build_request)
39
+ end
40
+
41
+ SMSTradeRB::Response.new(response.body)
42
+ end
43
+
44
+ private
45
+ def build_request
46
+ options = {
47
+ :key => key,
48
+ :message => message,
49
+ :to => to,
50
+ :route => route,
51
+ :from => from,
52
+ :debug => debug,
53
+ :charset => charset
54
+ }.map do |key, value|
55
+ [key, value].join('=') if value
56
+ end.compact
57
+
58
+ "/?#{options.join('&')}"
59
+ end
60
+
61
+ def check_phone_number(number)
62
+ if number and number.to_s !~ %r{^\+?[\s0-9\-\(\)]+$}
63
+ raise SMSTradeRB::InvalidFormat, "Invalid phone number: #{number}"
64
+ else
65
+ sanitize_phone_number(number)
66
+ end
67
+ end
68
+
69
+ def check_from_allowed(from, route)
70
+ if from and ![:gold, :direct].include?(route)
71
+ raise SMSTradeRB::InvalidOption, "Setting the from option is only allowed with a :gold or :direct route."
72
+ end
73
+ end
74
+
75
+ def check_route(route)
76
+ return nil unless route
77
+
78
+ if SMSTradeRB::ROUTES.include?(route.to_sym)
79
+ route
80
+ else
81
+ raise SMSTradeRB::InvalidRoute, "Route #{route} does not exist."
82
+ end
83
+ end
84
+
85
+ def check_value_length(value, limit)
86
+ if (bytesize(value) > 11)
87
+ raise SMSTradeRB::InvalidFormat, "Value '#{value}' too long. (limit: #{limit})"
88
+ end
89
+ end
90
+
91
+ def sanitize_phone_number(number)
92
+ return nil unless number
93
+ number.gsub(%r{[\s\-\(\)]+}, '')
94
+ end
95
+
96
+ # The following two methods came from rack-1.1.0.
97
+ def escape(s)
98
+ return nil unless s
99
+ s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
100
+ '%' + $1.unpack('H2'*bytesize($1)).join('%').upcase
101
+ }.tr(' ', '+')
102
+ end
103
+
104
+ def bytesize(s)
105
+ s.respond_to?(:bytesize) ? s.bytesize : s.size
106
+ end
107
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "smstraderb/constants"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'smstraderb'
7
+ s.version = SMSTradeRB::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Bernd Ahlers']
10
+ s.email = ['bernd@tuneafish.de']
11
+ s.homepage = 'http://rubygems.org/gems/smstraderb'
12
+ s.summary = %q{client library for the smstrade.de HTTP API}
13
+ s.description = %q{smstraderb provides a client library for the smstrade.de HTTP API.}
14
+
15
+ #s.rubyforge_project = "smstraderb"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ['lib']
21
+
22
+ s.add_development_dependency 'rake'
23
+ s.add_development_dependency 'rspec', '~> 1.3.0'
24
+ s.add_development_dependency 'artifice'
25
+ s.add_development_dependency 'rack-test'
26
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'smstraderb/constants'
3
+
4
+ describe SMSTradeRB, "Constants" do
5
+ it "provides a VERSION constant" do
6
+ SMSTradeRB::VERSION.should_not be_nil
7
+ end
8
+
9
+ it "provides a HTTP_GATEWAY constant" do
10
+ SMSTradeRB::HTTP_GATEWAY.should_not be_nil
11
+ end
12
+
13
+ it "provides a HTTPS_GATEWAY constant" do
14
+ SMSTradeRB::HTTPS_GATEWAY.should_not be_nil
15
+ end
16
+
17
+ it "provides the RESPONSE_CODES constat containing a hash" do
18
+ SMSTradeRB::RESPONSE_CODES.should be_a(Hash)
19
+ end
20
+
21
+ it "provides the MESSAGE_TYPES constant" do
22
+ SMSTradeRB::MESSAGE_TYPES.should_not be_nil
23
+ end
24
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+ require 'smstraderb/response'
3
+
4
+ describe SMSTradeRB::Response do
5
+ let (:response) { "100\n123456789\n0.055\n1" }
6
+
7
+ it "will raise an exception if the response string is nil" do
8
+ lambda {
9
+ SMSTradeRB::Response.new(nil)
10
+ }.should raise_error(SMSTradeRB::InvalidResponse)
11
+ end
12
+
13
+ it "will raise an exception with an empty response string" do
14
+ lambda {
15
+ SMSTradeRB::Response.new("")
16
+ }.should raise_error(SMSTradeRB::InvalidResponse)
17
+ end
18
+
19
+ it "will raise an exception if the response string does not start with an integer" do
20
+ lambda {
21
+ SMSTradeRB::Response.new("abc")
22
+ }.should raise_error(SMSTradeRB::InvalidResponse)
23
+ end
24
+
25
+ it "will raise an exception if the response code is unknown" do
26
+ lambda {
27
+ SMSTradeRB::Response.new("12134234123420")
28
+ }.should raise_error(SMSTradeRB::UnknownResponse)
29
+ end
30
+
31
+ describe "#code" do
32
+ it "returns the response code" do
33
+ SMSTradeRB::Response.new(response).code.should == 100
34
+ end
35
+ end
36
+
37
+ describe "#message_id" do
38
+ it "returns the message id" do
39
+ SMSTradeRB::Response.new(response).message_id.should == '123456789'
40
+ end
41
+
42
+ it "returns nil if the message_id is missing" do
43
+ SMSTradeRB::Response.new("100\n\n0.44").message_id.should be_nil
44
+ end
45
+ end
46
+
47
+ describe "#cost" do
48
+ it "returns the cost as a float" do
49
+ SMSTradeRB::Response.new(response).cost.should == 0.055
50
+ end
51
+
52
+ it "returns nil if the cost is missing" do
53
+ SMSTradeRB::Response.new('100').cost.should be_nil
54
+ end
55
+ end
56
+
57
+ describe "#count" do
58
+ it "returns the sms count as an integer" do
59
+ SMSTradeRB::Response.new(response).count.should == 1
60
+ end
61
+
62
+ it "returns nil if the count is missing" do
63
+ SMSTradeRB::Response.new("100\n\n\n\n\n").count.should be_nil
64
+ end
65
+ end
66
+
67
+ describe "#ok?" do
68
+ it "returns true if the return code is 100" do
69
+ SMSTradeRB::Response.new("100\n\n\n\n\n").should be_ok
70
+ end
71
+ end
72
+
73
+ describe "#error?" do
74
+ it "returns true if the return code is not 100" do
75
+ SMSTradeRB::Response.new("40").should be_error
76
+ end
77
+ end
78
+
79
+ describe "#response_message" do
80
+ it "returns an message for the return code" do
81
+ SMSTradeRB::Response.new("40").response_message.should == SMSTradeRB::RESPONSE_CODES[40]
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+ require 'smstraderb/server'
3
+
4
+ describe SMSTradeRB::Server do
5
+ def app
6
+ SMSTradeRB::Server.new
7
+ end
8
+
9
+ before(:each) do
10
+ @params = {
11
+ :key => 'secret-key',
12
+ :route => 'basic',
13
+ :to => '123',
14
+ :message => 'message text'
15
+ }
16
+ end
17
+
18
+ describe "#new" do
19
+ it "takes an options hash" do
20
+ rack_app = SMSTradeRB::Server.new(:testop => 'foobar')
21
+ rack_app[:testop].should == 'foobar'
22
+ end
23
+ end
24
+
25
+ it "responds with the code in the :code option" do
26
+ def app
27
+ SMSTradeRB::Server.new(:code => 999)
28
+ end
29
+ get '/', @params do |response|
30
+ response.body.should == '999'
31
+ end
32
+ end
33
+
34
+ it "responds to the '/' url" do
35
+ get '/' do |response|
36
+ response.should be_ok
37
+ end
38
+ end
39
+
40
+ it "responds with '10' if no recipient is set" do
41
+ @params.delete(:to)
42
+ get '/', @params do |response|
43
+ response.body.should == '10'
44
+ end
45
+ end
46
+
47
+ it "responds with '10' if the recipient format is wrong" do
48
+ @params[:to] = 'abcde'
49
+ get '/', @params do |response|
50
+ response.body.should == '10'
51
+ end
52
+ end
53
+
54
+ it "responds with '30' if no message text is set" do
55
+ @params.delete(:message)
56
+ get '/', @params do |response|
57
+ response.body.should == '30'
58
+ end
59
+ end
60
+
61
+ it "responds with '31' if the message type is invalid" do
62
+ @params[:messagetype] = 'foobar'
63
+ get '/', @params do |response|
64
+ response.body.should == '31'
65
+ end
66
+ end
67
+
68
+ it "responds with '40' if no route is set" do
69
+ @params.delete(:route)
70
+ get '/', @params do |response|
71
+ response.body.should == '40'
72
+ end
73
+ end
74
+
75
+ it "responds with '40' if an invalid route is set" do
76
+ @params[:route] = 'foobar'
77
+ get '/', @params do |response|
78
+ response.body.should == '40'
79
+ end
80
+ end
81
+
82
+ it "responds with '50' if no key is set" do
83
+ @params.delete(:key)
84
+ get '/', @params do |response|
85
+ response.body.should == '50'
86
+ end
87
+ end
88
+
89
+ describe "optional parameter" do
90
+ describe "message_id" do
91
+ it "responds with the message id in the second line" do
92
+ @params[:message_id] = '1'
93
+ get '/', @params do |response|
94
+ response.body.should == "100\n123456789"
95
+ end
96
+ end
97
+ end
98
+
99
+ describe "cost" do
100
+ it "responds with the costs in the third line" do
101
+ @params[:cost] = '1'
102
+ get '/', @params do |response|
103
+ response.body.should == "100\n\n0.055"
104
+ end
105
+ end
106
+ end
107
+
108
+ describe "count" do
109
+ it "responds with the sms count in the fourth line" do
110
+ @params[:count] = '1'
111
+ get '/', @params do |response|
112
+ response.body.should == "100\n\n\n1"
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+ require 'smstraderb'
3
+ require 'smstraderb/server'
4
+
5
+ describe SMSTradeRB do
6
+ it "sets the key if it's initialized with the :key option" do
7
+ SMSTradeRB.new(:key => 'myapikey').key.should == 'myapikey'
8
+ end
9
+
10
+ it "sets the message if initialized with the :message option" do
11
+ SMSTradeRB.new(:message => 'mymessage').message.should == 'mymessage'
12
+ end
13
+
14
+ describe "to option" do
15
+ it "sets the recipient (to) if initialized with the :to option" do
16
+ SMSTradeRB.new(:to => '123456').to.should == '123456'
17
+ end
18
+
19
+ it "raises an exception if the number is invalid" do
20
+ lambda {
21
+ SMSTradeRB.new(:to => '123456abc')
22
+ }.should raise_error(SMSTradeRB::InvalidFormat)
23
+ end
24
+
25
+ it "removes whitespace" do
26
+ SMSTradeRB.new(:to => '12 34 56').to.should == '123456'
27
+ end
28
+
29
+ it "removes dashes (-)" do
30
+ SMSTradeRB.new(:to => '12-34-56').to.should == '123456'
31
+ end
32
+
33
+ it "removes parenthesis" do
34
+ SMSTradeRB.new(:to => '(123)456').to.should == '123456'
35
+ end
36
+
37
+ it "allows phone numbers with a country prefix" do
38
+ SMSTradeRB.new(:to => '+49 12345').to.should == '+4912345'
39
+ end
40
+ end
41
+
42
+ describe "from option" do
43
+ context "route set to :gold" do
44
+ it "allows the from option to be set" do
45
+ SMSTradeRB.new(:route => :gold, :from => '123456').from.should == '123456'
46
+ end
47
+ end
48
+
49
+ context "route set to :direct" do
50
+ it "allows the from option to be set" do
51
+ SMSTradeRB.new(:route => :direct, :from => '123456').from.should == '123456'
52
+ end
53
+ end
54
+
55
+ it "raises an exception if route is not :gold or :direct" do
56
+ lambda {
57
+ SMSTradeRB.new(:from => '123456').from.should == '123456'
58
+ }.should raise_error(SMSTradeRB::InvalidOption)
59
+ end
60
+
61
+ it "verifies the length (max 11)" do
62
+ lambda {
63
+ SMSTradeRB.new(:route => :gold, :from => 'ab cd sdfses')
64
+ }.should raise_error(SMSTradeRB::InvalidFormat)
65
+ end
66
+ end
67
+
68
+ describe "routes" do
69
+ it "sets the route if initialized with the :route option" do
70
+ SMSTradeRB.new(:route => :gold).route.should == :gold
71
+ end
72
+
73
+ it "sets the route to :basic by default" do
74
+ SMSTradeRB.new.route.should == :basic
75
+ end
76
+
77
+ it "raises an exception on invalid routes" do
78
+ lambda {
79
+ SMSTradeRB.new(:route => :eeek_invalid)
80
+ }.should raise_error(SMSTradeRB::InvalidRoute)
81
+ end
82
+ end
83
+
84
+ describe "additional options and attributes" do
85
+ describe "debug" do
86
+ it "it returns 1 if set to true" do
87
+ SMSTradeRB.new(:debug => true).debug.should be(1)
88
+ end
89
+
90
+ it "it returns 0 if set to false" do
91
+ SMSTradeRB.new(:debug => false).debug.should be(0)
92
+ end
93
+ end
94
+
95
+ it "has a charset attribute" do
96
+ SMSTradeRB.new.charset.should_not be_nil
97
+ end
98
+ end
99
+
100
+ describe "#message" do
101
+ it "returns an urlencoded string" do
102
+ SMSTradeRB.new(:message => 'f$oo bar').message.should == 'f%24oo+bar'
103
+ end
104
+ end
105
+
106
+ describe "#from" do
107
+ it "returns an urlencoded string" do
108
+ SMSTradeRB.new(:route => :gold, :from => 'f$oo bar').from.should == 'f%24oo+bar'
109
+ end
110
+ end
111
+
112
+ describe "#send" do
113
+ context "success" do
114
+ it "returns a response object" do
115
+ Artifice.activate_with(SMSTradeRB::Server.new(:code => 999)) do
116
+ sms = SMSTradeRB.new(:route => :basic, :key => 'mykey', :debug => false)
117
+ sms.send(:to => '1234', :message => 'my message').code.should be(999)
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format specdoc
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'rack/test'
7
+ require 'artifice'
8
+
9
+ Spec::Runner.configure do |config|
10
+ include Rack::Test::Methods
11
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smstraderb
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
+ - Bernd Ahlers
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-22 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 27
44
+ segments:
45
+ - 1
46
+ - 3
47
+ - 0
48
+ version: 1.3.0
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: artifice
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: rack-test
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :development
78
+ version_requirements: *id004
79
+ description: smstraderb provides a client library for the smstrade.de HTTP API.
80
+ email:
81
+ - bernd@tuneafish.de
82
+ executables: []
83
+
84
+ extensions: []
85
+
86
+ extra_rdoc_files: []
87
+
88
+ files:
89
+ - .gitignore
90
+ - CHANGES.md
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - lib/smstraderb.rb
97
+ - lib/smstraderb/constants.rb
98
+ - lib/smstraderb/response.rb
99
+ - lib/smstraderb/server.rb
100
+ - smstraderb.gemspec
101
+ - spec/smstraderb/constants_spec.rb
102
+ - spec/smstraderb/response_spec.rb
103
+ - spec/smstraderb/server_spec.rb
104
+ - spec/smstraderb_spec.rb
105
+ - spec/spec.opts
106
+ - spec/spec_helper.rb
107
+ has_rdoc: true
108
+ homepage: http://rubygems.org/gems/smstraderb
109
+ licenses: []
110
+
111
+ post_install_message:
112
+ rdoc_options: []
113
+
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 1.3.7
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: client library for the smstrade.de HTTP API
141
+ test_files: []
142
+