1111 c = new_context(schemas, resources, context.get(' methods' ))
1212 hub_type = hub_type(c.schemas, util.canonical_name())
1313 ht_params = hub_type_params_s()
14+
15+ default_user_agent = " google-api-rust-client/" + cargo.build_version
1416%> \
1517<%block filter =" rust_comment" > \
1618<%util:gen_info source =" ${self.uri}" /> \
@@ -73,6 +75,7 @@ ${lib.hub_usage_example(c)}\
7375pub struct ${ hub_type}${ ht_params} {
7476 client: RefCell<C >,
7577 auth: RefCell<A >,
78+ _user_agent: String,
7679
7780 _m: PhantomData<NC >
7881}
@@ -86,6 +89,7 @@ impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params}
8689 ${ hub_type} {
8790 client: RefCell::new(client),
8891 auth: RefCell::new(authenticator),
92+ _user_agent: "${ default_user_agent} ".to_string(),
8993 _m: PhantomData
9094 }
9195 }
@@ -95,6 +99,16 @@ impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params}
9599 ${ rb_type(resource)} { hub: &self }
96100 }
97101 % endfor
102+
103+ /// Set the user-agent header field to use in all requests to the server.
104+ /// It defaults to `${ default_user_agent} `.
105+ ///
106+ /// Returns the previously set user-agent.
107+ pub fn user_agent(&mut self, agent_name: String) -> String {
108+ let prev = self._user_agent.clone();
109+ self._user_agent = agent_name;
110+ prev
111+ }
98112}
99113
100114
0 commit comments