wadl 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/TODO +1 -0
- data/bin/wadl +5 -1
- data/lib/wadl/cheap_schema.rb +73 -20
- data/lib/wadl/cli.rb +30 -13
- data/lib/wadl/request_format.rb +1 -1
- data/lib/wadl/version.rb +2 -2
- metadata +5 -5
data/README
CHANGED
data/TODO
CHANGED
data/bin/wadl
CHANGED
data/lib/wadl/cheap_schema.rb
CHANGED
@@ -294,39 +294,92 @@ module WADL
|
|
294
294
|
index_key == name
|
295
295
|
end
|
296
296
|
|
297
|
-
def
|
297
|
+
def each_attribute
|
298
|
+
[self.class.required_attributes, self.class.attributes].each { |list|
|
299
|
+
list.each { |attr|
|
300
|
+
val = attributes[attr.to_s]
|
301
|
+
yield attr, val if val
|
302
|
+
}
|
303
|
+
}
|
304
|
+
end
|
305
|
+
|
306
|
+
def each_member
|
307
|
+
self.class.members.each_value { |member_class|
|
308
|
+
member = send(member_class.names[:member])
|
309
|
+
yield member if member
|
310
|
+
}
|
311
|
+
end
|
312
|
+
|
313
|
+
def each_collection
|
314
|
+
self.class.collections.each_value { |collection_class|
|
315
|
+
collection = send(collection_class.names[:collection])
|
316
|
+
yield collection if collection && !collection.empty?
|
317
|
+
}
|
318
|
+
end
|
319
|
+
|
320
|
+
def paths(level = default = 0)
|
321
|
+
klass, paths = self.class, []
|
322
|
+
return paths if klass.may_be_reference? && attributes['href']
|
323
|
+
|
324
|
+
if klass == Resource
|
325
|
+
path = attributes['path']
|
326
|
+
paths << [level, path] if path
|
327
|
+
elsif klass == HTTPMethod
|
328
|
+
paths << [level]
|
329
|
+
end
|
330
|
+
|
331
|
+
each_member { |member|
|
332
|
+
paths.concat(member.paths(level))
|
333
|
+
}
|
334
|
+
|
335
|
+
each_collection { |collection|
|
336
|
+
collection.each { |member| paths.concat(member.paths(level + 1)) }
|
337
|
+
}
|
338
|
+
|
339
|
+
if default
|
340
|
+
memo = []
|
341
|
+
|
342
|
+
paths.map { |level, path|
|
343
|
+
if path
|
344
|
+
memo.slice!(level..-1)
|
345
|
+
memo[level] = path
|
346
|
+
|
347
|
+
nil # ignore
|
348
|
+
else
|
349
|
+
memo.join('/')
|
350
|
+
end
|
351
|
+
}.compact
|
352
|
+
else
|
353
|
+
paths
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
def to_s(indent = 0, collection = false)
|
298
358
|
klass = self.class
|
299
359
|
|
300
|
-
|
301
|
-
|
360
|
+
a = ' '
|
361
|
+
i = a * indent
|
362
|
+
s = "#{collection ? a * (indent - 1) + '- ' : i}#{klass.name}\n"
|
302
363
|
|
303
364
|
if klass.may_be_reference? and href = attributes['href']
|
304
|
-
s << "#{i} href=#{href}\n"
|
365
|
+
s << "#{i}= href=#{href}\n"
|
305
366
|
else
|
306
|
-
|
307
|
-
|
308
|
-
val = attributes[attr.to_s]
|
309
|
-
s << "#{i} #{attr}=#{val}\n" if val
|
310
|
-
}
|
367
|
+
each_attribute { |attr, val|
|
368
|
+
s << "#{i}* #{attr}=#{val}\n"
|
311
369
|
}
|
312
370
|
|
313
|
-
|
314
|
-
|
315
|
-
s << o.to_s(indent + 1) if o
|
371
|
+
each_member { |member|
|
372
|
+
s << member.to_s(indent + 1)
|
316
373
|
}
|
317
374
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
if c && !c.empty?
|
322
|
-
s << "#{i} Collection of #{c.size} #{collection_class.name}(s)\n"
|
323
|
-
c.each { |o| s << o.to_s(indent + 2) }
|
324
|
-
end
|
375
|
+
each_collection { |collection|
|
376
|
+
s << "#{i}> Collection of #{collection.size} #{collection.class}(s)\n"
|
377
|
+
collection.each { |member| s << member.to_s(indent + 2, true) }
|
325
378
|
}
|
326
379
|
|
327
380
|
if @contents && !@contents.empty?
|
328
381
|
sep = '-' * 80
|
329
|
-
s << "#{sep}\n#{@contents.join(' ')}\n#{sep}\n"
|
382
|
+
s << "#{sep}\n#{@contents.join(' ').strip}\n#{sep}\n"
|
330
383
|
end
|
331
384
|
end
|
332
385
|
|
data/lib/wadl/cli.rb
CHANGED
@@ -82,9 +82,16 @@ module WADL
|
|
82
82
|
parse_arguments(arguments)
|
83
83
|
abort USAGE if resource_path.empty?
|
84
84
|
|
85
|
-
abort
|
85
|
+
abort "WADL location is required! (Specify with '--wadl' or see '--help')" unless options[:wadl]
|
86
86
|
options[:wadl] %= options[:base_url] if options[:base_url]
|
87
87
|
|
88
|
+
if debug = options[:debug]
|
89
|
+
debug = 1 unless debug.is_a?(Integer)
|
90
|
+
|
91
|
+
stderr.puts api.paths if debug >= 1
|
92
|
+
stderr.puts api if debug >= 2
|
93
|
+
end
|
94
|
+
|
88
95
|
response = auth_resource.send(options[:method].downcase, :query => opts)
|
89
96
|
|
90
97
|
stderr.puts response.code.join(' ')
|
@@ -97,19 +104,16 @@ module WADL
|
|
97
104
|
|
98
105
|
def resource
|
99
106
|
@resource ||= begin
|
100
|
-
path = [options[:api_base], *resource_path].compact.join('
|
101
|
-
path.split(RESOURCE_PATH_RE).inject(api) { |m, n| m.send(n) }
|
107
|
+
path = [options[:api_base], *resource_path].compact.join('/')
|
108
|
+
path.split(RESOURCE_PATH_RE).inject(api) { |m, n| m.send(:find_resource_by_path, n) }
|
102
109
|
end
|
103
110
|
end
|
104
111
|
|
105
112
|
def auth_resource
|
106
|
-
@auth_resource ||=
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
else
|
111
|
-
resource
|
112
|
-
end
|
113
|
+
@auth_resource ||= options[:skip_auth] ? resource :
|
114
|
+
options[:oauth] ? oauth_resource :
|
115
|
+
options[:basic] ? basic_auth_resource :
|
116
|
+
resource
|
113
117
|
end
|
114
118
|
|
115
119
|
def reset(stdin = STDIN, stdout = STDOUT, stderr = STDERR)
|
@@ -232,7 +236,7 @@ module WADL
|
|
232
236
|
|
233
237
|
opts.separator ''
|
234
238
|
|
235
|
-
opts.on('-w', '--wadl FILE_OR_URL', "Path or URL to WADL file") { |wadl|
|
239
|
+
opts.on('-w', '--wadl FILE_OR_URL', "Path or URL to WADL file [Required]") { |wadl|
|
236
240
|
options[:wadl] = wadl
|
237
241
|
}
|
238
242
|
|
@@ -245,9 +249,15 @@ module WADL
|
|
245
249
|
}
|
246
250
|
|
247
251
|
opts.separator ''
|
248
|
-
opts.separator 'Basic auth options:'
|
249
252
|
|
250
|
-
opts.on('-
|
253
|
+
opts.on('--skip-auth', "Skip any authentication") {
|
254
|
+
options[:skip_auth] = true
|
255
|
+
}
|
256
|
+
|
257
|
+
opts.separator ''
|
258
|
+
opts.separator 'Basic Auth options:'
|
259
|
+
|
260
|
+
opts.on('-B', '--basic', "Perform Basic Auth") {
|
251
261
|
options[:basic] = true
|
252
262
|
}
|
253
263
|
|
@@ -317,9 +327,16 @@ module WADL
|
|
317
327
|
abort "#{File.basename($0)} v#{WADL::VERSION}"
|
318
328
|
}
|
319
329
|
|
330
|
+
opts.on('-d', '--debug [LEVEL]', Integer, "Enable debugging output") { |level|
|
331
|
+
options[:debug] = level || true
|
332
|
+
}
|
333
|
+
|
320
334
|
opts.on('-D', '--dump-config', "Dump config and exit") {
|
321
335
|
options[:dump_config] = true
|
322
336
|
}
|
337
|
+
|
338
|
+
opts.separator ''
|
339
|
+
opts.separator "PATH may be separated by any of #{RESOURCE_PATH_RE.source}."
|
323
340
|
}
|
324
341
|
end
|
325
342
|
|
data/lib/wadl/request_format.rb
CHANGED
data/lib/wadl/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wadl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Leonard Richardson
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-08-11 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|