rc-rest 2.2.1 → 3.0.0

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.
Binary file
@@ -1,3 +1,8 @@
1
+ = 3.0.0
2
+
3
+ * Upgrade to Nokogiri from REXML. This is incompatible with 2.x and older.
4
+ Thanks Aaron Patterson!
5
+
1
6
  = 2.2.1
2
7
 
3
8
  * Turn IOError into RCRest::CommunicationError for #post and #post_multipart.
data/README.txt CHANGED
@@ -1,16 +1,12 @@
1
1
  = rc-rest
2
2
 
3
- Rubyforge Project:
3
+ * http://seattlerb.rubyforge.org/rc-rest
4
+ * http://rubyforge.org/projects/rctools/
4
5
 
5
- http://rubyforge.org/projects/rctools/
6
+ == DESCRIPTION:
6
7
 
7
- Documentation:
8
-
9
- http://dev.robotcoop.com/Libraries/rc-rest/
10
-
11
- == About
12
-
13
- This is an abstract class for creating wrappers for REST web service APIs.
8
+ Robot Co-op REST web services base class. This library makes it easy to
9
+ implement REST-like web services APIs.
14
10
 
15
11
  == Installing rc-rest
16
12
 
@@ -30,3 +26,7 @@ RCRest#get and RCRest#make_url now accept a method argument as the
30
26
  first parameter. To use 2.x, pass the last component of the path to
31
27
  RCRest#get or RCRest#make_url.
32
28
 
29
+ == Upgrading from 2.x
30
+
31
+ RCRest now uses Nokogiri instead of REXML.
32
+
data/Rakefile CHANGED
@@ -1,17 +1,12 @@
1
1
  require 'hoe'
2
- require './lib/rc_rest'
3
2
 
4
- Hoe.new 'rc-rest', RCRest::VERSION do |p|
5
- p.summary = 'Robot Co-op REST web services base class'
6
- p.description = 'This library makes it easy to implement REST-like web services APIs.'
7
- p.author = 'Eric Hodel'
8
- p.email = 'drbrain@segment7.net'
9
- p.url = "http://seattlerb.rubyforge.org/rc-rest"
10
- p.rubyforge_name = 'seattlerb'
3
+ Hoe.plugin :seattlerb
4
+ Hoe.spec 'rc-rest' do |p|
5
+ self.rubyforge_name = 'seattlerb'
6
+ developer 'Eric Hodel', 'drbrain@segment7.net'
11
7
 
12
- p.changes = File.read('History.txt').scan(/\A(=.*?)^=/m).first.first
13
-
14
- p.extra_deps << ['ZenTest', '>= 3.4.2']
8
+ extra_deps << ['nokogiri', '>= 1.3.1']
9
+ extra_deps << ['minitest', '~> 1.4']
15
10
  end
16
11
 
17
12
  # vim: syntax=Ruby
@@ -1,6 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'open-uri'
3
- require 'rexml/document'
3
+ require 'nokogiri'
4
4
 
5
5
  ##
6
6
  # Abstract class for implementing REST APIs.
@@ -49,7 +49,7 @@ class RCRest
49
49
  ##
50
50
  # You are using this version of RCRest
51
51
 
52
- VERSION = '2.2.1'
52
+ VERSION = '3.0.0'
53
53
 
54
54
  ##
55
55
  # Abstract Error class.
@@ -88,8 +88,8 @@ class RCRest
88
88
  end
89
89
 
90
90
  ##
91
- # Must extract and raise an error from +xml+, an REXML::Document, if any.
92
- # Must return if no error could be found.
91
+ # Must extract and raise an error from +xml+, an Nokogiri::XML::Document, if
92
+ # any. Must return if no error could be found.
93
93
 
94
94
  def check_error(xml)
95
95
  raise NotImplementedError
@@ -100,7 +100,7 @@ class RCRest
100
100
 
101
101
  params.each do |k,v|
102
102
  if v.respond_to? :each and not String === v then
103
- v.each { |v| expanded_params << [k, v] }
103
+ v.each { |s| expanded_params << [k, s] }
104
104
  else
105
105
  expanded_params << [k, v]
106
106
  end
@@ -111,27 +111,27 @@ class RCRest
111
111
 
112
112
  ##
113
113
  # Performs a GET request for method +method+ with +params+. Calls
114
- # #parse_response on the concrete class with an REXML::Document instance and
115
- # returns its result.
114
+ # #parse_response on the concrete class with an Nokogiri::XML::Document
115
+ # instance and returns its result.
116
116
 
117
117
  def get(method, params = {})
118
118
  url = make_url method, params
119
119
 
120
120
  url.open do |xml|
121
- res = REXML::Document.new xml.read
121
+ res = Nokogiri::XML(xml, nil, nil, 0)
122
122
 
123
123
  check_error res
124
124
 
125
125
  return parse_response(res)
126
126
  end
127
127
  rescue IOError, SystemCallError, SocketError, Timeout::Error,
128
- REXML::ParseException => e
128
+ Nokogiri::XML::SyntaxError => e
129
129
  raise CommunicationError.new(e)
130
130
  rescue OpenURI::HTTPError => e
131
131
  begin
132
- xml = REXML::Document.new e.io.read
132
+ xml = Nokogiri::XML(e.io, nil, nil, 0)
133
133
  check_error xml
134
- rescue REXML::ParseException => e
134
+ rescue Nokogiri::XML::SyntaxError => e
135
135
  end
136
136
  new_e = CommunicationError.new e
137
137
  new_e.message << "\n\nunhandled error:\n#{xml.to_s}"
@@ -203,8 +203,8 @@ class RCRest
203
203
  end
204
204
 
205
205
  ##
206
- # Must parse results from +xml+, an REXML::Document, into something sensible
207
- # for the API.
206
+ # Must parse results from +xml+, an Nokogiri::XML::Document, into something
207
+ # sensible for the API.
208
208
 
209
209
  def parse_response(xml)
210
210
  raise NotImplementedError
@@ -212,8 +212,8 @@ class RCRest
212
212
 
213
213
  ##
214
214
  # Performs a POST request for method +method+ with +params+. Calls
215
- # #parse_response on the concrete class with an REXML::Document instance and
216
- # returns its result.
215
+ # #parse_response on the concrete class with an Nokogiri::XML::Document
216
+ # instance and returns its result.
217
217
 
218
218
  def post(method, params = {})
219
219
  url = make_url method, params
@@ -228,16 +228,16 @@ class RCRest
228
228
  http.request req
229
229
  end
230
230
 
231
- xml = REXML::Document.new res.body
231
+ xml = Nokogiri::XML(res.body, nil, nil, 0)
232
232
 
233
233
  check_error xml
234
234
 
235
235
  parse_response xml
236
236
  rescue SystemCallError, SocketError, Timeout::Error, IOError,
237
- REXML::ParseException => e
237
+ Nokogiri::XML::SyntaxError => e
238
238
  raise CommunicationError.new(e)
239
239
  rescue Net::HTTPError => e
240
- xml = REXML::Document.new e.res.body
240
+ xml = Nokogiri::XML(e.res.body) { |cfg| cfg.strict }
241
241
  check_error xml
242
242
  raise CommunicationError.new(e)
243
243
  end
@@ -245,7 +245,7 @@ class RCRest
245
245
  ##
246
246
  # Performs a POST request for method +method+ with +params+, submitting a
247
247
  # multipart form. Calls #parse_response on the concrete class with an
248
- # REXML::Document instance and returns its result.
248
+ # Nokogiri::XML::Document instance and returns its result.
249
249
 
250
250
  def post_multipart(method, params = {})
251
251
  url = make_url method, {}
@@ -261,16 +261,16 @@ class RCRest
261
261
  http.request req
262
262
  end
263
263
 
264
- xml = REXML::Document.new res.body
264
+ xml = Nokogiri::XML(res.body, nil, nil, 0)
265
265
 
266
266
  check_error xml
267
267
 
268
268
  parse_response xml
269
269
  rescue SystemCallError, SocketError, Timeout::Error, IOError,
270
- REXML::ParseException => e
270
+ Nokogiri::XML::SyntaxError => e
271
271
  raise CommunicationError.new(e)
272
272
  rescue Net::HTTPError => e
273
- xml = REXML::Document.new e.res.body
273
+ xml = Nokogiri::XML(e.res.body, nil, nil, 0)
274
274
  check_error xml
275
275
  raise CommunicationError.new(e)
276
276
  end
@@ -2,6 +2,9 @@ require 'net/http'
2
2
 
3
3
  class Net::HTTPResponse
4
4
 
5
+ undef_method :body if method_defined? :body
6
+ undef_method :body= if method_defined? :body=
7
+
5
8
  ##
6
9
  # Setter for body content
7
10
 
@@ -1,6 +1,5 @@
1
- require 'test/unit'
2
1
  require 'rubygems'
3
- require 'test/zentest_assertions'
2
+ require 'minitest/autorun'
4
3
  require 'rc_rest/uri_stub'
5
4
  require 'rc_rest/net_http_stub'
6
5
  require 'rc_rest'
@@ -14,7 +13,7 @@ class FakeService < RCRest
14
13
  end
15
14
 
16
15
  def check_error(xml)
17
- raise Error, xml.elements['error'].text if xml.elements['error']
16
+ raise Error, xml.at('error').text if xml.at('error')
18
17
  end
19
18
 
20
19
  def do_get
@@ -35,7 +34,7 @@ class FakeService < RCRest
35
34
 
36
35
  end
37
36
 
38
- class TestFakeService < Test::Unit::TestCase
37
+ class TestFakeService < MiniTest::Unit::TestCase
39
38
 
40
39
  def setup
41
40
  URI::HTTP.responses = []
@@ -51,7 +50,7 @@ class TestFakeService < Test::Unit::TestCase
51
50
  end
52
51
 
53
52
  def test_check_error
54
- xml = REXML::Document.new '<error>you broked it</error>'
53
+ xml = Nokogiri::XML '<error>you broked it</error>'
55
54
  @fs.check_error xml
56
55
 
57
56
  rescue FakeService::Error => e
@@ -62,7 +61,7 @@ class TestFakeService < Test::Unit::TestCase
62
61
  end
63
62
 
64
63
  def test_do_get
65
- xml = '<result>stuff</result>'
64
+ xml = "<?xml version=\"1.0\"?>\n<result>stuff</result>\n"
66
65
  URI::HTTP.responses << xml
67
66
 
68
67
  result = @fs.do_get
@@ -75,7 +74,7 @@ class TestFakeService < Test::Unit::TestCase
75
74
  xml = '<result>stuff</result><extra/>'
76
75
  URI::HTTP.responses << xml
77
76
 
78
- assert_raise RCRest::CommunicationError do @fs.do_get end
77
+ assert_raises RCRest::CommunicationError do @fs.do_get end
79
78
  end
80
79
 
81
80
  def test_do_get_error_400
@@ -84,7 +83,7 @@ class TestFakeService < Test::Unit::TestCase
84
83
  raise OpenURI::HTTPError.new('400 Bad Request', StringIO.new(xml))
85
84
  end
86
85
 
87
- assert_raise FakeService::Error do @fs.do_get end
86
+ assert_raises FakeService::Error do @fs.do_get end
88
87
  end
89
88
 
90
89
  def test_do_get_error_400_bad_xml
@@ -93,25 +92,26 @@ class TestFakeService < Test::Unit::TestCase
93
92
  raise OpenURI::HTTPError.new('400 Bad Request', StringIO.new(xml))
94
93
  end
95
94
 
96
- assert_raise RCRest::CommunicationError do @fs.do_get end
95
+ assert_raises RCRest::CommunicationError do @fs.do_get end
97
96
  end
98
97
 
99
98
  def test_do_get_error_unhandled
100
99
  URI::HTTP.responses << proc do
101
- xml = '<other_error>you did the bad thing</other_error>'
100
+ xml = "<?xml version=\"1.0\"?>\n<other_error>you did the bad thing</other_error>\n"
102
101
  raise OpenURI::HTTPError.new('500 Internal Server Error', StringIO.new(xml))
103
102
  end
104
103
 
105
- e = assert_raise RCRest::CommunicationError do @fs.do_get end
104
+ e = assert_raises RCRest::CommunicationError do @fs.do_get end
106
105
 
107
106
  expected = <<-EOF.strip
108
107
  Communication error: 500 Internal Server Error(OpenURI::HTTPError)
109
108
 
110
109
  unhandled error:
110
+ <?xml version=\"1.0\"?>
111
111
  <other_error>you did the bad thing</other_error>
112
112
  EOF
113
113
 
114
- assert_equal expected, e.message
114
+ assert_equal expected, e.message.strip
115
115
  end
116
116
 
117
117
  def test_do_get_eof_error
@@ -120,11 +120,11 @@ unhandled error:
120
120
  raise EOFError, 'end of file reached'
121
121
  end
122
122
 
123
- assert_raise RCRest::CommunicationError do @fs.do_get end
123
+ assert_raises RCRest::CommunicationError do @fs.do_get end
124
124
  end
125
125
 
126
126
  def test_do_post
127
- xml = '<result>stuff</result>'
127
+ xml = "<?xml version=\"1.0\"?>\n<result>stuff</result>\n"
128
128
  Net::HTTP.responses << xml
129
129
 
130
130
  result = @fs.do_post
@@ -143,7 +143,7 @@ unhandled error:
143
143
  xml = '<result>stuff</result><extra/>'
144
144
  Net::HTTP.responses << xml
145
145
 
146
- assert_raise RCRest::CommunicationError do @fs.do_post end
146
+ assert_raises RCRest::CommunicationError do @fs.do_post end
147
147
  end
148
148
 
149
149
  def test_do_post_eof_error
@@ -151,11 +151,11 @@ unhandled error:
151
151
  raise IOError, 'end of file reached'
152
152
  end
153
153
 
154
- assert_raise RCRest::CommunicationError do @fs.do_post end
154
+ assert_raises RCRest::CommunicationError do @fs.do_post end
155
155
  end
156
156
 
157
157
  def test_do_post_multipart
158
- xml = '<result>stuff</result>'
158
+ xml = "<?xml version=\"1.0\"?>\n<result>stuff</result>\n"
159
159
  Net::HTTP.responses << xml
160
160
 
161
161
  result = @fs.do_post_multipart
@@ -183,22 +183,22 @@ value\r
183
183
  raise EOFError, 'end of file reached'
184
184
  end
185
185
 
186
- assert_raise RCRest::CommunicationError do @fs.do_post_multipart end
186
+ assert_raises RCRest::CommunicationError do @fs.do_post_multipart end
187
187
  end
188
188
 
189
189
  def test_do_post_multipart_bad_xml
190
190
  xml = '<result>stuff</result><extra/>'
191
191
  Net::HTTP.responses << xml
192
192
 
193
- assert_raise RCRest::CommunicationError do @fs.do_post_multipart end
193
+ assert_raises RCRest::CommunicationError do @fs.do_post_multipart end
194
194
  end
195
195
 
196
196
  end
197
197
 
198
- class TestRCRest < Test::Unit::TestCase
198
+ class TestRCRest < MiniTest::Unit::TestCase
199
199
 
200
200
  def test_initialize
201
- e = assert_raise NotImplementedError do
201
+ e = assert_raises NotImplementedError do
202
202
  RCRest.new
203
203
  end
204
204
 
@@ -207,7 +207,7 @@ class TestRCRest < Test::Unit::TestCase
207
207
 
208
208
  def test_check_error
209
209
  r = RCRest.allocate
210
- assert_raise NotImplementedError do r.check_error nil end
210
+ assert_raises NotImplementedError do r.check_error nil end
211
211
  end
212
212
 
213
213
  def test_make_multipart
@@ -261,7 +261,7 @@ y z\r
261
261
 
262
262
  def test_parse_response
263
263
  r = RCRest.allocate
264
- assert_raise NotImplementedError do r.parse_response nil end
264
+ assert_raises NotImplementedError do r.parse_response nil end
265
265
  end
266
266
 
267
267
  end
metadata CHANGED
@@ -1,71 +1,120 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.1
3
- specification_version: 1
4
2
  name: rc-rest
5
3
  version: !ruby/object:Gem::Version
6
- version: 2.2.1
7
- date: 2007-01-31 00:00:00 -08:00
8
- summary: Robot Co-op REST web services base class
9
- require_paths:
10
- - lib
11
- email: drbrain@segment7.net
12
- homepage: http://seattlerb.rubyforge.org/rc-rest
13
- rubyforge_project: seattlerb
14
- description: This library makes it easy to implement REST-like web services APIs.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 3.0.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Eric Hodel
31
- files:
32
- - History.txt
33
- - LICENSE.txt
34
- - Manifest.txt
35
- - README.txt
36
- - Rakefile
37
- - lib/rc_rest.rb
38
- - lib/rc_rest/net_http_stub.rb
39
- - lib/rc_rest/uri_stub.rb
40
- - test/test_rc_rest.rb
41
- test_files:
42
- - test/test_rc_rest.rb
43
- rdoc_options: []
44
-
45
- extra_rdoc_files: []
46
-
47
- executables: []
48
-
49
- extensions: []
50
-
51
- requirements: []
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
14
+ YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
15
+ ZXQwHhcNMDcxMjIxMDIwNDE0WhcNMDgxMjIwMDIwNDE0WjBBMRAwDgYDVQQDDAdk
16
+ cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
17
+ FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76
18
+ LV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J
19
+ U5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm
20
+ Gj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY
21
+ mUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd
22
+ g62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh
23
+ sCANiQ8BAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
24
+ BBS5k4Z75VSpdM0AclG2UvzFA/VW5DANBgkqhkiG9w0BAQUFAAOCAQEAHagT4lfX
25
+ kP/hDaiwGct7XPuVGbrOsKRVD59FF5kETBxEc9UQ1clKWngf8JoVuEoKD774dW19
26
+ bU0GOVWO+J6FMmT/Cp7nuFJ79egMf/gy4gfUfQMuvfcr6DvZUPIs9P/TlK59iMYF
27
+ DIOQ3DxdF3rMzztNUCizN4taVscEsjCcgW6WkUJnGdqlu3OHWpQxZBJkBTjPCoc6
28
+ UW6on70SFPmAy/5Cq0OJNGEWBfgD9q7rrs/X8GGwUWqXb85RXnUVi/P8Up75E0ag
29
+ 14jEc90kN+C7oI/AGCBN0j6JnEtYIEJZibjjDJTSMWlUKKkj30kq7hlUC2CepJ4v
30
+ x52qPcexcYZR7w==
31
+ -----END CERTIFICATE-----
52
32
 
33
+ date: 2009-07-10 00:00:00 -07:00
34
+ default_executable:
53
35
  dependencies:
54
36
  - !ruby/object:Gem::Dependency
55
- name: ZenTest
37
+ name: nokogiri
38
+ type: :runtime
56
39
  version_requirement:
57
- version_requirements: !ruby/object:Gem::Version::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
58
41
  requirements:
59
42
  - - ">="
60
43
  - !ruby/object:Gem::Version
61
- version: 3.4.2
44
+ version: 1.3.1
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ type: :runtime
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: "1.4"
62
55
  version:
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: hoe
58
+ type: :development
65
59
  version_requirement:
66
- version_requirements: !ruby/object:Gem::Version::Requirement
60
+ version_requirements: !ruby/object:Gem::Requirement
67
61
  requirements:
68
62
  - - ">="
69
63
  - !ruby/object:Gem::Version
70
- version: 1.1.7
64
+ version: 2.3.2
71
65
  version:
66
+ description: |-
67
+ Robot Co-op REST web services base class. This library makes it easy to
68
+ implement REST-like web services APIs.
69
+ email:
70
+ - drbrain@segment7.net
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - History.txt
77
+ - LICENSE.txt
78
+ - Manifest.txt
79
+ - README.txt
80
+ files:
81
+ - History.txt
82
+ - LICENSE.txt
83
+ - Manifest.txt
84
+ - README.txt
85
+ - Rakefile
86
+ - lib/rc_rest.rb
87
+ - lib/rc_rest/net_http_stub.rb
88
+ - lib/rc_rest/uri_stub.rb
89
+ - test/test_rc_rest.rb
90
+ has_rdoc: true
91
+ homepage: http://seattlerb.rubyforge.org/rc-rest
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --main
97
+ - README.txt
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ version:
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: "0"
111
+ version:
112
+ requirements: []
113
+
114
+ rubyforge_project: seattlerb
115
+ rubygems_version: 1.3.4
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Robot Co-op REST web services base class
119
+ test_files:
120
+ - test/test_rc_rest.rb
Binary file