clickatell-ruby19 0.7.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,26 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require File.join(File.dirname(__FILE__), *%w[.. lib clickatell utility])
4
+
5
+ class CliOptionsTest < Test::Unit::TestCase
6
+
7
+ context "Sending a message" do
8
+ should "allow single recipients" do
9
+ options = Clickatell::Utility::Options.parse(%w{07944123456 testing})
10
+ assert_equal %w{07944123456}, options.recipient
11
+ end
12
+
13
+ should "allow multiple, comma-separated recipients" do
14
+ options = Clickatell::Utility::Options.parse(%w{07944123456,07944123457 testing})
15
+ assert_equal %w{07944123456 07944123457}, options.recipient
16
+ end
17
+ end
18
+
19
+ context "Checking balance" do
20
+ should "not require a recipient" do
21
+ options = Clickatell::Utility::Options.parse(%w{-b})
22
+ assert_nil options.recipient
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,75 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/../lib/clickatell'
3
+
4
+ module Clickatell
5
+ describe "API::CommandExecutor" do
6
+ it "should have test mode" do
7
+ executor = API::CommandExecutor.new({}, false, false, :test_mode)
8
+ executor.should be_in_test_mode
9
+ end
10
+
11
+ it "should default to not test mode" do
12
+ executor = API::CommandExecutor.new({})
13
+ executor.should_not be_in_test_mode
14
+ end
15
+
16
+ describe "#execute" do
17
+ describe "in non-test mode" do
18
+ before(:each) do
19
+ @executor = API::CommandExecutor.new({})
20
+ end
21
+
22
+ it "should not record requests" do
23
+ @executor.should_not respond_to(:sms_requests)
24
+ end
25
+ end
26
+
27
+ describe "in test mode" do
28
+ before(:each) do
29
+ @params = {:foo => 1, :bar => 2}
30
+ @executor = API::CommandExecutor.new(@params, false, false, :test_mode)
31
+ end
32
+
33
+ it "should not make any network calls" do
34
+ Net::HTTP.expects(:new).never
35
+ @executor.execute("foo", "http")
36
+ end
37
+
38
+ it "should start with an empty request collection" do
39
+ @executor.sms_requests.should be_empty
40
+ end
41
+
42
+ it "should record sms requests" do
43
+ @executor.execute("bar", "http")
44
+ @executor.sms_requests.should_not be_empty
45
+ end
46
+
47
+ it "should record a request for each call" do
48
+ @executor.execute("wibble", "http")
49
+ @executor.sms_requests.size.should == 1
50
+ @executor.execute("foozle", "http")
51
+ @executor.sms_requests.size.should == 2
52
+ end
53
+
54
+ it "should return a response that approximates a true Net::HttpResponse" do
55
+ response = @executor.execute("throat-warbler", "http")
56
+ response.body.should == "test"
57
+ end
58
+
59
+ describe "each recorded request" do
60
+ it "should return the command information" do
61
+ command = "rum_tum_tum"
62
+ @executor.execute(command, "http")
63
+
64
+ uri = @executor.sms_requests.first
65
+ uri.host.should == "api.clickatell.com"
66
+ uri.path.should include(command)
67
+ @params.collect { |k, v| "#{k}=#{v}"}.each do |query_parameter|
68
+ uri.query.should include(query_parameter)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/../lib/clickatell'
3
+
4
+ describe Hash do
5
+ it "should return only the keys specified" do
6
+ hash = {:a => 'foo', :b => 'bar', :c => 'baz'}
7
+ hash.only(:a, :b).should == {:a => 'foo', :b => 'bar'}
8
+ end
9
+
10
+ it "should return only the keys specified, ignoring keys that do not exist" do
11
+ hash = {:a => 'foo', :b => 'bar', :c => 'baz'}
12
+ hash.only(:a, :d).should == {:a => 'foo'}
13
+ end
14
+ end
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/../lib/clickatell'
3
+
4
+ module Clickatell
5
+
6
+ describe "Response parser" do
7
+ before do
8
+ Clickatell::API::Error.stubs(:parse).returns(Clickatell::API::Error.new('', ''))
9
+ end
10
+
11
+ before(:each) do
12
+ API.test_mode = false
13
+ end
14
+
15
+ it "should return hash for one-line success response" do
16
+ Response.parse(stub('response', :body => 'k1: foo k2: bar')).should == {'k1' => 'foo', 'k2' => 'bar'}
17
+ end
18
+
19
+ it "should return array of hashes for multi-line success response" do
20
+ Response.parse(stub('response', :body => "k1: foo\nk2: bar")).should == [{'k1' => 'foo'}, {'k2' => 'bar'}]
21
+ end
22
+
23
+ it "should raise API::Error if response contains an error message" do
24
+ proc { Response.parse(stub('response', :body => 'ERR: 001, Authentication failed')) }.should raise_error(Clickatell::API::Error)
25
+ end
26
+
27
+ {
28
+ '001' => 1, '002' => 2, '003' => 3, '004' => 4,
29
+ '005' => 5, '006' => 6, '007' => 7, '008' => 8,
30
+ '009' => 9, '010' => 10, '011' => 11, '012' => 12
31
+ }.each do |status_str, status_int|
32
+ it "should parse a message status code of #{status_int} when the response body contains a status code of #{status_str}" do
33
+ Response.parse(stub('response', :body => "ID: 0d1d7dda17d5a24edf1555dc0b679d0e Status: #{status_str}")).should == {'ID' => '0d1d7dda17d5a24edf1555dc0b679d0e', 'Status' => status_int}
34
+ end
35
+ end
36
+
37
+ describe "in test mode" do
38
+ before(:each) do
39
+ API.test_mode = true
40
+ end
41
+
42
+ it "should return something approximating a session_id" do
43
+ Response.parse("pretty much anything").should == { 'OK' => 'session_id' }
44
+ end
45
+ end
46
+ end
47
+
48
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'mocha'
4
+ require 'test/unit'
5
+
6
+ Spec::Runner.configure do |config|
7
+ config.mock_with :mocha
8
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clickatell-ruby19
3
+ version: !ruby/object:Gem::Version
4
+ hash: 1
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 7
9
+ - 1
10
+ version: 0.7.1
11
+ platform: ruby
12
+ authors:
13
+ - Luke Redpath
14
+ - Ahmed Al Hafoudh
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-06-15 00:00:00 +01:00
20
+ default_executable: sms
21
+ dependencies: []
22
+
23
+ description:
24
+ email: luke@lukeredpath.co.uk
25
+ executables:
26
+ - sms
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - History.txt
31
+ - License.txt
32
+ - RDOC_README.txt
33
+ files:
34
+ - .gitignore
35
+ - History.txt
36
+ - License.txt
37
+ - RDOC_README.txt
38
+ - README.textile
39
+ - Rakefile
40
+ - bin/sms
41
+ - clickatell.gemspec
42
+ - lib/clickatell.rb
43
+ - lib/clickatell/api.rb
44
+ - lib/clickatell/api/command.rb
45
+ - lib/clickatell/api/command_executor.rb
46
+ - lib/clickatell/api/error.rb
47
+ - lib/clickatell/api/message_status.rb
48
+ - lib/clickatell/response.rb
49
+ - lib/clickatell/utility.rb
50
+ - lib/clickatell/utility/options.rb
51
+ - lib/clickatell/version.rb
52
+ - lib/core-ext/hash.rb
53
+ - scripts/txt2html
54
+ - spec/api_spec.rb
55
+ - spec/cli_options_test.rb
56
+ - spec/command_executor_spec.rb
57
+ - spec/hash_ext_spec.rb
58
+ - spec/response_spec.rb
59
+ - spec/spec.opts
60
+ - spec/spec_helper.rb
61
+ - website/images/footer_bg.gif
62
+ - website/index.txt
63
+ - website/javascripts/codehighlighter/code_highlighter.js
64
+ - website/javascripts/codehighlighter/ruby.js
65
+ - website/javascripts/rounded_corners_lite.inc.js
66
+ - website/stylesheets/limechoc.css
67
+ - website/stylesheets/rdoc.css
68
+ - website/stylesheets/screen.css
69
+ - website/template.rhtml
70
+ has_rdoc: true
71
+ homepage: http://clickatell.rubyforge.org
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options:
76
+ - --main
77
+ - RDOC_README.txt
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.3.7
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Ruby interface to the Clickatell SMS gateway service.
105
+ test_files:
106
+ - spec/api_spec.rb
107
+ - spec/cli_options_test.rb
108
+ - spec/command_executor_spec.rb
109
+ - spec/hash_ext_spec.rb
110
+ - spec/response_spec.rb
111
+ - spec/spec_helper.rb