rapuncel 0.0.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +171 -0
- data/Rakefile +24 -0
- data/lib/rapuncel.rb +25 -0
- data/lib/rapuncel/adapters/net_http_adapter.rb +34 -0
- data/lib/rapuncel/base.rb +7 -0
- data/lib/rapuncel/client.rb +54 -0
- data/lib/rapuncel/connection.rb +75 -0
- data/lib/rapuncel/core_ext/array.rb +23 -0
- data/lib/rapuncel/core_ext/big_decimal.rb +7 -0
- data/lib/rapuncel/core_ext/boolean.rb +29 -0
- data/lib/rapuncel/core_ext/float.rb +11 -0
- data/lib/rapuncel/core_ext/hash.rb +32 -0
- data/lib/rapuncel/core_ext/integer.rb +11 -0
- data/lib/rapuncel/core_ext/nil.rb +7 -0
- data/lib/rapuncel/core_ext/object.rb +49 -0
- data/lib/rapuncel/core_ext/string.rb +12 -0
- data/lib/rapuncel/core_ext/symbol.rb +7 -0
- data/lib/rapuncel/core_ext/time.rb +14 -0
- data/lib/rapuncel/proxy.rb +82 -0
- data/lib/rapuncel/request.rb +49 -0
- data/lib/rapuncel/response.rb +92 -0
- data/rapuncel-0.0.1.preview.gem +0 -0
- data/rapuncel.gemspec +22 -0
- data/test/functional/client_test.rb +54 -0
- data/test/functional_test_helper.rb +13 -0
- data/test/test_helper.rb +38 -0
- data/test/test_server.rb +28 -0
- data/test/unit/array_test.rb +96 -0
- data/test/unit/boolean_test.rb +34 -0
- data/test/unit/connection_test.rb +17 -0
- data/test/unit/float_test.rb +23 -0
- data/test/unit/hash_test.rb +54 -0
- data/test/unit/int_test.rb +27 -0
- data/test/unit/nil_test.rb +16 -0
- data/test/unit/object_test.rb +83 -0
- data/test/unit/proxy_test.rb +52 -0
- data/test/unit/request_test.rb +34 -0
- data/test/unit/response_test.rb +100 -0
- data/test/unit/string_test.rb +40 -0
- data/test/unit/time_test.rb +23 -0
- metadata +154 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ProxyTest < ActiveSupport::TestCase
|
4
|
+
class TestClient
|
5
|
+
def call_to_ruby request, *args
|
6
|
+
[request] + args
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
test "Proxy should still provide __ methods" do
|
11
|
+
t = Object.new
|
12
|
+
t.expects(:call_to_ruby).never
|
13
|
+
|
14
|
+
p = Rapuncel::Proxy.new t
|
15
|
+
|
16
|
+
p.__inspect__
|
17
|
+
p.__tap__ {}
|
18
|
+
p.__freeze__
|
19
|
+
end
|
20
|
+
|
21
|
+
test "Proxy should delegate standard Object instance methods to Client" do
|
22
|
+
t = TestClient.new
|
23
|
+
|
24
|
+
p = Rapuncel::Proxy.new t
|
25
|
+
request = p.inspect
|
26
|
+
|
27
|
+
assert_equal 'inspect', request.first
|
28
|
+
end
|
29
|
+
|
30
|
+
test "Proxy should delegate non-existing methods to Client" do
|
31
|
+
t = TestClient.new
|
32
|
+
|
33
|
+
p = Rapuncel::Proxy.new t
|
34
|
+
request = p.whatever 'arg1', 'foobar', 1234
|
35
|
+
|
36
|
+
assert_equal 'whatever', request.first
|
37
|
+
assert_equal ['arg1', 'foobar', 1234], request[1..-1]
|
38
|
+
end
|
39
|
+
|
40
|
+
test "Proxy should dynamically define methods as soon as needed" do
|
41
|
+
t = TestClient.new
|
42
|
+
|
43
|
+
p = Rapuncel::Proxy.new t
|
44
|
+
|
45
|
+
assert p.respond_to?('foobar')
|
46
|
+
assert !Rapuncel::Proxy.instance_methods.include?('foobar')
|
47
|
+
|
48
|
+
p.foobar
|
49
|
+
|
50
|
+
assert Rapuncel::Proxy.instance_methods.include?('foobar')
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RequestTest < ActiveSupport::TestCase
|
4
|
+
def get_test_request
|
5
|
+
Rapuncel::Request.new 'test_method', "one argument", "another"
|
6
|
+
end
|
7
|
+
|
8
|
+
test "Serialized request shuold have xml version=1.0" do
|
9
|
+
xml = get_test_request.to_xml_rpc
|
10
|
+
|
11
|
+
assert xml.match(/<\?xml version=['"]1.0/)
|
12
|
+
end
|
13
|
+
|
14
|
+
test "Serialized request should have 1 methodCall tag" do
|
15
|
+
xml = get_test_request.to_xml_rpc
|
16
|
+
assert_select xml, '/methodCall', 1
|
17
|
+
end
|
18
|
+
|
19
|
+
test "Serialized request should contain methodName" do
|
20
|
+
xml = get_test_request.to_xml_rpc
|
21
|
+
|
22
|
+
assert_select xml, '/methodCall/methodName', 'test_method'
|
23
|
+
end
|
24
|
+
|
25
|
+
test "Serialized request should contain params" do
|
26
|
+
xml = get_test_request.to_xml_rpc
|
27
|
+
|
28
|
+
assert_select xml, '/methodCall/params', 1
|
29
|
+
assert_select xml, '/methodCall/params/param/value', 2
|
30
|
+
|
31
|
+
assert_select xml, '/methodCall/params/param/value', 'one argument', 1
|
32
|
+
assert_select xml, '/methodCall/params/param/value', 'another', 1
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
class ResponseTest < ActiveSupport::TestCase
|
5
|
+
class MockReponse
|
6
|
+
attr_accessor :body, :code
|
7
|
+
|
8
|
+
def initialize body, success = true, code = 200
|
9
|
+
@body, @success, @code = body, success, code
|
10
|
+
end
|
11
|
+
|
12
|
+
def success?
|
13
|
+
@success
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'Response should not be an Array' do
|
18
|
+
mock = MockReponse.new <<-XML
|
19
|
+
<?xml version='1.0'?>
|
20
|
+
<methodResponse>
|
21
|
+
<params>
|
22
|
+
<param>
|
23
|
+
<value>
|
24
|
+
<string>foo foo foo</string>
|
25
|
+
</value>
|
26
|
+
</param>
|
27
|
+
</params>
|
28
|
+
</methodResponse>
|
29
|
+
XML
|
30
|
+
|
31
|
+
r = Rapuncel::Response.new mock
|
32
|
+
|
33
|
+
|
34
|
+
assert r.success?
|
35
|
+
assert !r.fault?
|
36
|
+
assert !r.error?
|
37
|
+
assert_equal "foo foo foo", r.to_ruby
|
38
|
+
assert_equal "foo foo foo", r.result
|
39
|
+
end
|
40
|
+
|
41
|
+
test "Response should handle faults" do
|
42
|
+
mock = MockReponse.new <<-XML
|
43
|
+
<?xml version='1.0'?>
|
44
|
+
<methodResponse>
|
45
|
+
<fault>
|
46
|
+
<value>
|
47
|
+
<struct>
|
48
|
+
<member>
|
49
|
+
<name>
|
50
|
+
faultCode
|
51
|
+
</name>
|
52
|
+
<value>
|
53
|
+
<int>
|
54
|
+
42
|
55
|
+
</int>
|
56
|
+
</value>
|
57
|
+
</member>
|
58
|
+
<member>
|
59
|
+
<name>
|
60
|
+
faultString
|
61
|
+
</name>
|
62
|
+
<value>
|
63
|
+
<string>
|
64
|
+
Don't panic.
|
65
|
+
</string>
|
66
|
+
</value>
|
67
|
+
</member>
|
68
|
+
</struct>
|
69
|
+
</value>
|
70
|
+
</fault>
|
71
|
+
</methodResponse>
|
72
|
+
XML
|
73
|
+
|
74
|
+
r = Rapuncel::Response.new mock
|
75
|
+
|
76
|
+
assert r.fault?
|
77
|
+
assert !r.success?
|
78
|
+
assert !r.error?
|
79
|
+
|
80
|
+
assert_kind_of Rapuncel::Response::Fault, r.to_ruby
|
81
|
+
assert_kind_of Rapuncel::Response::Fault, r.fault
|
82
|
+
|
83
|
+
assert_equal 42, r.fault.code
|
84
|
+
end
|
85
|
+
|
86
|
+
test "Response should handle errors" do
|
87
|
+
mock = MockReponse.new "Not Found", false, 404
|
88
|
+
|
89
|
+
r = Rapuncel::Response.new mock
|
90
|
+
|
91
|
+
assert r.error?
|
92
|
+
assert !r.fault?
|
93
|
+
assert !r.success?
|
94
|
+
|
95
|
+
assert_kind_of Rapuncel::Response::Error, r.to_ruby
|
96
|
+
assert_kind_of Rapuncel::Response::Error, r.error
|
97
|
+
|
98
|
+
assert_equal 404, r.error.code
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
class StringTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
|
7
|
+
test "A string should simply be written between two <string></string> tags" do
|
8
|
+
str = "blabla"
|
9
|
+
xml = str.to_xml_rpc
|
10
|
+
assert_select xml, '/string', 1
|
11
|
+
assert_select xml, '/string', str
|
12
|
+
end
|
13
|
+
|
14
|
+
test "A symbol should simply be written between two <string></string> tags" do
|
15
|
+
sym = :blabla
|
16
|
+
xml = sym.to_xml_rpc
|
17
|
+
assert_select xml, '/string', 1
|
18
|
+
assert_select xml, '/string', sym.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
test "A string to_xml_rpc from_xml_rpc should be itself, even with whitespace" do #weird characters too?? or do we need base64 for that
|
23
|
+
str = "yabba dabba doo! \t"
|
24
|
+
xml = str.to_xml_rpc
|
25
|
+
|
26
|
+
|
27
|
+
xml_node = Nokogiri::XML(xml).children.first
|
28
|
+
|
29
|
+
assert_equal str, String.from_xml_rpc(xml_node)
|
30
|
+
end
|
31
|
+
|
32
|
+
test "CRLF and CR should be normalized" do
|
33
|
+
str = "one\r\ntwo\rthree\nfour"
|
34
|
+
xml = str.to_xml_rpc
|
35
|
+
|
36
|
+
xml_node = Nokogiri::XML(xml).children.first
|
37
|
+
|
38
|
+
assert_equal "one\ntwo\nthree\nfour", String.from_xml_rpc(xml_node)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TimeTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test "Time.now should be written down in the iso 8601 standard between dateTime.iso8601 tags" do
|
6
|
+
t = Time.now
|
7
|
+
xml = t.to_xml_rpc
|
8
|
+
|
9
|
+
assert_select xml, '/dateTime.iso8601', 1
|
10
|
+
assert_select xml, '/dateTime.iso8601', t.iso8601
|
11
|
+
end
|
12
|
+
|
13
|
+
test "A time converted to xml and reparsed should be equal to its starting point" do
|
14
|
+
t = Time.now
|
15
|
+
xml = t.to_xml_rpc
|
16
|
+
|
17
|
+
xml_node = Nokogiri::XML(xml).children.first
|
18
|
+
|
19
|
+
reparsed = Time.from_xml_rpc(xml_node)
|
20
|
+
|
21
|
+
assert_equal t.to_i, reparsed.to_i # can't use assert_equal here! need to find a decent equality operator!!
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rapuncel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: -1851332166
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
- alpha
|
11
|
+
version: 0.0.1.alpha
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- Michael Eickenberg
|
15
|
+
- Marian Theisen
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2010-12-02 00:00:00 +01:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: nokogiri
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 3
|
32
|
+
segments:
|
33
|
+
- 0
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: activesupport
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
46
|
+
segments:
|
47
|
+
- 3
|
48
|
+
- 0
|
49
|
+
- 0
|
50
|
+
version: 3.0.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: mocha
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
description: Rapuncel is a simple XML-RPC Client based on Nokogiri, thus provides a fast and easy way to interact with XML-RPC services.
|
68
|
+
email: marian@cice-online.net
|
69
|
+
executables: []
|
70
|
+
|
71
|
+
extensions: []
|
72
|
+
|
73
|
+
extra_rdoc_files: []
|
74
|
+
|
75
|
+
files:
|
76
|
+
- lib/rapuncel/adapters/net_http_adapter.rb
|
77
|
+
- lib/rapuncel/base.rb
|
78
|
+
- lib/rapuncel/client.rb
|
79
|
+
- lib/rapuncel/connection.rb
|
80
|
+
- lib/rapuncel/core_ext/array.rb
|
81
|
+
- lib/rapuncel/core_ext/big_decimal.rb
|
82
|
+
- lib/rapuncel/core_ext/boolean.rb
|
83
|
+
- lib/rapuncel/core_ext/float.rb
|
84
|
+
- lib/rapuncel/core_ext/hash.rb
|
85
|
+
- lib/rapuncel/core_ext/integer.rb
|
86
|
+
- lib/rapuncel/core_ext/nil.rb
|
87
|
+
- lib/rapuncel/core_ext/object.rb
|
88
|
+
- lib/rapuncel/core_ext/string.rb
|
89
|
+
- lib/rapuncel/core_ext/symbol.rb
|
90
|
+
- lib/rapuncel/core_ext/time.rb
|
91
|
+
- lib/rapuncel/proxy.rb
|
92
|
+
- lib/rapuncel/request.rb
|
93
|
+
- lib/rapuncel/response.rb
|
94
|
+
- lib/rapuncel.rb
|
95
|
+
- MIT-LICENSE
|
96
|
+
- Rakefile
|
97
|
+
- rapuncel-0.0.1.preview.gem
|
98
|
+
- rapuncel.gemspec
|
99
|
+
- README.md
|
100
|
+
- test/functional/client_test.rb
|
101
|
+
- test/functional_test_helper.rb
|
102
|
+
- test/test_helper.rb
|
103
|
+
- test/test_server.rb
|
104
|
+
- test/unit/array_test.rb
|
105
|
+
- test/unit/boolean_test.rb
|
106
|
+
- test/unit/connection_test.rb
|
107
|
+
- test/unit/float_test.rb
|
108
|
+
- test/unit/hash_test.rb
|
109
|
+
- test/unit/int_test.rb
|
110
|
+
- test/unit/nil_test.rb
|
111
|
+
- test/unit/object_test.rb
|
112
|
+
- test/unit/proxy_test.rb
|
113
|
+
- test/unit/request_test.rb
|
114
|
+
- test/unit/response_test.rb
|
115
|
+
- test/unit/string_test.rb
|
116
|
+
- test/unit/time_test.rb
|
117
|
+
has_rdoc: true
|
118
|
+
homepage: http://github.com/cice/rapuncel
|
119
|
+
licenses: []
|
120
|
+
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ">"
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
hash: 25
|
141
|
+
segments:
|
142
|
+
- 1
|
143
|
+
- 3
|
144
|
+
- 1
|
145
|
+
version: 1.3.1
|
146
|
+
requirements: []
|
147
|
+
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 1.3.7
|
150
|
+
signing_key:
|
151
|
+
specification_version: 3
|
152
|
+
summary: Simple XML-RPC Client
|
153
|
+
test_files: []
|
154
|
+
|