clickatell 0.7.1 → 0.8.0

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.
@@ -1,3 +1,10 @@
1
+ == 0.8
2
+
3
+ * Added fix for Ruby 1.9 (Ahmed Al Hafoudh)
4
+ * Fixed a bug handling error codes above 008 (Sean Kibler)
5
+ * Added HTTP proxy support (Josh Bassett)
6
+
7
+
1
8
  == 0.7.1
2
9
 
3
10
  * Fixed broken -b (balance) command
@@ -6,35 +6,68 @@ h2. Basic Usage
6
6
 
7
7
  You will need your API_ID as well as your account username and password.
8
8
 
9
+ <pre>
10
+ <code>
9
11
  require 'rubygems'
10
12
  require 'clickatell'
11
-
13
+
12
14
  api = Clickatell::API.authenticate('your_api_id', 'your_username', 'your_password')
13
15
  api.send_message('447771234567', 'Hello from clickatell')
16
+ </code>
17
+ </pre>
14
18
 
15
19
  To send a message to multiple recipients, simply pass in an array of numbers.
16
20
 
21
+ <pre>
22
+ <code>
17
23
  api.send_message(['447771234567', '447771234568'], 'Hello from clickatell')
18
-
24
+ </code>
25
+ </pre>
26
+
27
+ h2. HTTP Proxy
28
+
29
+ You can configure the library to use a HTTP proxy when communicating with Clickatell.
30
+
31
+ <pre>
32
+ <code>
33
+ Clickatell::API.proxy_host = 'my.proxy.com'
34
+ Clickatell::API.proxy_port = 1234
35
+ Clickatell::API.proxy_username = 'joeschlub'
36
+ Clickatell::API.proxy_password = 'secret'
37
+ </code>
38
+ </pre>
39
+
19
40
  h2. Command-line SMS Utility
20
41
 
21
- The Clickatell gem also comes with a command-line utility that will allow you to send an SMS directly from the command-line.
42
+ The Clickatell gem also comes with a command-line utility that will allow you to send an SMS directly from the command-line.
22
43
 
23
44
  You will need to create a YAML configuration file in your home directory, in a file called .clickatell that resembles the following:
24
45
 
46
+ <pre>
47
+ <code>
25
48
  # ~/.clickatell
26
49
  api_key: your_api_id
27
50
  username: your_username
28
51
  password: your_password
29
-
52
+ </code>
53
+ </pre>
54
+
30
55
  You can then use the sms utility to send a message to a single recipient:
31
56
 
57
+ <pre>
58
+ <code>
32
59
  sms 447771234567 'Hello from clickatell'
33
-
60
+ </code>
61
+ </pre>
62
+
34
63
  Alternatively, you can specify the username and password as a command line option. Run +sms+ without any arguments for a full list of options.
35
64
 
36
65
  The sms utility also supports multiple, comma-separated recipients (up to 100).
37
66
 
67
+ <pre>
68
+ <code>
38
69
  sms 447771111111,447772222222 "Hello everyone"
70
+ </code>
71
+ </pre>
39
72
 
40
- See http://clickatell.rubyforge.org for further instructions.
73
+ See http://clickatell.rubyforge.org for further instructions.
@@ -0,0 +1,84 @@
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{clickatell}
8
+ s.version = "0.8.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Luke Redpath"]
12
+ s.date = %q{2010-07-26}
13
+ s.default_executable = %q{sms}
14
+ s.email = %q{luke@lukeredpath.co.uk}
15
+ s.executables = ["sms"]
16
+ s.extra_rdoc_files = [
17
+ "History.txt",
18
+ "License.txt",
19
+ "RDOC_README.txt"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "History.txt",
24
+ "License.txt",
25
+ "RDOC_README.txt",
26
+ "README.textile",
27
+ "Rakefile",
28
+ "bin/sms",
29
+ "clickatell.gemspec",
30
+ "lib/clickatell.rb",
31
+ "lib/clickatell/api.rb",
32
+ "lib/clickatell/api/command.rb",
33
+ "lib/clickatell/api/command_executor.rb",
34
+ "lib/clickatell/api/error.rb",
35
+ "lib/clickatell/api/message_status.rb",
36
+ "lib/clickatell/response.rb",
37
+ "lib/clickatell/utility.rb",
38
+ "lib/clickatell/utility/options.rb",
39
+ "lib/clickatell/version.rb",
40
+ "lib/core-ext/hash.rb",
41
+ "scripts/txt2html",
42
+ "spec/api_spec.rb",
43
+ "spec/cli_options_test.rb",
44
+ "spec/command_executor_spec.rb",
45
+ "spec/hash_ext_spec.rb",
46
+ "spec/response_spec.rb",
47
+ "spec/spec.opts",
48
+ "spec/spec_helper.rb",
49
+ "website/images/footer_bg.gif",
50
+ "website/index.txt",
51
+ "website/javascripts/codehighlighter/code_highlighter.js",
52
+ "website/javascripts/codehighlighter/ruby.js",
53
+ "website/javascripts/rounded_corners_lite.inc.js",
54
+ "website/stylesheets/limechoc.css",
55
+ "website/stylesheets/rdoc.css",
56
+ "website/stylesheets/screen.css",
57
+ "website/template.rhtml"
58
+ ]
59
+ s.homepage = %q{http://clickatell.rubyforge.org}
60
+ s.rdoc_options = ["--main", "RDOC_README.txt"]
61
+ s.require_paths = ["lib"]
62
+ s.rubygems_version = %q{1.3.7}
63
+ s.summary = %q{Ruby interface to the Clickatell SMS gateway service.}
64
+ s.test_files = [
65
+ "spec/api_spec.rb",
66
+ "spec/cli_options_test.rb",
67
+ "spec/command_executor_spec.rb",
68
+ "spec/hash_ext_spec.rb",
69
+ "spec/response_spec.rb",
70
+ "spec/spec_helper.rb",
71
+ "test/clickatell_api_test.rb"
72
+ ]
73
+
74
+ if s.respond_to? :specification_version then
75
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
76
+ s.specification_version = 3
77
+
78
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
79
+ else
80
+ end
81
+ else
82
+ end
83
+ end
84
+
@@ -24,6 +24,9 @@ module Clickatell
24
24
  # Allow customizing URL
25
25
  attr_accessor :api_service_host
26
26
 
27
+ # Set to your HTTP proxy details (off by default)
28
+ attr_accessor :proxy_host, :proxy_port, :proxy_username, :proxy_password
29
+
27
30
  # Set to true to test message sending; this will not actually send
28
31
  # messages but will collect sent messages in a testable collection.
29
32
  # (off by default)
@@ -69,12 +72,13 @@ module Clickatell
69
72
  # Additional options:
70
73
  # :from - the from number/name
71
74
  # :set_mobile_originated - mobile originated flag
72
- #
75
+ # :client_message_id - user specified message id that can be used in place of Clickatell issued API message ID for querying message
73
76
  # Returns a new message ID if successful.
74
77
  def send_message(recipient, message_text, opts={})
75
- valid_options = opts.only(:from, :mo, :callback)
78
+ valid_options = opts.only(:from, :mo, :callback, :climsgid)
76
79
  valid_options.merge!(:req_feat => '48') if valid_options[:from]
77
80
  valid_options.merge!(:mo => '1') if opts[:set_mobile_originated]
81
+ valid_options.merge!(:climsgid => opts[:client_message_id]) if opts[:client_message_id]
78
82
  recipient = recipient.join(",")if recipient.is_a?(Array)
79
83
  response = execute_command('sendmsg', 'http',
80
84
  {:to => recipient, :text => message_text}.merge(valid_options)
@@ -98,6 +102,11 @@ module Clickatell
98
102
  response = execute_command('querymsg', 'http', :apimsgid => message_id)
99
103
  parse_response(response)['Status']
100
104
  end
105
+
106
+ def message_charge(message_id)
107
+ response = execute_command('getmsgcharge', 'http', :apimsgid => message_id)
108
+ parse_response(response)['charge'].to_f
109
+ end
101
110
 
102
111
  # Returns the number of credits remaining as a float.
103
112
  def account_balance
@@ -31,7 +31,11 @@ module Clickatell
31
31
  def execute(command_name, service, parameters={})
32
32
  request_uri = command(command_name, service, parameters)
33
33
  puts "[debug] Sending request to #{request_uri}" if @debug
34
- get_response(request_uri).first
34
+ result = get_response(request_uri)
35
+ if result.is_a?(Array)
36
+ result = result.first
37
+ end
38
+ result
35
39
  end
36
40
 
37
41
  protected
@@ -46,10 +50,19 @@ module Clickatell
46
50
  sms_requests << uri
47
51
  [FakeHttpResponse.new]
48
52
  else
49
- http = Net::HTTP.new(uri.host, uri.port)
50
- http.use_ssl = (uri.scheme == 'https')
51
- http.start do |http|
52
- resp, body = http.get([uri.path, uri.query].join('?'))
53
+ request = [uri.path, uri.query].join('?')
54
+
55
+ if API.proxy_host
56
+ http = Net::HTTP::Proxy(API.proxy_host, API.proxy_port, API.proxy_username, API.proxy_password)
57
+ http.start(uri.host) do |http|
58
+ resp, body = http.get(request)
59
+ end
60
+ else
61
+ http = Net::HTTP.new(uri.host, uri.port)
62
+ http.use_ssl = (uri.scheme == 'https')
63
+ http.start do |http|
64
+ resp, body = http.get(request)
65
+ end
53
66
  end
54
67
  end
55
68
  end
@@ -3,18 +3,18 @@ module Clickatell
3
3
 
4
4
  class MessageStatus
5
5
  STATUS_MAP = {
6
- 1 => 'Message unknown',
7
- 2 => 'Message queued',
8
- 3 => 'Delivered to gateway',
9
- 4 => 'Received by recipient',
10
- 5 => 'Error with message',
11
- 6 => 'User cancelled messaged delivery',
12
- 7 => 'Error delivering message',
13
- 8 => 'OK',
14
- 9 => 'Routing error',
15
- 10 => 'Message expired',
16
- 11 => 'Message queued for later delivery',
17
- 12 => 'Out of credit'
6
+ '001' => 'Message unknown',
7
+ '002' => 'Message queued',
8
+ '003' => 'Delivered to gateway',
9
+ '004' => 'Received by recipient',
10
+ '005' => 'Error with message',
11
+ '006' => 'User cancelled messaged delivery',
12
+ '007' => 'Error delivering message',
13
+ '008' => 'OK',
14
+ '009' => 'Routing error',
15
+ '010' => 'Message expired',
16
+ '011' => 'Message queued for later delivery',
17
+ '012' => 'Out of credit'
18
18
  }
19
19
 
20
20
  def self.[](code)
@@ -1,8 +1,8 @@
1
1
  module Clickatell #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 7
5
- TINY = 1
4
+ MINOR = 8
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
 
@@ -147,6 +147,12 @@ module Clickatell
147
147
  Response.stubs(:parse).with(response).returns('ID' => 'message_id')
148
148
  @api.send_message('4477791234567', 'hello world', :callback => 1)
149
149
  end
150
+
151
+ it "should set the client message id to the number passed in the options hash" do
152
+ @executor.expects(:execute).with('sendmsg', 'http', has_entry(:climsgid => 12345678)).returns(response=mock('response'))
153
+ Response.stubs(:parse).with(response).returns('ID' => 'message_id')
154
+ @api.send_message('4477791234567', 'hello world', :client_message_id => 12345678)
155
+ end
150
156
 
151
157
  it "should ignore any invalid parameters when sending a message" do
152
158
  @executor.expects(:execute).with('sendmsg', 'http', Not(has_key(:any_old_param))).returns(response = stub('response'))
@@ -22,6 +22,36 @@ module Clickatell
22
22
  it "should not record requests" do
23
23
  @executor.should_not respond_to(:sms_requests)
24
24
  end
25
+
26
+ describe "without a proxy" do
27
+ before do
28
+ @http = mock()
29
+ @http.expects(:use_ssl=).with(false)
30
+ @http.expects(:start).returns([])
31
+ Net::HTTP.expects(:new).with(API::Command::API_SERVICE_HOST, 80).returns(@http)
32
+ end
33
+
34
+ it "should execute commands through the proxy" do
35
+ @executor.execute("foo", "http")
36
+ end
37
+ end
38
+
39
+ describe "with a proxy" do
40
+ before do
41
+ API.proxy_host = @proxy_host = "proxy.example.com"
42
+ API.proxy_port = @proxy_port = "1234"
43
+ API.proxy_username = @proxy_username = "joeschlub"
44
+ API.proxy_password = @proxy_password = "secret"
45
+
46
+ @http = mock()
47
+ @http.expects(:start).with(API::Command::API_SERVICE_HOST).returns([])
48
+ Net::HTTP.expects(:Proxy).with(@proxy_host, @proxy_port, @proxy_username, @proxy_password).returns(@http)
49
+ end
50
+
51
+ it "should execute commands through the proxy" do
52
+ @executor.execute("foo", "http")
53
+ end
54
+ end
25
55
  end
26
56
 
27
57
  describe "in test mode" do
@@ -0,0 +1,94 @@
1
+ require 'test_helper'
2
+ require 'clickatell/api'
3
+
4
+ class ClickatellApiTest < Test::Unit::TestCase
5
+
6
+ context "Clickatell::API" do
7
+ setup do
8
+ @client = mock('client')
9
+ @client.stubs(:session_id).returns('dummy_session_id')
10
+
11
+ @api = Clickatell::API.new(@client)
12
+ end
13
+
14
+ context "#ping" do
15
+ should "perform the ping command with the current session id" do
16
+ @client.expects(:perform_command).with('ping',
17
+ has_entry(:session_id => 'dummy_session_id')).returns(stub_response)
18
+ @api.ping
19
+ end
20
+
21
+ should "return true when successful" do
22
+ @client.stubs(:perform_command).with('ping', anything).returns(stub_response("OK:"))
23
+ assert @api.ping
24
+ end
25
+
26
+ should "return false when failed" do
27
+ @client.stubs(:perform_command).with('ping', anything).returns(stub_response("ERR:"))
28
+ assert !@api.ping
29
+ end
30
+ end
31
+
32
+ context "#send_message with a single recipient" do
33
+ should "perform the sendmsg command with the correct options" do
34
+ @client.expects(:perform_command).with('sendmsg',
35
+ has_entries(:to => '07999000000', :text => 'testing')).returns(stub_response)
36
+
37
+ @api.send_message('07999000000', 'testing')
38
+ end
39
+
40
+ should "allow a custom sender to be set" do
41
+ @client.expects(:perform_command).with('sendmsg',
42
+ has_entry(:from => 'SENDER')).returns(stub_response)
43
+
44
+ @api.send_message('07999000000', 'testing', :from => 'SENDER')
45
+ end
46
+
47
+ should "set the req_feat parameter when specifying a custom sender" do
48
+ @client.expects(:perform_command).with('sendmsg',
49
+ has_entry(:req_feat => '48')).returns(stub_response)
50
+
51
+ @api.send_message('07999000000', 'testing', :from => 'SENDER')
52
+ end
53
+
54
+ should "set the mobile originated flag if specified" do
55
+ @client.expects(:perform_command).with('sendmsg',
56
+ has_entry(:mo => '1')).returns(stub_response)
57
+
58
+ @api.send_message('07999000000', 'testing', :set_mobile_originated => true)
59
+ end
60
+
61
+ should "return a single message ID" do
62
+ @client.stubs(:perform_command).returns(stub_response(%{
63
+ ID: 99999123
64
+ }))
65
+ assert_equal %w{99999123}, @api.send_message('07999000000', 'testing')
66
+ end
67
+ end
68
+
69
+ context "#send_message with multiple recipients" do
70
+ should "perform the sendmsg command with a comma-separated list of recipients" do
71
+ @client.expects(:perform_command).with('sendmsg',
72
+ has_entry(:to => '07999000000,07999000001,07999000002')).returns(stub_response)
73
+
74
+ @api.send_message(%w{07999000000 07999000001 07999000002}, 'testing')
75
+ end
76
+
77
+ should "return an array of message IDs" do
78
+ @client.stubs(:perform_command).returns(stub_response(%{
79
+ ID: 0000001
80
+ ID: 0000002
81
+ ID: 0000003
82
+ }))
83
+ expected = %w{0000001 0000002 0000003}
84
+ assert_equal expected, @api.send_message(%w{07999000000 07999000001 07999000002}, 'testing')
85
+ end
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ def stub_response(body = '', code = 200)
92
+ stub('Net::HTTP::Response', :code => 200, :body => body)
93
+ end
94
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clickatell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ hash: 63
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Luke Redpath
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-12-01 00:00:00 +00:00
18
+ date: 2010-07-26 00:00:00 +01:00
13
19
  default_executable: sms
14
20
  dependencies: []
15
21
 
@@ -31,6 +37,7 @@ files:
31
37
  - README.textile
32
38
  - Rakefile
33
39
  - bin/sms
40
+ - clickatell.gemspec
34
41
  - lib/clickatell.rb
35
42
  - lib/clickatell/api.rb
36
43
  - lib/clickatell/api/command.rb
@@ -59,6 +66,7 @@ files:
59
66
  - website/stylesheets/rdoc.css
60
67
  - website/stylesheets/screen.css
61
68
  - website/template.rhtml
69
+ - test/clickatell_api_test.rb
62
70
  has_rdoc: true
63
71
  homepage: http://clickatell.rubyforge.org
64
72
  licenses: []
@@ -70,21 +78,27 @@ rdoc_options:
70
78
  require_paths:
71
79
  - lib
72
80
  required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
73
82
  requirements:
74
83
  - - ">="
75
84
  - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
76
88
  version: "0"
77
- version:
78
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
79
91
  requirements:
80
92
  - - ">="
81
93
  - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
82
97
  version: "0"
83
- version:
84
98
  requirements: []
85
99
 
86
100
  rubyforge_project:
87
- rubygems_version: 1.3.5
101
+ rubygems_version: 1.3.7
88
102
  signing_key:
89
103
  specification_version: 3
90
104
  summary: Ruby interface to the Clickatell SMS gateway service.
@@ -95,3 +109,4 @@ test_files:
95
109
  - spec/hash_ext_spec.rb
96
110
  - spec/response_spec.rb
97
111
  - spec/spec_helper.rb
112
+ - test/clickatell_api_test.rb