wadl 0.2.8 → 0.3.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.
@@ -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-2013 Jens Wille #
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-2013 Jens Wille #
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(HTTPMethod::OAUTH_HEADER,
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-2013 Jens Wille #
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-2013 Jens Wille #
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
@@ -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-2013 Jens Wille #
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
@@ -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-2013 Jens Wille #
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-2013 Jens Wille #
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)
@@ -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-2013 Jens Wille #
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
- begin
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 if defined?(MIME::Types)
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
@@ -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-2013 Jens Wille #
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
@@ -3,8 +3,8 @@ module WADL
3
3
  module Version
4
4
 
5
5
  MAJOR = 0
6
- MINOR = 2
7
- TINY = 8
6
+ MINOR = 3
7
+ TINY = 0
8
8
 
9
9
  class << self
10
10
 
@@ -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-2013 Jens Wille #
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(:path => { 'person' => 'king', 'a' => 'fink' }),
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(:path => { 'person' => 'king' }),
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(:path => { 'person' => 'king', 'a' => 'fink',
140
- 'and' => 'he can bite me' }),
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(:path => { :person => 'king', :a => ['fink', 'dolt'] })
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(:path => { :fate => 'Clotho' }),
157
+ assert_equal(resource.uri(path: { fate: 'Clotho' }),
167
158
  'http://www.example.com/fates/Clotho')
168
159
 
169
- assert_raises(ArgumentError) { resource.uri(:path => { :fate => 'Groucho' }) }
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(:path => { 'person' => 'king', 'a' => 'fink' }),
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!(:path => { 'person' => 'king', 'a' => 'fink' })
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(:path => { 'do something' => 'revolt' }),
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(:path => { 'person' => 'fink', 'do something' => 'revolt' })
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(:path => { :a => ['pony', 'water slide', 'BB gun'] }), 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(:opinion => 'ungood'),
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(:path => { :light3 => 'true' }), on_uri)
245
- assert_equal(lights.uri(:path => { :light3 => '1' }), on_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(:path => { :light3 => 'false' }), off_uri)
249
- assert_equal(lights.uri(:path => { :light3 => false }), off_uri)
250
- assert_equal(lights.uri(:path => { :light3 => 'True' }), off_uri)
251
- assert_equal(lights.uri(:path => { :light3 => true }), off_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 RequestFormatTests < WADLTest
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(:query => { :api_key => 'foobar' }).find_resource('color')
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 = { :color => 'blue' }
292
- query = { :shade => 'light' }
282
+ path = { color: 'blue' }
283
+ query = { shade: 'light' }
293
284
 
294
- assert_equal(graphic.request.uri(@color, :path => path, :query => query),
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 % { :new_graphic => 'foobar', 'filename' => 'blue.jpg' },
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 % { :new_graphic => 'foobar' } }
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 AuthTests < WADLTest
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 = { :path => { :id => 42 } }
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)