Updated to use v1 of the discovery API.
git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@155 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef
This commit is contained in:
parent
7d370c6d10
commit
ef2abc0493
|
@ -401,7 +401,7 @@ HTML
|
||||||
def list
|
def list
|
||||||
api = options[:api]
|
api = options[:api]
|
||||||
unless api
|
unless api
|
||||||
STDERR.puts('No service name supplied.')
|
STDERR.puts('No API name supplied.')
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
client = Google::APIClient.new(:authorization => nil)
|
client = Google::APIClient.new(:authorization => nil)
|
||||||
|
|
|
@ -219,11 +219,9 @@ module Google
|
||||||
# @return [Addressable::URI] The URI of the directory document.
|
# @return [Addressable::URI] The URI of the directory document.
|
||||||
def directory_uri
|
def directory_uri
|
||||||
template = Addressable::Template.new(
|
template = Addressable::Template.new(
|
||||||
"https://{host}/discovery/v0.3/directory"
|
"https://{host}/discovery/v1/apis"
|
||||||
)
|
)
|
||||||
return template.expand({
|
return template.expand({"host" => self.host})
|
||||||
"host" => self.host
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -250,8 +248,8 @@ module Google
|
||||||
version = version || 'v1'
|
version = version || 'v1'
|
||||||
return @discovery_uris["#{api}:#{version}"] ||= (begin
|
return @discovery_uris["#{api}:#{version}"] ||= (begin
|
||||||
template = Addressable::Template.new(
|
template = Addressable::Template.new(
|
||||||
"https://{host}/discovery/v0.3/describe/" +
|
"https://{host}/discovery/v1/apis/" +
|
||||||
"{api}/{version}"
|
"{api}/{version}/rest"
|
||||||
)
|
)
|
||||||
template.expand({
|
template.expand({
|
||||||
"host" => self.host,
|
"host" => self.host,
|
||||||
|
|
|
@ -101,20 +101,20 @@ module Google
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Returns the base URI for this version of the service.
|
# Returns the base URI for the discovery document.
|
||||||
#
|
#
|
||||||
# @return [Addressable::URI] The base URI that methods are joined to.
|
# @return [Addressable::URI] The base URI.
|
||||||
attr_reader :document_base
|
attr_reader :document_base
|
||||||
|
|
||||||
##
|
##
|
||||||
# Returns the base URI for this version of the service.
|
# Returns the base URI for this version of the service.
|
||||||
#
|
#
|
||||||
# @return [Addressable::URI] The base URI that methods are joined to.
|
# @return [Addressable::URI] The base URI that methods are joined to.
|
||||||
def rest_base
|
def method_base
|
||||||
if @discovery_document['restBasePath']
|
if @discovery_document['basePath']
|
||||||
return @rest_base ||= (
|
return @method_base ||= (
|
||||||
self.document_base +
|
self.document_base +
|
||||||
Addressable::URI.parse(@discovery_document['restBasePath'])
|
Addressable::URI.parse(@discovery_document['basePath'])
|
||||||
).normalize
|
).normalize
|
||||||
else
|
else
|
||||||
return nil
|
return nil
|
||||||
|
@ -126,13 +126,13 @@ module Google
|
||||||
#
|
#
|
||||||
# @param [Addressable::URI, #to_str, String] new_base
|
# @param [Addressable::URI, #to_str, String] new_base
|
||||||
# The new base URI to use for the service.
|
# The new base URI to use for the service.
|
||||||
def rest_base=(new_rest_base)
|
def method_base=(new_method_base)
|
||||||
@rest_base = Addressable::URI.parse(new_rest_base)
|
@method_base = Addressable::URI.parse(new_method_base)
|
||||||
self.resources.each do |resource|
|
self.resources.each do |resource|
|
||||||
resource.rest_base = @rest_base
|
resource.method_base = @method_base
|
||||||
end
|
end
|
||||||
self.methods.each do |method|
|
self.methods.each do |method|
|
||||||
method.rest_base = @rest_base
|
method.method_base = @method_base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ module Google
|
||||||
def resources
|
def resources
|
||||||
return @resources ||= (
|
return @resources ||= (
|
||||||
(@discovery_document['resources'] || []).inject([]) do |accu, (k, v)|
|
(@discovery_document['resources'] || []).inject([]) do |accu, (k, v)|
|
||||||
accu << ::Google::APIClient::Resource.new(self.rest_base, k, v)
|
accu << ::Google::APIClient::Resource.new(self.method_base, k, v)
|
||||||
accu
|
accu
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
@ -158,7 +158,7 @@ module Google
|
||||||
def methods
|
def methods
|
||||||
return @methods ||= (
|
return @methods ||= (
|
||||||
(@discovery_document['methods'] || []).inject([]) do |accu, (k, v)|
|
(@discovery_document['methods'] || []).inject([]) do |accu, (k, v)|
|
||||||
accu << ::Google::APIClient::Method.new(self.rest_base, k, v)
|
accu << ::Google::APIClient::Method.new(self.method_base, k, v)
|
||||||
accu
|
accu
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
@ -176,7 +176,7 @@ module Google
|
||||||
return @hash ||= (begin
|
return @hash ||= (begin
|
||||||
methods_hash = {}
|
methods_hash = {}
|
||||||
self.methods.each do |method|
|
self.methods.each do |method|
|
||||||
methods_hash[method.rpc_method] = method
|
methods_hash[method.id] = method
|
||||||
end
|
end
|
||||||
self.resources.each do |resource|
|
self.resources.each do |resource|
|
||||||
methods_hash.merge!(resource.to_h)
|
methods_hash.merge!(resource.to_h)
|
||||||
|
@ -191,7 +191,7 @@ module Google
|
||||||
# @return [String] The service's state, as a <code>String</code>.
|
# @return [String] The service's state, as a <code>String</code>.
|
||||||
def inspect
|
def inspect
|
||||||
sprintf(
|
sprintf(
|
||||||
"#<%s:%#0x NAME:%s>", self.class.to_s, self.object_id, self.name
|
"#<%s:%#0x ID:%s>", self.class.to_s, self.object_id, self.id
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -211,8 +211,8 @@ module Google
|
||||||
# The section of the discovery document that applies to this resource.
|
# The section of the discovery document that applies to this resource.
|
||||||
#
|
#
|
||||||
# @return [Google::APIClient::Resource] The constructed resource object.
|
# @return [Google::APIClient::Resource] The constructed resource object.
|
||||||
def initialize(rest_base, resource_name, discovery_document)
|
def initialize(method_base, resource_name, discovery_document)
|
||||||
@rest_base = rest_base
|
@method_base = method_base
|
||||||
@name = resource_name
|
@name = resource_name
|
||||||
@discovery_document = discovery_document
|
@discovery_document = discovery_document
|
||||||
metaclass = (class <<self; self; end)
|
metaclass = (class <<self; self; end)
|
||||||
|
@ -247,20 +247,20 @@ module Google
|
||||||
# Returns the base URI for this resource.
|
# Returns the base URI for this resource.
|
||||||
#
|
#
|
||||||
# @return [Addressable::URI] The base URI that methods are joined to.
|
# @return [Addressable::URI] The base URI that methods are joined to.
|
||||||
attr_reader :rest_base
|
attr_reader :method_base
|
||||||
|
|
||||||
##
|
##
|
||||||
# Updates the hierarchy of resources and methods with the new base.
|
# Updates the hierarchy of resources and methods with the new base.
|
||||||
#
|
#
|
||||||
# @param [Addressable::URI, #to_str, String] new_base
|
# @param [Addressable::URI, #to_str, String] new_base
|
||||||
# The new base URI to use for the resource.
|
# The new base URI to use for the resource.
|
||||||
def rest_base=(new_rest_base)
|
def method_base=(new_method_base)
|
||||||
@rest_base = Addressable::URI.parse(new_rest_base)
|
@method_base = Addressable::URI.parse(new_method_base)
|
||||||
self.resources.each do |resource|
|
self.resources.each do |resource|
|
||||||
resource.rest_base = @rest_base
|
resource.method_base = @method_base
|
||||||
end
|
end
|
||||||
self.methods.each do |method|
|
self.methods.each do |method|
|
||||||
method.rest_base = @rest_base
|
method.method_base = @method_base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ module Google
|
||||||
def resources
|
def resources
|
||||||
return @resources ||= (
|
return @resources ||= (
|
||||||
(@discovery_document['resources'] || []).inject([]) do |accu, (k, v)|
|
(@discovery_document['resources'] || []).inject([]) do |accu, (k, v)|
|
||||||
accu << ::Google::APIClient::Resource.new(self.rest_base, k, v)
|
accu << ::Google::APIClient::Resource.new(self.method_base, k, v)
|
||||||
accu
|
accu
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
@ -284,7 +284,7 @@ module Google
|
||||||
def methods
|
def methods
|
||||||
return @methods ||= (
|
return @methods ||= (
|
||||||
(@discovery_document['methods'] || []).inject([]) do |accu, (k, v)|
|
(@discovery_document['methods'] || []).inject([]) do |accu, (k, v)|
|
||||||
accu << ::Google::APIClient::Method.new(self.rest_base, k, v)
|
accu << ::Google::APIClient::Method.new(self.method_base, k, v)
|
||||||
accu
|
accu
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
@ -299,7 +299,7 @@ module Google
|
||||||
return @hash ||= (begin
|
return @hash ||= (begin
|
||||||
methods_hash = {}
|
methods_hash = {}
|
||||||
self.methods.each do |method|
|
self.methods.each do |method|
|
||||||
methods_hash[method.rpc_method] = method
|
methods_hash[method.id] = method
|
||||||
end
|
end
|
||||||
self.resources.each do |resource|
|
self.resources.each do |resource|
|
||||||
methods_hash.merge!(resource.to_h)
|
methods_hash.merge!(resource.to_h)
|
||||||
|
@ -326,7 +326,7 @@ module Google
|
||||||
##
|
##
|
||||||
# Creates a description of a particular method.
|
# Creates a description of a particular method.
|
||||||
#
|
#
|
||||||
# @param [Addressable::URI] rest_base
|
# @param [Addressable::URI] method_base
|
||||||
# The base URI for the service.
|
# The base URI for the service.
|
||||||
# @param [String] method_name
|
# @param [String] method_name
|
||||||
# The identifier for the method.
|
# The identifier for the method.
|
||||||
|
@ -334,8 +334,8 @@ module Google
|
||||||
# The section of the discovery document that applies to this method.
|
# The section of the discovery document that applies to this method.
|
||||||
#
|
#
|
||||||
# @return [Google::APIClient::Method] The constructed method object.
|
# @return [Google::APIClient::Method] The constructed method object.
|
||||||
def initialize(rest_base, method_name, discovery_document)
|
def initialize(method_base, method_name, discovery_document)
|
||||||
@rest_base = rest_base
|
@method_base = method_base
|
||||||
@name = method_name
|
@name = method_name
|
||||||
@discovery_document = discovery_document
|
@discovery_document = discovery_document
|
||||||
end
|
end
|
||||||
|
@ -358,24 +358,24 @@ module Google
|
||||||
#
|
#
|
||||||
# @return [Addressable::URI]
|
# @return [Addressable::URI]
|
||||||
# The base URI that this method will be joined to.
|
# The base URI that this method will be joined to.
|
||||||
attr_reader :rest_base
|
attr_reader :method_base
|
||||||
|
|
||||||
##
|
##
|
||||||
# Updates the method with the new base.
|
# Updates the method with the new base.
|
||||||
#
|
#
|
||||||
# @param [Addressable::URI, #to_str, String] new_base
|
# @param [Addressable::URI, #to_str, String] new_base
|
||||||
# The new base URI to use for the method.
|
# The new base URI to use for the method.
|
||||||
def rest_base=(new_rest_base)
|
def method_base=(new_method_base)
|
||||||
@rest_base = Addressable::URI.parse(new_rest_base)
|
@method_base = Addressable::URI.parse(new_method_base)
|
||||||
@uri_template = nil
|
@uri_template = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Returns the RPC name for the method.
|
# Returns the method ID.
|
||||||
#
|
#
|
||||||
# @return [String] The RPC name.
|
# @return [String] The method identifier.
|
||||||
def rpc_method
|
def id
|
||||||
return @discovery_document['rpcMethod']
|
return @discovery_document['id']
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -389,7 +389,7 @@ module Google
|
||||||
# because of the way the discovery document provides the URIs.
|
# because of the way the discovery document provides the URIs.
|
||||||
# This should be fixed soon.
|
# This should be fixed soon.
|
||||||
return @uri_template ||= Addressable::Template.new(
|
return @uri_template ||= Addressable::Template.new(
|
||||||
self.rest_base + @discovery_document['restPath']
|
self.method_base + @discovery_document['path']
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -568,8 +568,8 @@ module Google
|
||||||
# @return [String] The method's state, as a <code>String</code>.
|
# @return [String] The method's state, as a <code>String</code>.
|
||||||
def inspect
|
def inspect
|
||||||
sprintf(
|
sprintf(
|
||||||
"#<%s:%#0x NAME:%s>",
|
"#<%s:%#0x ID:%s>",
|
||||||
self.class.to_s, self.object_id, self.rpc_method
|
self.class.to_s, self.object_id, self.id
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,7 +70,7 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should correctly determine the discovery URI' do
|
it 'should correctly determine the discovery URI' do
|
||||||
@client.discovery_uri('prediction').should ===
|
@client.discovery_uri('prediction').should ===
|
||||||
'https://www.googleapis.com/discovery/v0.3/describe/prediction/v1'
|
'https://www.googleapis.com/discovery/v1/apis/prediction/v1/rest'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly generate API objects' do
|
it 'should correctly generate API objects' do
|
||||||
|
@ -157,7 +157,7 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should allow modification to the base URIs for testing purposes' do
|
it 'should allow modification to the base URIs for testing purposes' do
|
||||||
prediction = @client.discovered_api('prediction', 'v1')
|
prediction = @client.discovered_api('prediction', 'v1')
|
||||||
prediction.rest_base =
|
prediction.method_base =
|
||||||
'https://testing-domain.googleapis.com/prediction/v1/'
|
'https://testing-domain.googleapis.com/prediction/v1/'
|
||||||
request = @client.generate_request(
|
request = @client.generate_request(
|
||||||
prediction.training.insert,
|
prediction.training.insert,
|
||||||
|
@ -227,7 +227,7 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should correctly determine the discovery URI' do
|
it 'should correctly determine the discovery URI' do
|
||||||
@client.discovery_uri('buzz').should ===
|
@client.discovery_uri('buzz').should ===
|
||||||
'https://www.googleapis.com/discovery/v0.3/describe/buzz/v1'
|
'https://www.googleapis.com/discovery/v1/apis/buzz/v1/rest'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should find APIs that are in the discovery document' do
|
it 'should find APIs that are in the discovery document' do
|
||||||
|
@ -318,7 +318,7 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should correctly determine the discovery URI' do
|
it 'should correctly determine the discovery URI' do
|
||||||
@client.discovery_uri('latitude').should ===
|
@client.discovery_uri('latitude').should ===
|
||||||
'https://www.googleapis.com/discovery/v0.3/describe/latitude/v1'
|
'https://www.googleapis.com/discovery/v1/apis/latitude/v1/rest'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should find APIs that are in the discovery document' do
|
it 'should find APIs that are in the discovery document' do
|
||||||
|
@ -383,7 +383,7 @@ describe Google::APIClient do
|
||||||
|
|
||||||
it 'should correctly determine the discovery URI' do
|
it 'should correctly determine the discovery URI' do
|
||||||
@client.discovery_uri('moderator').should ===
|
@client.discovery_uri('moderator').should ===
|
||||||
'https://www.googleapis.com/discovery/v0.3/describe/moderator/v1'
|
'https://www.googleapis.com/discovery/v1/apis/moderator/v1/rest'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should find APIs that are in the discovery document' do
|
it 'should find APIs that are in the discovery document' do
|
||||||
|
|
Loading…
Reference in New Issue