From d59901bf1edb4e4cb620ed4bcb0ea5134e25bf31 Mon Sep 17 00:00:00 2001 From: Ethan Date: Wed, 28 Dec 2011 21:04:16 -0700 Subject: [PATCH] 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 --- lib/google/api_client.rb | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/google/api_client.rb b/lib/google/api_client.rb index e75bb784d..fb5f53626 100644 --- a/lib/google/api_client.rb +++ b/lib/google/api_client.rb @@ -174,16 +174,17 @@ module Google # @return [String] # The user agent string used in the User-Agent header. attr_accessor :user_agent + + def relative_uri(path, expand={}) + Addressable::Template.new(baseURI+path).expand(expand) + end ## # Returns the URI for the directory document. # # @return [Addressable::URI] The URI of the directory document. def directory_uri - template = Addressable::Template.new( - "https://{host}/discovery/v1/apis" - ) - return template.expand({"host" => self.host}) + relative_uri('/apis') end ## @@ -209,15 +210,7 @@ module Google api = api.to_s version = version || 'v1' return @discovery_uris["#{api}:#{version}"] ||= (begin - template = Addressable::Template.new( - "https://{host}/discovery/v1/apis/" + - "{api}/{version}/rest" - ) - template.expand({ - "host" => self.host, - "api" => api, - "version" => version - }) + relative_uri("/apis/{api}/{version}/rest", 'api' => api, 'version' => version) end) end