add method ApiClient#relative_uri which constructs a full uri from a given relative path, respecting specified protocol, host, and port; and allowing expanded parameters passed through Addressable::Template

This commit is contained in:
Ethan 2011-12-28 21:04:16 -07:00
parent c50f92c50c
commit d59901bf1e
1 changed files with 6 additions and 13 deletions

View File

@ -175,15 +175,16 @@ module Google
# The user agent string used in the User-Agent header. # The user agent string used in the User-Agent header.
attr_accessor :user_agent attr_accessor :user_agent
def relative_uri(path, expand={})
Addressable::Template.new(baseURI+path).expand(expand)
end
## ##
# Returns the URI for the directory document. # Returns the URI for the directory document.
# #
# @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( relative_uri('/apis')
"https://{host}/discovery/v1/apis"
)
return template.expand({"host" => self.host})
end end
## ##
@ -209,15 +210,7 @@ module Google
api = api.to_s api = api.to_s
version = version || 'v1' version = version || 'v1'
return @discovery_uris["#{api}:#{version}"] ||= (begin return @discovery_uris["#{api}:#{version}"] ||= (begin
template = Addressable::Template.new( relative_uri("/apis/{api}/{version}/rest", 'api' => api, 'version' => version)
"https://{host}/discovery/v1/apis/" +
"{api}/{version}/rest"
)
template.expand({
"host" => self.host,
"api" => api,
"version" => version
})
end) end)
end end