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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 502bdfe2423d3d6020d35cfd788adcdb5711af80
|
4
|
+
data.tar.gz: 8e38d68bc3a3574ed72cc86c4146ad964135925d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60ed00a1f22ed3d648900ae3a56b7470bf985b15d9811f250a0c45154305c4e2b8671477a5cf5bf98d50d0ae6908f5736ad61799082d29db01f471ce3b3568d2
|
7
|
+
data.tar.gz: 2f2acd870930374c2f3a8986478106cb06f4c7795392ca71a05717882abda265813dc80073be744f79c6899e175257de2a348d414ca0e3df5fe20f340dd91fe3
|
data/README
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
== VERSION
|
4
4
|
|
5
|
-
This documentation refers to wadl version 0.
|
5
|
+
This documentation refers to wadl version 0.3.0
|
6
6
|
|
7
7
|
|
8
8
|
== DESCRIPTION
|
@@ -44,12 +44,12 @@ The 20060802 WADL standard is almost entirely supported. However,
|
|
44
44
|
|
45
45
|
== LINKS
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
Homepage:: http://www.crummy.com/software/wadl.rb
|
48
|
+
WADL Specification:: https://wadl.java.net
|
49
|
+
Documentation:: https://blackwinter.github.com/wadl
|
50
|
+
Source code:: https://github.com/blackwinter/wadl
|
51
|
+
RubyGem:: https://rubygems.org/gems/wadl
|
52
|
+
Travis CI:: https://travis-ci.org/blackwinter/wadl
|
53
53
|
|
54
54
|
|
55
55
|
== AUTHORS
|
@@ -61,7 +61,7 @@ RubyGem:: http://rubygems.org/gems/wadl
|
|
61
61
|
== LICENSE AND COPYRIGHT
|
62
62
|
|
63
63
|
Copyright (C) 2006-2008 Leonard Richardson
|
64
|
-
Copyright (C) 2010-
|
64
|
+
Copyright (C) 2010-2014 Jens Wille
|
65
65
|
|
66
66
|
wadl is free software: you can redistribute it and/or modify it under
|
67
67
|
the terms of the GNU Affero General Public License as published by the
|
data/Rakefile
CHANGED
@@ -1,18 +1,25 @@
|
|
1
|
-
|
1
|
+
require_relative 'lib/wadl/version'
|
2
2
|
|
3
3
|
begin
|
4
4
|
require 'hen'
|
5
5
|
|
6
6
|
Hen.lay! {{
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
7
|
+
gem: {
|
8
|
+
name: %q{wadl},
|
9
|
+
version: WADL::VERSION,
|
10
|
+
summary: %q{Super cheap Ruby WADL client.},
|
11
|
+
description: %q{Ruby client for the Web Application Description Language.},
|
12
|
+
authors: ['Leonard Richardson', 'Jens Wille'],
|
13
|
+
email: 'jens.wille@gmail.com',
|
14
|
+
license: %q{AGPL-3.0},
|
15
|
+
homepage: :blackwinter,
|
16
|
+
dependencies: {
|
17
|
+
'cyclops' => ['~> 0.0', '>= 0.0.4'],
|
18
|
+
'mime-types' => '~> 2.4',
|
19
|
+
'safe_yaml' => '~> 1.0'
|
20
|
+
},
|
21
|
+
|
22
|
+
required_ruby_version: '>= 1.9.3'
|
16
23
|
}
|
17
24
|
}}
|
18
25
|
rescue LoadError => err
|
data/lib/wadl.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# wadl -- 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,7 +26,7 @@
|
|
26
26
|
###############################################################################
|
27
27
|
#++
|
28
28
|
|
29
|
-
|
29
|
+
require_relative 'wadl/version'
|
30
30
|
|
31
31
|
module WADL
|
32
32
|
|
@@ -38,6 +38,8 @@ module WADL
|
|
38
38
|
autoload :Fault, 'wadl/fault'
|
39
39
|
autoload :HasDocs, 'wadl/has_docs'
|
40
40
|
autoload :HTTPMethod, 'wadl/http_method'
|
41
|
+
autoload :HTTPRequest, 'wadl/http_request'
|
42
|
+
autoload :HTTPResponse, 'wadl/http_response'
|
41
43
|
autoload :Link, 'wadl/link'
|
42
44
|
autoload :Option, 'wadl/option'
|
43
45
|
autoload :Param, 'wadl/param'
|
@@ -54,4 +56,17 @@ module WADL
|
|
54
56
|
autoload :URIParts, 'wadl/uri_parts'
|
55
57
|
autoload :XMLRepresentation, 'wadl/xml_representation'
|
56
58
|
|
59
|
+
class << self
|
60
|
+
|
61
|
+
def require_oauth(lib)
|
62
|
+
require "oauth/#{lib}"
|
63
|
+
rescue LoadError => err
|
64
|
+
define_singleton_method(__method__) { |*| } # only warn once
|
65
|
+
warn "For OAuth support, install the `oauth' library. (#{err})"
|
66
|
+
end
|
67
|
+
|
68
|
+
private :require_oauth
|
69
|
+
|
70
|
+
end
|
71
|
+
|
57
72
|
end
|
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-
|
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
|
# The Address class keeps track of the user's path through a resource
|
data/lib/wadl/application.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/lib/wadl/cheap_schema.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 cheap way of defining an XML schema as Ruby classes and then parsing
|
@@ -389,8 +387,3 @@ module WADL
|
|
389
387
|
end
|
390
388
|
|
391
389
|
end
|
392
|
-
|
393
|
-
# Simple backport for Ruby <= 1.8.5
|
394
|
-
class Object # :nodoc:
|
395
|
-
def instance_variable_defined?(sym); instance_eval("defined?(#{sym})"); end
|
396
|
-
end unless Object.method_defined?(:instance_variable_defined?)
|
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-
|
6
|
+
# Copyright (C) 2010-2014 Jens Wille #
|
7
7
|
# #
|
8
8
|
# Authors: #
|
9
9
|
# Jens Wille <jens.wille@gmail.com> #
|
@@ -25,19 +25,16 @@
|
|
25
25
|
#++
|
26
26
|
|
27
27
|
require 'cgi'
|
28
|
+
require 'cyclops'
|
29
|
+
require 'open-uri'
|
28
30
|
require 'stringio'
|
29
|
-
require 'nuggets/util/cli'
|
30
31
|
require 'wadl'
|
31
32
|
|
32
|
-
begin
|
33
|
-
require 'oauth/cli'
|
34
|
-
rescue LoadError
|
35
|
-
warn "For OAuth support, install the `oauth' library."
|
36
|
-
end
|
37
|
-
|
38
33
|
module WADL
|
39
34
|
|
40
|
-
|
35
|
+
require_oauth :cli
|
36
|
+
|
37
|
+
class CLI < Cyclops
|
41
38
|
|
42
39
|
OPTION_RE = %r{\A--?(.+?)(?:=(.+))?\z}
|
43
40
|
RESOURCE_PATH_RE = %r{[. /]}
|
@@ -53,12 +50,12 @@ module WADL
|
|
53
50
|
|
54
51
|
def defaults
|
55
52
|
super.merge(
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
59
|
-
:
|
60
|
-
:
|
61
|
-
:
|
53
|
+
config: 'config.yaml',
|
54
|
+
method: HTTPRequest::DEFAULT_METHOD.upcase,
|
55
|
+
user: ENV['USER'] || '',
|
56
|
+
request_token_url: '%s/oauth/request_token',
|
57
|
+
access_token_url: '%s/oauth/access_token',
|
58
|
+
authorize_url: '%s/oauth/authorize'
|
62
59
|
)
|
63
60
|
end
|
64
61
|
|
@@ -85,20 +82,23 @@ module WADL
|
|
85
82
|
stderr.puts api if debug >= 2
|
86
83
|
end
|
87
84
|
|
88
|
-
response = auth_resource.send(options[:method].downcase, :
|
85
|
+
response = auth_resource.send(options[:method].downcase, query: query)
|
89
86
|
|
90
87
|
stderr.puts response.code.join(' ')
|
91
88
|
stdout.puts response.representation unless response.code.first =~ /\A[45]/
|
92
89
|
end
|
93
90
|
|
94
91
|
def api
|
95
|
-
@api ||=
|
92
|
+
@api ||= Application.from_wadl(open(options[:wadl]))
|
96
93
|
end
|
97
94
|
|
98
95
|
def resource
|
99
96
|
@resource ||= begin
|
100
|
-
path = [options[:api_base], *resource_path].compact.join('/')
|
101
|
-
path
|
97
|
+
path = [options[:api_base], *resource_path].compact.join('/')
|
98
|
+
path = path.sub(/\A\//, '').split(RESOURCE_PATH_RE)
|
99
|
+
|
100
|
+
path.inject(api) { |m, n| m.send(:find_resource_by_path, n) or
|
101
|
+
quit "Resource not found: #{path.join('/')}: #{n}" }
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -123,7 +123,8 @@ module WADL
|
|
123
123
|
|
124
124
|
def parse_arguments(arguments)
|
125
125
|
@resource_path, @query, skip_next = [], {}, false
|
126
|
-
|
126
|
+
|
127
|
+
parse_query
|
127
128
|
|
128
129
|
arguments.each_with_index { |arg, index|
|
129
130
|
if skip_next
|
@@ -148,14 +149,12 @@ module WADL
|
|
148
149
|
}
|
149
150
|
end
|
150
151
|
|
151
|
-
def parse_query
|
152
|
-
|
152
|
+
def parse_query
|
153
|
+
return unless query_string = options[:query]
|
153
154
|
|
154
155
|
query_string.split(QUERY_SEPARATOR_RE).each { |pair|
|
155
|
-
add_param(
|
156
|
+
add_param(query, *pair.split('=', 2).map { |v| CGI.unescape(v) })
|
156
157
|
}
|
157
|
-
|
158
|
-
params
|
159
158
|
end
|
160
159
|
|
161
160
|
def add_param(params, key, value)
|
@@ -183,7 +182,7 @@ module WADL
|
|
183
182
|
|
184
183
|
def basic_auth_resource
|
185
184
|
user, pass = options.values_at(:user, :password)
|
186
|
-
pass ||=
|
185
|
+
pass ||= askpass("Password for user #{user}: ")
|
187
186
|
|
188
187
|
quit 'USER and PASSWORD required' unless user && pass
|
189
188
|
|
@@ -241,111 +240,77 @@ module WADL
|
|
241
240
|
end
|
242
241
|
|
243
242
|
def opts(opts)
|
244
|
-
opts.
|
245
|
-
|
246
|
-
}
|
247
|
-
|
248
|
-
opts.separator ''
|
243
|
+
opts.option(:wadl__FILE_OR_URL,
|
244
|
+
'Path or URL to WADL file [Required]')
|
249
245
|
|
250
|
-
opts.
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
opts.on('-m', '--method METHOD', "Request method [Default: #{defaults[:method]}]") { |method|
|
255
|
-
options[:method] = method.upcase
|
256
|
-
}
|
246
|
+
opts.option(:method__METHOD,
|
247
|
+
"Request method [Default: #{defaults[:method]}]",
|
248
|
+
&:upcase!)
|
257
249
|
|
258
|
-
opts.
|
259
|
-
options[:api_base] = api_base
|
260
|
-
}
|
250
|
+
opts.option(:api_base__PATH, 'Base path for API')
|
261
251
|
|
262
|
-
opts.
|
263
|
-
options[:query] = parse_query(query)
|
264
|
-
}
|
252
|
+
opts.option(:query__QUERY, 'Query string to pass to request')
|
265
253
|
|
266
|
-
opts.separator
|
254
|
+
opts.separator
|
267
255
|
|
268
|
-
opts.
|
269
|
-
options[:skip_auth] = true
|
270
|
-
}
|
256
|
+
opts.switch('skip_auth', 'Skip any authentication')
|
271
257
|
|
272
|
-
opts.separator
|
258
|
+
opts.separator
|
273
259
|
opts.separator 'Basic Auth options:'
|
274
260
|
|
275
|
-
opts.
|
276
|
-
options[:basic] = true
|
277
|
-
}
|
261
|
+
opts.switch(:basic, :B, 'Perform Basic Auth')
|
278
262
|
|
279
|
-
opts.separator
|
263
|
+
opts.separator
|
280
264
|
|
281
|
-
opts.
|
282
|
-
options[:user] = user
|
283
|
-
}
|
265
|
+
opts.option('user__USER', 'User name')
|
284
266
|
|
285
|
-
opts.
|
286
|
-
options[:password] = password
|
287
|
-
}
|
267
|
+
opts.option('password__PASSWORD', 'Password for user')
|
288
268
|
|
289
|
-
opts.separator
|
269
|
+
opts.separator
|
290
270
|
opts.separator 'OAuth options:'
|
291
271
|
|
292
|
-
opts.
|
293
|
-
options[:oauth] = true
|
294
|
-
}
|
272
|
+
opts.switch(:oauth, :O, 'Perform OAuth')
|
295
273
|
|
296
|
-
opts.separator
|
274
|
+
opts.separator
|
297
275
|
|
298
|
-
opts.
|
299
|
-
options[:consumer_key] = consumer_key
|
300
|
-
}
|
276
|
+
opts.option('consumer_key__KEY', 'Consumer key to use')
|
301
277
|
|
302
|
-
opts.
|
303
|
-
options[:consumer_secret] = consumer_secret
|
304
|
-
}
|
278
|
+
opts.option('consumer_secret__SECRET', 'Consumer secret to use')
|
305
279
|
|
306
|
-
opts.separator
|
280
|
+
opts.separator
|
307
281
|
|
308
|
-
opts.
|
309
|
-
options[:token] = token
|
310
|
-
}
|
282
|
+
opts.option('token__TOKEN', 'Access token to use')
|
311
283
|
|
312
|
-
opts.
|
313
|
-
options[:secret] = secret
|
314
|
-
}
|
284
|
+
opts.option('secret__SECRET', 'Token secret to use')
|
315
285
|
|
316
|
-
opts.separator
|
286
|
+
opts.separator
|
317
287
|
|
318
|
-
opts.
|
319
|
-
options[:base_url] = base_url
|
320
|
-
}
|
288
|
+
opts.option(:base_url__URL, 'Base URL [Default: "dirname" of WADL]')
|
321
289
|
|
322
|
-
opts.
|
323
|
-
|
324
|
-
}
|
290
|
+
opts.option('request_token_url__URL',
|
291
|
+
"Request token URL [Default: #{defaults[:request_token_url] % 'BASE_URL'}]")
|
325
292
|
|
326
|
-
opts.
|
327
|
-
|
328
|
-
}
|
293
|
+
opts.option('access_token_url__URL',
|
294
|
+
"Access token URL [Default: #{defaults[:access_token_url] % 'BASE_URL'}]")
|
329
295
|
|
330
|
-
opts.
|
331
|
-
|
332
|
-
}
|
296
|
+
opts.option('authorize_url__URL',
|
297
|
+
"Authorize URL [Default: #{defaults[:authorize_url] % 'BASE_URL'}]")
|
333
298
|
end
|
334
299
|
|
335
300
|
def generic_opts(opts)
|
336
|
-
|
337
|
-
|
338
|
-
opts.on('-d', '--debug [LEVEL]', Integer, 'Enable debugging output') { |level|
|
301
|
+
opts.option(:debug__LEVEL?, Integer, 'Enable debugging output') { |level|
|
339
302
|
options[:debug] = level || true
|
340
303
|
}
|
341
304
|
|
342
|
-
opts.
|
343
|
-
|
344
|
-
|
305
|
+
opts.switch(:dump_config, :D, 'Dump config and exit')
|
306
|
+
|
307
|
+
opts.separator
|
308
|
+
|
309
|
+
super
|
345
310
|
end
|
346
311
|
|
347
312
|
def post_opts(opts)
|
348
|
-
opts.separator
|
313
|
+
opts.separator
|
349
314
|
opts.separator "PATH may be separated by any of #{RESOURCE_PATH_RE.source}."
|
350
315
|
end
|
351
316
|
|