diff --git a/src/mako/api/lib.rs.mako b/src/mako/api/lib.rs.mako index 72c60244b3..42e03436d3 100644 --- a/src/mako/api/lib.rs.mako +++ b/src/mako/api/lib.rs.mako @@ -1,6 +1,6 @@ <%namespace name="lib" file="lib/lib.mako"/>\ <%namespace name="util" file="../lib/util.mako"/>\ -<% +<% from util import (new_context, rust_comment, rust_module_doc_comment) c = new_context(schemas, resources, context.get('methods')) @@ -15,7 +15,7 @@ ${lib.docs(c)} // Unused attributes happen thanks to defined, but unused structures // We don't warn about this, as depending on the API, some data structures or facilities are never used. -// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any +// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any // unused imports in fully featured APIs. Same with unused_mut ... . #![allow(unused_imports, unused_mut, dead_code)] @@ -92,6 +92,8 @@ pub struct ${hub_type}${ht_params} { client: RefCell, auth: RefCell, _user_agent: String, + _base_url: String, + _root_url: String, } impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> Hub for ${hub_type}${ht_params} {} @@ -104,6 +106,8 @@ impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params} client: RefCell::new(client), auth: RefCell::new(authenticator), _user_agent: "${default_user_agent}".to_string(), + _base_url: "${baseUrl}".to_string(), + _root_url: "${rootUrl}".to_string(), } } @@ -122,6 +126,26 @@ impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params} self._user_agent = agent_name; prev } + + /// Set the base url to use in all requests to the server. + /// It defaults to `${baseUrl}`. + /// + /// Returns the previously set base url. + pub fn base_url(&mut self, new_base_url: String) -> String { + let prev = self._base_url.clone(); + self._base_url = new_base_url; + prev + } + + /// Set the root url to use in all requests to the server. + /// It defaults to `${rootUrl}`. + /// + /// Returns the previously set root url. + pub fn root_url(&mut self, new_root_url: String) -> String { + let prev = self._root_url.clone(); + self._root_url = new_root_url; + prev + } } @@ -157,4 +181,3 @@ ${mbuild.new(resource, method, c)} % endfor ## method in methods % endfor ## resource, methods - diff --git a/src/mako/api/lib/mbuild.mako b/src/mako/api/lib/mbuild.mako index 7b388c9bc5..d131fdf1bf 100644 --- a/src/mako/api/lib/mbuild.mako +++ b/src/mako/api/lib/mbuild.mako @@ -577,7 +577,7 @@ match result { else if \ % endif protocol == "${mp.protocol}" { - ("${join_url(rootUrl, mp.path)}".to_string(), "${upload_type_map.get(mp.protocol, mp.protocol)}") + (self.hub._root_url.clone() + "${mp.path}", "${upload_type_map.get(mp.protocol, mp.protocol)}") } \ % endfor else { @@ -585,7 +585,7 @@ else { }; params.push(("uploadType", upload_type.to_string())); % else: - let mut url = "${baseUrl}${m.path}".to_string(); + let mut url = self.hub._base_url.clone() + "${m.path}"; % endif % if not default_scope: % if no_auth is UNDEFINED: