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:
parent
b0846efa4a
commit
f63bf8199f
|
@ -132,6 +132,11 @@ HTML
|
||||||
"Sets the URI to perform a request against") do |u|
|
"Sets the URI to perform a request against") do |u|
|
||||||
options[:uri] = u
|
options[:uri] = u
|
||||||
end
|
end
|
||||||
|
opts.on(
|
||||||
|
"--discovery-uri <uri>", String,
|
||||||
|
"Sets the URI to perform discovery") do |u|
|
||||||
|
options[:discovery_uri] = u
|
||||||
|
end
|
||||||
opts.on(
|
opts.on(
|
||||||
"-m", "--method <method>", String,
|
"-m", "--method <method>", String,
|
||||||
"Sets the HTTP method to use for the request") do |m|
|
"Sets the HTTP method to use for the request") do |m|
|
||||||
|
@ -264,10 +269,17 @@ HTML
|
||||||
|
|
||||||
def list
|
def list
|
||||||
service_name = options[:service_name]
|
service_name = options[:service_name]
|
||||||
|
unless service_name
|
||||||
|
STDERR.puts('No service name supplied.')
|
||||||
|
exit(1)
|
||||||
|
end
|
||||||
client = Google::APIClient.new(
|
client = Google::APIClient.new(
|
||||||
:service => service_name,
|
:service => service_name,
|
||||||
:authorization => nil
|
:authorization => nil
|
||||||
)
|
)
|
||||||
|
if options[:discovery_uri]
|
||||||
|
client.discovery_uri = options[:discovery_uri]
|
||||||
|
end
|
||||||
service_version =
|
service_version =
|
||||||
options[:service_version] ||
|
options[:service_version] ||
|
||||||
client.latest_service_version(service_name).version
|
client.latest_service_version(service_name).version
|
||||||
|
@ -334,6 +346,9 @@ HTML
|
||||||
method ||= request_body == '' ? 'GET' : 'POST'
|
method ||= request_body == '' ? 'GET' : 'POST'
|
||||||
method.upcase!
|
method.upcase!
|
||||||
client = Google::APIClient.new(:authorization => authorization_type)
|
client = Google::APIClient.new(:authorization => authorization_type)
|
||||||
|
if options[:discovery_uri]
|
||||||
|
client.discovery_uri = options[:discovery_uri]
|
||||||
|
end
|
||||||
configure_authorization.call(client) if signed
|
configure_authorization.call(client) if signed
|
||||||
request = [method, uri.to_str, headers, [request_body]]
|
request = [method, uri.to_str, headers, [request_body]]
|
||||||
request = client.sign_request(request)
|
request = client.sign_request(request)
|
||||||
|
@ -353,6 +368,9 @@ HTML
|
||||||
:service => service_name,
|
:service => service_name,
|
||||||
:authorization => authorization_type
|
:authorization => authorization_type
|
||||||
)
|
)
|
||||||
|
if options[:discovery_uri]
|
||||||
|
client.discovery_uri = options[:discovery_uri]
|
||||||
|
end
|
||||||
configure_authorization.call(client) if signed
|
configure_authorization.call(client) if signed
|
||||||
service_version =
|
service_version =
|
||||||
options[:service_version] ||
|
options[:service_version] ||
|
||||||
|
|
|
@ -131,6 +131,15 @@ module Google
|
||||||
end)
|
end)
|
||||||
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.
|
# Returns the parsed discovery document.
|
||||||
#
|
#
|
||||||
|
|
|
@ -155,7 +155,11 @@ module Google
|
||||||
split_version = lambda do |version|
|
split_version = lambda do |version|
|
||||||
dotted_version = version[/^v?(\d+(.\d+)*)-?(.*?)?$/, 1]
|
dotted_version = version[/^v?(\d+(.\d+)*)-?(.*?)?$/, 1]
|
||||||
suffix = version[/^v?(\d+(.\d+)*)-?(.*?)?$/, 3]
|
suffix = version[/^v?(\d+(.\d+)*)-?(.*?)?$/, 3]
|
||||||
|
if dotted_version && suffix
|
||||||
[dotted_version.split('.').map { |v| v.to_i }, suffix]
|
[dotted_version.split('.').map { |v| v.to_i }, suffix]
|
||||||
|
else
|
||||||
|
[[-1], version]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
self_sortable, self_suffix = split_version.call(self.version)
|
self_sortable, self_suffix = split_version.call(self.version)
|
||||||
other_sortable, other_suffix = split_version.call(other.version)
|
other_sortable, other_suffix = split_version.call(other.version)
|
||||||
|
|
|
@ -156,6 +156,8 @@ describe Google::APIClient, 'configured for the prediction API' do
|
||||||
Google::APIClient::Service.new('two', 'v2', {})
|
Google::APIClient::Service.new('two', 'v2', {})
|
||||||
@client.discovered_services <<
|
@client.discovered_services <<
|
||||||
Google::APIClient::Service.new('two', 'v2beta1', {})
|
Google::APIClient::Service.new('two', 'v2beta1', {})
|
||||||
|
@client.discovered_services <<
|
||||||
|
Google::APIClient::Service.new('two', 'test2', {})
|
||||||
@client.latest_service_version('two').version.should == 'v2'
|
@client.latest_service_version('two').version.should == 'v2'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue