clickatell 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/README.textile +7 -0
- data/bin/sms +2 -2
- data/lib/clickatell/api.rb +3 -1
- data/lib/clickatell/response.rb +9 -1
- data/lib/clickatell/utility/options.rb +4 -1
- data/lib/clickatell/version.rb +1 -1
- data/spec/api_spec.rb +9 -0
- data/spec/response_spec.rb +14 -0
- metadata +5 -7
data/History.txt
CHANGED
data/README.textile
CHANGED
@@ -12,6 +12,9 @@ You will need your API_ID as well as your account username and password.
|
|
12
12
|
api = Clickatell::API.authenticate('your_api_id', 'your_username', 'your_password')
|
13
13
|
api.send_message('447771234567', 'Hello from clickatell')
|
14
14
|
|
15
|
+
To send a message to multiple recipients, simply pass in an array of numbers.
|
16
|
+
|
17
|
+
api.send_message(['447771234567', '447771234568'], 'Hello from clickatell')
|
15
18
|
|
16
19
|
h2. Command-line SMS Utility
|
17
20
|
|
@@ -30,4 +33,8 @@ You can then use the sms utility to send a message to a single recipient:
|
|
30
33
|
|
31
34
|
Alternatively, you can specify the username and password as a command line option. Run +sms+ without any arguments for a full list of options.
|
32
35
|
|
36
|
+
The sms utility also supports multiple, comma-separated recipients (up to 100).
|
37
|
+
|
38
|
+
sms 447771111111,447772222222 "Hello everyone"
|
39
|
+
|
33
40
|
See http://clickatell.rubyforge.org for further instructions.
|
data/bin/sms
CHANGED
@@ -30,11 +30,11 @@ begin
|
|
30
30
|
puts "Status: #{Clickatell::API::MessageStatus[status]} (##{status})."
|
31
31
|
exit 0
|
32
32
|
else
|
33
|
-
puts "Sending '#{options.message}' to #{options.recipient}..."
|
33
|
+
puts "Sending '#{options.message}' to #{[options.recipient].flatten.join(", ")}..."
|
34
34
|
additional_opts = {}
|
35
35
|
additional_opts[:from] = options.from if options.from
|
36
36
|
msg_id = api.send_message(options.recipient, options.message, additional_opts)
|
37
|
-
puts "Message sent successfully (message id: #{msg_id})."
|
37
|
+
puts "Message sent successfully (message id: #{[msg_id].flatten.join(", ")})."
|
38
38
|
exit 0
|
39
39
|
end
|
40
40
|
|
data/lib/clickatell/api.rb
CHANGED
@@ -75,10 +75,12 @@ module Clickatell
|
|
75
75
|
valid_options = opts.only(:from, :mo, :callback)
|
76
76
|
valid_options.merge!(:req_feat => '48') if valid_options[:from]
|
77
77
|
valid_options.merge!(:mo => '1') if opts[:set_mobile_originated]
|
78
|
+
recipient = recipient.join(",")if recipient.is_a?(Array)
|
78
79
|
response = execute_command('sendmsg', 'http',
|
79
80
|
{:to => recipient, :text => message_text}.merge(valid_options)
|
80
81
|
)
|
81
|
-
parse_response(response)
|
82
|
+
response = parse_response(response)
|
83
|
+
response.is_a?(Array) ? response.map { |r| r['ID'] } : response['ID']
|
82
84
|
end
|
83
85
|
|
84
86
|
def send_wap_push(recipient, media_url, notification_text='', opts={})
|
data/lib/clickatell/response.rb
CHANGED
@@ -15,7 +15,15 @@ module Clickatell
|
|
15
15
|
if http_response.body.scan(/ERR/).any?
|
16
16
|
raise Clickatell::API::Error.parse(http_response.body)
|
17
17
|
end
|
18
|
-
|
18
|
+
results = http_response.body.split("\n").map do |line|
|
19
|
+
# YAML.load converts integer strings that have leading zeroes into integers
|
20
|
+
# using octal rather than decimal. This isn't what we want, so we'll strip out any
|
21
|
+
# leading zeroes in numbers here.
|
22
|
+
response_fields = line.scan(PARSE_REGEX)
|
23
|
+
response_fields = response_fields.collect { |field| field.gsub(/\b0+(\d+)\b/, '\1') }
|
24
|
+
YAML.load(response_fields.join("\n"))
|
25
|
+
end
|
26
|
+
results.length == 1 ? results.first : results
|
19
27
|
end
|
20
28
|
|
21
29
|
end
|
@@ -9,7 +9,8 @@ module Clickatell
|
|
9
9
|
def parse(args)
|
10
10
|
@options = self.default_options
|
11
11
|
parser = OptionParser.new do |opts|
|
12
|
-
opts.banner = "Usage: sms [options] recipient message"
|
12
|
+
opts.banner = "Usage: sms [options] recipient(s) message"
|
13
|
+
opts.separator " Recipients can be a comma-separated list, up to 100 max."
|
13
14
|
opts.separator ""
|
14
15
|
opts.separator "Specific options:"
|
15
16
|
|
@@ -73,6 +74,8 @@ module Clickatell
|
|
73
74
|
puts parser
|
74
75
|
exit
|
75
76
|
end
|
77
|
+
|
78
|
+
@options.recipient = @options.recipient.split(",")
|
76
79
|
|
77
80
|
return @options
|
78
81
|
|
data/lib/clickatell/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -121,6 +121,15 @@ module Clickatell
|
|
121
121
|
@api.send_message('4477791234567', 'hello world & goodbye').should == 'message_id'
|
122
122
|
end
|
123
123
|
|
124
|
+
it "should support sending messages to a multiple numbers, returning the message ids" do
|
125
|
+
@executor.expects(:execute).with('sendmsg', 'http',
|
126
|
+
:to => '4477791234567,447779999999',
|
127
|
+
:text => 'hello world & goodbye'
|
128
|
+
).returns(response = stub('response'))
|
129
|
+
Response.stubs(:parse).with(response).returns([{'ID' => 'message_1_id'}, {'ID' => 'message_2_id'}])
|
130
|
+
@api.send_message(['4477791234567', '447779999999'], 'hello world & goodbye').should == ['message_1_id', 'message_2_id']
|
131
|
+
end
|
132
|
+
|
124
133
|
it "should set the :from parameter and set the :req_feat to 48 when using a custom from string when sending a message" do
|
125
134
|
@executor.expects(:execute).with('sendmsg', 'http', has_entries(:from => 'LUKE', :req_feat => '48')).returns(response = stub('response'))
|
126
135
|
Response.stubs(:parse).with(response).returns('ID' => 'message_id')
|
data/spec/response_spec.rb
CHANGED
@@ -16,9 +16,23 @@ module Clickatell
|
|
16
16
|
Response.parse(stub('response', :body => 'k1: foo k2: bar')).should == {'k1' => 'foo', 'k2' => 'bar'}
|
17
17
|
end
|
18
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
|
+
|
19
23
|
it "should raise API::Error if response contains an error message" do
|
20
24
|
proc { Response.parse(stub('response', :body => 'ERR: 001, Authentication failed')) }.should raise_error(Clickatell::API::Error)
|
21
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
|
22
36
|
|
23
37
|
describe "in test mode" do
|
24
38
|
before(:each) do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clickatell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Redpath
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-07 00:00:00 +01:00
|
13
13
|
default_executable: sms
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -44,23 +44,21 @@ files:
|
|
44
44
|
- spec/response_spec.rb
|
45
45
|
- spec/spec.opts
|
46
46
|
- spec/spec_helper.rb
|
47
|
-
- lib/clickatell
|
48
|
-
- lib/clickatell/api
|
49
47
|
- lib/clickatell/api/command.rb
|
50
48
|
- lib/clickatell/api/command_executor.rb
|
51
49
|
- lib/clickatell/api/error.rb
|
52
50
|
- lib/clickatell/api/message_status.rb
|
53
51
|
- lib/clickatell/api.rb
|
54
52
|
- lib/clickatell/response.rb
|
55
|
-
- lib/clickatell/utility
|
56
53
|
- lib/clickatell/utility/options.rb
|
57
54
|
- lib/clickatell/utility.rb
|
58
55
|
- lib/clickatell/version.rb
|
59
56
|
- lib/clickatell.rb
|
60
|
-
- lib/core-ext
|
61
57
|
- lib/core-ext/hash.rb
|
62
58
|
has_rdoc: true
|
63
59
|
homepage: http://clickatell.rubyforge.org
|
60
|
+
licenses: []
|
61
|
+
|
64
62
|
post_install_message:
|
65
63
|
rdoc_options:
|
66
64
|
- --main
|
@@ -82,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
80
|
requirements: []
|
83
81
|
|
84
82
|
rubyforge_project: clickatell
|
85
|
-
rubygems_version: 1.3.
|
83
|
+
rubygems_version: 1.3.5
|
86
84
|
signing_key:
|
87
85
|
specification_version: 2
|
88
86
|
summary: Ruby interface to the Clickatell SMS gateway service.
|