wadl 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to wadl version 0.2.6
5
+ This documentation refers to wadl version 0.2.7
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -45,8 +45,8 @@ The 20060802 WADL standard is almost entirely supported. However,
45
45
  == LINKS
46
46
 
47
47
  <b></b>
48
- Homepage:: http://www.crummy.com/software/wadl.rb/
49
- WADL:: http://wadl.dev.java.net/
48
+ Homepage:: http://www.crummy.com/software/wadl.rb
49
+ WADL:: http://wadl.java.net
50
50
  Documentation:: http://rdoc.info/projects/blackwinter/wadl
51
51
  Source code:: http://github.com/blackwinter/wadl
52
52
 
@@ -60,7 +60,7 @@ Source code:: http://github.com/blackwinter/wadl
60
60
  == LICENSE AND COPYRIGHT
61
61
 
62
62
  Copyright (C) 2006-2008 Leonard Richardson
63
- Copyright (C) 2010-2011 Jens Wille
63
+ Copyright (C) 2010-2012 Jens Wille
64
64
 
65
65
  wadl is free software: you can redistribute it and/or modify it under
66
66
  the terms of the GNU Affero General Public License as published by the
data/lib/wadl/address.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-2011 Jens Wille #
7
+ # Copyright (C) 2010-2012 Jens Wille #
8
8
  # #
9
9
  # Authors: #
10
10
  # Leonard Richardson <leonardr@segfault.org> (Original author) #
@@ -50,11 +50,13 @@ module WADL
50
50
  path_params = {}, query_params = {}, header_params = {})
51
51
  @path_fragments, @query_vars, @headers = path_fragments, query_vars, headers
52
52
  @path_params, @query_params, @header_params = path_params, query_params, header_params
53
+
54
+ @auth = {}
53
55
  end
54
56
 
55
57
  # Perform a deep copy.
56
58
  def deep_copy
57
- Address.new(
59
+ address = Address.new(
58
60
  _deep_copy_array(@path_fragments),
59
61
  _deep_copy_array(@query_vars),
60
62
  _deep_copy_hash(@headers),
@@ -62,6 +64,10 @@ module WADL
62
64
  @query_params.dup,
63
65
  @header_params.dup
64
66
  )
67
+
68
+ @auth.each { |header, value| address.auth(header, value) }
69
+
70
+ address
65
71
  end
66
72
 
67
73
  def to_s
@@ -69,6 +75,7 @@ module WADL
69
75
  " Path fragments: #{@path_fragments.inspect}\n" <<
70
76
  " Query variables: #{@query_vars.inspect}\n" <<
71
77
  " Header variables: #{@headers.inspect}\n" <<
78
+ " Authorization parameters: #{@auth.inspect}\n" <<
72
79
  " Unbound path parameters: #{@path_params.inspect}\n" <<
73
80
  " Unbound query parameters: #{@query_params.inspect}\n" <<
74
81
  " Unbound header parameters: #{@header_params.inspect}\n"
@@ -82,6 +89,8 @@ module WADL
82
89
  query_var_values = args[:query] || {}
83
90
  header_var_values = args[:headers] || {}
84
91
 
92
+ @auth.each { |header, value| header_var_values[header] = value }.clear
93
+
85
94
  # Bind variables found in the path fragments.
86
95
  path_params_to_delete = []
87
96
 
@@ -89,17 +98,17 @@ module WADL
89
98
  if fragment.respond_to?(:to_str)
90
99
  # This fragment is a string which might contain {} substitutions.
91
100
  # Make any substitutions available to the provided path variables.
92
- self.class.embedded_param_names(fragment).each { |param_name|
93
- value = path_var_values[param_name] || path_var_values[param_name.to_sym]
101
+ self.class.embedded_param_names(fragment).each { |name|
102
+ value = path_var_values[name] || path_var_values[name.to_sym]
94
103
 
95
- value = if param = path_params[param_name]
104
+ value = if param = path_params[name]
96
105
  path_params_to_delete << param
97
106
  param % value
98
107
  else
99
- Param.default.format(value, param_name)
108
+ Param.default.format(value, name)
100
109
  end
101
110
 
102
- fragment.gsub!("{#{param_name}}", value)
111
+ fragment.gsub!("{#{name}}", value)
103
112
  }
104
113
  else
105
114
  # This fragment is an array of Param objects (style 'matrix'
@@ -107,15 +116,15 @@ module WADL
107
116
  # happen, the array will become a mixed array of Param objects
108
117
  # and strings.
109
118
  fragment.each_with_index { |param, i|
110
- if param.respond_to?(:name)
111
- name = param.name
119
+ next unless param.respond_to?(:name)
112
120
 
113
- value = path_var_values[name] || path_var_values[name.to_sym]
114
- value = param % value
115
- fragment[i] = value if value
121
+ name = param.name
116
122
 
117
- path_params_to_delete << param
118
- end
123
+ value = path_var_values[name] || path_var_values[name.to_sym]
124
+ value = param % value
125
+ fragment[i] = value if value
126
+
127
+ path_params_to_delete << param
119
128
  }
120
129
  end
121
130
  }
@@ -142,6 +151,11 @@ module WADL
142
151
  self
143
152
  end
144
153
 
154
+ def auth(header, value)
155
+ @auth[header] = value
156
+ self
157
+ end
158
+
145
159
  def uri(args = {})
146
160
  obj, uri = deep_copy.bind!(args), ''
147
161
 
data/lib/wadl/cli.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # #
4
4
  # A component of wadl, the super cheap Ruby WADL client. #
5
5
  # #
6
- # Copyright (C) 2010-2011 Jens Wille #
6
+ # Copyright (C) 2010-2012 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
9
  # Jens Wille <jens.wille@uni-koeln.de> #
@@ -134,12 +134,14 @@ module WADL
134
134
  if arg =~ OPTION_RE
135
135
  key, value, next_arg = $1, $2, arguments[index + 1]
136
136
 
137
- add_param(query, key, value || if next_arg =~ OPTION_RE
137
+ value ||= if next_arg.nil? || next_arg =~ OPTION_RE
138
138
  '1' # "true"
139
139
  else
140
140
  skip_next = true
141
141
  next_arg
142
- end)
142
+ end
143
+
144
+ add_param(query, key, value)
143
145
  else
144
146
  resource_path << arg
145
147
  end
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-2011 Jens Wille #
7
+ # Copyright (C) 2010-2012 Jens Wille #
8
8
  # #
9
9
  # Authors: #
10
10
  # Leonard Richardson <leonardr@segfault.org> (Original author) #
@@ -44,19 +44,24 @@ module WADL
44
44
  super
45
45
  end
46
46
 
47
+ def resource_and_address(child = self, *args)
48
+ ResourceAndAddress.new(child, *args)
49
+ end
50
+
47
51
  def dereference_with_context(child)
48
- ResourceAndAddress.new(child, parent.address)
52
+ resource_and_address(child, parent.address)
49
53
  end
50
54
 
51
55
  # Returns a ResourceAndAddress object bound to this resource
52
56
  # and the given query variables.
53
57
  def bind(args = {})
54
- ResourceAndAddress.new(self).bind!(args)
58
+ resource_and_address.bind!(args)
55
59
  end
56
60
 
57
61
  # Sets basic auth parameters
58
62
  def with_basic_auth(user, pass, header = 'Authorization')
59
- bind(:headers => { header => "Basic #{["#{user}:#{pass}"].pack('m')}" })
63
+ resource_and_address.auth(header,
64
+ "Basic #{["#{user}:#{pass}"].pack('m')}")
60
65
  end
61
66
 
62
67
  # Sets OAuth parameters
@@ -67,8 +72,8 @@ module WADL
67
72
  # :access_token
68
73
  # :token_secret
69
74
  def with_oauth(*args)
70
- header, prefix = HTTPMethod::OAUTH_HEADER, HTTPMethod::OAUTH_PREFIX
71
- bind(:headers => { header => "#{prefix}#{args.to_yaml}" })
75
+ resource_and_address.auth(HTTPMethod::OAUTH_HEADER,
76
+ "#{HTTPMethod::OAUTH_PREFIX}#{args.to_yaml}")
72
77
  end
73
78
 
74
79
  def uri(args = {}, working_address = nil)
@@ -70,6 +70,11 @@ module WADL
70
70
  self
71
71
  end
72
72
 
73
+ def auth(header, value)
74
+ @address.auth(header, value)
75
+ self
76
+ end
77
+
73
78
  def uri(args = {})
74
79
  @address.deep_copy.bind!(args).uri
75
80
  end
data/lib/wadl/version.rb CHANGED
@@ -4,7 +4,7 @@ module WADL
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 2
7
- TINY = 6
7
+ TINY = 7
8
8
 
9
9
  class << self
10
10
 
data/test/wadl_test.rb CHANGED
@@ -24,7 +24,7 @@ class WADLTest < Test::Unit::TestCase
24
24
  EOT
25
25
  end
26
26
 
27
- # Null test to shut the compiler up.
27
+ # Null test to shut the compiler up. (Ruby < 1.9)
28
28
  def test_null
29
29
  end
30
30
 
@@ -251,10 +251,12 @@ class PathParameters < WADLTest
251
251
  assert_equal(lights.uri(:path => { :light3 => true }), off_uri)
252
252
  end
253
253
 
254
- class RequestFormatTests < WADLTest
254
+ end
255
+
256
+ class RequestFormatTests < WADLTest
255
257
 
256
- def setup
257
- @wadl = wadl(<<-EOT)
258
+ def setup
259
+ @wadl = wadl(<<-EOT)
258
260
  <resources base="http://www.example.com/">
259
261
  <resource id="top" path="palette">
260
262
  <param style="form" name="api_key" />
@@ -279,32 +281,79 @@ class PathParameters < WADLTest
279
281
  </representation>
280
282
  </request>
281
283
  </method>
282
- EOT
284
+ EOT
285
+
286
+ @color = @wadl.find_resource('top').bind(:query => { :api_key => 'foobar' }).find_resource('color')
287
+ end
288
+
289
+ def test_query_vars
290
+ graphic = @color.find_method('get_graphic')
291
+ path = { :color => 'blue' }
292
+ query = { :shade => 'light' }
293
+
294
+ assert_equal(graphic.request.uri(@color, :path => path, :query => query),
295
+ 'http://www.example.com/palette/colors/blue?shade=light')
296
+
297
+ assert_raises(ArgumentError) { graphic.request.uri(@color, path) }
298
+ end
299
+
300
+ def test_representation
301
+ graphic = @color.find_method('set_graphic')
302
+ representation = graphic.request.find_form
283
303
 
284
- @color = @wadl.find_resource('top').bind(:query => { :api_key => 'foobar' }).find_resource('color')
285
- end
304
+ assert_equal(representation % { :new_graphic => 'foobar', 'filename' => 'blue.jpg' },
305
+ 'new_graphic=foobar&filename=blue.jpg')
286
306
 
287
- def test_query_vars
288
- graphic = @color.find_method('get_graphic')
289
- path = { :color => 'blue' }
290
- query = { :shade => 'light' }
307
+ assert_raises(ArgumentError) { representation % { :new_graphic => 'foobar' } }
308
+ end
309
+
310
+ end
291
311
 
292
- assert_equal(graphic.request.uri(@color, :path => path, :query => query),
293
- 'http://www.example.com/palette/colors/blue?shade=light')
312
+ class AuthTests < WADLTest
313
+
314
+ def setup
315
+ @wadl = wadl(<<-EOT)
316
+ <resources base="http://www.example.com/">
317
+ <resource path="service/{id}.json" id="service_id_json">
318
+ <param name="Authorization" style="header"/>
319
+ <param name="id" style="template" type="plain"/>
320
+ <method name="DELETE" id="DELETE-service_id_json">
321
+ <request></request>
322
+ <response></response>
323
+ </method>
324
+ <method name="PUT" id="PUT-service_id_json">
325
+ <request>
326
+ <param name="body" style="header" type="application/json"/>
327
+ </request>
328
+ <response></response>
329
+ </method>
330
+ <method name="GET" id="GET-service_id_json">
331
+ <request></request>
332
+ <response>
333
+ <representation type="application/json"/>
334
+ </response>
335
+ </method>
336
+ </resource>
337
+ </resources>
338
+ EOT
294
339
 
295
- assert_raises(ArgumentError) { graphic.request.uri(@color, path) }
296
- end
340
+ @service = @wadl.resource(:service_id_json)
341
+ end
297
342
 
298
- def test_representation
299
- graphic = @color.find_method('set_graphic')
300
- representation = graphic.request.find_form
343
+ def test_basic_auth
344
+ assert_equal("Basic dTpw\n",
345
+ @service.with_basic_auth('u', 'p').uri.headers['Authorization'])
346
+ end
301
347
 
302
- assert_equal(representation % { :new_graphic => 'foobar', 'filename' => 'blue.jpg' },
303
- 'new_graphic=foobar&filename=blue.jpg')
348
+ def test_template_params_with_basic_auth
349
+ arg = { :path => { :id => 42 } }
350
+ uri = 'http://www.example.com/service/42.json'
304
351
 
305
- assert_raises(ArgumentError) { representation % { :new_graphic => 'foobar' } }
306
- end
352
+ assert_equal(uri, u1 = @service.bind(arg).uri)
353
+ assert_equal(nil, u1.headers['Authorization'])
307
354
 
355
+ assert_equal(uri, u2 = @service.with_basic_auth('u', 'p').bind(arg).uri)
356
+ assert_equal("Basic dTpw\n", u2.headers['Authorization'])
308
357
  end
309
358
 
310
359
  end
metadata CHANGED
@@ -1,162 +1,150 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: wadl
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.7
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 6
10
- version: 0.2.6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Leonard Richardson
14
9
  - Jens Wille
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2011-09-06 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2012-10-15 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rest-open-uri
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
33
23
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: mime-types
37
24
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
39
26
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: mime-types
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
47
39
  type: :runtime
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: ruby-nuggets
51
40
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
41
+ version_requirements: !ruby/object:Gem::Requirement
53
42
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 5
58
- segments:
59
- - 0
60
- - 7
61
- - 3
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: ruby-nuggets
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
62
54
  version: 0.7.3
63
55
  type: :runtime
64
- version_requirements: *id003
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 0.7.3
65
63
  description: Ruby client for the Web Application Description Language.
66
- email:
64
+ email:
67
65
  - leonardr@segfault.org
68
66
  - jens.wille@uni-koeln.de
69
- executables:
67
+ executables:
70
68
  - wadl
71
69
  extensions: []
72
-
73
- extra_rdoc_files:
70
+ extra_rdoc_files:
74
71
  - README
75
72
  - COPYING
76
73
  - ChangeLog
77
- files:
78
- - lib/wadl.rb
79
- - lib/wadl/uri_parts.rb
80
- - lib/wadl/resource.rb
81
- - lib/wadl/response.rb
82
- - lib/wadl/option.rb
83
- - lib/wadl/param.rb
84
- - lib/wadl/application.rb
85
- - lib/wadl/resource_and_address.rb
74
+ files:
86
75
  - lib/wadl/fault_format.rb
87
76
  - lib/wadl/version.rb
88
- - lib/wadl/link.rb
89
- - lib/wadl/response_format.rb
90
- - lib/wadl/resources.rb
91
- - lib/wadl/representation_container.rb
92
77
  - lib/wadl/cli.rb
93
78
  - lib/wadl/address.rb
94
79
  - lib/wadl/http_method.rb
95
- - lib/wadl/has_docs.rb
80
+ - lib/wadl/option.rb
81
+ - lib/wadl/request_format.rb
82
+ - lib/wadl/link.rb
83
+ - lib/wadl/representation_container.rb
84
+ - lib/wadl/response.rb
96
85
  - lib/wadl/xml_representation.rb
97
- - lib/wadl/cheap_schema.rb
98
- - lib/wadl/resource_container.rb
99
86
  - lib/wadl/resource_type.rb
87
+ - lib/wadl/response_format.rb
88
+ - lib/wadl/resource_and_address.rb
89
+ - lib/wadl/resource_container.rb
90
+ - lib/wadl/documentation.rb
91
+ - lib/wadl/resources.rb
92
+ - lib/wadl/application.rb
93
+ - lib/wadl/uri_parts.rb
94
+ - lib/wadl/has_docs.rb
100
95
  - lib/wadl/fault.rb
101
- - lib/wadl/request_format.rb
102
96
  - lib/wadl/representation_format.rb
103
- - lib/wadl/documentation.rb
97
+ - lib/wadl/param.rb
98
+ - lib/wadl/resource.rb
99
+ - lib/wadl/cheap_schema.rb
100
+ - lib/wadl.rb
104
101
  - bin/wadl
105
- - ChangeLog
106
102
  - COPYING
107
- - README
108
- - Rakefile
109
103
  - TODO
110
- - example/YahooSearch.rb
104
+ - ChangeLog
105
+ - Rakefile
106
+ - README
107
+ - example/config.yaml
108
+ - example/delicious.rb
109
+ - example/yahoo.wadl
111
110
  - example/yahoo.rb
111
+ - example/crummy.rb
112
+ - example/YahooSearch.rb
112
113
  - example/crummy.wadl
113
- - example/YahooSearch.wadl
114
- - example/README
115
114
  - example/delicious.wadl
116
- - example/yahoo.wadl
117
- - example/delicious.rb
118
- - example/crummy.rb
119
- - example/config.yaml
115
+ - example/README
116
+ - example/YahooSearch.wadl
120
117
  - test/wadl_test.rb
121
118
  homepage: http://github.com/blackwinter/wadl
122
119
  licenses: []
123
-
124
120
  post_install_message:
125
- rdoc_options:
126
- - --line-numbers
127
- - --main
128
- - README
129
- - --all
121
+ rdoc_options:
130
122
  - --charset
131
123
  - UTF-8
124
+ - --line-numbers
125
+ - --all
132
126
  - --title
133
- - wadl Application documentation (v0.2.6)
134
- require_paths:
127
+ - wadl Application documentation (v0.2.7)
128
+ - --main
129
+ - README
130
+ require_paths:
135
131
  - lib
136
- required_ruby_version: !ruby/object:Gem::Requirement
132
+ required_ruby_version: !ruby/object:Gem::Requirement
137
133
  none: false
138
- requirements:
139
- - - ">="
140
- - !ruby/object:Gem::Version
141
- hash: 3
142
- segments:
143
- - 0
144
- version: "0"
145
- required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
139
  none: false
147
- requirements:
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- hash: 3
151
- segments:
152
- - 0
153
- version: "0"
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
154
144
  requirements: []
155
-
156
145
  rubyforge_project:
157
- rubygems_version: 1.8.10
146
+ rubygems_version: 1.8.24
158
147
  signing_key:
159
148
  specification_version: 3
160
149
  summary: Ruby client for the Web Application Description Language.
161
150
  test_files: []
162
-