wadl 0.1.2 → 0.1.3.1
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.
- data/README +1 -1
- data/Rakefile +1 -1
- data/TODO +2 -0
- data/examples/README +2 -0
- data/lib/wadl.rb +24 -1234
- data/lib/wadl/address.rb +193 -0
- data/lib/wadl/application.rb +71 -0
- data/lib/wadl/cheap_schema.rb +343 -0
- data/lib/wadl/documentation.rb +41 -0
- data/lib/wadl/fault.rb +48 -0
- data/lib/wadl/fault_format.rb +67 -0
- data/lib/wadl/has_docs.rb +49 -0
- data/lib/wadl/http_method.rb +108 -0
- data/lib/wadl/link.rb +40 -0
- data/lib/wadl/option.rb +40 -0
- data/lib/wadl/param.rb +134 -0
- data/lib/wadl/representation_container.rb +47 -0
- data/lib/wadl/representation_format.rb +73 -0
- data/lib/wadl/request_format.rb +68 -0
- data/lib/wadl/resource.rb +163 -0
- data/lib/wadl/resource_and_address.rb +108 -0
- data/lib/wadl/resource_container.rb +58 -0
- data/lib/wadl/resource_type.rb +44 -0
- data/lib/wadl/resources.rb +44 -0
- data/lib/wadl/response.rb +36 -0
- data/lib/wadl/response_format.rb +108 -0
- data/lib/wadl/uri_parts.rb +63 -0
- data/lib/wadl/version.rb +1 -1
- data/lib/wadl/xml_representation.rb +64 -0
- data/test/test_wadl.rb +7 -0
- metadata +43 -8
@@ -0,0 +1,41 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of wadl, the super cheap Ruby WADL client. #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
+
# Copyright (C) 2010 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
11
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
12
|
+
# #
|
13
|
+
# wadl is free software; you can redistribute it and/or modify it under the #
|
14
|
+
# terms of the GNU General Public License as published by the Free Software #
|
15
|
+
# Foundation; either version 3 of the License, or (at your option) any later #
|
16
|
+
# version. #
|
17
|
+
# #
|
18
|
+
# wadl is distributed in the hope that it will be useful, but WITHOUT ANY #
|
19
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
20
|
+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
|
21
|
+
# details. #
|
22
|
+
# #
|
23
|
+
# You should have received a copy of the GNU General Public License along #
|
24
|
+
# with wadl. If not, see <http://www.gnu.org/licenses/>. #
|
25
|
+
# #
|
26
|
+
###############################################################################
|
27
|
+
#++
|
28
|
+
|
29
|
+
require 'wadl'
|
30
|
+
|
31
|
+
module WADL
|
32
|
+
|
33
|
+
class Documentation < CheapSchema
|
34
|
+
|
35
|
+
in_document 'doc'
|
36
|
+
has_attributes 'xml:lang', :title
|
37
|
+
contents_are_mixed_data
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/lib/wadl/fault.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of wadl, the super cheap Ruby WADL client. #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
+
# Copyright (C) 2010 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
11
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
12
|
+
# #
|
13
|
+
# wadl is free software; you can redistribute it and/or modify it under the #
|
14
|
+
# terms of the GNU General Public License as published by the Free Software #
|
15
|
+
# Foundation; either version 3 of the License, or (at your option) any later #
|
16
|
+
# version. #
|
17
|
+
# #
|
18
|
+
# wadl is distributed in the hope that it will be useful, but WITHOUT ANY #
|
19
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
20
|
+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
|
21
|
+
# details. #
|
22
|
+
# #
|
23
|
+
# You should have received a copy of the GNU General Public License along #
|
24
|
+
# with wadl. If not, see <http://www.gnu.org/licenses/>. #
|
25
|
+
# #
|
26
|
+
###############################################################################
|
27
|
+
#++
|
28
|
+
|
29
|
+
require 'wadl'
|
30
|
+
|
31
|
+
module WADL
|
32
|
+
|
33
|
+
class Fault < Exception
|
34
|
+
|
35
|
+
attr_accessor :code, :headers, :representation, :format
|
36
|
+
|
37
|
+
def initialize(code, headers, representation, format)
|
38
|
+
@code, @headers, @representation, @format = code, headers, representation, format
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
# A container for application-specific faults
|
44
|
+
|
45
|
+
module Faults
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of wadl, the super cheap Ruby WADL client. #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
+
# Copyright (C) 2010 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
11
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
12
|
+
# #
|
13
|
+
# wadl is free software; you can redistribute it and/or modify it under the #
|
14
|
+
# terms of the GNU General Public License as published by the Free Software #
|
15
|
+
# Foundation; either version 3 of the License, or (at your option) any later #
|
16
|
+
# version. #
|
17
|
+
# #
|
18
|
+
# wadl is distributed in the hope that it will be useful, but WITHOUT ANY #
|
19
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
20
|
+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
|
21
|
+
# details. #
|
22
|
+
# #
|
23
|
+
# You should have received a copy of the GNU General Public License along #
|
24
|
+
# with wadl. If not, see <http://www.gnu.org/licenses/>. #
|
25
|
+
# #
|
26
|
+
###############################################################################
|
27
|
+
#++
|
28
|
+
|
29
|
+
require 'wadl'
|
30
|
+
|
31
|
+
module WADL
|
32
|
+
|
33
|
+
class FaultFormat < RepresentationFormat
|
34
|
+
|
35
|
+
in_document 'fault'
|
36
|
+
has_attributes :id, :mediaType, :element, :status
|
37
|
+
has_many Param
|
38
|
+
may_be_reference
|
39
|
+
|
40
|
+
attr_writer :subclass
|
41
|
+
|
42
|
+
def subclass
|
43
|
+
attributes['href'] ? dereference.subclass : @subclass
|
44
|
+
end
|
45
|
+
|
46
|
+
# Define a custom subclass for this fault, so that the programmer
|
47
|
+
# can rescue this particular fault.
|
48
|
+
def self.from_element(*args)
|
49
|
+
me = super
|
50
|
+
|
51
|
+
me.subclass = if name = me.attributes['id']
|
52
|
+
begin
|
53
|
+
WADL::Faults.const_defined?(name) ?
|
54
|
+
WADL::Faults.const_get(name) :
|
55
|
+
WADL::Faults.const_set(name, Class.new(Fault))
|
56
|
+
rescue NameError
|
57
|
+
# This fault format's ID can't be a class name. Use the
|
58
|
+
# generic subclass of Fault.
|
59
|
+
end
|
60
|
+
end || Fault unless me.attributes['href']
|
61
|
+
|
62
|
+
me
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of wadl, the super cheap Ruby WADL client. #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
+
# Copyright (C) 2010 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
11
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
12
|
+
# #
|
13
|
+
# wadl is free software; you can redistribute it and/or modify it under the #
|
14
|
+
# terms of the GNU General Public License as published by the Free Software #
|
15
|
+
# Foundation; either version 3 of the License, or (at your option) any later #
|
16
|
+
# version. #
|
17
|
+
# #
|
18
|
+
# wadl is distributed in the hope that it will be useful, but WITHOUT ANY #
|
19
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
20
|
+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
|
21
|
+
# details. #
|
22
|
+
# #
|
23
|
+
# You should have received a copy of the GNU General Public License along #
|
24
|
+
# with wadl. If not, see <http://www.gnu.org/licenses/>. #
|
25
|
+
# #
|
26
|
+
###############################################################################
|
27
|
+
#++
|
28
|
+
|
29
|
+
require 'wadl'
|
30
|
+
|
31
|
+
module WADL
|
32
|
+
|
33
|
+
class HasDocs < CheapSchema
|
34
|
+
|
35
|
+
has_many Documentation
|
36
|
+
|
37
|
+
# Convenience method to define a no-argument singleton method on
|
38
|
+
# this object.
|
39
|
+
def define_singleton(r, sym, method)
|
40
|
+
name = r.send(sym)
|
41
|
+
|
42
|
+
if name && name !~ /\W/ && !r.respond_to?(name) && !respond_to?(name)
|
43
|
+
instance_eval(%Q{def #{name}\n#{method}('#{name}')\nend})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of wadl, the super cheap Ruby WADL client. #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
+
# Copyright (C) 2010 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
11
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
12
|
+
# #
|
13
|
+
# wadl is free software; you can redistribute it and/or modify it under the #
|
14
|
+
# terms of the GNU General Public License as published by the Free Software #
|
15
|
+
# Foundation; either version 3 of the License, or (at your option) any later #
|
16
|
+
# version. #
|
17
|
+
# #
|
18
|
+
# wadl is distributed in the hope that it will be useful, but WITHOUT ANY #
|
19
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
20
|
+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
|
21
|
+
# details. #
|
22
|
+
# #
|
23
|
+
# You should have received a copy of the GNU General Public License along #
|
24
|
+
# with wadl. If not, see <http://www.gnu.org/licenses/>. #
|
25
|
+
# #
|
26
|
+
###############################################################################
|
27
|
+
#++
|
28
|
+
|
29
|
+
require 'yaml'
|
30
|
+
require 'rest-open-uri'
|
31
|
+
require 'wadl'
|
32
|
+
|
33
|
+
module WADL
|
34
|
+
|
35
|
+
class HTTPMethod < HasDocs
|
36
|
+
|
37
|
+
OAUTH_HEADER = 'Authorization'
|
38
|
+
OAUTH_PREFIX = 'OAuth:'
|
39
|
+
|
40
|
+
in_document 'method'
|
41
|
+
as_collection 'http_methods'
|
42
|
+
has_required :id, :name
|
43
|
+
has_one RequestFormat, ResponseFormat
|
44
|
+
may_be_reference
|
45
|
+
|
46
|
+
# Args:
|
47
|
+
# :path - Values for path parameters
|
48
|
+
# :query - Values for query parameters
|
49
|
+
# :headers - Values for header parameters
|
50
|
+
# :send_representation
|
51
|
+
# :expect_representation
|
52
|
+
def call(resource, args = {})
|
53
|
+
unless parent.respond_to?(:uri)
|
54
|
+
raise "You can't call a method that's not attached to a resource! (You may have dereferenced a method when you shouldn't have)"
|
55
|
+
end
|
56
|
+
|
57
|
+
resource ||= parent
|
58
|
+
method = dereference
|
59
|
+
|
60
|
+
uri = method.request ? method.request.uri(resource, args) : resource.uri(args)
|
61
|
+
headers = uri.headers.dup
|
62
|
+
|
63
|
+
headers['Accept'] = expect_representation.mediaType if args[:expect_representation]
|
64
|
+
headers['User-Agent'] = 'Ruby WADL client' unless headers['User-Agent']
|
65
|
+
headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
66
|
+
headers[:method] = name.downcase.to_sym
|
67
|
+
headers[:body] = args[:send_representation]
|
68
|
+
|
69
|
+
set_oauth_header(headers, uri)
|
70
|
+
|
71
|
+
response = begin
|
72
|
+
open(uri, headers)
|
73
|
+
rescue OpenURI::HTTPError => err
|
74
|
+
err.io
|
75
|
+
end
|
76
|
+
|
77
|
+
method.response.build(response)
|
78
|
+
end
|
79
|
+
|
80
|
+
def set_oauth_header(headers, uri)
|
81
|
+
args = headers[OAUTH_HEADER] or return
|
82
|
+
|
83
|
+
yaml = args.dup
|
84
|
+
yaml.sub!(/\A#{OAUTH_PREFIX}/, '') or return
|
85
|
+
|
86
|
+
consumer_key, consumer_secret, access_token, token_secret = YAML.load(yaml)
|
87
|
+
|
88
|
+
require 'oauth/client/helper'
|
89
|
+
|
90
|
+
request = OpenURI::Methods[headers[:method]].new(uri.to_s)
|
91
|
+
|
92
|
+
consumer = OAuth::Consumer.new(consumer_key, consumer_secret)
|
93
|
+
token = OAuth::AccessToken.new(consumer, access_token, token_secret)
|
94
|
+
|
95
|
+
helper = OAuth::Client::Helper.new(request,
|
96
|
+
:request_uri => request.path,
|
97
|
+
:consumer => consumer,
|
98
|
+
:token => token,
|
99
|
+
:scheme => 'header',
|
100
|
+
:signature_method => 'HMAC-SHA1'
|
101
|
+
)
|
102
|
+
|
103
|
+
headers[OAUTH_HEADER] = helper.header
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
data/lib/wadl/link.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of wadl, the super cheap Ruby WADL client. #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
+
# Copyright (C) 2010 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
11
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
12
|
+
# #
|
13
|
+
# wadl is free software; you can redistribute it and/or modify it under the #
|
14
|
+
# terms of the GNU General Public License as published by the Free Software #
|
15
|
+
# Foundation; either version 3 of the License, or (at your option) any later #
|
16
|
+
# version. #
|
17
|
+
# #
|
18
|
+
# wadl is distributed in the hope that it will be useful, but WITHOUT ANY #
|
19
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
20
|
+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
|
21
|
+
# details. #
|
22
|
+
# #
|
23
|
+
# You should have received a copy of the GNU General Public License along #
|
24
|
+
# with wadl. If not, see <http://www.gnu.org/licenses/>. #
|
25
|
+
# #
|
26
|
+
###############################################################################
|
27
|
+
#++
|
28
|
+
|
29
|
+
require 'wadl'
|
30
|
+
|
31
|
+
module WADL
|
32
|
+
|
33
|
+
class Link < HasDocs
|
34
|
+
|
35
|
+
in_document 'link'
|
36
|
+
has_attributes :href, :rel, :rev
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/wadl/option.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of wadl, the super cheap Ruby WADL client. #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
+
# Copyright (C) 2010 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
11
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
12
|
+
# #
|
13
|
+
# wadl is free software; you can redistribute it and/or modify it under the #
|
14
|
+
# terms of the GNU General Public License as published by the Free Software #
|
15
|
+
# Foundation; either version 3 of the License, or (at your option) any later #
|
16
|
+
# version. #
|
17
|
+
# #
|
18
|
+
# wadl is distributed in the hope that it will be useful, but WITHOUT ANY #
|
19
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
20
|
+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
|
21
|
+
# details. #
|
22
|
+
# #
|
23
|
+
# You should have received a copy of the GNU General Public License along #
|
24
|
+
# with wadl. If not, see <http://www.gnu.org/licenses/>. #
|
25
|
+
# #
|
26
|
+
###############################################################################
|
27
|
+
#++
|
28
|
+
|
29
|
+
require 'wadl'
|
30
|
+
|
31
|
+
module WADL
|
32
|
+
|
33
|
+
class Option < HasDocs
|
34
|
+
|
35
|
+
in_document 'option'
|
36
|
+
has_required :value
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/wadl/param.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of wadl, the super cheap Ruby WADL client. #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2006-2008 Leonard Richardson #
|
7
|
+
# Copyright (C) 2010 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Leonard Richardson <leonardr@segfault.org> (Original author) #
|
11
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
12
|
+
# #
|
13
|
+
# wadl is free software; you can redistribute it and/or modify it under the #
|
14
|
+
# terms of the GNU General Public License as published by the Free Software #
|
15
|
+
# Foundation; either version 3 of the License, or (at your option) any later #
|
16
|
+
# version. #
|
17
|
+
# #
|
18
|
+
# wadl is distributed in the hope that it will be useful, but WITHOUT ANY #
|
19
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
20
|
+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
|
21
|
+
# details. #
|
22
|
+
# #
|
23
|
+
# You should have received a copy of the GNU General Public License along #
|
24
|
+
# with wadl. If not, see <http://www.gnu.org/licenses/>. #
|
25
|
+
# #
|
26
|
+
###############################################################################
|
27
|
+
#++
|
28
|
+
|
29
|
+
require 'wadl'
|
30
|
+
|
31
|
+
module WADL
|
32
|
+
|
33
|
+
class Param < HasDocs
|
34
|
+
|
35
|
+
in_document 'param'
|
36
|
+
has_required :name
|
37
|
+
has_attributes :type, :default, :style, :path, :required, :repeating, :fixed
|
38
|
+
has_many Option, Link
|
39
|
+
may_be_reference
|
40
|
+
|
41
|
+
# cf. <http://www.w3.org/TR/xmlschema-2/#boolean>
|
42
|
+
BOOLEAN_RE = %r{\A(?:true|1)\z}
|
43
|
+
|
44
|
+
# A default Param object to use for a path parameter that is
|
45
|
+
# only specified as a name in the path of a resource.
|
46
|
+
def self.default
|
47
|
+
@default ||= begin
|
48
|
+
default = Param.new
|
49
|
+
|
50
|
+
default.required = 'true'
|
51
|
+
default.style = 'plain'
|
52
|
+
default.type = 'xsd:string'
|
53
|
+
|
54
|
+
default
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def required?
|
59
|
+
required =~ BOOLEAN_RE
|
60
|
+
end
|
61
|
+
|
62
|
+
def repeating?
|
63
|
+
repeating =~ BOOLEAN_RE
|
64
|
+
end
|
65
|
+
|
66
|
+
def inspect
|
67
|
+
%Q{Param "#{name}"}
|
68
|
+
end
|
69
|
+
|
70
|
+
# Validates and formats a proposed value for this parameter. Returns
|
71
|
+
# the formatted value. Raises an ArgumentError if the value
|
72
|
+
# is invalid.
|
73
|
+
#
|
74
|
+
# The 'name' and 'style' arguments are used in conjunction with the
|
75
|
+
# default Param object.
|
76
|
+
def format(value, name = nil, style = nil)
|
77
|
+
name ||= self.name
|
78
|
+
style ||= self.style
|
79
|
+
|
80
|
+
value = fixed if fixed
|
81
|
+
value ||= default if default
|
82
|
+
|
83
|
+
unless value
|
84
|
+
if required?
|
85
|
+
raise ArgumentError, %Q{No value provided for required param "#{name}"!}
|
86
|
+
else
|
87
|
+
return '' # No value provided and none required.
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if value.respond_to?(:each) && !value.respond_to?(:to_str)
|
92
|
+
if repeating?
|
93
|
+
values = value
|
94
|
+
else
|
95
|
+
raise ArgumentError, %Q{Multiple values provided for single-value param "#{name}"}
|
96
|
+
end
|
97
|
+
else
|
98
|
+
values = [value]
|
99
|
+
end
|
100
|
+
|
101
|
+
# If the param lists acceptable values in option tags, make sure that
|
102
|
+
# all values are found in those tags.
|
103
|
+
if options && !options.empty?
|
104
|
+
values.each { |value|
|
105
|
+
unless find_option(value)
|
106
|
+
acceptable = options.map { |o| o.value }.join('", "')
|
107
|
+
raise ArgumentError, %Q{"#{value}" is not among the acceptable parameter values ("#{acceptable}")}
|
108
|
+
end
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
if style == 'query' || parent.is_a?(RequestFormat) || (
|
113
|
+
parent.respond_to?(:is_form_representation?) && parent.is_form_representation?
|
114
|
+
)
|
115
|
+
values.map { |v| "#{URI.escape(name)}=#{URI.escape(v.to_s)}" }.join('&')
|
116
|
+
elsif style == 'matrix'
|
117
|
+
if type == 'xsd:boolean'
|
118
|
+
values.map { |v| ";#{name}" if v =~ BOOLEAN_RE }.compact.join
|
119
|
+
else
|
120
|
+
values.map { |v| ";#{URI.escape(name)}=#{URI.escape(v.to_s)}" if v }.compact.join
|
121
|
+
end
|
122
|
+
elsif style == 'header'
|
123
|
+
values.join(',')
|
124
|
+
else
|
125
|
+
# All other cases: plain text representation.
|
126
|
+
values.map { |v| URI.escape(v.to_s) }.join(',')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
alias_method :%, :format
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|