Added option to support manually specified discovery URI.

git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@101 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef
This commit is contained in:
Bob Aman 2010-10-22 22:21:26 +00:00
parent b0846efa4a
commit f63bf8199f
4 changed files with 34 additions and 1 deletions

View File

@ -132,6 +132,11 @@ HTML
"Sets the URI to perform a request against") do |u|
options[:uri] = u
end
opts.on(
"--discovery-uri <uri>", String,
"Sets the URI to perform discovery") do |u|
options[:discovery_uri] = u
end
opts.on(
"-m", "--method <method>", String,
"Sets the HTTP method to use for the request") do |m|
@ -264,10 +269,17 @@ HTML
def list
service_name = options[:service_name]
unless service_name
STDERR.puts('No service name supplied.')
exit(1)
end
client = Google::APIClient.new(
:service => service_name,
:authorization => nil
)
if options[:discovery_uri]
client.discovery_uri = options[:discovery_uri]
end
service_version =
options[:service_version] ||
client.latest_service_version(service_name).version
@ -334,6 +346,9 @@ HTML
method ||= request_body == '' ? 'GET' : 'POST'
method.upcase!
client = Google::APIClient.new(:authorization => authorization_type)
if options[:discovery_uri]
client.discovery_uri = options[:discovery_uri]
end
configure_authorization.call(client) if signed
request = [method, uri.to_str, headers, [request_body]]
request = client.sign_request(request)
@ -353,6 +368,9 @@ HTML
:service => service_name,
:authorization => authorization_type
)
if options[:discovery_uri]
client.discovery_uri = options[:discovery_uri]
end
configure_authorization.call(client) if signed
service_version =
options[:service_version] ||

View File

@ -131,6 +131,15 @@ module Google
end)
end
##
# Sets the discovery URI for the client.
#
# @param [Addressable::URI, #to_str, String] new_discovery_uri
# The new discovery URI.
def discovery_uri=(new_discovery_uri)
@options[:discovery_uri] = Addressable::URI.parse(new_discovery_uri)
end
##
# Returns the parsed discovery document.
#

View File

@ -155,7 +155,11 @@ module Google
split_version = lambda do |version|
dotted_version = version[/^v?(\d+(.\d+)*)-?(.*?)?$/, 1]
suffix = version[/^v?(\d+(.\d+)*)-?(.*?)?$/, 3]
[dotted_version.split('.').map { |v| v.to_i }, suffix]
if dotted_version && suffix
[dotted_version.split('.').map { |v| v.to_i }, suffix]
else
[[-1], version]
end
end
self_sortable, self_suffix = split_version.call(self.version)
other_sortable, other_suffix = split_version.call(other.version)

View File

@ -156,6 +156,8 @@ describe Google::APIClient, 'configured for the prediction API' do
Google::APIClient::Service.new('two', 'v2', {})
@client.discovered_services <<
Google::APIClient::Service.new('two', 'v2beta1', {})
@client.discovered_services <<
Google::APIClient::Service.new('two', 'test2', {})
@client.latest_service_version('two').version.should == 'v2'
end