wadl 0.1.8 → 0.2.0

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to wadl version 0.1.8
5
+ This documentation refers to wadl version 0.2.0
6
6
 
7
7
 
8
8
  == DESCRIPTION
data/TODO CHANGED
@@ -1 +1,2 @@
1
1
  * WADL formatters (plain text, HTML?)
2
+ * Caching of downloaded WADL file
data/bin/wadl CHANGED
@@ -28,4 +28,8 @@
28
28
 
29
29
  require 'wadl/cli'
30
30
 
31
- WADL::CLI.execute(ARGV, STDIN, STDOUT, STDERR)
31
+ begin
32
+ WADL::CLI.execute(ARGV, STDIN, STDOUT, STDERR)
33
+ rescue ArgumentError => err
34
+ abort err
35
+ end
@@ -294,39 +294,92 @@ module WADL
294
294
  index_key == name
295
295
  end
296
296
 
297
- def to_s(indent = 0)
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
- i = ' ' * indent
301
- s = "#{i}#{klass.name}\n"
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
- [klass.required_attributes, klass.attributes].each { |list|
307
- list.each { |attr|
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
- klass.members.each_value { |member_class|
314
- o = send(member_class.names[:member])
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
- klass.collections.each_value { |collection_class|
319
- c = send(collection_class.names[:collection])
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
 
@@ -82,9 +82,16 @@ module WADL
82
82
  parse_arguments(arguments)
83
83
  abort USAGE if resource_path.empty?
84
84
 
85
- abort 'WADL required' unless options[:wadl]
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 ||= if options[:basic]
107
- basic_auth_resource
108
- elsif options[:oauth]
109
- oauth_resource
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('-B', '--basic', "Perform Basic auth") {
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
 
@@ -56,7 +56,7 @@ module WADL
56
56
  value = query_values[name] || query_values[name.to_sym]
57
57
  value = param.format(value, nil, 'query')
58
58
 
59
- uri.query << value if value
59
+ uri.query << value if value && !value.empty?
60
60
  end
61
61
  }
62
62
 
@@ -3,8 +3,8 @@ module WADL
3
3
  module Version
4
4
 
5
5
  MAJOR = 0
6
- MINOR = 1
7
- TINY = 8
6
+ MINOR = 2
7
+ TINY = 0
8
8
 
9
9
  class << self
10
10
 
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: 11
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 8
10
- version: 0.1.8
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-06-10 00:00:00 +02:00
19
+ date: 2010-08-11 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency