Regen all APIs from new JSON

This commit is contained in:
Guy Taylor
2019-04-04 18:16:26 +01:00
committed by Sebastian Thiel
parent 86a884c48b
commit 2ad9f3781d
1212 changed files with 440610 additions and 142417 deletions

View File

@@ -131,6 +131,98 @@ impl<'n> Engine<'n> {
}
}
fn _user_activity_search(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
-> Result<(), DoitError> {
let mut field_cursor = FieldCursor::default();
let mut object = json::value::Value::Object(Default::default());
for kvarg in opt.values_of("kv").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let last_errc = err.issues.len();
let (key, value) = parse_kv_arg(&*kvarg, err, false);
let mut temp_cursor = field_cursor.clone();
if let Err(field_err) = temp_cursor.set(&*key) {
err.issues.push(field_err);
}
if value.is_none() {
field_cursor = temp_cursor.clone();
if err.issues.len() > last_errc {
err.issues.remove(last_errc);
}
continue;
}
let type_info: Option<(&'static str, JsonTypeInfo)> =
match &temp_cursor.to_string()[..] {
"page-size" => Some(("pageSize", JsonTypeInfo { jtype: JsonType::Int, ctype: ComplexType::Pod })),
"date-range.start-date" => Some(("dateRange.startDate", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
"date-range.end-date" => Some(("dateRange.endDate", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
"activity-types" => Some(("activityTypes", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Vec })),
"page-token" => Some(("pageToken", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
"user.user-id" => Some(("user.userId", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
"user.type" => Some(("user.type", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
"view-id" => Some(("viewId", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
_ => {
let suggestion = FieldCursor::did_you_mean(key, &vec!["activity-types", "date-range", "end-date", "page-size", "page-token", "start-date", "type", "user", "user-id", "view-id"]);
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
None
}
};
if let Some((field_cursor_str, type_info)) = type_info {
FieldCursor::from(field_cursor_str).set_json_value(&mut object, value.unwrap(), type_info, err, &temp_cursor);
}
}
let mut request: api::SearchUserActivityRequest = json::value::from_value(object).unwrap();
let mut call = self.hub.user_activity().search(request);
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
_ => {
let mut found = false;
for param in &self.gp {
if key == *param {
found = true;
call = call.param(self.gpm.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset"));
break;
}
}
if !found {
err.issues.push(CLIError::UnknownParameter(key.to_string(),
{let mut v = Vec::new();
v.extend(self.gp.iter().map(|v|*v));
v } ));
}
}
}
}
let protocol = CallType::Standard;
if dry_run {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
Ok(mut f) => f,
Err(io_err) => return Err(DoitError::IoError(opt.value_of("out").unwrap_or("-").to_string(), io_err)),
};
match match protocol {
CallType::Standard => call.doit(),
_ => unreachable!()
} {
Err(api_err) => Err(DoitError::ApiError(api_err)),
Ok((mut response, output_schema)) => {
let mut value = json::value::to_value(&output_schema).expect("serde to work");
remove_json_null_values(&mut value);
json::to_writer_pretty(&mut ostream, &value).unwrap();
ostream.flush().unwrap();
Ok(())
}
}
}
}
fn _doit(&self, dry_run: bool) -> Result<Result<(), DoitError>, Option<InvalidOptionsError>> {
let mut err = InvalidOptionsError::new();
let mut call_result: Result<(), DoitError> = Ok(());
@@ -147,6 +239,17 @@ impl<'n> Engine<'n> {
}
}
},
("user-activity", Some(opt)) => {
match opt.subcommand() {
("search", Some(opt)) => {
call_result = self._user_activity_search(opt, dry_run, &mut err);
},
_ => {
err.issues.push(CLIError::MissingMethodError("user-activity".to_string()));
writeln!(io::stderr(), "{}\n", opt.usage()).ok();
}
}
},
_ => {
err.issues.push(CLIError::MissingCommandError);
writeln!(io::stderr(), "{}\n", self.opt.usage()).ok();
@@ -257,11 +360,36 @@ fn main() {
]),
]),
("user-activity", "methods: 'search'", vec![
("search",
Some(r##"Returns User Activity data."##),
"Details at http://byron.github.io/google-apis-rs/google_analyticsreporting4_cli/user-activity_search",
vec![
(Some(r##"kv"##),
Some(r##"r"##),
Some(r##"Set various fields of the request structure, matching the key=value form"##),
Some(true),
Some(true)),
(Some(r##"v"##),
Some(r##"p"##),
Some(r##"Set various optional parameters, matching the key=value form"##),
Some(false),
Some(true)),
(Some(r##"out"##),
Some(r##"o"##),
Some(r##"Specify the file into which to write the program's output"##),
Some(false),
Some(false)),
]),
]),
];
let mut app = App::new("analyticsreporting4")
.author("Sebastian Thiel <byronimo@gmail.com>")
.version("1.0.8+20181008")
.version("1.0.8+20190401")
.about("Accesses Analytics report data.")
.after_help("All documentation details can be found at http://byron.github.io/google-apis-rs/google_analyticsreporting4_cli")
.arg(Arg::with_name("url")