wadl 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,75 @@
1
+ = wadl - Ruby client for the Web Application Description Language.
2
+
3
+ == VERSION
4
+
5
+ This documentation refers to wadl version 0.1.1
6
+
7
+
8
+ == DESCRIPTION
9
+
10
+ This is a Ruby client for the Web Application Description Language. It
11
+ hides the details of HTTP communication between a web service client
12
+ and a REST or HTTP+POX web service.
13
+
14
+ We hope that WADL descriptors and client libraries will replace
15
+ one-off wrapper libraries specific to one service and one programming
16
+ language -- or at least make such wrapper libraries much easier to
17
+ write.
18
+
19
+ === Interesting Features:
20
+
21
+ * Traversing the tree of resources is like traversing a data
22
+ structure. Here's code to get recent posts from del.icio.us:
23
+
24
+ WADL::Application.from_wadl(open("delicious.wadl")).v1.posts.recent.get
25
+
26
+ * Faults are custom subclasses named after the fault ID. You can catch
27
+ specific faults.
28
+
29
+ * You can bind some parameters (such as authentication parameters or
30
+ API keys) permanently to the WADL application, and leave others (such
31
+ as search queries) to be bound differently for each request.
32
+
33
+ * This feature isn't in the WADL standard yet: you can define
34
+ "header"-style parameters to be included in the HTTP request
35
+ headers. See delicious.wadl for an example.
36
+
37
+ === Shortcomings:
38
+
39
+ The 20060802 WADL standard is almost entirely supported. However,
40
+
41
+ * XML grammars are more or less ignored
42
+ * As are links
43
+
44
+
45
+ == LINKS
46
+
47
+ <b></b>
48
+ Homepage:: <http://www.crummy.com/software/wadl.rb/>
49
+ WADL:: <http://wadl.dev.java.net/>
50
+ Documentation:: <http://rdoc.info/projects/blackwinter/wadl>
51
+ Source code:: <http://github.com/blackwinter/wadl>
52
+
53
+
54
+ == AUTHORS
55
+
56
+ * Leonard Richardson <mailto:leonardr@segfault.org> (Original author)
57
+ * Jens Wille <mailto:jens.wille@uni-koeln.de>
58
+
59
+
60
+ == LICENSE AND COPYRIGHT
61
+
62
+ Copyright (C) 2006-2008 Leonard Richardson
63
+ Copyright (C) 2010 Jens Wille
64
+
65
+ wadl is free software: you can redistribute it and/or modify it under
66
+ the terms of the GNU General Public License as published by the Free Software
67
+ Foundation, either version 3 of the License, or (at your option) any later
68
+ version.
69
+
70
+ wadl is distributed in the hope that it will be useful, but WITHOUT
71
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
72
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
73
+
74
+ You should have received a copy of the GNU General Public License along with
75
+ wadl. If not, see <http://www.gnu.org/licenses/>.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require %q{lib/wadl/version}
2
+
3
+ begin
4
+ require 'hen'
5
+
6
+ Hen.lay! {{
7
+ :gem => {
8
+ :name => %q{wadl},
9
+ :version => WADL::VERSION,
10
+ :summary => %q{Ruby client for the Web Application Description Language.},
11
+ :authors => ['Leonard Richardson', 'Jens Wille'],
12
+ :email => ['leonardr@segfault.org', 'jens.wille@uni-koeln.de'],
13
+ :homepage => 'http://github.com/blackwinter/wadl',
14
+ :files => FileList['lib/**/*.rb'].to_a,
15
+ :extra_files => FileList['[A-Z]*', 'examples/*', 'test/**/*.rb'].to_a,
16
+ :dependencies => %w[rest-open-uri mime-types]
17
+ }
18
+ }}
19
+ rescue LoadError
20
+ abort "Please install the 'hen' gem first."
21
+ end
22
+
23
+ ### Place your custom Rake tasks here.
@@ -0,0 +1,7 @@
1
+ require 'wadl'
2
+
3
+ yahoo = WADL::Application.from_wadl(open("YahooSearch.wadl"))
4
+ expected_representation = yahoo.newsSearch.search.response.representations[0]
5
+ result = yahoo.newsSearch.get(:query => {:appid => "selectric", :query => "bar"},
6
+ :expected_representation => expected_representation)
7
+ puts result.representation
@@ -0,0 +1,88 @@
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ The contents of this file are subject to the terms
4
+ of the Common Development and Distribution License
5
+ (the "License"). You may not use this file except
6
+ in compliance with the License.
7
+
8
+ You can obtain a copy of the license at
9
+ http://www.opensource.org/licenses/cddl1.php
10
+ See the License for the specific language governing
11
+ permissions and limitations under the License.
12
+ -->
13
+ <application xmlns:xsd="http://www.w3.org/2001/XMLSchema"
14
+ xmlns:yn="urn:yahoo:yn"
15
+ xmlns:ya="urn:yahoo:api"
16
+ xmlns:html="http://www.w3.org/1999/xhtml"
17
+ xmlns="http://research.sun.com/wadl/2006/07">
18
+
19
+ <grammars>
20
+ <include href="NewsSearchResponse.xsd"/>
21
+ <include href="NewsSearchError.xsd"/>
22
+ </grammars>
23
+
24
+ <resources base="http://api.search.yahoo.com/NewsSearchService/V1/">
25
+ <resource path="newsSearch">
26
+ <doc xml:lang="en" title="Yahoo News Search Service">
27
+ The <html:i>Yahoo News Search</html:i> service provides online searching of news
28
+ stories from around the world.
29
+ </doc>
30
+ <param name="appid" type="xsd:string" required="true" style="form">
31
+ <doc>The application ID. See <html:a href="http://developer.yahoo.com/faq/index.html#appid">Application IDs</html:a> for more information.</doc>
32
+ </param>
33
+ <method href="#search"/>
34
+ </resource>
35
+ </resources>
36
+
37
+ <method name="GET" id="search">
38
+ <doc xml:lang="en" title="Search news stories by keyword"/>
39
+ <request>
40
+ <param name="query" type="xsd:string" required="true">
41
+ <doc xml:lang="en" title="Space separated keywords to search for"/>
42
+ </param>
43
+ <param name="type" type="xsd:string" default="all">
44
+ <doc xml:lang="en" title="Keyword matching"/>
45
+ <option value="all">
46
+ <doc>All query terms.</doc>
47
+ </option>
48
+ <option value="any">
49
+ <doc>Any query terms.</doc>
50
+ </option>
51
+ <option value="phrase">
52
+ <doc>Query terms as a phrase.</doc>
53
+ </option>
54
+ </param>
55
+ <param name="results" type="xsd:int" default="10">
56
+ <doc xml:lang="en" title="Number of results"/>
57
+ </param>
58
+ <param name="start" type="xsd:int" default="1">
59
+ <doc xml:lang="en" title="Index of first result"/>
60
+ </param>
61
+ <param name="sort" type="xsd:string" default="rank">
62
+ <doc xml:lang="en" title="Sort by date or rank"/>
63
+ <option value="rank"/>
64
+ <option value="date"/>
65
+ </param>
66
+ <param name="language" type="xsd:string">
67
+ <doc xml:lang="en" title="Language filter, omit for any language"/>
68
+ </param>
69
+ <param name="output" type="xsd:string" default="xml">
70
+ <doc>The format for the output. If <html:em>json</html:em> is requested, the results will be returned in <html:a href="http://developer.yahoo.com/common/json.html">JSON</html:a> format. If <html:em>php</html:em> is requested, the results will be returned in <html:a href="http://developer.yahoo.com/common/phpserial.html">Serialized PHP</html:a> format.</doc>
71
+ <option value="xml"/>
72
+ <option value="json"/>
73
+ <option value="php"/>
74
+ </param>
75
+ <param name="callback" type="xsd:string">
76
+ <doc>The name of the callback function to wrap around the JSON data. The following characters are allowed: A-Z a-z 0-9 . [] and _. If output=json has not been requested, this parameter has no effect. More information on the callback can be found in the <html:a href="http://developer.yahoo.com/common/json.html#callbackparam">Yahoo! Developer Network JSON Documentation</html:a>.</doc>
77
+ </param>
78
+ </request>
79
+ <response>
80
+ <representation mediaType="application/xml" element="yn:ResultSet">
81
+ <doc xml:lang="en" title="A list of news items matching the query"/>
82
+ </representation>
83
+ <fault id="SearchError" status="400" mediaType="application/xml"
84
+ element="ya:Error"/>
85
+ </response>
86
+ </method>
87
+
88
+ </application>
@@ -0,0 +1,17 @@
1
+ require 'wadl'
2
+
3
+ crummy = WADL::Application.from_wadl(open("crummy.wadl"))
4
+ add_resource = crummy.find_resource(:add)
5
+
6
+ repr_format = add_resource.find_method(:add).request.representations[0]
7
+ representation = repr_format % {:password => 'mypassword',
8
+ :entry => 'This is an entry',
9
+ :title => 'The title!' }
10
+ result = add_resource.post(:path => {:weblog => "personal"},
11
+ :send_representation => representation)
12
+ if format = result.format and format.id == 'CreatedAtURI'
13
+ puts "Success!"
14
+ puts result.headers['Location']
15
+ else
16
+ puts result
17
+ end
@@ -0,0 +1,34 @@
1
+ <?xml version="1.0"?>
2
+
3
+ <!--Example of WADL being used to turn a not-particularly-RESTful CGI
4
+ application into a web service.-->
5
+
6
+ <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7
+ xsi:schemaLocation="http://research.sun.com/wadl wadl.xsd"
8
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
9
+ xmlns:nb="urn:newsbruiser:nb"
10
+ xmlns="http://research.sun.com/wadl">
11
+
12
+ <resources base="http://www.crummy.com/nb/nb.cgi/">
13
+ <resource path="add" id="add">
14
+ <param name="weblog" type="xsd:string" />
15
+ <method href="#add"/>
16
+ </resource>
17
+ </resources>
18
+
19
+ <method name="POST" id="add">
20
+ <request>
21
+ <representation mediaType="application/x-www-form-encoded">
22
+ <param name="password" type="xsd:string" required="true" />
23
+ <param name="entry" type="xsd:string" required="true" />
24
+ <param name="title" type="xsd:string" />
25
+ <param name="make_change" type="xsd:string" fixed="true" />
26
+ <param name="Button" type="xsd:string" fixed="Publish" />
27
+ </representation>
28
+ </request>
29
+
30
+ <response>
31
+ <fault id="CreatedAtURI" status="302" />
32
+ </response>
33
+ </method>
34
+ </application>
@@ -0,0 +1,24 @@
1
+ require 'wadl'
2
+
3
+ delicious = WADL::Application.from_wadl(open("delicious.wadl")).v1
4
+ delicious = delicious.with_basic_auth('username', 'password' )
5
+
6
+ query_args = { :url => 'https://wadl.dev.java.net/',
7
+ :description => 'WADL homepage',
8
+ :extended => 'Posted with Ruby WADL client' }
9
+ begin
10
+ delicious.posts.add.get(:query => query_args)
11
+ rescue WADL::Faults::AuthorizationRequired
12
+ puts "Invalid authentication information!"
13
+ end
14
+
15
+ #delicious.posts.add.addPost(:query => query_args)
16
+ #delicious.posts.addPost(:query => query_args)
17
+
18
+ begin
19
+ delicious.posts.recent.get.representation.each_element("post") do |e|
20
+ puts "#{e.attributes['description']}: #{e.attributes['href']}"
21
+ end
22
+ rescue WADL::Faults::AuthorizationRequired
23
+ puts "Invalid authentication information!"
24
+ end
@@ -0,0 +1,348 @@
1
+ <?xml version="1.0"?>
2
+ <!-- This is a bootleg WADL file for the del.icio.us API. -->
3
+
4
+ <application xmlns:xsd="http://www.w3.org/2001/XMLSchema"
5
+ xmlns:html="http://www.w3.org/1999/xhtml"
6
+ xmlns="http://research.sun.com/wadl/2006/07">
7
+
8
+ <resources base="https://api.del.icio.us/">
9
+ <doc xml:lang="en" title="The del.icio.us API v1">
10
+ Post or retrieve your bookmarks from the social networking website.
11
+ Limit requests to one per second.
12
+ </doc>
13
+
14
+ <resource path="v1">
15
+ <param name="Authorization" style="header" required="true">
16
+ <doc xml:lang="en">All del.icio.us API calls must be authenticated
17
+ using Basic HTTP auth.</doc>
18
+ </param>
19
+
20
+ <resource path="update"><method href="#getLastUpdateTime" /></resource>
21
+
22
+ <resource path="tags">
23
+ <resource path="get"><method href="#getTags" /></resource>
24
+ <resource path="rename"><method href="#renameTag" /></resource>
25
+ </resource>
26
+
27
+ <resource path="posts">
28
+ <resource path="get"><method href="#getPosts" /></resource>
29
+ <resource path="recent"><method href="#getRecentPosts" /></resource>
30
+ <resource path="all"><method href="#getAllPosts" /></resource>
31
+ <resource path="dates"><method href="#getDates" /></resource>
32
+
33
+ <resource path="add"><method href="#addPost" /></resource>
34
+ <resource path="delete"><method href="#deletePost" /></resource>
35
+ </resource>
36
+
37
+ <resource path="bundles">
38
+ <resource path="all"><method href="#getBundles" /></resource>
39
+ <resource path="set"><method href="#makeBundle" /></resource>
40
+ <resource path="delete"><method href="#deleteBundle" /></resource>
41
+ </resource>
42
+ </resource>
43
+ </resources>
44
+
45
+ <!-- Methods -->
46
+
47
+ <!-- "update" method -->
48
+
49
+ <method id="getLastUpdateTime" name="GET">
50
+ <response>
51
+ <representation mediaType="application/xml" element="update">
52
+ <doc xml:lang="en" title="A note on structure">
53
+ The "time" attribute contains the last update time for the
54
+ authenticated user, in ISO8661 format.
55
+ </doc>
56
+ </representation>
57
+ <fault href="#AuthorizationRequired" />
58
+ </response>
59
+ </method>
60
+
61
+ <!-- "tags" methods -->
62
+
63
+ <method id="getTags" name="GET">
64
+ <response>
65
+ <representation mediaType="application/xml" element="tags">
66
+ <doc xml:lang="en" title="Schema description">
67
+ Contains "tag" tags, each with "count" and "tag" attributes.
68
+ </doc>
69
+ </representation>
70
+ <fault href="#AuthorizationRequired" />
71
+ </response>
72
+ </method>
73
+
74
+ <method id="renameTag" name="POST">
75
+ <request>
76
+ <param name="old" required="true" style="form">
77
+ <doc xml:lang="en" title="Tag to rename." />
78
+ </param>
79
+ <param name="new" required="true" style="form">
80
+ <doc xml:lang="en" title="New name." />
81
+ </param>
82
+ </request>
83
+
84
+ <response>
85
+ <representation href="#resultCodeDone" />
86
+ <fault href="#AuthorizationRequired" />
87
+ </response>
88
+ </method>
89
+
90
+ <!-- "posts" methods part I: ways of getting posts -->
91
+
92
+ <method id="getPosts" name="GET">
93
+ <doc xml:lang="en" title="Returns posts matching the arguments.">
94
+ If no date or url is given, most recent date will be used.
95
+ </doc>
96
+
97
+ <request>
98
+ <param name="tag" style="form">
99
+ <doc xml:lang="en" title="Filter by this tag." />
100
+ </param>
101
+ <param name="dt" style="form">
102
+ <doc xml:lang="en" title="Filter by this date (CCYY-MM-DDThh:mm:ssZ)." />
103
+ </param>
104
+ <param name="url" style="form">
105
+ <doc xml:lang="en" title="Filter by this URL." />
106
+ </param>
107
+ </request>
108
+ <response>
109
+ <representation mediaType="application/xml" element="posts">
110
+ <doc xml:lang="en" title="Sample response">
111
+ &lt;posts dt=&quot;2005-11-28&quot; tag=&quot;webdev&quot; user=&quot;user&quot;&gt;
112
+ &lt;post href=&quot;http://www.howtocreate.co.uk/tutorials/texterise.php?dom=1&quot;
113
+ description=&quot;JavaScript DOM reference&quot;
114
+ extended=&quot;dom reference&quot;
115
+ hash=&quot;c0238dc0c44f07daedd9a1fd9bbdeebd&quot;
116
+ others=&quot;55&quot; tag=&quot;dom javascript webdev&quot; time=&quot;2005-11-28T05:26:09Z&quot; /&gt;
117
+ &lt;/posts&gt;
118
+ </doc>
119
+ </representation>
120
+ </response>
121
+ </method>
122
+
123
+ <method id="getRecentPosts" name="GET">
124
+
125
+ <doc xml:lang="en" title="Returns a list of the most recent posts.">
126
+ Filtered by argument. Maximum 100.
127
+ </doc>
128
+
129
+ <request>
130
+ <param name="tag" style="form">
131
+ <doc xml:lang="en" title="Filter by this tag." />
132
+ </param>
133
+ <param name="count" style="form" default="15">
134
+ <doc xml:lang="en" title="Number of items to retrieve.">Maximum: 100</doc>
135
+ </param>
136
+ </request>
137
+
138
+ <response>
139
+ <representation href="#postList" />
140
+ <fault href="#AuthorizationRequired" />
141
+ </response>
142
+ </method>
143
+
144
+ <method id="getAllPosts" name="GET">
145
+ <doc xml:lang="en" title="Returns all posts">
146
+ Please use sparingly. Call the update function to see if you need
147
+ to fetch this at all.
148
+ </doc>
149
+
150
+ <request>
151
+ <param name="tag" style="form">
152
+ <doc xml:lang="en" title="Filter by this tag." />
153
+ </param>
154
+ </request>
155
+
156
+ <response>
157
+ <representation href="#postList" />
158
+ <fault href="#AuthorizationRequired" />
159
+ </response>
160
+ </method>
161
+
162
+ <method id="getDates" name="GET">
163
+ <doc xml:lang="en"
164
+ title="Returns a list of dates with the number of posts at each date." />
165
+
166
+ <request>
167
+ <param name="tag" style="form">
168
+ <doc xml:lang="en" title="Filter by this tag." />
169
+ </param>
170
+ </request>
171
+ <response>
172
+ <representation mediaType="application/xml">
173
+ <doc xml:lang="en" title="Sample">
174
+ &lt;dates tag=&quot;&quot; user=&quot;user&quot;&gt;
175
+ &lt;date count=&quot;5&quot; date=&quot;2005-11-29&quot; /&gt;
176
+ &lt;date count=&quot;15&quot; date=&quot;2005-11-28&quot; /&gt;
177
+ &lt;date count=&quot;2&quot; date=&quot;2005-11-26&quot; /&gt;
178
+ &lt;date count=&quot;2&quot; date=&quot;2005-11-25&quot; /&gt;
179
+ &lt;date count=&quot;7&quot; date=&quot;2005-11-23&quot; /&gt;
180
+ &lt;date count=&quot;20&quot; date=&quot;2005-11-22&quot; /&gt;
181
+ &lt;date count=&quot;16&quot; date=&quot;2005-11-21&quot; /&gt;
182
+ &lt;date count=&quot;4&quot; date=&quot;2005-11-19&quot; /&gt;
183
+ &lt;/dates&gt;
184
+ </doc>
185
+ </representation>
186
+ </response>
187
+ </method>
188
+
189
+ <!-- "posts" methods part II: ways of manipulating posts -->
190
+
191
+ <method id="addPost" name="GET">
192
+ <doc xml:lang="en" title="Add a post to del.icio.us" />
193
+ <request>
194
+ <param name="url" required="true" style="form">
195
+ <doc xml:lang="en" title="The URL of the item." />
196
+ </param>
197
+
198
+ <param name="description" required="true" style="form">
199
+ <doc xml:lang="en" title="The description of the item." />
200
+ </param>
201
+
202
+ <param name="extended" style="form">
203
+ <doc xml:lang="en" title="Notes for the item." />
204
+ </param>
205
+
206
+ <param name="tags" style="form">
207
+ <doc xml:lang="en" title="Tags for the item.">Space delimited</doc>
208
+ </param>
209
+
210
+ <param name="dt" style="form">
211
+ <doc xml:lang="en" title="Datestamp of the item.">
212
+ Format: "CCYY-MM-DDThh:mm:ssZ". Requires a LITERAL "T" and "Z"
213
+ like in
214
+ <html:a href="http://www.cl.cam.ac.uk/~mgk25/iso-time.html">ISO8601</html:a>.
215
+ For example: "1984-09-01T14:21:31Z"
216
+ </doc>
217
+ </param>
218
+
219
+ <param name="replace" default="" style="form">
220
+ <doc xml:lang="en"
221
+ title="Unless set to &quot;no&quot;, a post will overwrite an
222
+ earlier post with the same URL." />
223
+ <option value="" />
224
+ <option value="no" />
225
+ </param>
226
+
227
+ <param name="shared" style="form">
228
+ <doc xml:lang="en" title="Set to &quot;no&quot; to make the item private." />
229
+ <option value="" />
230
+ <option value="no" />
231
+ </param>
232
+
233
+ </request>
234
+
235
+ <response>
236
+ <representation href="#resultCode" />
237
+ <fault href="#AuthorizationRequired" />
238
+ </response>
239
+ </method>
240
+
241
+ <method id="deletePost" name="GET">
242
+ <doc xml:lang="en" title="Delete a post from del.icio.us" />
243
+
244
+ <request>
245
+ <param name="url" required="true" style="form">
246
+ <doc xml:lang="en" title="The URL of the item." />
247
+ </param>
248
+ </request>
249
+
250
+ <response>
251
+ <representation href="#resultCodeDone" />
252
+ <fault href="#AuthorizationRequired" />
253
+ </response>
254
+ </method>
255
+
256
+ <!-- "bundles" methods -->
257
+
258
+ <method id="getBundles" name="GET">
259
+ <doc xml:lang="en" title="Retrieve all of a user's bundles." />
260
+
261
+ <response>
262
+ <representation mediaType="application/xml" element="bundles">
263
+ <doc xml:lang="en" title="Sample">
264
+ &lt;bundles&gt;
265
+ &lt;bundle name=&quot;music&quot; tags=&quot;ipod mp3 music&quot; /&gt;
266
+ &lt;/bundles&gt;
267
+ </doc>
268
+ </representation>
269
+ <fault href="#AuthorizationRequired" />
270
+ </response>
271
+ </method>
272
+
273
+ <method id="makeBundle" name="GET">
274
+ <doc xml:lang="en" title="Assign a set of tags to a single bundle.">
275
+ Wipes away previous settings for bundle.
276
+ </doc>
277
+
278
+ <request>
279
+ <param name="bundle" style="form">
280
+ <doc xml:lang="en" title="The bundle name." />
281
+ </param>
282
+ <param name="tags" required="true" style="form">
283
+ <doc xml:lang="en" title="List of tags.">Space-separated.</doc>
284
+ </param>
285
+ </request>
286
+
287
+ <response>
288
+ <representation mediaType="application/xml" element="result">
289
+ <doc xml:lang="en" title="A note on structure">
290
+ On success, contents are &quot;done&quot; On failure,
291
+ contents are &quot;you must supply a bundle name and at least one
292
+ tag&quot;
293
+ </doc>
294
+ </representation>
295
+ <fault href="#AuthorizationRequired" />
296
+ </response>
297
+ </method>
298
+
299
+ <method id="deleteBundle" name="GET">
300
+ <doc xml:lang="en" title="Deletes a bundle." />
301
+ <request>
302
+ <param name="bundle" style="form">
303
+ <doc xml:lang="en" title="The bundle name." />
304
+ </param>
305
+ </request>
306
+
307
+ <response>
308
+ <representation href="#resultCodeDone" />
309
+ <fault href="#AuthorizationRequired" />
310
+ </response>
311
+ </method>
312
+
313
+ <!-- Commonly used representations -->
314
+
315
+ <representation id="postList" mediaType="text/xml" element="posts">
316
+ <doc xml:lang="en" title="Sample">
317
+ &lt;posts tag=&quot;&quot; user=&quot;user&quot;&gt;
318
+ &lt;post href=&quot;http://www.weather.com/&quot; description=&quot;weather.com&quot;
319
+ hash=&quot;6cfedbe75f413c56b6ce79e6fa102aba&quot; tag=&quot;weather reference&quot;
320
+ time=&quot;2005-11-29T20:30:47Z&quot; /&gt;
321
+ &lt;post href=&quot;http://www.nytimes.com/&quot;
322
+ description=&quot;The New York Times - Breaking News, World News &amp; Multimedia&quot;
323
+ extended=&quot;requires login&quot; hash=&quot;ca1e6357399774951eed4628d69eb84b&quot;
324
+ tag=&quot;news media&quot; time=&quot;2005-11-29T20:30:05Z&quot; /&gt;
325
+ &lt;/posts&gt;
326
+ </doc>
327
+ </representation>
328
+
329
+ <representation id="resultCode" mediaType="application/xml" element="result">
330
+ <doc xml:lang="en" title="A note on structure">
331
+ This representation has the same structure whether or not the
332
+ operation succeeded. If it succeeded, the value of the 'code'
333
+ attribute is "done". Otherwise, it's "something went wrong".
334
+ </doc>
335
+ </representation>
336
+
337
+ <representation id="resultCodeDone" mediaType="application/xml" element="result">
338
+ <doc xml:lang="en" title="A note on structure">
339
+ Allegedly, this representation has a "code" attribute whose value
340
+ is always "done". I think it might actually be the same as the
341
+ resultCode representation.
342
+ </doc>
343
+ </representation>
344
+
345
+ <fault id="AuthorizationRequired" status="401" />
346
+
347
+
348
+ </application>
data/examples/yahoo.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'wadl'
2
+
3
+ yahoo = WADL::Application.from_wadl(open("yahoo.wadl"))
4
+ search_resource = yahoo.find_resource(:newsSearch)
5
+ expected_representation = search_resource.find_method(:search).response.representations[0]
6
+ result = search_resource.get({:appid => "selectric", :query => "bar"},
7
+ expected_representation)
8
+ puts result.representation
9
+
10
+ begin
11
+ search_resource.get(:query => "bar")
12
+ rescue ArgumentError
13
+ puts "Couldn't call method without providing value for required variable. (Good)"
14
+ end
@@ -0,0 +1,37 @@
1
+ <?xml version="1.0"?>
2
+ <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi:schemaLocation="http://research.sun.com/wadl wadl.xsd"
4
+ xmlns:tns="urn:yahoo:yn"
5
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
6
+ xmlns:yn="urn:yahoo:yn"
7
+ xmlns:ya="urn:yahoo:api"
8
+ xmlns="http://research.sun.com/wadl">
9
+ <grammars>
10
+ <include href="NewsSearchResponse.xsd"/>
11
+ <include href="http://api.search.yahoo.com/Api/V1/error.xsd"/>
12
+ </grammars>
13
+
14
+ <resources base="http://api.search.yahoo.com/NewsSearchService/V1/">
15
+ <resource uri="newsSearch">
16
+ <method href="#search"/>
17
+ </resource>
18
+ </resources>
19
+
20
+ <method name="GET" id="search">
21
+ <request>
22
+ <query.variable name="appid" type="xsd:string" required="true"/>
23
+ <query.variable name="query" type="xsd:string" required="true"/>
24
+ <query.variable name="type" type="xsd:string"/>
25
+ <query.variable name="results" type="xsd:int"/>
26
+ <query.variable name="start" type="xsd:int"/>
27
+ <query.variable name="sort" type="xsd:string"/>
28
+ <query.variable name="language" type="xsd:string"/>
29
+ </request>
30
+
31
+ <response>
32
+ <representation mediaType="application/xml" element="yn:ResultSet"/>
33
+ <fault id="SearchError" status="400" mediaType="text/xml"
34
+ element="ya:Error"/>
35
+ </response>
36
+ </method>
37
+ </application>