wadl 0.2.3 → 0.2.4

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.2.3
5
+ This documentation refers to wadl version 0.2.4
6
6
 
7
7
 
8
8
  == DESCRIPTION
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  :authors => ['Leonard Richardson', 'Jens Wille'],
12
12
  :email => ['leonardr@segfault.org', 'jens.wille@uni-koeln.de'],
13
13
  :homepage => :blackwinter,
14
- :dependencies => %w[rest-open-uri mime-types]
14
+ :dependencies => %w[rest-open-uri mime-types] << ['ruby-nuggets', '>= 0.7.3']
15
15
  }
16
16
  }}
17
17
  rescue LoadError => err
data/bin/wadl CHANGED
@@ -27,9 +27,4 @@
27
27
  #++
28
28
 
29
29
  require 'wadl/cli'
30
-
31
- begin
32
- WADL::CLI.execute(ARGV, STDIN, STDOUT, STDERR)
33
- rescue ArgumentError => err
34
- abort err
35
- end
30
+ WADL::CLI.execute
data/lib/wadl/cli.rb CHANGED
@@ -24,11 +24,9 @@
24
24
  ###############################################################################
25
25
  #++
26
26
 
27
- require 'optparse'
28
- require 'yaml'
29
27
  require 'cgi'
30
- require 'highline'
31
28
  require 'stringio'
29
+ require 'nuggets/util/cli'
32
30
  require 'wadl'
33
31
 
34
32
  begin
@@ -39,18 +37,7 @@ end
39
37
 
40
38
  module WADL
41
39
 
42
- class CLI
43
-
44
- USAGE = "Usage: #{$0} [-h|--help] [options] <resource-path> [-- arguments]"
45
-
46
- DEFAULTS = {
47
- :config => 'config.yaml',
48
- :method => 'GET',
49
- :user => ENV['USER'] || '',
50
- :request_token_url => '%s/oauth/request_token',
51
- :access_token_url => '%s/oauth/access_token',
52
- :authorize_url => '%s/oauth/authorize'
53
- }
40
+ class CLI < ::Util::CLI
54
41
 
55
42
  OPTION_RE = %r{\A--?(.+?)(?:=(.+))?\z}
56
43
  RESOURCE_PATH_RE = %r{[. /]}
@@ -58,35 +45,37 @@ module WADL
58
45
  ARRAY_SUFFIX_RE = %r{\[\]\z}
59
46
  HASH_SUFFIX_RE = %r{\[(.+)\]\z}
60
47
 
61
- def self.execute(*args)
62
- new.execute(*args)
63
- end
64
-
65
- attr_reader :options, :config, :defaults
66
- attr_reader :stdin, :stdout, :stderr
67
- attr_reader :resource_path, :opts
48
+ class << self
68
49
 
69
- def initialize(defaults = DEFAULTS)
70
- @defaults = defaults
50
+ def usage(*)
51
+ "#{super} <resource-path> [-- arguments]"
52
+ end
71
53
 
72
- reset
54
+ def defaults
55
+ super.merge(
56
+ :config => 'config.yaml',
57
+ :method => 'GET',
58
+ :user => ENV['USER'] || '',
59
+ :request_token_url => '%s/oauth/request_token',
60
+ :access_token_url => '%s/oauth/access_token',
61
+ :authorize_url => '%s/oauth/authorize'
62
+ )
63
+ end
73
64
 
74
- # prevent backtrace on ^C
75
- trap(:INT) { exit 130 }
76
65
  end
77
66
 
78
- def execute(arguments = [], *inouterr)
79
- reset(*inouterr)
80
-
81
- abort USAGE if arguments.empty?
82
- parse_options(arguments, defaults)
67
+ attr_reader :resource_path, :opts
83
68
 
84
- abort YAML.dump(options), 0, stdout if options.delete(:dump_config)
69
+ def run(arguments)
70
+ if options.delete(:dump_config)
71
+ stdout.puts(YAML.dump(options))
72
+ exit
73
+ end
85
74
 
86
75
  parse_arguments(arguments)
87
- abort USAGE if resource_path.empty?
76
+ quit if resource_path.empty?
88
77
 
89
- abort "WADL location is required! (Specify with '--wadl' or see '--help')" unless options[:wadl]
78
+ quit "WADL location is required! (Specify with '--wadl' or see '--help')" unless options[:wadl]
90
79
  options[:wadl] %= options[:base_url] if options[:base_url]
91
80
 
92
81
  if debug = options[:debug]
@@ -109,7 +98,7 @@ module WADL
109
98
  def resource
110
99
  @resource ||= begin
111
100
  path = [options[:api_base], *resource_path].compact.join('/').split(RESOURCE_PATH_RE)
112
- path.inject(api) { |m, n| m.send(:find_resource_by_path, n) } or abort "Resource not found: #{path.join('/')}"
101
+ path.inject(api) { |m, n| m.send(:find_resource_by_path, n) } or quit "Resource not found: #{path.join('/')}"
113
102
  end
114
103
  end
115
104
 
@@ -121,29 +110,15 @@ module WADL
121
110
  end
122
111
 
123
112
  def reset(stdin = STDIN, stdout = STDOUT, stderr = STDERR)
124
- @stdin, @stdout, @stderr = stdin, stdout, stderr
113
+ super
125
114
  @api = @resource = @auth_resource = nil
126
- @options, @config = {}, {}
127
115
  end
128
116
 
129
117
  private
130
118
 
131
- def ask(question, &block)
132
- HighLine.new(stdin, stdout).ask(question, &block)
133
- end
134
-
135
- def abort(msg = nil, status = 1, output = stderr)
136
- output.puts msg if msg
137
- exit status
138
- end
139
-
140
- def parse_options(arguments, defaults)
141
- option_parser(defaults).parse!(arguments)
142
-
143
- config_file = options[:config] || defaults[:config]
144
- @config = YAML.load_file(config_file) if File.readable?(config_file)
145
-
146
- [config, defaults].each { |hash| hash.each { |key, value| options[key] ||= value } }
119
+ def parse_options(arguments)
120
+ quit if arguments.empty?
121
+ super
147
122
  end
148
123
 
149
124
  def parse_arguments(arguments)
@@ -208,7 +183,7 @@ module WADL
208
183
  user, pass = options.values_at(:user, :password)
209
184
  pass ||= ask("Password for user #{user}: ") { |q| q.echo = false }
210
185
 
211
- abort 'USER and PASSWORD required' unless user && pass
186
+ quit 'USER and PASSWORD required' unless user && pass
212
187
 
213
188
  resource.with_basic_auth(user, pass)
214
189
  end
@@ -217,11 +192,11 @@ module WADL
217
192
  consumer_key, consumer_secret = options.values_at(:consumer_key, :consumer_secret)
218
193
  access_token, token_secret = options.values_at(:token, :secret)
219
194
 
220
- abort "CONSUMER KEY and SECRET required" unless consumer_key && consumer_secret
195
+ quit "CONSUMER KEY and SECRET required" unless consumer_key && consumer_secret
221
196
 
222
197
  unless access_token && token_secret
223
198
  access_token, token_secret = oauthorize(consumer_key, consumer_secret)
224
- abort 'Authorization failed!?' unless access_token && token_secret
199
+ quit 'Authorization failed!?' unless access_token && token_secret
225
200
  end
226
201
 
227
202
  resource.with_oauth(consumer_key, consumer_secret, access_token, token_secret)
@@ -263,127 +238,115 @@ module WADL
263
238
  [access_token, token_secret]
264
239
  end
265
240
 
266
- def option_parser(defaults)
267
- OptionParser.new { |opts|
268
- opts.banner = USAGE
269
-
270
- opts.separator ''
271
- opts.separator 'Options:'
272
-
273
- opts.on('-c', '--config YAML', "Config file [Default: #{defaults[:config]}#{' (currently not present)' unless File.readable?(defaults[:config])}]") { |config|
274
- options[:config] = config
275
- }
276
-
277
- opts.separator ''
278
-
279
- opts.on('-w', '--wadl FILE_OR_URL', "Path or URL to WADL file [Required]") { |wadl|
280
- options[:wadl] = wadl
281
- }
282
-
283
- opts.on('-m', '--method METHOD', "Request method [Default: #{defaults[:method]}]") { |method|
284
- options[:method] = method.upcase
285
- }
241
+ def opts(opts)
242
+ opts.on('-c', '--config YAML', "Config file [Default: #{defaults[:config]}#{' (currently not present)' unless File.readable?(defaults[:config])}]") { |config|
243
+ options[:config] = config
244
+ }
286
245
 
287
- opts.on('-a', '--api-base PATH', "Base path for API") { |api_base|
288
- options[:api_base] = api_base
289
- }
246
+ opts.separator ''
290
247
 
291
- opts.on('-q', '--query QUERY', "Query string to pass to request") { |query|
292
- options[:query] = parse_query(query)
293
- }
248
+ opts.on('-w', '--wadl FILE_OR_URL', "Path or URL to WADL file [Required]") { |wadl|
249
+ options[:wadl] = wadl
250
+ }
294
251
 
295
- opts.separator ''
252
+ opts.on('-m', '--method METHOD', "Request method [Default: #{defaults[:method]}]") { |method|
253
+ options[:method] = method.upcase
254
+ }
296
255
 
297
- opts.on('--skip-auth', "Skip any authentication") {
298
- options[:skip_auth] = true
299
- }
256
+ opts.on('-a', '--api-base PATH', "Base path for API") { |api_base|
257
+ options[:api_base] = api_base
258
+ }
300
259
 
301
- opts.separator ''
302
- opts.separator 'Basic Auth options:'
260
+ opts.on('-q', '--query QUERY', "Query string to pass to request") { |query|
261
+ options[:query] = parse_query(query)
262
+ }
303
263
 
304
- opts.on('-B', '--basic', "Perform Basic Auth") {
305
- options[:basic] = true
306
- }
264
+ opts.separator ''
307
265
 
308
- opts.separator ''
266
+ opts.on('--skip-auth', "Skip any authentication") {
267
+ options[:skip_auth] = true
268
+ }
309
269
 
310
- opts.on('--user USER', "User name") { |user|
311
- options[:user] = user
312
- }
270
+ opts.separator ''
271
+ opts.separator 'Basic Auth options:'
313
272
 
314
- opts.on('--password PASSWORD', "Password for user") { |password|
315
- options[:password] = password
316
- }
273
+ opts.on('-B', '--basic', "Perform Basic Auth") {
274
+ options[:basic] = true
275
+ }
317
276
 
318
- opts.separator ''
319
- opts.separator 'OAuth options:'
277
+ opts.separator ''
320
278
 
321
- opts.on('-O', '--oauth', "Perform OAuth") {
322
- options[:oauth] = true
323
- }
279
+ opts.on('--user USER', "User name") { |user|
280
+ options[:user] = user
281
+ }
324
282
 
325
- opts.separator ''
283
+ opts.on('--password PASSWORD', "Password for user") { |password|
284
+ options[:password] = password
285
+ }
326
286
 
327
- opts.on('--consumer-key KEY', "Consumer key to use") { |consumer_key|
328
- options[:consumer_key] = consumer_key
329
- }
287
+ opts.separator ''
288
+ opts.separator 'OAuth options:'
330
289
 
331
- opts.on('--consumer-secret SECRET', "Consumer secret to use") { |consumer_secret|
332
- options[:consumer_secret] = consumer_secret
333
- }
290
+ opts.on('-O', '--oauth', "Perform OAuth") {
291
+ options[:oauth] = true
292
+ }
334
293
 
335
- opts.separator ''
294
+ opts.separator ''
336
295
 
337
- opts.on('--token TOKEN', "Access token to use") { |token|
338
- options[:token] = token
339
- }
296
+ opts.on('--consumer-key KEY', "Consumer key to use") { |consumer_key|
297
+ options[:consumer_key] = consumer_key
298
+ }
340
299
 
341
- opts.on('--secret SECRET', "Token secret to use") { |secret|
342
- options[:secret] = secret
343
- }
300
+ opts.on('--consumer-secret SECRET', "Consumer secret to use") { |consumer_secret|
301
+ options[:consumer_secret] = consumer_secret
302
+ }
344
303
 
345
- opts.separator ''
304
+ opts.separator ''
346
305
 
347
- opts.on('-b', '--base-url URL', "Base URL [Default: \"dirname\" of WADL]") { |base_url|
348
- options[:base_url] = base_url
349
- }
306
+ opts.on('--token TOKEN', "Access token to use") { |token|
307
+ options[:token] = token
308
+ }
350
309
 
351
- opts.on('--request-token-url URL', "Request token URL [Default: #{defaults[:request_token_url] % 'BASE_URL'}]") { |request_token_url|
352
- options[:request_token_url] = request_token_url
353
- }
310
+ opts.on('--secret SECRET', "Token secret to use") { |secret|
311
+ options[:secret] = secret
312
+ }
354
313
 
355
- opts.on('--access-token-url URL', "Access token URL [Default: #{defaults[:access_token_url] % 'BASE_URL'}]") { |access_token_url|
356
- options[:access_token_url] = access_token_url
357
- }
314
+ opts.separator ''
358
315
 
359
- opts.on('--authorize-url URL', "Authorize URL [Default: #{defaults[:authorize_url] % 'BASE_URL'}]") { |authorize_url|
360
- options[:authorize_url] = authorize_url
361
- }
316
+ opts.on('-b', '--base-url URL', "Base URL [Default: \"dirname\" of WADL]") { |base_url|
317
+ options[:base_url] = base_url
318
+ }
362
319
 
363
- opts.separator ''
364
- opts.separator 'Generic options:'
320
+ opts.on('--request-token-url URL', "Request token URL [Default: #{defaults[:request_token_url] % 'BASE_URL'}]") { |request_token_url|
321
+ options[:request_token_url] = request_token_url
322
+ }
365
323
 
366
- opts.on('-h', '--help', 'Print this help message and exit') {
367
- abort opts.to_s
368
- }
324
+ opts.on('--access-token-url URL', "Access token URL [Default: #{defaults[:access_token_url] % 'BASE_URL'}]") { |access_token_url|
325
+ options[:access_token_url] = access_token_url
326
+ }
369
327
 
370
- opts.on('--version', 'Print program version and exit') {
371
- abort "#{File.basename($0)} v#{WADL::VERSION}"
372
- }
328
+ opts.on('--authorize-url URL', "Authorize URL [Default: #{defaults[:authorize_url] % 'BASE_URL'}]") { |authorize_url|
329
+ options[:authorize_url] = authorize_url
330
+ }
331
+ end
373
332
 
374
- opts.on('-d', '--debug [LEVEL]', Integer, "Enable debugging output") { |level|
375
- options[:debug] = level || true
376
- }
333
+ def generic_opts(opts)
334
+ super
377
335
 
378
- opts.on('-D', '--dump-config', "Dump config and exit") {
379
- options[:dump_config] = true
380
- }
336
+ opts.on('-d', '--debug [LEVEL]', Integer, 'Enable debugging output') { |level|
337
+ options[:debug] = level || true
338
+ }
381
339
 
382
- opts.separator ''
383
- opts.separator "PATH may be separated by any of #{RESOURCE_PATH_RE.source}."
340
+ opts.on('-D', '--dump-config', 'Dump config and exit') {
341
+ options[:dump_config] = true
384
342
  }
385
343
  end
386
344
 
345
+ def post_opts(opts)
346
+ opts.separator ''
347
+ opts.separator "PATH may be separated by any of #{RESOURCE_PATH_RE.source}."
348
+ end
349
+
387
350
  end
388
351
 
389
352
  end
data/lib/wadl/resource.rb CHANGED
@@ -138,19 +138,25 @@ module WADL
138
138
  def find_method_by_id(id)
139
139
  id = id.to_s
140
140
  each_http_method { |m| return m if m.dereference.id == id }
141
+ nil
141
142
  end
142
143
 
143
144
  def find_method_by_http_method(action)
144
145
  action = action.to_s.downcase
145
146
  each_http_method { |m| return m if m.dereference.name.downcase == action }
147
+ nil
146
148
  end
147
149
 
148
150
  # Methods for reading or writing this resource
149
- def self.define_http_methods(klass = self, methods = %w[get post put delete])
151
+ def self.define_http_methods(klass = self, methods = %w[head get post put delete])
150
152
  methods.each { |method|
151
153
  klass.class_eval <<-EOT, __FILE__, __LINE__ + 1
152
154
  def #{method}(*args, &block)
153
- find_method_by_http_method(:#{method}).call(self, *args, &block)
155
+ if method = find_method_by_http_method(:#{method})
156
+ method.call(self, *args, &block)
157
+ else
158
+ raise ArgumentError, 'Method not allowed ("#{method}")'
159
+ end
154
160
  end
155
161
  EOT
156
162
  }
data/lib/wadl/version.rb CHANGED
@@ -4,7 +4,7 @@ module WADL
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 2
7
- TINY = 3
7
+ TINY = 4
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: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
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: 2011-04-29 00:00:00 Z
19
+ date: 2011-07-14 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rest-open-uri
@@ -46,6 +46,22 @@ dependencies:
46
46
  version: "0"
47
47
  type: :runtime
48
48
  version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: ruby-nuggets
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 5
58
+ segments:
59
+ - 0
60
+ - 7
61
+ - 3
62
+ version: 0.7.3
63
+ type: :runtime
64
+ version_requirements: *id003
49
65
  description: Ruby client for the Web Application Description Language.
50
66
  email:
51
67
  - leonardr@segfault.org
@@ -109,10 +125,10 @@ post_install_message:
109
125
  rdoc_options:
110
126
  - --charset
111
127
  - UTF-8
112
- - --title
113
- - wadl Application documentation (v0.2.3)
114
128
  - --main
115
129
  - README
130
+ - --title
131
+ - wadl Application documentation (v0.2.4)
116
132
  - --line-numbers
117
133
  - --all
118
134
  require_paths:
@@ -138,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
154
  requirements: []
139
155
 
140
156
  rubyforge_project:
141
- rubygems_version: 1.7.2
157
+ rubygems_version: 1.8.5
142
158
  signing_key:
143
159
  specification_version: 3
144
160
  summary: Ruby client for the Web Application Description Language.