bobes-textmagic 0.3.0 → 0.3.1
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.
- data/.gitignore +2 -0
- data/History.txt +8 -0
- data/README.rdoc +3 -3
- data/VERSION.yml +1 -1
- data/lib/executor.rb +6 -5
- data/test/test_executor.rb +12 -10
- data/test/test_helper.rb +0 -6
- data/textmagic.gemspec +3 -2
- metadata +3 -2
data/History.txt
ADDED
data/README.rdoc
CHANGED
@@ -11,11 +11,11 @@ SMS Gateway, visit the official {API documentation}[http://api.textmagic.com]
|
|
11
11
|
or {Google group}[http://groups.google.com/group/textmagic-api].
|
12
12
|
|
13
13
|
Links:
|
14
|
-
|
14
|
+
Doc[http://tuzinsky.com/textmagic/rdoc]
|
15
15
|
|
|
16
|
-
|
16
|
+
Code[http://github.com/bobes/textmagic/tree/master]
|
17
17
|
|
|
18
|
-
Blame[http://
|
18
|
+
Blame[http://tuzinsky.com]
|
19
19
|
|
20
20
|
|
21
21
|
== Installation
|
data/VERSION.yml
CHANGED
data/lib/executor.rb
CHANGED
@@ -7,13 +7,14 @@ module TextMagic
|
|
7
7
|
include HTTParty
|
8
8
|
base_uri "http://www.textmagic.com/app"
|
9
9
|
|
10
|
-
# Executes a command by sending a request to the TextMagic's
|
11
|
-
# gateway. This is a low-level generic method used by methods
|
12
|
-
# TextMagic::API class. You should never need to use this method
|
10
|
+
# Executes a command by sending a request to the TextMagic's Bulk
|
11
|
+
# SMS gateway. This is a low-level generic method used by methods
|
12
|
+
# in TextMagic::API class. You should never need to use this method
|
13
13
|
# directly.
|
14
14
|
#
|
15
15
|
# Parameters specified in the +options+ hash will be added to the
|
16
|
-
# HTTP request's
|
16
|
+
# HTTP POST request's body together with command, username and
|
17
|
+
# password.
|
17
18
|
#
|
18
19
|
# Returns a hash with values parsed from the server's response if
|
19
20
|
# the command was successfully executed. In case the server replies
|
@@ -25,7 +26,7 @@ module TextMagic
|
|
25
26
|
end
|
26
27
|
options.merge!(:username => username, :password => password, :cmd => command)
|
27
28
|
options.delete_if { |key, value| key.nil? || key.to_s.blank? || value.nil? || value.to_s.blank? }
|
28
|
-
response = self.
|
29
|
+
response = self.post('/api', :body => options, :format => :json)
|
29
30
|
raise Error.new(response) if response && response['error_code']
|
30
31
|
response
|
31
32
|
end
|
data/test/test_executor.rb
CHANGED
@@ -10,51 +10,53 @@ class ExecutorTest < Test::Unit::TestCase
|
|
10
10
|
|
11
11
|
@username, @password = random_string, random_string
|
12
12
|
@command, @options = random_string, random_hash
|
13
|
-
@uri =
|
13
|
+
@uri = "http://www.textmagic.com/app/api"
|
14
14
|
end
|
15
15
|
|
16
16
|
should 'not send HTTP request without command' do
|
17
|
-
TextMagic::API::Executor.expects(:
|
17
|
+
TextMagic::API::Executor.expects(:post).never
|
18
18
|
lambda {
|
19
19
|
TextMagic::API::Executor.execute(nil, @username, @password, @options)
|
20
20
|
}.should raise_error(TextMagic::API::Error)
|
21
21
|
end
|
22
22
|
|
23
23
|
should 'not send HTTP request without username' do
|
24
|
-
TextMagic::API::Executor.expects(:
|
24
|
+
TextMagic::API::Executor.expects(:post).never
|
25
25
|
lambda {
|
26
26
|
TextMagic::API::Executor.execute(@command, nil, @password, @options)
|
27
27
|
}.should raise_error(TextMagic::API::Error)
|
28
28
|
end
|
29
29
|
|
30
30
|
should 'not send HTTP request without password' do
|
31
|
-
TextMagic::API::Executor.expects(:
|
31
|
+
TextMagic::API::Executor.expects(:post).never
|
32
32
|
lambda {
|
33
33
|
TextMagic::API::Executor.execute(@command, @username, nil, @options)
|
34
34
|
}.should raise_error(TextMagic::API::Error)
|
35
35
|
end
|
36
36
|
|
37
|
-
should 'send a
|
37
|
+
should 'send a POST request to proper uri' do
|
38
38
|
response = random_string
|
39
|
-
FakeWeb.register_uri(:
|
39
|
+
FakeWeb.register_uri(:post, @uri, :string => response)
|
40
40
|
TextMagic::API::Executor.execute(@command, @username, @password, @options)
|
41
41
|
end
|
42
42
|
|
43
43
|
should 'not send parameters with empty keys' do
|
44
44
|
options_with_empty_values = @options.merge(nil => random_string, '' => random_string)
|
45
|
-
|
45
|
+
@options.merge!(:username => @username, :password => @password, :cmd => @command)
|
46
|
+
TextMagic::API::Executor.expects(:post).with('/api', :body => @options, :format => :json)
|
46
47
|
TextMagic::API::Executor.execute(@command, @username, @password, options_with_empty_values)
|
47
48
|
end
|
48
49
|
|
49
50
|
should 'not send parameters with empty values' do
|
50
51
|
options_with_empty_values = @options.merge(random_string => nil, random_string => '')
|
51
|
-
|
52
|
+
@options.merge!(:username => @username, :password => @password, :cmd => @command)
|
53
|
+
TextMagic::API::Executor.expects(:post).with('/api', :body => @options, :format => :json)
|
52
54
|
TextMagic::API::Executor.execute(@command, @username, @password, options_with_empty_values)
|
53
55
|
end
|
54
56
|
|
55
57
|
should 'raise an error if the response contains error_code' do
|
56
58
|
response = "{error_code:#{1 + rand(10)}}"
|
57
|
-
FakeWeb.register_uri(:
|
59
|
+
FakeWeb.register_uri(:post, @uri, :string => response)
|
58
60
|
lambda {
|
59
61
|
TextMagic::API::Executor.execute(@command, @username, @password, @options)
|
60
62
|
}.should raise_error(TextMagic::API::Error)
|
@@ -62,7 +64,7 @@ class ExecutorTest < Test::Unit::TestCase
|
|
62
64
|
|
63
65
|
should 'return a hash with values from the response' do
|
64
66
|
hash = random_hash
|
65
|
-
FakeWeb.register_uri(:
|
67
|
+
FakeWeb.register_uri(:post, @uri, :string => hash.to_json)
|
66
68
|
response = TextMagic::API::Executor.execute(@command, @username, @password, @options)
|
67
69
|
response.should == hash
|
68
70
|
end
|
data/test/test_helper.rb
CHANGED
@@ -27,12 +27,6 @@ def random_hash
|
|
27
27
|
hash
|
28
28
|
end
|
29
29
|
|
30
|
-
def build_uri(command, username, password, options = {})
|
31
|
-
options.merge!(:cmd => command, :username => username, :password => password)
|
32
|
-
uri = "http://www.textmagic.com/app/api?"
|
33
|
-
uri << options.collect { |key, value| "#{key}=#{value}"}.join('&')
|
34
|
-
end
|
35
|
-
|
36
30
|
def load_response(filename)
|
37
31
|
File.read(File.join(File.dirname(__FILE__), 'fixtures', filename) + '.json')
|
38
32
|
end
|
data/textmagic.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
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.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Vladimir Bobes Tuzinsky"]
|
9
|
-
s.date = %q{2009-05-
|
9
|
+
s.date = %q{2009-05-30}
|
10
10
|
s.email = %q{vladimir.tuzinsky@gmail.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.files = [
|
16
16
|
".document",
|
17
17
|
".gitignore",
|
18
|
+
"History.txt",
|
18
19
|
"LICENSE",
|
19
20
|
"README.rdoc",
|
20
21
|
"Rakefile",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Bobes Tuzinsky
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -64,6 +64,7 @@ extra_rdoc_files:
|
|
64
64
|
files:
|
65
65
|
- .document
|
66
66
|
- .gitignore
|
67
|
+
- History.txt
|
67
68
|
- LICENSE
|
68
69
|
- README.rdoc
|
69
70
|
- Rakefile
|