Class: WADL::CLI
Constant Summary
- OPTION_RE =
%r{\A--?(.+?)(?:=(.+))?\z}- RESOURCE_PATH_RE =
%r{[. /]}- QUERY_SEPARATOR_RE =
%r{[&;]}n- ARRAY_SUFFIX_RE =
%r{\[\]\z}- HASH_SUFFIX_RE =
%r{\[(.+)\]\z}
Instance Attribute Summary (collapse)
-
- (Object) query
readonly
Returns the value of attribute query.
-
- (Object) resource_path
readonly
Returns the value of attribute resource_path.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) api
- - (Object) auth_resource
- - (Object) reset(stdin = STDIN, stdout = STDOUT, stderr = STDERR)
- - (Object) resource
- - (Object) run(arguments)
Instance Attribute Details
- (Object) query (readonly)
Returns the value of attribute query
67 68 69 |
# File 'lib/wadl/cli.rb', line 67 def query @query end |
- (Object) resource_path (readonly)
Returns the value of attribute resource_path
67 68 69 |
# File 'lib/wadl/cli.rb', line 67 def resource_path @resource_path end |
Class Method Details
+ (Object) defaults
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/wadl/cli.rb', line 54 def defaults super.merge( :config => 'config.yaml', :method => 'GET', :user => ENV['USER'] || '', :request_token_url => '%s/oauth/request_token', :access_token_url => '%s/oauth/access_token', :authorize_url => '%s/oauth/authorize' ) end |
+ (Object) usage
50 51 52 |
# File 'lib/wadl/cli.rb', line 50 def usage(*) "#{super} <resource-path> [-- arguments]" end |
Instance Method Details
- (Object) api
94 95 96 |
# File 'lib/wadl/cli.rb', line 94 def api @api ||= WADL::Application.from_wadl(open([:wadl])) end |
- (Object) auth_resource
105 106 107 108 109 110 |
# File 'lib/wadl/cli.rb', line 105 def auth_resource @auth_resource ||= [:skip_auth] ? resource : [:oauth] ? oauth_resource : [:basic] ? basic_auth_resource : resource end |
- (Object) reset(stdin = STDIN, stdout = STDOUT, stderr = STDERR)
112 113 114 115 |
# File 'lib/wadl/cli.rb', line 112 def reset(stdin = STDIN, stdout = STDOUT, stderr = STDERR) super @api = @resource = @auth_resource = nil end |
- (Object) resource
98 99 100 101 102 103 |
# File 'lib/wadl/cli.rb', line 98 def resource @resource ||= begin path = [[:api_base], *resource_path].compact.join('/').split(RESOURCE_PATH_RE) path.inject(api) { |m, n| m.send(:find_resource_by_path, n) } or quit "Resource not found: #{path.join('/')}" end end |
- (Object) run(arguments)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/wadl/cli.rb', line 69 def run(arguments) if .delete(:dump_config) stdout.puts(YAML.dump()) exit end parse_arguments(arguments) quit if resource_path.empty? quit "WADL location is required! (Specify with '--wadl' or see '--help')" unless [:wadl] [:wadl] %= [:base_url] if [:base_url] if debug = [:debug] debug = 1 unless debug.is_a?(Integer) stderr.puts api.paths if debug >= 1 stderr.puts api if debug >= 2 end response = auth_resource.send([:method].downcase, :query => query) stderr.puts response.code.join(' ') stdout.puts response.representation unless response.code.first =~ /\A[45]/ end |