Skip to content

Commit

Permalink
Fixed issue with discovery URIs and renamed --service-version to --ap…
Browse files Browse the repository at this point in the history
…i-version.
  • Loading branch information
Bob Aman committed Oct 6, 2011
1 parent 88e123d commit 9387bfa
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions bin/google-api
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ HTML
options[:api] = s
end
opts.on(
"--service-version <id>", String,
"Select service version") do |id|
"--api-version <id>", String,
"Select api version") do |id|
options[:version] = id
end
opts.on(
Expand Down Expand Up @@ -165,7 +165,7 @@ HTML
"\nAvailable commands:\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" +
" 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" +
" irb Start an interactive client session"
)
Expand Down Expand Up @@ -238,17 +238,27 @@ HTML
end

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

return client
end

def api_version(api, version)
def api_version(api_name, version)
v = version
if !version
if client.preferred_version(api)
v = client.preferred_version(api).version
if client.preferred_version(api_name)
v = client.preferred_version(api_name).version
else
v = 'v1'
end
Expand Down Expand Up @@ -399,18 +409,18 @@ HTML
end

def list
api = options[:api]
unless api
api_name = options[:api]
unless api_name
STDERR.puts('No API name supplied.')
exit(1)
end
client = Google::APIClient.new(:authorization => nil)
if options[:discovery_uri]
client.discovery_uri = options[:discovery_uri]
end
version = api_version(api, options[:version])
service = client.discovered_api(api, version)
rpcnames = service.to_h.keys
version = api_version(api_name, options[:version])
api = client.discovered_api(api_name, version)
rpcnames = api.to_h.keys
puts rpcnames.sort.join("\n")
exit(0)
end
Expand Down Expand Up @@ -457,14 +467,14 @@ HTML
STDERR.puts('No rpcname supplied.')
exit(1)
end
api = options[:api] || self.rpcname[/^([^\.]+)\./, 1]
version = api_version(api, options[:version])
service = client.discovered_api(api, version)
method = service.to_h[self.rpcname]
api_name = options[:api] || self.rpcname[/^([^\.]+)\./, 1]
version = api_version(api_name, options[:version])
api = client.discovered_api(api_name, version)
method = api.to_h[self.rpcname]
if !method
STDERR.puts(
"Method #{self.rpcname} does not exist for " +
"#{api}-#{version}."
"#{api_name}-#{version}."
)
exit(1)
end
Expand Down

0 comments on commit 9387bfa

Please sign in to comment.