Fixed issue with discovery URIs and renamed --service-version to --api-version.

This commit is contained in:
Bob Aman 2011-10-06 12:35:02 +03:00
parent 88e123ddf7
commit 9387bfa593
1 changed files with 27 additions and 17 deletions

View File

@ -108,8 +108,8 @@ HTML
options[:api] = s options[:api] = s
end end
opts.on( opts.on(
"--service-version <id>", String, "--api-version <id>", String,
"Select service version") do |id| "Select api version") do |id|
options[:version] = id options[:version] = id
end end
opts.on( opts.on(
@ -165,7 +165,7 @@ HTML
"\nAvailable commands:\n" + "\nAvailable commands:\n" +
" oauth-1-login Log a user into an API with OAuth 1.0a\n" + " oauth-1-login Log a user into an API with OAuth 1.0a\n" +
" oauth-2-login Log a user into an API with OAuth 2.0 d10\n" + " oauth-2-login Log a user into an API with OAuth 2.0 d10\n" +
" list List the methods available for a service\n" + " list List the methods available for an API\n" +
" execute Execute a method on the API\n" + " execute Execute a method on the API\n" +
" irb Start an interactive client session" " irb Start an interactive client session"
) )
@ -238,17 +238,27 @@ HTML
end end
if options[:discovery_uri] if options[:discovery_uri]
client.discovery_uri = options[:discovery_uri] if options[:api] && options[:version]
client.register_discovery_uri(
options[:api], options[:version], options[:discovery_uri]
)
else
STDERR.puts(
'Cannot register a discovery URI without ' +
'specifying an API and version.'
)
exit(1)
end
end end
return client return client
end end
def api_version(api, version) def api_version(api_name, version)
v = version v = version
if !version if !version
if client.preferred_version(api) if client.preferred_version(api_name)
v = client.preferred_version(api).version v = client.preferred_version(api_name).version
else else
v = 'v1' v = 'v1'
end end
@ -399,8 +409,8 @@ HTML
end end
def list def list
api = options[:api] api_name = options[:api]
unless api unless api_name
STDERR.puts('No API name supplied.') STDERR.puts('No API name supplied.')
exit(1) exit(1)
end end
@ -408,9 +418,9 @@ HTML
if options[:discovery_uri] if options[:discovery_uri]
client.discovery_uri = options[:discovery_uri] client.discovery_uri = options[:discovery_uri]
end end
version = api_version(api, options[:version]) version = api_version(api_name, options[:version])
service = client.discovered_api(api, version) api = client.discovered_api(api_name, version)
rpcnames = service.to_h.keys rpcnames = api.to_h.keys
puts rpcnames.sort.join("\n") puts rpcnames.sort.join("\n")
exit(0) exit(0)
end end
@ -457,14 +467,14 @@ HTML
STDERR.puts('No rpcname supplied.') STDERR.puts('No rpcname supplied.')
exit(1) exit(1)
end end
api = options[:api] || self.rpcname[/^([^\.]+)\./, 1] api_name = options[:api] || self.rpcname[/^([^\.]+)\./, 1]
version = api_version(api, options[:version]) version = api_version(api_name, options[:version])
service = client.discovered_api(api, version) api = client.discovered_api(api_name, version)
method = service.to_h[self.rpcname] method = api.to_h[self.rpcname]
if !method if !method
STDERR.puts( STDERR.puts(
"Method #{self.rpcname} does not exist for " + "Method #{self.rpcname} does not exist for " +
"#{api}-#{version}." "#{api_name}-#{version}."
) )
exit(1) exit(1)
end end