textmagic 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +7 -0
- data/History.txt +4 -0
- data/README.md +131 -0
- data/Rakefile +1 -3
- data/bin/tm +5 -5
- data/lib/textmagic/executor.rb +1 -2
- data/lib/textmagic/version.rb +1 -1
- data/test/test_api.rb +100 -76
- data/test/test_charset.rb +25 -25
- data/test/test_error.rb +9 -9
- data/test/test_executor.rb +20 -23
- data/test/test_helper.rb +10 -14
- data/test/test_response.rb +100 -100
- data/test/test_validation.rb +50 -50
- data/textmagic.gemspec +1 -5
- metadata +17 -60
- data/README.rdoc +0 -153
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c810998c9e416e69841a07869dc802818d1a4a65
|
4
|
+
data.tar.gz: 3c5c28da54b76a1d939b15ae2edecec92c313a42
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4041fbd28087e80983118b69ab1e5abae41ba8ea9a846844df83d81696f20c8765ecf18ef48e634a821ff8e4006214583b9c8c4bea27e33712ddf3f30abcb9c5
|
7
|
+
data.tar.gz: 40968523dc18f0c1c6816d8eb64c4713291e5f52bcef386ebc87189868377c878302f36ed24b716fb374e22a942c8ac2cd42886737eb5bf92a259bd39dc5ea69
|
data/Gemfile
CHANGED
data/History.txt
CHANGED
data/README.md
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# TextMagic
|
2
|
+
|
3
|
+
`textmagic` gem is a Ruby interface to the [TextMagic](http://www.textmagic.com)
|
4
|
+
Bulk SMS Gateway.
|
5
|
+
It can be used to easily integrate SMS features into your application.
|
6
|
+
It supports sending messages, receiving replies and more. You need to have
|
7
|
+
a valid [TextMagic](http://www.textmagic.com) account to use this gem.
|
8
|
+
|
9
|
+
To learn more about the TextMagic Bulk SMS Gateway, visit the official
|
10
|
+
[API documentation](http://api.textmagic.com)
|
11
|
+
or [Google group](http://groups.google.com/group/textmagic-api).
|
12
|
+
|
13
|
+
This document will give you a good overview of the gem's functionality. For
|
14
|
+
more information consult the detailed [documentation](http://tuzinsky.com/textmagic/rdoc/).
|
15
|
+
|
16
|
+
|
17
|
+
## Basic usage
|
18
|
+
|
19
|
+
First create an API instance with your credentials:
|
20
|
+
|
21
|
+
api = TextMagic::API.new(username, password)
|
22
|
+
|
23
|
+
These credentials will be used in all requests to the SMS gateway.
|
24
|
+
|
25
|
+
|
26
|
+
### Account balance
|
27
|
+
|
28
|
+
Check your account's balance:
|
29
|
+
|
30
|
+
api.account.balance
|
31
|
+
# => 314.15
|
32
|
+
|
33
|
+
|
34
|
+
### Sending messages
|
35
|
+
|
36
|
+
To send a message to a single phone number, run:
|
37
|
+
|
38
|
+
api.send 'Hi Wilma!', '999314159265'
|
39
|
+
|
40
|
+
You can even specify multiple phone numbers:
|
41
|
+
|
42
|
+
api.send 'Hello everybody', '999314159265', '999271828182'
|
43
|
+
|
44
|
+
Unicode messages are supported as well:
|
45
|
+
|
46
|
+
api.send 'Вильма Привет!', '999314159265'
|
47
|
+
|
48
|
+
Long messages will be split to up to 3 parts. To limit maximum number
|
49
|
+
of parts, specify an optional `max_length` parameter:
|
50
|
+
|
51
|
+
api.send 'Very very long message...', '999314159265', :max_length => 2
|
52
|
+
|
53
|
+
If you want to postpone message delivery, specify a `send_time` parameter:
|
54
|
+
|
55
|
+
api.send 'Two hours later', '999314159265', :send_time => Time.now.to_i + 7200
|
56
|
+
|
57
|
+
|
58
|
+
### Checking sent message status
|
59
|
+
|
60
|
+
If you want to check sent message status, you have to use `message_id`
|
61
|
+
returned in response to `send` command.
|
62
|
+
|
63
|
+
api.send('Hi Wilma!', '999314159265')
|
64
|
+
# => '141421'
|
65
|
+
status = api.message_status('141421')
|
66
|
+
# => 'd'
|
67
|
+
status.completed_time
|
68
|
+
# => Fri May 22 10:10:18 +0200 2009
|
69
|
+
|
70
|
+
You can also check statuses of several messages at once, in which case
|
71
|
+
you'll get a hash with message ids as keys:
|
72
|
+
|
73
|
+
api.send('Hi Wilma!', '999314159265', '999271828182').message_id
|
74
|
+
# => { '999314159265' => '141421', '999271828182' => '173205' }
|
75
|
+
statuses = api.message_status('141421', '173205')
|
76
|
+
# => { '141421' => 'r', '173205' => 'd' }
|
77
|
+
statuses['173205'].created_time
|
78
|
+
# => Thu May 28 16:41:45 +0200 2009
|
79
|
+
|
80
|
+
**It is strongly recommended to setup callbacks to receive updates on message status
|
81
|
+
instead of using this method. Learn more about callbacks at
|
82
|
+
[TextMagic API](http://api.textmagic.com/https-api) site**
|
83
|
+
|
84
|
+
|
85
|
+
### Receiving replies
|
86
|
+
|
87
|
+
To receive all available replies, run:
|
88
|
+
|
89
|
+
replies = api.receive
|
90
|
+
# => ['999271828182: Hello Fred!', '999314159265: Good day!']
|
91
|
+
replies.first.text
|
92
|
+
# => 'Hello Fred!'
|
93
|
+
replies.last.from
|
94
|
+
# => '999314159265'
|
95
|
+
replies.last.message_id
|
96
|
+
# => '178082'
|
97
|
+
|
98
|
+
To prevent receiving old replies again, supply `last_retrieved_id` argument:
|
99
|
+
|
100
|
+
api.receive('178082')
|
101
|
+
# => []
|
102
|
+
|
103
|
+
**It is strongly recommended to setup callbacks to receive replies instead of
|
104
|
+
using this method. Learn more about callbacks at
|
105
|
+
[TextMagic API](http://api.textmagic.com/https-api) site**
|
106
|
+
|
107
|
+
|
108
|
+
### Deleting retrieved replies
|
109
|
+
|
110
|
+
After you retrieve replies, you can delete them from server by running:
|
111
|
+
|
112
|
+
api.delete_reply '141421', '178082'
|
113
|
+
# => true
|
114
|
+
|
115
|
+
|
116
|
+
## Command-line utility
|
117
|
+
|
118
|
+
The `textmagic` gem also features a handy command-line utility. It gives you access
|
119
|
+
to all of the gem's features. Run
|
120
|
+
|
121
|
+
tm
|
122
|
+
|
123
|
+
from your console to see help on its usage.
|
124
|
+
|
125
|
+
*Note: This gem has been tested with Ruby versions 1.9.3 to 2.1.2.
|
126
|
+
If you have any troubles using this gem, contact the author (or submit a patch).*
|
127
|
+
|
128
|
+
|
129
|
+
## Copyright
|
130
|
+
|
131
|
+
Copyright (c) 2009-2014 Vladimír Bobeš Tužinský. See LICENSE for details.
|
data/Rakefile
CHANGED
data/bin/tm
CHANGED
@@ -67,9 +67,9 @@ api = TextMagic::API.new(options['username'], options['password'])
|
|
67
67
|
|
68
68
|
begin
|
69
69
|
case command
|
70
|
-
when 'account'
|
70
|
+
when 'account'
|
71
71
|
puts "Your account's balance: #{api.account.balance} credits"
|
72
|
-
when 'send'
|
72
|
+
when 'send'
|
73
73
|
unless phones = ARGV.shift
|
74
74
|
puts "Phone number(s) and message not specified. Use --help option to find out details"
|
75
75
|
exit 1
|
@@ -84,7 +84,7 @@ begin
|
|
84
84
|
response.each do |phone, message_id|
|
85
85
|
puts "Message id (#{phone}): #{message_id}"
|
86
86
|
end
|
87
|
-
when 'status'
|
87
|
+
when 'status'
|
88
88
|
if ARGV.empty?
|
89
89
|
puts "Message id(s) not specified. Use --help option to find out details"
|
90
90
|
exit 1
|
@@ -92,13 +92,13 @@ begin
|
|
92
92
|
api.status(ARGV).each do |message_id, status|
|
93
93
|
puts "Status (#{message_id}): #{status}"
|
94
94
|
end
|
95
|
-
when 'receive'
|
95
|
+
when 'receive'
|
96
96
|
response = api.receive(ARGV.first)
|
97
97
|
response.each do |message|
|
98
98
|
puts "#{message} [#{message.message_id}, #{message.timestamp}]"
|
99
99
|
end
|
100
100
|
puts 'No new messages' if response.empty?
|
101
|
-
when 'delete'
|
101
|
+
when 'delete'
|
102
102
|
api.delete(ARGV)
|
103
103
|
puts 'Message(s) deleted'
|
104
104
|
else
|
data/lib/textmagic/executor.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module TextMagic
|
2
|
-
|
3
2
|
class API
|
4
3
|
|
5
4
|
class Executor
|
6
5
|
|
7
6
|
include HTTParty
|
8
|
-
base_uri "
|
7
|
+
base_uri "https://www.textmagic.com/app"
|
9
8
|
|
10
9
|
# Executes a command by sending a request to the TextMagic's Bulk
|
11
10
|
# SMS gateway. This is a low-level generic method used by methods
|
data/lib/textmagic/version.rb
CHANGED
data/test/test_api.rb
CHANGED
@@ -2,19 +2,21 @@
|
|
2
2
|
|
3
3
|
require "test_helper"
|
4
4
|
|
5
|
-
|
5
|
+
describe "API" do
|
6
6
|
|
7
|
-
|
7
|
+
describe "Initialization" do
|
8
8
|
|
9
|
-
should
|
10
|
-
|
9
|
+
it " should require username and password" do
|
10
|
+
assert_raises ArgumentError do
|
11
|
+
TextMagic::API.new
|
12
|
+
end
|
11
13
|
TextMagic::API.new(random_string, random_string)
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
|
-
|
17
|
+
describe "Account command" do
|
16
18
|
|
17
|
-
|
19
|
+
before do
|
18
20
|
@username, @password = random_string, random_string
|
19
21
|
@api = TextMagic::API.new(@username, @password)
|
20
22
|
@response = random_string
|
@@ -23,21 +25,21 @@ class APITest < Test::Unit::TestCase
|
|
23
25
|
TextMagic::API::Response.stubs(:account).returns(@processed_response)
|
24
26
|
end
|
25
27
|
|
26
|
-
should
|
28
|
+
it "should call Executor execute with correct arguments" do
|
27
29
|
TextMagic::API::Executor.expects(:execute).with("account", @username, @password).returns(@response)
|
28
30
|
@api.account
|
29
31
|
end
|
30
32
|
|
31
|
-
should
|
33
|
+
it "should call Response.account method to process the response hash" do
|
32
34
|
processed_response = rand
|
33
35
|
TextMagic::API::Response.expects(:account).with(@response).returns(processed_response)
|
34
|
-
@api.account
|
36
|
+
assert_equal processed_response, @api.account
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
|
-
|
40
|
+
describe "Send command" do
|
39
41
|
|
40
|
-
|
42
|
+
before do
|
41
43
|
@username, @password = random_string, random_string
|
42
44
|
@text, @phone = random_string, random_phone
|
43
45
|
@api = TextMagic::API.new(@username, @password)
|
@@ -47,92 +49,108 @@ class APITest < Test::Unit::TestCase
|
|
47
49
|
TextMagic::API::Response.stubs(:send).returns(@processed_response)
|
48
50
|
end
|
49
51
|
|
50
|
-
should
|
52
|
+
it "should call Executor execute with correct arguments" do
|
51
53
|
TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => @phone, :unicode => 0).returns(@response)
|
52
54
|
@api.send(@text, @phone)
|
53
55
|
end
|
54
56
|
|
55
|
-
should
|
57
|
+
it "should join multiple phone numbers supplied as an array" do
|
56
58
|
phones = Array.new(3) { random_phone }
|
57
59
|
TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => phones.join(","), :unicode => 0).returns(@response)
|
58
60
|
@api.send(@text, phones)
|
59
61
|
end
|
60
62
|
|
61
|
-
should
|
63
|
+
it "should join multiple phone numbers supplied as arguments" do
|
62
64
|
phones = Array.new(3) { random_phone }
|
63
65
|
TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => phones.join(","), :unicode => 0).returns(@response)
|
64
66
|
@api.send(@text, *phones)
|
65
67
|
end
|
66
68
|
|
67
|
-
should
|
69
|
+
it "should replace true with 1 for unicode" do
|
68
70
|
TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => @phone, :unicode => 1).returns(@response)
|
69
71
|
@api.send(@text, @phone, :unicode => true)
|
70
72
|
end
|
71
73
|
|
72
|
-
should
|
74
|
+
it "should set unicode value to 0 if it is not set to by user and text contains only characters from GSM 03.38 charset" do
|
73
75
|
TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => @phone, :unicode => 0).returns(@response).times(2)
|
74
76
|
@api.send(@text, @phone)
|
75
77
|
@api.send(@text, @phone, :unicode => false)
|
76
78
|
end
|
77
79
|
|
78
|
-
should
|
80
|
+
it "should raise an error if unicode is set to 0 and text contains characters outside of GSM 03.38 charset" do
|
79
81
|
text = "Вильма Привет"
|
80
|
-
|
82
|
+
assert_raises TextMagic::API::Error do
|
83
|
+
@api.send(text, @phone, :unicode => false)
|
84
|
+
end
|
81
85
|
end
|
82
86
|
|
83
|
-
should
|
84
|
-
|
85
|
-
|
87
|
+
it "should raise an error if unicode value is not valid" do
|
88
|
+
assert_raises TextMagic::API::Error do
|
89
|
+
@api.send(@text, @phone, :unicode => 2 + rand(10))
|
90
|
+
end
|
91
|
+
assert_raises TextMagic::API::Error do
|
92
|
+
@api.send(@text, @phone, :unicode => random_string)
|
93
|
+
end
|
86
94
|
end
|
87
95
|
|
88
|
-
should
|
89
|
-
|
90
|
-
|
96
|
+
it "should raise an error if no phone numbers are specified" do
|
97
|
+
assert_raises TextMagic::API::Error do
|
98
|
+
@api.send(@text)
|
99
|
+
end
|
100
|
+
assert_raises TextMagic::API::Error do
|
101
|
+
@api.send(@text, [])
|
102
|
+
end
|
91
103
|
end
|
92
104
|
|
93
|
-
should
|
105
|
+
it "should raise an error if format of any of the specified phone numbers is invalid" do
|
94
106
|
TextMagic::API.expects(:validate_phones).returns(false)
|
95
|
-
|
107
|
+
assert_raises TextMagic::API::Error do
|
108
|
+
@api.send(@text, random_string)
|
109
|
+
end
|
96
110
|
end
|
97
111
|
|
98
|
-
should
|
99
|
-
|
112
|
+
it "should raise an error if text is nil" do
|
113
|
+
assert_raises TextMagic::API::Error do
|
114
|
+
@api.send(nil, @phone)
|
115
|
+
end
|
100
116
|
end
|
101
117
|
|
102
|
-
should
|
118
|
+
it "should raise an error if text is too long" do
|
103
119
|
TextMagic::API.expects(:validate_text_length).returns(false)
|
104
|
-
|
120
|
+
assert_raises TextMagic::API::Error do
|
121
|
+
@api.send(@text, @phone)
|
122
|
+
end
|
105
123
|
end
|
106
124
|
|
107
|
-
should
|
125
|
+
it "should support send_time option" do
|
108
126
|
time = Time.now + rand
|
109
127
|
TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => @phone, :unicode => 0, :send_time => time.to_i).returns(@response)
|
110
128
|
@api.send(@text, @phone, :send_time => time.to_i)
|
111
129
|
end
|
112
130
|
|
113
|
-
should
|
131
|
+
it "should convert send_time to Fixnum" do
|
114
132
|
time = Time.now + rand
|
115
133
|
TextMagic::API::Executor.expects(:execute).with("send", @username, @password, :text => @text, :phone => @phone, :unicode => 0, :send_time => time.to_i).returns(@response)
|
116
134
|
@api.send(@text, @phone, :send_time => time)
|
117
135
|
end
|
118
136
|
|
119
|
-
should
|
137
|
+
it "should call Response.send method to process the response hash (single phone)" do
|
120
138
|
processed_response = rand
|
121
139
|
TextMagic::API::Response.expects(:send).with(@response, true).returns(processed_response)
|
122
|
-
@api.send(@text, random_phone)
|
140
|
+
assert_equal processed_response, @api.send(@text, random_phone)
|
123
141
|
end
|
124
142
|
|
125
|
-
should
|
143
|
+
it "should call Response.send method to process the response hash (multiple phones)" do
|
126
144
|
processed_response = rand
|
127
145
|
TextMagic::API::Response.expects(:send).with(@response, false).returns(processed_response).twice
|
128
|
-
@api.send(@text, [random_phone])
|
129
|
-
@api.send(@text, random_phone, random_phone)
|
146
|
+
assert_equal processed_response, @api.send(@text, [random_phone])
|
147
|
+
assert_equal processed_response, @api.send(@text, random_phone, random_phone)
|
130
148
|
end
|
131
149
|
end
|
132
150
|
|
133
|
-
|
151
|
+
describe "Message status command" do
|
134
152
|
|
135
|
-
|
153
|
+
before do
|
136
154
|
@username, @password = random_string, random_string
|
137
155
|
@api = TextMagic::API.new(@username, @password)
|
138
156
|
@response = random_string
|
@@ -141,44 +159,46 @@ class APITest < Test::Unit::TestCase
|
|
141
159
|
TextMagic::API::Response.stubs(:message_status).returns(@processed_response)
|
142
160
|
end
|
143
161
|
|
144
|
-
should
|
162
|
+
it "should call Executor execute with correct arguments" do
|
145
163
|
id = random_string
|
146
164
|
TextMagic::API::Executor.expects(:execute).with("message_status", @username, @password, :ids => id).returns(@response)
|
147
165
|
@api.message_status(id)
|
148
166
|
end
|
149
167
|
|
150
|
-
should
|
168
|
+
it "should join ids supplied as array" do
|
151
169
|
ids = Array.new(3) { random_string }
|
152
170
|
TextMagic::API::Executor.expects(:execute).with("message_status", @username, @password, :ids => ids.join(","))
|
153
171
|
@api.message_status(ids)
|
154
172
|
end
|
155
173
|
|
156
|
-
should
|
174
|
+
it "should join ids supplied as arguments" do
|
157
175
|
ids = Array.new(3) { random_string }
|
158
176
|
TextMagic::API::Executor.expects(:execute).with("message_status", @username, @password, :ids => ids.join(","))
|
159
177
|
@api.message_status(*ids)
|
160
178
|
end
|
161
179
|
|
162
|
-
should
|
180
|
+
it "should not call execute and should raise an exception if no ids are specified" do
|
163
181
|
TextMagic::API::Executor.expects(:execute).never
|
164
|
-
|
182
|
+
assert_raises TextMagic::API::Error do
|
183
|
+
@api.message_status
|
184
|
+
end
|
165
185
|
end
|
166
186
|
|
167
|
-
should
|
187
|
+
it "should call Response.message_status method to process the response hash (single id)" do
|
168
188
|
TextMagic::API::Response.expects(:message_status).with(@response, true).returns(@processed_response)
|
169
|
-
@api.message_status(random_string)
|
189
|
+
assert_equal @processed_response, @api.message_status(random_string)
|
170
190
|
end
|
171
191
|
|
172
|
-
should
|
192
|
+
it "should call Response.message_status method to process the response hash (multiple ids)" do
|
173
193
|
TextMagic::API::Response.expects(:message_status).with(@response, false).returns(@processed_response).twice
|
174
|
-
@api.message_status([random_string])
|
175
|
-
@api.message_status(random_string, random_string)
|
194
|
+
assert_equal @processed_response, @api.message_status([random_string])
|
195
|
+
assert_equal @processed_response, @api.message_status(random_string, random_string)
|
176
196
|
end
|
177
197
|
end
|
178
198
|
|
179
|
-
|
199
|
+
describe "Receive command" do
|
180
200
|
|
181
|
-
|
201
|
+
before do
|
182
202
|
@username, @password = random_string, random_string
|
183
203
|
@api = TextMagic::API.new(@username, @password)
|
184
204
|
@response = random_string
|
@@ -187,26 +207,26 @@ class APITest < Test::Unit::TestCase
|
|
187
207
|
TextMagic::API::Response.stubs(:receive).returns(@processed_response)
|
188
208
|
end
|
189
209
|
|
190
|
-
should
|
210
|
+
it "should call Executor execute with correct arguments" do
|
191
211
|
TextMagic::API::Executor.expects(:execute).with("receive", @username, @password, :last_retrieved_id => nil)
|
192
212
|
@api.receive
|
193
213
|
end
|
194
214
|
|
195
|
-
should
|
215
|
+
it "should accept last_retrieved_id optional value" do
|
196
216
|
last_retrieved_id = rand(1e10)
|
197
217
|
TextMagic::API::Executor.expects(:execute).with("receive", @username, @password, :last_retrieved_id => last_retrieved_id)
|
198
218
|
@api.receive(last_retrieved_id)
|
199
219
|
end
|
200
220
|
|
201
|
-
should
|
221
|
+
it "should call Response.receive method to process the response hash" do
|
202
222
|
TextMagic::API::Response.expects(:receive).with(@response).returns(@processed_response)
|
203
|
-
@api.receive(random_string)
|
223
|
+
assert_equal @processed_response, @api.receive(random_string)
|
204
224
|
end
|
205
225
|
end
|
206
226
|
|
207
|
-
|
227
|
+
describe "Delete reply command" do
|
208
228
|
|
209
|
-
|
229
|
+
before do
|
210
230
|
@username, @password = random_string, random_string
|
211
231
|
@api = TextMagic::API.new(@username, @password)
|
212
232
|
@response = random_string
|
@@ -215,37 +235,39 @@ class APITest < Test::Unit::TestCase
|
|
215
235
|
TextMagic::API::Response.stubs(:delete_reply).returns(@processed_response)
|
216
236
|
end
|
217
237
|
|
218
|
-
should
|
238
|
+
it "should call Executor execute with correct arguments" do
|
219
239
|
id = random_string
|
220
240
|
TextMagic::API::Executor.expects(:execute).with("delete_reply", @username, @password, :ids => id)
|
221
241
|
@api.delete_reply(id)
|
222
242
|
end
|
223
243
|
|
224
|
-
should
|
244
|
+
it "should join ids supplied as array" do
|
225
245
|
ids = Array.new(3) { random_string }
|
226
246
|
TextMagic::API::Executor.expects(:execute).with("delete_reply", @username, @password, :ids => ids.join(","))
|
227
247
|
@api.delete_reply(ids)
|
228
248
|
end
|
229
249
|
|
230
|
-
should
|
250
|
+
it "should join ids supplied as arguments" do
|
231
251
|
ids = Array.new(3) { random_string }
|
232
252
|
TextMagic::API::Executor.expects(:execute).with("delete_reply", @username, @password, :ids => ids.join(","))
|
233
253
|
@api.delete_reply(*ids)
|
234
254
|
end
|
235
255
|
|
236
|
-
should
|
256
|
+
it "should not call execute and should raise an exception if no ids are specified" do
|
237
257
|
TextMagic::API::Executor.expects(:execute).never
|
238
|
-
|
258
|
+
assert_raises TextMagic::API::Error do
|
259
|
+
@api.delete_reply
|
260
|
+
end
|
239
261
|
end
|
240
262
|
|
241
|
-
should
|
242
|
-
@api.delete_reply(random_string)
|
263
|
+
it "should return true" do
|
264
|
+
assert_equal true, @api.delete_reply(random_string)
|
243
265
|
end
|
244
266
|
end
|
245
267
|
|
246
|
-
|
268
|
+
describe "Check number command" do
|
247
269
|
|
248
|
-
|
270
|
+
before do
|
249
271
|
@username, @password = random_string, random_string
|
250
272
|
@api = TextMagic::API.new(@username, @password)
|
251
273
|
@response = random_string
|
@@ -254,38 +276,40 @@ class APITest < Test::Unit::TestCase
|
|
254
276
|
TextMagic::API::Response.stubs(:check_number).returns(@processed_response)
|
255
277
|
end
|
256
278
|
|
257
|
-
should
|
279
|
+
it "should call Executor execute with correct arguments" do
|
258
280
|
phone = random_phone
|
259
281
|
TextMagic::API::Executor.expects(:execute).with("check_number", @username, @password, :phone => phone)
|
260
282
|
@api.check_number(phone)
|
261
283
|
end
|
262
284
|
|
263
|
-
should
|
285
|
+
it "should join phones supplied as array" do
|
264
286
|
phones = Array.new(3) { random_phone }
|
265
287
|
TextMagic::API::Executor.expects(:execute).with("check_number", @username, @password, :phone => phones.join(","))
|
266
288
|
@api.check_number(phones)
|
267
289
|
end
|
268
290
|
|
269
|
-
should
|
291
|
+
it "should join phones supplied as arguments" do
|
270
292
|
phones = Array.new(3) { random_phone }
|
271
293
|
TextMagic::API::Executor.expects(:execute).with("check_number", @username, @password, :phone => phones.join(","))
|
272
294
|
@api.check_number(*phones)
|
273
295
|
end
|
274
296
|
|
275
|
-
should
|
297
|
+
it "should not call execute and should raise an exception if no phones are specified" do
|
276
298
|
TextMagic::API::Executor.expects(:execute).never
|
277
|
-
|
299
|
+
assert_raises TextMagic::API::Error do
|
300
|
+
@api.check_number
|
301
|
+
end
|
278
302
|
end
|
279
303
|
|
280
|
-
should
|
304
|
+
it "should call Response.check_number method to process the response hash (single phone)" do
|
281
305
|
TextMagic::API::Response.expects(:check_number).with(@response, true).returns(@processed_response)
|
282
|
-
@api.check_number(random_string)
|
306
|
+
assert_equal @processed_response, @api.check_number(random_string)
|
283
307
|
end
|
284
308
|
|
285
|
-
should
|
309
|
+
it "should call Response.check_number method to process the response hash (mulitple phones)" do
|
286
310
|
TextMagic::API::Response.expects(:check_number).with(@response, false).returns(@processed_response).twice
|
287
|
-
@api.check_number([random_string])
|
288
|
-
@api.check_number(random_string, random_string)
|
311
|
+
assert_equal @processed_response, @api.check_number([random_string])
|
312
|
+
assert_equal @processed_response, @api.check_number(random_string, random_string)
|
289
313
|
end
|
290
314
|
end
|
291
315
|
end
|