bobes-textmagic 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/LICENSE +1 -1
- data/README.rdoc +19 -5
- data/Rakefile +9 -1
- data/VERSION.yml +1 -1
- data/bin/tm +111 -0
- data/lib/api.rb +2 -0
- data/lib/charset.rb +5 -0
- data/lib/response.rb +1 -0
- data/lib/textmagic.rb +3 -6
- data/lib/validation.rb +1 -1
- data/test/test_charset.rb +17 -0
- data/test/test_helper.rb +1 -1
- data/test/test_validation.rb +12 -0
- data/textmagic.gemspec +12 -3
- metadata +8 -7
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== unreleased features
|
2
|
+
|
3
|
+
* Fixed message length validation to count escaped characters twice for non-unicode messages.
|
4
|
+
* Aliased message_status as status and delete_reply as delete.
|
5
|
+
* Account command returns balance as Fixnum if possible.
|
6
|
+
* Added a command line utility.
|
7
|
+
|
1
8
|
== 0.3.1 2009-05-30
|
2
9
|
|
3
10
|
* Sending POST requests instead of GET.
|
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -94,8 +94,9 @@ you'll get a hash with message ids as keys:
|
|
94
94
|
|
95
95
|
See TextMagic::API.message_status for more information on +message_status+ method.
|
96
96
|
|
97
|
-
<b>It is strongly
|
98
|
-
instead of using this method
|
97
|
+
<b>It is strongly recommended to setup callbacks to receive updates on message status
|
98
|
+
instead of using this method. Learn more about callbacks at
|
99
|
+
{TextMagic API}[http://api.textmagic.com/https-api] site</b>
|
99
100
|
|
100
101
|
=== Receiving replies
|
101
102
|
|
@@ -108,7 +109,7 @@ To receive all available replies, run:
|
|
108
109
|
replies.last.from
|
109
110
|
# => '999314159265'
|
110
111
|
replies.last.message_id
|
111
|
-
# => '
|
112
|
+
# => '178082'
|
112
113
|
|
113
114
|
To prevent receiving old replies again, supply +last_retrieved_id+ argument:
|
114
115
|
|
@@ -117,8 +118,9 @@ To prevent receiving old replies again, supply +last_retrieved_id+ argument:
|
|
117
118
|
|
118
119
|
See TextMagic::API.receive for more information on +message_status+ method.
|
119
120
|
|
120
|
-
<b>It is strongly
|
121
|
-
using this method
|
121
|
+
<b>It is strongly recommended to setup callbacks to receive replies instead of
|
122
|
+
using this method. Learn more about callbacks at
|
123
|
+
{TextMagic API}[http://api.textmagic.com/https-api] site</b>
|
122
124
|
|
123
125
|
=== Deleting retrieved replies
|
124
126
|
|
@@ -130,6 +132,18 @@ After you retrieve replies, you can delete them from server by running:
|
|
130
132
|
See TextMagic::API.delete_reply for more information on +message_status+ method.
|
131
133
|
|
132
134
|
|
135
|
+
== Command-line utility
|
136
|
+
|
137
|
+
The +textmagic+ gem also features a handy command-line utility. It gives you access
|
138
|
+
to all of the gem's features. Run
|
139
|
+
|
140
|
+
tm
|
141
|
+
|
142
|
+
from your console to see help on its usage.
|
143
|
+
|
144
|
+
<i>Note: This has only been tested on a Mac. If you have any troubles using this
|
145
|
+
utility, contact the author (or submit a patch).</i>
|
146
|
+
|
133
147
|
== Copyright
|
134
148
|
|
135
149
|
Copyright (c) 2009 Vladimír Bobeš Tužinský. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -7,9 +7,15 @@ begin
|
|
7
7
|
Jeweler::Tasks.new do |gem|
|
8
8
|
gem.name = "textmagic"
|
9
9
|
gem.summary = %Q{Ruby interface to the TextMagic's Bulk SMS Gateway}
|
10
|
+
gem.description = %Q{
|
11
|
+
textmagic is a Ruby interface to the TextMagic's Bulk SMS Gateway.
|
12
|
+
It can be used to easily integrate SMS features into your application.
|
13
|
+
It supports sending messages, receiving replies and more.
|
14
|
+
You need to have a valid TextMagic account to use this gem. You can get one at http://www.textmagic.com.
|
15
|
+
}
|
10
16
|
gem.email = "vladimir.tuzinsky@gmail.com"
|
11
17
|
gem.homepage = "http://github.com/bobes/textmagic"
|
12
|
-
gem.authors = ["
|
18
|
+
gem.authors = ["Vladimír Bobeš Tužinský"]
|
13
19
|
gem.rubyforge_project = "textmagic"
|
14
20
|
gem.add_runtime_dependency "httparty", ">= 0.4.3"
|
15
21
|
gem.add_development_dependency "mocha", ">= 0.9.5"
|
@@ -57,6 +63,8 @@ Rake::RDocTask.new do |rdoc|
|
|
57
63
|
rdoc.rdoc_dir = 'rdoc'
|
58
64
|
rdoc.title = "textmagic #{version}"
|
59
65
|
rdoc.rdoc_files.include('README*')
|
66
|
+
rdoc.rdoc_files.include('LICENSE')
|
67
|
+
rdoc.rdoc_files.include('History*')
|
60
68
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
61
69
|
rdoc.options << '--charset' << 'utf8'
|
62
70
|
rdoc.options << '--fmt' << 'shtml'
|
data/VERSION.yml
CHANGED
data/bin/tm
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
lib = File.join(File.dirname(__FILE__), '..', 'lib', 'textmagic')
|
5
|
+
|
6
|
+
if File.exist?("#{lib}.rb")
|
7
|
+
require lib
|
8
|
+
else
|
9
|
+
require 'rubygems'
|
10
|
+
require 'textmagic'
|
11
|
+
end
|
12
|
+
|
13
|
+
filename = File.join(ENV['HOME'], '.textmagic')
|
14
|
+
options = YAML.load_file(filename) if File.exist?(filename)
|
15
|
+
options ||= {}
|
16
|
+
|
17
|
+
parser = OptionParser.new do |opts|
|
18
|
+
opts.banner = 'Usage:'
|
19
|
+
opts.separator " "
|
20
|
+
opts.separator [
|
21
|
+
"tm account",
|
22
|
+
'tm send PHONE[,PHONE2[,PHONE3 ...]] MESSAGE',
|
23
|
+
'tm status MESSAGE_ID',
|
24
|
+
'tm receive [LAST_RETREIVED_ID]',
|
25
|
+
'tm delete MESSAGE_ID [MESSAGE_ID2 [MESSAGE_ID3 ...]]'
|
26
|
+
]
|
27
|
+
|
28
|
+
opts.separator " "
|
29
|
+
opts.separator "Specific options:"
|
30
|
+
|
31
|
+
opts.on('-u', '--username USERNAME',
|
32
|
+
"Specify your TextMagic API username (overrides ~/.textmagic setting)") do |username|
|
33
|
+
options['username'] = username
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on('-p', '--password PASSWORD',
|
37
|
+
"Specify your TextMagic API password (overrides ~/.textmagic setting)") do |password|
|
38
|
+
options['password'] = password
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on_tail('-h', '--help', "Show this message") do
|
42
|
+
puts opts
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
parser.parse!
|
48
|
+
|
49
|
+
if ARGV.empty?
|
50
|
+
puts parser
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
|
54
|
+
command = ARGV.shift
|
55
|
+
|
56
|
+
unless options['username']
|
57
|
+
puts "Username not specified. Use --help option to find out details"
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
|
61
|
+
unless options['password']
|
62
|
+
puts "Password not specified. Use --help option to find out details"
|
63
|
+
exit 1
|
64
|
+
end
|
65
|
+
|
66
|
+
api = TextMagic::API.new(options['username'], options['password'])
|
67
|
+
|
68
|
+
begin
|
69
|
+
case command
|
70
|
+
when 'account':
|
71
|
+
puts "Your account's balance: #{api.account.balance} credits"
|
72
|
+
when 'send':
|
73
|
+
unless phones = ARGV.shift
|
74
|
+
puts "Phone number(s) and message not specified. Use --help option to find out details"
|
75
|
+
exit 1
|
76
|
+
end
|
77
|
+
if (text = ARGV.join(' ')).empty?
|
78
|
+
puts "Message not specified. Use --help option to find out details"
|
79
|
+
exit 1
|
80
|
+
end
|
81
|
+
response = api.send(text, phones.split(','))
|
82
|
+
puts "Sent text: #{response.sent_text}"
|
83
|
+
puts "Parts: #{response.parts_count}"
|
84
|
+
response.each do |phone, message_id|
|
85
|
+
puts "Message id (#{phone}): #{message_id}"
|
86
|
+
end
|
87
|
+
when 'status':
|
88
|
+
if ARGV.empty?
|
89
|
+
puts "Message id(s) not specified. Use --help option to find out details"
|
90
|
+
exit 1
|
91
|
+
end
|
92
|
+
api.status(ARGV).each do |message_id, status|
|
93
|
+
puts "Status (#{message_id}): #{status}"
|
94
|
+
end
|
95
|
+
when 'receive':
|
96
|
+
response = api.receive(ARGV.first)
|
97
|
+
response.each do |message|
|
98
|
+
puts "#{message} [#{message.message_id}, #{message.timestamp}]"
|
99
|
+
end
|
100
|
+
puts 'No new messages' if response.empty?
|
101
|
+
when 'delete':
|
102
|
+
api.delete(ARGV)
|
103
|
+
puts 'Message(s) deleted'
|
104
|
+
else
|
105
|
+
puts "Unknown command #{command}. Use --help option to find out details"
|
106
|
+
exit 1
|
107
|
+
end
|
108
|
+
rescue TextMagic::API::Error => e
|
109
|
+
puts e
|
110
|
+
exit 1
|
111
|
+
end
|
data/lib/api.rb
CHANGED
@@ -135,6 +135,7 @@ module TextMagic
|
|
135
135
|
hash = Executor.execute('message_status', @username, @password, :ids => ids.join(','))
|
136
136
|
TextMagic::API::Response.message_status(hash, single)
|
137
137
|
end
|
138
|
+
alias :status :message_status
|
138
139
|
|
139
140
|
# Executes a receive command by sending a request to the TextMagic's
|
140
141
|
# SMS gateway.
|
@@ -188,5 +189,6 @@ module TextMagic
|
|
188
189
|
Executor.execute('delete_reply', @username, @password, :ids => ids.join(','))
|
189
190
|
true
|
190
191
|
end
|
192
|
+
alias :delete :delete_reply
|
191
193
|
end
|
192
194
|
end
|
data/lib/charset.rb
CHANGED
@@ -5,6 +5,7 @@ module TextMagic
|
|
5
5
|
module Charset
|
6
6
|
|
7
7
|
GSM_CHARSET = "@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\e\f^{}\\[~]|€ÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà".scan(/./u)
|
8
|
+
ESCAPED_CHARS = "{}\\~[]|€"
|
8
9
|
|
9
10
|
# Returns +true+ if the supplied text contains only characters from
|
10
11
|
# GSM 03.38 charset, otherwise it returns +false+.
|
@@ -18,6 +19,10 @@ module TextMagic
|
|
18
19
|
def is_unicode(text)
|
19
20
|
!is_gsm(text)
|
20
21
|
end
|
22
|
+
|
23
|
+
def real_length(text, unicode)
|
24
|
+
text.size + (unicode ? 0 : text.scan(/[\{\}\\\~\[\]\|\€]/).size)
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
data/lib/response.rb
CHANGED
data/lib/textmagic.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
gem 'httparty'
|
3
3
|
require 'httparty'
|
4
|
-
|
5
|
-
require
|
6
|
-
|
7
|
-
require 'response'
|
8
|
-
require 'executor'
|
9
|
-
require 'error'
|
4
|
+
%w[charset validation api response executor error].each do |lib|
|
5
|
+
require File.join(File.dirname(__FILE__), lib)
|
6
|
+
end
|
10
7
|
|
11
8
|
module TextMagic #:nodoc:
|
12
9
|
end
|
data/lib/validation.rb
CHANGED
@@ -17,7 +17,7 @@ module TextMagic
|
|
17
17
|
# 70, 134 and 201 respectively.</em>
|
18
18
|
def validate_text_length(text, unicode, parts = 3)
|
19
19
|
max_text_length = (unicode ? MAX_LENGTH_UNICODE : MAX_LENGTH_GSM)[parts - 1]
|
20
|
-
text
|
20
|
+
real_length(text, unicode) <= max_text_length
|
21
21
|
end
|
22
22
|
|
23
23
|
# Validates a list of phone numbers. Returns +true+ if the list is not empty
|
data/test/test_charset.rb
CHANGED
@@ -25,4 +25,21 @@ class CharsetTest < Test::Unit::TestCase
|
|
25
25
|
TextMagic::API.is_gsm('Thai: สวัสดี').should == false
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
context 'real_length method' do
|
30
|
+
|
31
|
+
should 'count escaped characters as two and all others as one for non-unicode text' do
|
32
|
+
escaped = "{}\\~[]|€"
|
33
|
+
unescaped = random_string
|
34
|
+
text = "#{escaped}#{unescaped}".scan(/./).sort_by { rand }.join
|
35
|
+
TextMagic::API.real_length(text, false).should == unescaped.size + escaped.size * 2
|
36
|
+
end
|
37
|
+
|
38
|
+
should 'count all characters as one for unicode text' do
|
39
|
+
escaped = "{}\\~[]|€"
|
40
|
+
unescaped = random_string
|
41
|
+
text = "#{escaped}#{unescaped}".scan(/./).sort_by { rand }.join
|
42
|
+
TextMagic::API.real_length(text, true).should == unescaped.size + escaped.size
|
43
|
+
end
|
44
|
+
end
|
28
45
|
end
|
data/test/test_helper.rb
CHANGED
data/test/test_validation.rb
CHANGED
@@ -5,6 +5,12 @@ class ValidationTest < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
context 'validate_text_length method for non-unicode texts' do
|
7
7
|
|
8
|
+
should 'use real_length method to determine the real length of the message' do
|
9
|
+
text = random_string
|
10
|
+
TextMagic::API.expects(:real_length).with(text, false).returns(0)
|
11
|
+
TextMagic::API.validate_text_length(text, false, 1)
|
12
|
+
end
|
13
|
+
|
8
14
|
should 'return true if parts limit is set to 1 and text length is less than or equal to 160' do
|
9
15
|
TextMagic::API.validate_text_length(random_string(160), false, 1).should == true
|
10
16
|
end
|
@@ -34,6 +40,12 @@ class ValidationTest < Test::Unit::TestCase
|
|
34
40
|
|
35
41
|
context 'validate_text_length method for unicode texts' do
|
36
42
|
|
43
|
+
should 'use real_length method to determine the real length of the message' do
|
44
|
+
text = random_string
|
45
|
+
TextMagic::API.expects(:real_length).with(text, true).returns(0)
|
46
|
+
TextMagic::API.validate_text_length(text, true, 1)
|
47
|
+
end
|
48
|
+
|
37
49
|
should 'return true if parts limit is set to 1 and text length is less than or equal to 70' do
|
38
50
|
TextMagic::API.validate_text_length(random_string(70), true, 1).should == true
|
39
51
|
end
|
data/textmagic.gemspec
CHANGED
@@ -2,12 +2,20 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{textmagic}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["
|
9
|
-
s.date = %q{2009-
|
8
|
+
s.authors = ["Vladim\303\255r Bobe\305\241 Tu\305\276insk\303\275"]
|
9
|
+
s.date = %q{2009-06-07}
|
10
|
+
s.default_executable = %q{tm}
|
11
|
+
s.description = %q{
|
12
|
+
textmagic is a Ruby interface to the TextMagic's Bulk SMS Gateway.
|
13
|
+
It can be used to easily integrate SMS features into your application.
|
14
|
+
It supports sending messages, receiving replies and more.
|
15
|
+
You need to have a valid TextMagic account to use this gem. You can get one at http://www.textmagic.com.
|
16
|
+
}
|
10
17
|
s.email = %q{vladimir.tuzinsky@gmail.com}
|
18
|
+
s.executables = ["tm"]
|
11
19
|
s.extra_rdoc_files = [
|
12
20
|
"LICENSE",
|
13
21
|
"README.rdoc"
|
@@ -20,6 +28,7 @@ Gem::Specification.new do |s|
|
|
20
28
|
"README.rdoc",
|
21
29
|
"Rakefile",
|
22
30
|
"VERSION.yml",
|
31
|
+
"bin/tm",
|
23
32
|
"lib/api.rb",
|
24
33
|
"lib/charset.rb",
|
25
34
|
"lib/error.rb",
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bobes-textmagic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- "Vladim\xC3\xADr Bobe\xC5\xA1 Tu\xC5\xBEinsk\xC3\xBD"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
13
|
-
default_executable:
|
12
|
+
date: 2009-06-07 00:00:00 -07:00
|
13
|
+
default_executable: tm
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -52,10 +52,10 @@ dependencies:
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: 0.1.0
|
54
54
|
version:
|
55
|
-
description:
|
55
|
+
description: textmagic is a Ruby interface to the TextMagic's Bulk SMS Gateway. It can be used to easily integrate SMS features into your application. It supports sending messages, receiving replies and more. You need to have a valid TextMagic account to use this gem. You can get one at http://www.textmagic.com.
|
56
56
|
email: vladimir.tuzinsky@gmail.com
|
57
|
-
executables:
|
58
|
-
|
57
|
+
executables:
|
58
|
+
- tm
|
59
59
|
extensions: []
|
60
60
|
|
61
61
|
extra_rdoc_files:
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- README.rdoc
|
70
70
|
- Rakefile
|
71
71
|
- VERSION.yml
|
72
|
+
- bin/tm
|
72
73
|
- lib/api.rb
|
73
74
|
- lib/charset.rb
|
74
75
|
- lib/error.rb
|