lookout-clickatell 0.8.3

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,30 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/../lib/clickatell/utility'
3
+
4
+ describe "CLI options" do
5
+
6
+ context "when sending a message" do
7
+ it "should allow single recipients" do
8
+ options = Clickatell::Utility::Options.parse(%w{07944123456 testing})
9
+ options.recipient.should include("07944123456")
10
+ end
11
+
12
+ it "should allow multiple, comma-separated recipients" do
13
+ options = Clickatell::Utility::Options.parse(%w{07944123456,07944123457 testing})
14
+ options.recipient.should include(*%w{07944123456 07944123457})
15
+ end
16
+
17
+ it "should strip + symbols from the beginning of numbers" do
18
+ options = Clickatell::Utility::Options.parse(%w{+447944123456 testing})
19
+ options.recipient.should include("447944123456")
20
+ end
21
+ end
22
+
23
+ context "when checking balance" do
24
+ it "should not require a recipient" do
25
+ options = Clickatell::Utility::Options.parse(%w{-b})
26
+ options.recipient.should be_nil
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,120 @@
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 default to not test mode" do
7
+ executor = API::CommandExecutor.new({})
8
+ executor.should_not be_in_test_mode
9
+ end
10
+
11
+ it "should have test mode" do
12
+ API.test_mode = true
13
+ executor = API::CommandExecutor.new({})
14
+ executor.should be_in_test_mode
15
+ end
16
+
17
+ describe "#execute" do
18
+ describe "in non-test mode" do
19
+ before(:each) do
20
+ API.test_mode = false
21
+ @executor = API::CommandExecutor.new({})
22
+ end
23
+
24
+ it "should not record requests" do
25
+ @executor.should_not respond_to(:sms_requests)
26
+ end
27
+
28
+ describe "without a proxy" do
29
+ before do
30
+ @http = mock()
31
+ @http.expects(:use_ssl=).with(false)
32
+ @http.expects(:start).returns([])
33
+ Net::HTTP.expects(:new).with(API::Command::API_SERVICE_HOST, 80).returns(@http)
34
+ end
35
+
36
+ it "should execute commands through the proxy" do
37
+ @executor.execute("foo", "http")
38
+ end
39
+ end
40
+
41
+ describe "with a proxy" do
42
+ before do
43
+ API.proxy_host = @proxy_host = "proxy.example.com"
44
+ API.proxy_port = @proxy_port = "1234"
45
+ API.proxy_username = @proxy_username = "joeschlub"
46
+ API.proxy_password = @proxy_password = "secret"
47
+
48
+ @http = mock()
49
+ @http.expects(:start).with(API::Command::API_SERVICE_HOST).returns([])
50
+ @http.expects(:use_ssl=)
51
+ Net::HTTP.expects(:Proxy).with(@proxy_host, @proxy_port, @proxy_username, @proxy_password).returns(@http)
52
+ end
53
+
54
+ it "should execute commands through the proxy" do
55
+ @executor.execute("foo", "http")
56
+ end
57
+
58
+ describe "when in secure_mode" do
59
+ before do
60
+ API.secure_mode = true
61
+ @http.expects(:ca_path=)
62
+ @http.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
63
+ end
64
+ it "should execute commands through the proxy using ssl" do
65
+ @executor.execute("foo", "http")
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "in test mode" do
72
+ before(:each) do
73
+ @params = {:foo => 1, :bar => 2}
74
+ API.test_mode = true
75
+ @executor = API::CommandExecutor.new(@params)
76
+ end
77
+
78
+ it "should not make any network calls" do
79
+ Net::HTTP.expects(:new).never
80
+ @executor.execute("foo", "http")
81
+ end
82
+
83
+ it "should start with an empty request collection" do
84
+ @executor.sms_requests.should be_empty
85
+ end
86
+
87
+ it "should record sms requests" do
88
+ @executor.execute("bar", "http")
89
+ @executor.sms_requests.should_not be_empty
90
+ end
91
+
92
+ it "should record a request for each call" do
93
+ @executor.execute("wibble", "http")
94
+ @executor.sms_requests.size.should == 1
95
+ @executor.execute("foozle", "http")
96
+ @executor.sms_requests.size.should == 2
97
+ end
98
+
99
+ it "should return a response that approximates a true Net::HttpResponse" do
100
+ response = @executor.execute("throat-warbler", "http")
101
+ response.body.should == "test"
102
+ end
103
+
104
+ describe "each recorded request" do
105
+ it "should return the command information" do
106
+ command = "rum_tum_tum"
107
+ @executor.execute(command, "http")
108
+
109
+ uri = @executor.sms_requests.first
110
+ uri.host.should == "api.clickatell.com"
111
+ uri.path.should include(command)
112
+ @params.collect { |k, v| "#{k}=#{v}"}.each do |query_parameter|
113
+ uri.query.should include(query_parameter)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ 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
@@ -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,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lookout-clickatell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Luke Redpath
9
+ - Kyle Barton
10
+ - R. Tyler Croy
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-07-06 00:00:00.000000000Z
15
+ dependencies: []
16
+ description: Ruby interface to the Clickatell SMS gateway service.
17
+ email:
18
+ - luke@lukeredpath.co.uk
19
+ executables:
20
+ - sms
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - .gitignore
25
+ - Gemfile
26
+ - History.txt
27
+ - License.txt
28
+ - RDOC_README.txt
29
+ - README.textile
30
+ - Rakefile
31
+ - bin/sms
32
+ - clickatell.gemspec
33
+ - lib/clickatell.rb
34
+ - lib/clickatell/api.rb
35
+ - lib/clickatell/api/command.rb
36
+ - lib/clickatell/api/command_executor.rb
37
+ - lib/clickatell/api/error.rb
38
+ - lib/clickatell/api/message_status.rb
39
+ - lib/clickatell/response.rb
40
+ - lib/clickatell/utility.rb
41
+ - lib/clickatell/utility/options.rb
42
+ - lib/clickatell/version.rb
43
+ - lib/core-ext/hash.rb
44
+ - scripts/txt2html
45
+ - spec/api_spec.rb
46
+ - spec/cli_options_spec.rb
47
+ - spec/command_executor_spec.rb
48
+ - spec/hash_ext_spec.rb
49
+ - spec/response_spec.rb
50
+ - spec/spec.opts
51
+ - spec/spec_helper.rb
52
+ - website/images/footer_bg.gif
53
+ - website/index.txt
54
+ - website/javascripts/codehighlighter/code_highlighter.js
55
+ - website/javascripts/codehighlighter/ruby.js
56
+ - website/javascripts/rounded_corners_lite.inc.js
57
+ - website/stylesheets/limechoc.css
58
+ - website/stylesheets/rdoc.css
59
+ - website/stylesheets/screen.css
60
+ - website/template.rhtml
61
+ homepage: https://github.com/lookout/clickatell
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ segments:
74
+ - 0
75
+ hash: 784157112864947881
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ segments:
83
+ - 0
84
+ hash: 784157112864947881
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.10
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Ruby interface to the Clickatell SMS gateway service.
91
+ test_files:
92
+ - spec/api_spec.rb
93
+ - spec/cli_options_spec.rb
94
+ - spec/command_executor_spec.rb
95
+ - spec/hash_ext_spec.rb
96
+ - spec/response_spec.rb
97
+ - spec/spec.opts
98
+ - spec/spec_helper.rb