wadl 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README +8 -8
- data/Rakefile +17 -10
- data/lib/wadl.rb +17 -2
- data/lib/wadl/address.rb +1 -3
- data/lib/wadl/application.rb +1 -2
- data/lib/wadl/cheap_schema.rb +1 -8
- data/lib/wadl/cli.rb +62 -97
- data/lib/wadl/documentation.rb +1 -3
- data/lib/wadl/fault.rb +1 -3
- data/lib/wadl/fault_format.rb +4 -6
- data/lib/wadl/has_docs.rb +1 -3
- data/lib/wadl/http_method.rb +11 -54
- data/lib/wadl/http_request.rb +139 -0
- data/lib/wadl/http_response.rb +44 -0
- data/lib/wadl/link.rb +1 -3
- data/lib/wadl/option.rb +1 -3
- data/lib/wadl/param.rb +2 -2
- data/lib/wadl/representation_container.rb +1 -3
- data/lib/wadl/representation_format.rb +6 -5
- data/lib/wadl/request_format.rb +1 -3
- data/lib/wadl/resource.rb +2 -4
- data/lib/wadl/resource_and_address.rb +1 -2
- data/lib/wadl/resource_container.rb +1 -3
- data/lib/wadl/resource_type.rb +1 -3
- data/lib/wadl/resources.rb +1 -3
- data/lib/wadl/response.rb +1 -3
- data/lib/wadl/response_format.rb +4 -9
- data/lib/wadl/uri_parts.rb +1 -3
- data/lib/wadl/version.rb +2 -2
- data/lib/wadl/xml_representation.rb +1 -2
- data/test/wadl_test.rb +76 -37
- metadata +87 -33
data/lib/wadl/request_format.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# A component of wadl, the super cheap Ruby WADL client. #
|
5
5
|
# #
|
6
6
|
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
-
# Copyright (C) 2010-
|
7
|
+
# Copyright (C) 2010-2014 Jens Wille #
|
8
8
|
# #
|
9
9
|
# Authors: #
|
10
10
|
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
@@ -26,8 +26,6 @@
|
|
26
26
|
###############################################################################
|
27
27
|
#++
|
28
28
|
|
29
|
-
require 'wadl'
|
30
|
-
|
31
29
|
module WADL
|
32
30
|
|
33
31
|
class RequestFormat < HasDocs
|
data/lib/wadl/resource.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# A component of wadl, the super cheap Ruby WADL client. #
|
5
5
|
# #
|
6
6
|
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
-
# Copyright (C) 2010-
|
7
|
+
# Copyright (C) 2010-2014 Jens Wille #
|
8
8
|
# #
|
9
9
|
# Authors: #
|
10
10
|
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
@@ -27,7 +27,6 @@
|
|
27
27
|
#++
|
28
28
|
|
29
29
|
require 'set'
|
30
|
-
require 'wadl'
|
31
30
|
|
32
31
|
module WADL
|
33
32
|
|
@@ -72,8 +71,7 @@ module WADL
|
|
72
71
|
# :access_token
|
73
72
|
# :token_secret
|
74
73
|
def with_oauth(*args)
|
75
|
-
resource_and_address.auth(
|
76
|
-
"#{HTTPMethod::OAUTH_PREFIX}#{args.to_yaml}")
|
74
|
+
resource_and_address.auth(*HTTPRequest.oauth_header(args))
|
77
75
|
end
|
78
76
|
|
79
77
|
def uri(args = {}, working_address = nil)
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# A component of wadl, the super cheap Ruby WADL client. #
|
5
5
|
# #
|
6
6
|
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
-
# Copyright (C) 2010-
|
7
|
+
# Copyright (C) 2010-2014 Jens Wille #
|
8
8
|
# #
|
9
9
|
# Authors: #
|
10
10
|
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
@@ -27,7 +27,6 @@
|
|
27
27
|
#++
|
28
28
|
|
29
29
|
require 'delegate'
|
30
|
-
require 'wadl'
|
31
30
|
|
32
31
|
module WADL
|
33
32
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# A component of wadl, the super cheap Ruby WADL client. #
|
5
5
|
# #
|
6
6
|
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
-
# Copyright (C) 2010-
|
7
|
+
# Copyright (C) 2010-2014 Jens Wille #
|
8
8
|
# #
|
9
9
|
# Authors: #
|
10
10
|
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
@@ -26,8 +26,6 @@
|
|
26
26
|
###############################################################################
|
27
27
|
#++
|
28
28
|
|
29
|
-
require 'wadl'
|
30
|
-
|
31
29
|
module WADL
|
32
30
|
|
33
31
|
# A mixin for objects that contain resources. If you include this, be
|
data/lib/wadl/resource_type.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# A component of wadl, the super cheap Ruby WADL client. #
|
5
5
|
# #
|
6
6
|
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
-
# Copyright (C) 2010-
|
7
|
+
# Copyright (C) 2010-2014 Jens Wille #
|
8
8
|
# #
|
9
9
|
# Authors: #
|
10
10
|
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
@@ -26,8 +26,6 @@
|
|
26
26
|
###############################################################################
|
27
27
|
#++
|
28
28
|
|
29
|
-
require 'wadl'
|
30
|
-
|
31
29
|
module WADL
|
32
30
|
|
33
31
|
# A type of resource. Basically a mixin of methods and params for actual
|
data/lib/wadl/resources.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# A component of wadl, the super cheap Ruby WADL client. #
|
5
5
|
# #
|
6
6
|
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
-
# Copyright (C) 2010-
|
7
|
+
# Copyright (C) 2010-2014 Jens Wille #
|
8
8
|
# #
|
9
9
|
# Authors: #
|
10
10
|
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
@@ -26,8 +26,6 @@
|
|
26
26
|
###############################################################################
|
27
27
|
#++
|
28
28
|
|
29
|
-
require 'wadl'
|
30
|
-
|
31
29
|
module WADL
|
32
30
|
|
33
31
|
class Resources < HasDocs
|
data/lib/wadl/response.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# A component of wadl, the super cheap Ruby WADL client. #
|
5
5
|
# #
|
6
6
|
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
-
# Copyright (C) 2010-
|
7
|
+
# Copyright (C) 2010-2014 Jens Wille #
|
8
8
|
# #
|
9
9
|
# Authors: #
|
10
10
|
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
@@ -26,8 +26,6 @@
|
|
26
26
|
###############################################################################
|
27
27
|
#++
|
28
28
|
|
29
|
-
require 'wadl'
|
30
|
-
|
31
29
|
module WADL
|
32
30
|
|
33
31
|
class Response < Struct.new(:code, :headers, :representation, :format)
|
data/lib/wadl/response_format.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# A component of wadl, the super cheap Ruby WADL client. #
|
5
5
|
# #
|
6
6
|
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
-
# Copyright (C) 2010-
|
7
|
+
# Copyright (C) 2010-2014 Jens Wille #
|
8
8
|
# #
|
9
9
|
# Authors: #
|
10
10
|
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
@@ -26,12 +26,7 @@
|
|
26
26
|
###############################################################################
|
27
27
|
#++
|
28
28
|
|
29
|
-
|
30
|
-
require 'mime/types'
|
31
|
-
rescue LoadError
|
32
|
-
end
|
33
|
-
|
34
|
-
require 'wadl'
|
29
|
+
require 'mime/types'
|
35
30
|
|
36
31
|
module WADL
|
37
32
|
|
@@ -70,7 +65,7 @@ module WADL
|
|
70
65
|
response_raw_sub_type == raw_sub_type
|
71
66
|
end
|
72
67
|
}
|
73
|
-
end
|
68
|
+
end
|
74
69
|
|
75
70
|
# If all else fails, try to find a response that specifies no
|
76
71
|
# media type. TODO: check if this would be valid WADL.
|
@@ -98,7 +93,7 @@ module WADL
|
|
98
93
|
end
|
99
94
|
|
100
95
|
klass = response_format.is_a?(FaultFormat) ? response_format.subclass : Response
|
101
|
-
obj = klass.new(http_response.status, http_response, body, response_format)
|
96
|
+
obj = klass.new(http_response.status, http_response.headers, body, response_format)
|
102
97
|
|
103
98
|
obj.is_a?(Exception) ? raise(obj) : obj
|
104
99
|
end
|
data/lib/wadl/uri_parts.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# A component of wadl, the super cheap Ruby WADL client. #
|
5
5
|
# #
|
6
6
|
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
-
# Copyright (C) 2010-
|
7
|
+
# Copyright (C) 2010-2014 Jens Wille #
|
8
8
|
# #
|
9
9
|
# Authors: #
|
10
10
|
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
@@ -26,8 +26,6 @@
|
|
26
26
|
###############################################################################
|
27
27
|
#++
|
28
28
|
|
29
|
-
require 'wadl'
|
30
|
-
|
31
29
|
module WADL
|
32
30
|
|
33
31
|
# Classes to keep track of the logical structure of a URI.
|
data/lib/wadl/version.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# A component of wadl, the super cheap Ruby WADL client. #
|
5
5
|
# #
|
6
6
|
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
-
# Copyright (C) 2010-
|
7
|
+
# Copyright (C) 2010-2014 Jens Wille #
|
8
8
|
# #
|
9
9
|
# Authors: #
|
10
10
|
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
@@ -27,7 +27,6 @@
|
|
27
27
|
#++
|
28
28
|
|
29
29
|
require 'rexml/document'
|
30
|
-
require 'wadl'
|
31
30
|
|
32
31
|
module WADL
|
33
32
|
|
data/test/wadl_test.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
# Unit tests for the Ruby WADL library.
|
2
2
|
|
3
|
-
begin
|
4
|
-
require 'rubygems'
|
5
|
-
rescue LoadError
|
6
|
-
end
|
7
|
-
|
8
3
|
$LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
|
9
4
|
|
10
5
|
require 'test/unit'
|
@@ -24,10 +19,6 @@ class WADLTest < Test::Unit::TestCase
|
|
24
19
|
EOT
|
25
20
|
end
|
26
21
|
|
27
|
-
# Null test to shut the compiler up. (Ruby < 1.9)
|
28
|
-
def test_null
|
29
|
-
end
|
30
|
-
|
31
22
|
end
|
32
23
|
|
33
24
|
class FindingWhatYouNeed < WADLTest
|
@@ -129,15 +120,15 @@ class PathParameters < WADLTest
|
|
129
120
|
insult_resource = @wadl.find_resource_by_path('the/{person}/is/{a}')
|
130
121
|
|
131
122
|
# Test simple substitution.
|
132
|
-
assert_equal(insult_resource.uri(:
|
123
|
+
assert_equal(insult_resource.uri(path: { 'person' => 'king', 'a' => 'fink' }),
|
133
124
|
'http://www.example.com/the/king/is/;a=fink')
|
134
125
|
# Test default values.
|
135
|
-
assert_equal(insult_resource.uri(:
|
126
|
+
assert_equal(insult_resource.uri(path: { 'person' => 'king' }),
|
136
127
|
'http://www.example.com/the/king/is/;a=dork')
|
137
128
|
|
138
129
|
# Test use of optional paramaters.
|
139
|
-
assert_equal(insult_resource.uri(:
|
140
|
-
|
130
|
+
assert_equal(insult_resource.uri(path: { 'person' => 'king', 'a' => 'fink',
|
131
|
+
'and' => 'he can bite me' }),
|
141
132
|
'http://www.example.com/the/king/is/;a=fink/;and=he%20can%20bite%20me')
|
142
133
|
|
143
134
|
# Don't provide required argument.
|
@@ -145,7 +136,7 @@ class PathParameters < WADLTest
|
|
145
136
|
|
146
137
|
# Provide multiple values for single-valued argument.
|
147
138
|
assert_raises(ArgumentError) {
|
148
|
-
insult_resource.uri(:
|
139
|
+
insult_resource.uri(path: { person: 'king', a: %w[fink dolt] })
|
149
140
|
}
|
150
141
|
end
|
151
142
|
|
@@ -163,10 +154,10 @@ class PathParameters < WADLTest
|
|
163
154
|
</resources>
|
164
155
|
EOT
|
165
156
|
|
166
|
-
assert_equal(resource.uri(:
|
157
|
+
assert_equal(resource.uri(path: { fate: 'Clotho' }),
|
167
158
|
'http://www.example.com/fates/Clotho')
|
168
159
|
|
169
|
-
assert_raises(ArgumentError) { resource.uri(:
|
160
|
+
assert_raises(ArgumentError) { resource.uri(path: { fate: 'Groucho' }) }
|
170
161
|
end
|
171
162
|
|
172
163
|
# This one's complicated. We bind a resource's path parameters to
|
@@ -178,19 +169,19 @@ class PathParameters < WADLTest
|
|
178
169
|
assert_equal(im_mad_because.uri, 'http://www.example.com/im/mad/because')
|
179
170
|
|
180
171
|
insult = im_mad_because.find_resource('insult')
|
181
|
-
assert_equal(insult.uri(:
|
172
|
+
assert_equal(insult.uri(path: { 'person' => 'king', 'a' => 'fink' }),
|
182
173
|
'http://www.example.com/im/mad/because/the/king/is/;a=fink')
|
183
174
|
|
184
|
-
im_mad_because_hes_a_fink = insult.bind!(:
|
175
|
+
im_mad_because_hes_a_fink = insult.bind!(path: { 'person' => 'king', 'a' => 'fink' })
|
185
176
|
assert_equal(im_mad_because_hes_a_fink.uri,
|
186
177
|
'http://www.example.com/im/mad/because/the/king/is/;a=fink')
|
187
178
|
|
188
179
|
im_mad_because_hes_a_fink_lets = im_mad_because_hes_a_fink.find_resource("so-let's")
|
189
|
-
assert_equal(im_mad_because_hes_a_fink_lets.uri(:
|
180
|
+
assert_equal(im_mad_because_hes_a_fink_lets.uri(path: { 'do something' => 'revolt' }),
|
190
181
|
"http://www.example.com/im/mad/because/the/king/is/;a=fink/so-let's/revolt")
|
191
182
|
|
192
183
|
im_mad_because_hes_a_fink_lets_revolt = im_mad_because_hes_a_fink_lets.
|
193
|
-
bind(:
|
184
|
+
bind(path: { 'person' => 'fink', 'do something' => 'revolt' })
|
194
185
|
|
195
186
|
assert_equal(im_mad_because_hes_a_fink_lets_revolt.uri,
|
196
187
|
"http://www.example.com/im/mad/because/the/king/is/;a=fink/so-let's/revolt")
|
@@ -210,7 +201,7 @@ class PathParameters < WADLTest
|
|
210
201
|
{ 'plain' => 'http://www.example.com/i/want/pony,water%20slide,BB%20gun',
|
211
202
|
'matrix' => 'http://www.example.com/i/want/;a=pony;a=water%20slide;a=BB%20gun' }.each { |style, uri|
|
212
203
|
list = wadl(text % style).find_resource('list')
|
213
|
-
assert_equal(list.uri(:
|
204
|
+
assert_equal(list.uri(path: { a: ['pony', 'water slide', 'BB gun'] }), uri)
|
214
205
|
}
|
215
206
|
end
|
216
207
|
|
@@ -223,7 +214,7 @@ class PathParameters < WADLTest
|
|
223
214
|
</resources>
|
224
215
|
EOT
|
225
216
|
|
226
|
-
assert_equal(poll.uri(:
|
217
|
+
assert_equal(poll.uri(opinion: 'ungood'),
|
227
218
|
'http://www.example.com/big-brother-is/doubleplusgood')
|
228
219
|
end
|
229
220
|
|
@@ -241,19 +232,19 @@ class PathParameters < WADLTest
|
|
241
232
|
on_uri = 'http://www.example.com/light-panel/;light1;light3'
|
242
233
|
off_uri = 'http://www.example.com/light-panel/;light1'
|
243
234
|
|
244
|
-
assert_equal(lights.uri(:
|
245
|
-
assert_equal(lights.uri(:
|
235
|
+
assert_equal(lights.uri(path: { light3: 'true' }), on_uri)
|
236
|
+
assert_equal(lights.uri(path: { light3: '1' }), on_uri)
|
246
237
|
|
247
238
|
assert_equal(lights.uri, off_uri)
|
248
|
-
assert_equal(lights.uri(:
|
249
|
-
assert_equal(lights.uri(:
|
250
|
-
assert_equal(lights.uri(:
|
251
|
-
assert_equal(lights.uri(:
|
239
|
+
assert_equal(lights.uri(path: { light3: 'false' }), off_uri)
|
240
|
+
assert_equal(lights.uri(path: { light3: false }), off_uri)
|
241
|
+
assert_equal(lights.uri(path: { light3: 'True' }), off_uri)
|
242
|
+
assert_equal(lights.uri(path: { light3: true }), off_uri)
|
252
243
|
end
|
253
244
|
|
254
245
|
end
|
255
246
|
|
256
|
-
class
|
247
|
+
class RequestFormatTest < WADLTest
|
257
248
|
|
258
249
|
def setup
|
259
250
|
@wadl = wadl(<<-EOT)
|
@@ -283,15 +274,15 @@ class RequestFormatTests < WADLTest
|
|
283
274
|
</method>
|
284
275
|
EOT
|
285
276
|
|
286
|
-
@color = @wadl.find_resource('top').bind(:
|
277
|
+
@color = @wadl.find_resource('top').bind(query: { api_key: 'foobar' }).find_resource('color')
|
287
278
|
end
|
288
279
|
|
289
280
|
def test_query_vars
|
290
281
|
graphic = @color.find_method('get_graphic')
|
291
|
-
path = { :
|
292
|
-
query = { :
|
282
|
+
path = { color: 'blue' }
|
283
|
+
query = { shade: 'light' }
|
293
284
|
|
294
|
-
assert_equal(graphic.request.uri(@color, :
|
285
|
+
assert_equal(graphic.request.uri(@color, path: path, query: query),
|
295
286
|
'http://www.example.com/palette/colors/blue?shade=light')
|
296
287
|
|
297
288
|
assert_raises(ArgumentError) { graphic.request.uri(@color, path) }
|
@@ -301,15 +292,63 @@ class RequestFormatTests < WADLTest
|
|
301
292
|
graphic = @color.find_method('set_graphic')
|
302
293
|
representation = graphic.request.find_form
|
303
294
|
|
304
|
-
assert_equal(representation % { :
|
295
|
+
assert_equal(representation % { new_graphic: 'foobar', 'filename' => 'blue.jpg' },
|
305
296
|
'new_graphic=foobar&filename=blue.jpg')
|
306
297
|
|
307
|
-
assert_raises(ArgumentError) { representation % { :
|
298
|
+
assert_raises(ArgumentError) { representation % { new_graphic: 'foobar' } }
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
class ResponseFormatTest < WADLTest
|
304
|
+
|
305
|
+
def setup
|
306
|
+
@wadl = wadl(<<-EOT)
|
307
|
+
<resources base="http://www.example.com/">
|
308
|
+
<resource id="top" path="palette">
|
309
|
+
<method name="GET" id="get_graphic">
|
310
|
+
<request></request>
|
311
|
+
<response>
|
312
|
+
<representation mediaType="application/json"/>
|
313
|
+
</response>
|
314
|
+
</method>
|
315
|
+
</resource>
|
316
|
+
<resource id="bottom" path="palette">
|
317
|
+
<method name="GET" id="set_graphic">
|
318
|
+
<request></request>
|
319
|
+
<response>
|
320
|
+
<representation mediaType="application/json"/>
|
321
|
+
</response>
|
322
|
+
<response>
|
323
|
+
<representation mediaType="text/xml"/>
|
324
|
+
</response>
|
325
|
+
</method>
|
326
|
+
</resource>
|
327
|
+
</resources>
|
328
|
+
EOT
|
329
|
+
end
|
330
|
+
|
331
|
+
def test_representation
|
332
|
+
graphic = @wadl.find_resource('top').find_method('get_graphic')
|
333
|
+
representations = graphic.response.representations
|
334
|
+
|
335
|
+
assert_equal(1, representations.size)
|
336
|
+
assert_equal('application/json', representations.first.mediaType)
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_multiple_response_formats
|
340
|
+
graphic = @wadl.find_resource('bottom').find_method('set_graphic')
|
341
|
+
responses = graphic.responses
|
342
|
+
|
343
|
+
assert_equal(2, responses.size)
|
344
|
+
assert_equal(%w[application/json text/xml], responses.map { |response|
|
345
|
+
response.representations.first.mediaType
|
346
|
+
})
|
308
347
|
end
|
309
348
|
|
310
349
|
end
|
311
350
|
|
312
|
-
class
|
351
|
+
class AuthTest < WADLTest
|
313
352
|
|
314
353
|
def setup
|
315
354
|
@wadl = wadl(<<-EOT)
|
@@ -346,7 +385,7 @@ class AuthTests < WADLTest
|
|
346
385
|
end
|
347
386
|
|
348
387
|
def test_template_params_with_basic_auth
|
349
|
-
arg = { :
|
388
|
+
arg = { path: { id: 42 } }
|
350
389
|
uri = 'http://www.example.com/service/42.json'
|
351
390
|
|
352
391
|
assert_equal(uri, u1 = @service.bind(arg).uri)
|