wadl 0.2.8 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09edcf1ce635ec8148e28aab9b7d912bd7858b25
4
- data.tar.gz: 04206b57c6fee54444eb16c0d0cee770b331fdfe
3
+ metadata.gz: 502bdfe2423d3d6020d35cfd788adcdb5711af80
4
+ data.tar.gz: 8e38d68bc3a3574ed72cc86c4146ad964135925d
5
5
  SHA512:
6
- metadata.gz: 8e3be1528667417365e6396db2d312533cbaaeadf1cae215b6d9859ded081b4aa19861ea6304dc8189a53fd34cc474d5f68d75d282be53395101b2afed5fd931
7
- data.tar.gz: 33f00a807e7199aadf88118ac7c2d21944d08eddadd26c7c8da5a7adb4bc64bbf8b5f5cc93e8b4919b323913407868fd063664d1c7cce5228921725b4e1c946e
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.2.8
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
- <b></b>
48
- Homepage:: http://www.crummy.com/software/wadl.rb
49
- WADL:: http://wadl.java.net
50
- Documentation:: http://blackwinter.github.com/wadl
51
- Source code:: http://github.com/blackwinter/wadl
52
- RubyGem:: http://rubygems.org/gems/wadl
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-2013 Jens Wille
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
- require File.expand_path(%q{../lib/wadl/version}, __FILE__)
1
+ require_relative 'lib/wadl/version'
2
2
 
3
3
  begin
4
4
  require 'hen'
5
5
 
6
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@gmail.com'],
13
- :license => %q{AGPL-3.0},
14
- :homepage => :blackwinter,
15
- :dependencies => %w[rest-open-uri mime-types] << ['ruby-nuggets', '>= 0.7.3']
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-2013 Jens Wille #
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
- require 'wadl/version'
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-2013 Jens Wille #
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
@@ -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-2013 Jens Wille #
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
 
@@ -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-2013 Jens Wille #
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-2013 Jens Wille #
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
- class CLI < ::Util::CLI
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
- :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'
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, :query => query)
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 ||= WADL::Application.from_wadl(open(options[:wadl]))
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('/').split(RESOURCE_PATH_RE)
101
- path.inject(api) { |m, n| m.send(:find_resource_by_path, n) } or quit "Resource not found: #{path.join('/')}"
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
- query.update(options[:query]) if options[:query]
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(query_string)
152
- params = {}
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(params, *pair.split('=', 2).map { |v| CGI.unescape(v) })
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 ||= ask("Password for user #{user}: ") { |q| q.echo = false }
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.on('-c', '--config YAML', "Config file [Default: #{defaults[:config]}#{' (currently not present)' unless File.readable?(defaults[:config])}]") { |config|
245
- options[:config] = config
246
- }
247
-
248
- opts.separator ''
243
+ opts.option(:wadl__FILE_OR_URL,
244
+ 'Path or URL to WADL file [Required]')
249
245
 
250
- opts.on('-w', '--wadl FILE_OR_URL', "Path or URL to WADL file [Required]") { |wadl|
251
- options[:wadl] = wadl
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.on('-a', '--api-base PATH', "Base path for API") { |api_base|
259
- options[:api_base] = api_base
260
- }
250
+ opts.option(:api_base__PATH, 'Base path for API')
261
251
 
262
- opts.on('-q', '--query QUERY', "Query string to pass to request") { |query|
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.on('--skip-auth', "Skip any authentication") {
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.on('-B', '--basic', "Perform Basic Auth") {
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.on('--user USER', "User name") { |user|
282
- options[:user] = user
283
- }
265
+ opts.option('user__USER', 'User name')
284
266
 
285
- opts.on('--password PASSWORD', "Password for user") { |password|
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.on('-O', '--oauth', "Perform OAuth") {
293
- options[:oauth] = true
294
- }
272
+ opts.switch(:oauth, :O, 'Perform OAuth')
295
273
 
296
- opts.separator ''
274
+ opts.separator
297
275
 
298
- opts.on('--consumer-key KEY', "Consumer key to use") { |consumer_key|
299
- options[:consumer_key] = consumer_key
300
- }
276
+ opts.option('consumer_key__KEY', 'Consumer key to use')
301
277
 
302
- opts.on('--consumer-secret SECRET', "Consumer secret to use") { |consumer_secret|
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.on('--token TOKEN', "Access token to use") { |token|
309
- options[:token] = token
310
- }
282
+ opts.option('token__TOKEN', 'Access token to use')
311
283
 
312
- opts.on('--secret SECRET', "Token secret to use") { |secret|
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.on('-b', '--base-url URL', "Base URL [Default: \"dirname\" of WADL]") { |base_url|
319
- options[:base_url] = base_url
320
- }
288
+ opts.option(:base_url__URL, 'Base URL [Default: "dirname" of WADL]')
321
289
 
322
- opts.on('--request-token-url URL', "Request token URL [Default: #{defaults[:request_token_url] % 'BASE_URL'}]") { |request_token_url|
323
- options[:request_token_url] = request_token_url
324
- }
290
+ opts.option('request_token_url__URL',
291
+ "Request token URL [Default: #{defaults[:request_token_url] % 'BASE_URL'}]")
325
292
 
326
- opts.on('--access-token-url URL', "Access token URL [Default: #{defaults[:access_token_url] % 'BASE_URL'}]") { |access_token_url|
327
- options[:access_token_url] = access_token_url
328
- }
293
+ opts.option('access_token_url__URL',
294
+ "Access token URL [Default: #{defaults[:access_token_url] % 'BASE_URL'}]")
329
295
 
330
- opts.on('--authorize-url URL', "Authorize URL [Default: #{defaults[:authorize_url] % 'BASE_URL'}]") { |authorize_url|
331
- options[:authorize_url] = authorize_url
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
- super
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.on('-D', '--dump-config', 'Dump config and exit') {
343
- options[:dump_config] = true
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